PageSourceSearch

https://argenx.de/etc.clientlibs/argenx/clientlibs/clientlib-base.…-4b1c9a0268e3f6b9533f1026e0bb9c62-lc.min.js

js argenx.de collected 2026-10-05 06:09:03 UTC 671,959 bytes, 21,909 lines download raw bytes

1/*******************************************************************************
2 * Copyright 2019 Adobe
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************/
16
17/**
18 * Element.matches()
19 * https://developer.mozilla.org/enUS/docs/Web/API/Element/matches#Polyfill
20 */
21if (!Element.prototype.matches) {
22    Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
23}
24
25// eslint-disable-next-line valid-jsdoc
26/**
27 * Element.closest()
28 * https://developer.mozilla.org/enUS/docs/Web/API/Element/closest#Polyfill
29 */
30if (!Element.prototype.closest) {
31    Element.prototype.closest = function(s) {
32        "use strict";
33        var el = this;
34        if (!document.documentElement.contains(el)) {
35            return null;
36        }
37        do {
38            if (el.matches(s)) {
39                return el;
40            }
41            el = el.parentElement || el.parentNode;
42        } while (el !== null && el.nodeType === 1);
43        return null;
44    };
45}
46
47/*******************************************************************************
48 * Copyright 2019 Adobe
49 *
50 * Licensed under the Apache License, Version 2.0 (the "License");
51 * you may not use this file except in compliance with the License.
52 * You may obtain a copy of the License at
53 *
54 *     http://www.apache.org/licenses/LICENSE-2.0
55 *
56 * Unless required by applicable law or agreed to in writing, software
57 * distributed under the License is distributed on an "AS IS" BASIS,
58 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59 * See the License for the specific language governing permissions and
60 * limitations under the License.
61 ******************************************************************************/
62(function() {
63    "use strict";
64
65    var containerUtils = window.CQ && window.CQ.CoreComponents && window.CQ.CoreComponents.container && window.CQ.CoreComponents.container.utils ? window.CQ.CoreComponents.container.utils : undefined;
66    if (!containerUtils) {
67        // eslint-disable-next-line no-console
68        console.warn("Accordion: container utilities at window.CQ.CoreComponents.container.utils are not available. This can lead to missing features. Ensure the core.wcm.components.commons.site.container client library is included on the page.");
69    }
70    var dataLayerEnabled;
71    var dataLayer;
72    var dataLayerName;
73    var delay = 100;
74
75    var NS = "cmp";
76    var IS = "accordion";
77
78    var keyCodes = {
79        ENTER: 13,
80        SPACE: 32,
81        END: 35,
82        HOME: 36,
83        ARROW_LEFT: 37,
84        ARROW_UP: 38,
85        ARROW_RIGHT: 39,
86        ARROW_DOWN: 40
87    };
88
89    var selectors = {
90        self: "[data-" + NS + '-is="' + IS + '"]'
91    };
92
93    var cssClasses = {
94        button: {
95            disabled: "cmp-accordion__button--disabled",
96            expanded: "cmp-accordion__button--expanded"
97        },
98        panel: {
99            hidden: "cmp-accordion__panel--hidden",
100            expanded: "cmp-accordion__panel--expanded"
101        }
102    };
103
104    var dataAttributes = {
105        item: {
106            expanded: "data-cmp-expanded"
107        }
108    };
109
110    var properties = {
111        /**
112         * Determines whether a single accordion item is forced to be expanded at a time.
113         * Expanding one item will collapse all others.
114         *
115         * @memberof Accordion
116         * @type {Boolean}
117         * @default false
118         */
119        "singleExpansion": {
120            "default": false,
121            "transform": function(value) {
122                return !(value === null || typeof value === "undefined");
123            }
124        }
125    };
126
127    /**
128     * Accordion Configuration.
129     *
130     * @typedef {Object} AccordionConfig Represents an Accordion configuration
131     * @property {HTMLElement} element The HTMLElement representing the Accordion
132     * @property {Object} options The Accordion options
133     */
134
135    /**
136     * Accordion.
137     *
138     * @class Accordion
139     * @classdesc An interactive Accordion component for toggling panels of related content
140     * @param {AccordionConfig} config The Accordion configuration
141     */
142    function Accordion(config) {
143        var that = this;
144
145        if (config && config.element) {
146            init(config);
147        }
148
149        /**
150         * Initializes the Accordion.
151         *
152         * @private
153         * @param {AccordionConfig} config The Accordion configuration
154         */
155        function init(config) {
156            that._config = config;
157
158            // prevents multiple initialization
159            config.element.removeAttribute("data-" + NS + "-is");
160
161            setupProperties(config.options);
162            cacheElements(config.element);
163
164            if (that._elements["item"]) {
165                // ensures multiple element types are arrays.
166                that._elements["item"] = Array.isArray(that._elements["item"]) ? that._elements["item"] : [that._elements["item"]];
167                that._elements["button"] = Array.isArray(that._elements["button"]) ? that._elements["button"] : [that._elements["button"]];
168                that._elements["panel"] = Array.isArray(that._elements["panel"]) ? that._elements["panel"] : [that._elements["panel"]];
169
170                if (that._properties.singleExpansion) {
171                    var expandedItems = getExpandedItems();
172                    // multiple expanded items annotated, display the last item open.
173                    if (expandedItems.length > 1) {
174                        toggle(expandedItems.length - 1);
175                    }
176                }
177
178                refreshItems();
179                bindEvents();
180                scrollToDeepLinkIdInAccordion();
181            }
182            if (window.Granite && window.Granite.author && window.Granite.author.MessageChannel) {
183                /*
184                 * Editor message handling:
185                 * - subscribe to "cmp.panelcontainer" message requests sent by the editor frame
186                 * - check that the message data panel container type is correct and that the id (path) matches this specific Accordion component
187                 * - if so, route the "navigate" operation to enact a navigation of the Accordion based on index data
188                 */
189                window.CQ.CoreComponents.MESSAGE_CHANNEL = window.CQ.CoreComponents.MESSAGE_CHANNEL || new window.Granite.author.MessageChannel("cqauthor", window);
190                window.CQ.CoreComponents.MESSAGE_CHANNEL.subscribeRequestMessage("cmp.panelcontainer", function(message) {
191                    if (message.data && message.data.type === "cmp-accordion" && message.data.id === that._elements.self.dataset["cmpPanelcontainerId"]) {
192                        if (message.data.operation === "navigate") {
193                            // switch to single expansion mode when navigating in edit mode.
194                            var singleExpansion = that._properties.singleExpansion;
195                            that._properties.singleExpansion = true;
196                            toggle(message.data.index);
197
198                            // revert to the configured state.
199                            that._properties.singleExpansion = singleExpansion;
200                        }
201                    }
202                });
203            }
204        }
205
206        /**
207         * Displays the panel containing the element that corresponds to the deep link in the URI fragment
208         * and scrolls the browser to this element.
209         */
210        function scrollToDeepLinkIdInAccordion() {
211            if (containerUtils) {
212                var deepLinkItemIdx = containerUtils.getDeepLinkItemIdx(that, "item", "item");
213                if (deepLinkItemIdx > -1) {
214                    var deepLinkItem = that._elements["item"][deepLinkItemIdx];
215                    if (deepLinkItem && !deepLinkItem.hasAttribute(dataAttributes.item.expanded)) {
216                        // if single expansion: close all accordion items
217                        if (that._properties.singleExpansion) {
218                            for (var j = 0; j < that._elements["item"].length; j++) {
219                                if (that._elements["item"][j].hasAttribute(dataAttributes.item.expanded)) {
220                                    setItemExpanded(that._elements["item"][j], false, true);
221                                }
222                            }
223                        }
224                        // expand the accordion item containing the deep link
225                        setItemExpanded(deepLinkItem, true, true);
226                    }
227                    var hashId = window.location.hash.substring(1);
228                    if (hashId) {
229                        var hashItem = document.querySelector("[id='" + hashId + "']");
230                        if (hashItem) {
231                            hashItem.scrollIntoView();
232                        }
233                    }
234                }
235            }
236        }
237
238        /**
239         * Caches the Accordion elements as defined via the {@code data-accordion-hook="ELEMENT_NAME"} markup API.
240         *
241         * @private
242         * @param {HTMLElement} wrapper The Accordion wrapper element
243         */
244        function cacheElements(wrapper) {
245            that._elements = {};
246            that._elements.self = wrapper;
247            var hooks = that._elements.self.querySelectorAll("[data-" + NS + "-hook-" + IS + "]");
248
249            for (var i = 0; i < hooks.length; i++) {
250                var hook = hooks[i];
251                if (hook.closest("." + NS + "-" + IS) === that._elements.self) { // only process own accordion elements
252                    var capitalized = IS;
253                    capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
254                    var key = hook.dataset[NS + "Hook" + capitalized];
255                    if (that._elements[key]) {
256                        if (!Array.isArray(that._elements[key])) {
257                            var tmp = that._elements[key];
258                            that._elements[key] = [tmp];
259                        }
260                        that._elements[key].push(hook);
261                    } else {
262                        that._elements[key] = hook;
263                    }
264                }
265            }
266        }
267
268        /**
269         * Sets up properties for the Accordion based on the passed options.
270         *
271         * @private
272         * @param {Object} options The Accordion options
273         */
274        function setupProperties(options) {
275            that._properties = {};
276
277            for (var key in properties) {
278                if (Object.prototype.hasOwnProperty.call(properties, key)) {
279                    var property = properties[key];
280                    var value = null;
281
282                    if (options && options[key] != null) {
283                        value = options[key];
284
285                        // transform the provided option
286                        if (property && typeof property.transform === "function") {
287                            value = property.transform(value);
288                        }
289                    }
290
291                    if (value === null) {
292                        // value still null, take the property default
293                        value = properties[key]["default"];
294                    }
295
296                    that._properties[key] = value;
297                }
298            }
299        }
300
301        /**
302         * Binds Accordion event handling.
303         *
304         * @private
305         */
306        function bindEvents() {
307            window.addEventListener("hashchange", scrollToDeepLinkIdInAccordion, false);
308            var buttons = that._elements["button"];
309            if (buttons) {
310                for (var i = 0; i < buttons.length; i++) {
311                    (function(index) {
312                        buttons[i].addEventListener("click", function(event) {
313                            toggle(index);
314                            focusButton(index);
315                        });
316                        buttons[i].addEventListener("keydown", function(event) {
317                            onButtonKeyDown(event, index);
318                        });
319                    })(i);
320                }
321            }
322        }
323
324        /**
325         * Handles button keydown events.
326         *
327         * @private
328         * @param {Object} event The keydown event
329         * @param {Number} index The index of the button triggering the event
330         */
331        function onButtonKeyDown(event, index) {
332            var lastIndex = that._elements["button"].length - 1;
333
334            switch (event.keyCode) {
335                case keyCodes.ARROW_LEFT:
336                case keyCodes.ARROW_UP:
337                    event.preventDefault();
338                    if (index > 0) {
339                        focusButton(index - 1);
340                    }
341                    break;
342                case keyCodes.ARROW_RIGHT:
343                case keyCodes.ARROW_DOWN:
344                    event.preventDefault();
345                    if (index < lastIndex) {
346                        focusButton(index + 1);
347                    }
348                    break;
349                case keyCodes.HOME:
350                    event.preventDefault();
351                    focusButton(0);
352                    break;
353                case keyCodes.END:
354                    event.preventDefault();
355                    focusButton(lastIndex);
356                    break;
357                case keyCodes.ENTER:
358                case keyCodes.SPACE:
359                    event.preventDefault();
360                    toggle(index);
361                    focusButton(index);
362                    break;
363                default:
364                    return;
365            }
366        }
367
368        /**
369         * General handler for toggle of an item.
370         *
371         * @private
372         * @param {Number} index The index of the item to toggle
373         */
374        function toggle(index) {
375            var item = that._elements["item"][index];
376            if (item) {
377                if (that._properties.singleExpansion) {
378                    // ensure only a single item is expanded if single expansion is enabled.
379                    for (var i = 0; i < that._elements["item"].length; i++) {
380                        if (that._elements["item"][i] !== item) {
381                            var expanded = getItemExpanded(that._elements["item"][i]);
382                            if (expanded) {
383                                setItemExpanded(that._elements["item"][i], false);
384                            }
385                        }
386                    }
387                }
388                setItemExpanded(item, !getItemExpanded(item));
389
390                if (dataLayerEnabled) {
391                    var accordionId = that._elements.self.id;
392                    var expandedItems = getExpandedItems()
393                        .map(function(item) {
394                            return getDataLayerId(item);
395                        });
396
397                    var uploadPayload = { component: {} };
398                    uploadPayload.component[accordionId] = { shownItems: expandedItems };
399
400                    var removePayload = { component: {} };
401                    removePayload.component[accordionId] = { shownItems: undefined };
402
403                    dataLayer.push(removePayload);
404                    dataLayer.push(uploadPayload);
405                }
406            }
407        }
408
409        /**
410         * Sets an item's expanded state based on the provided flag and refreshes its internals.
411         *
412         * @private
413         * @param {HTMLElement} item The item to mark as expanded, or not expanded
414         * @param {Boolean} expanded true to mark the item expanded, false otherwise
415         * @param {Boolean} keepHash true to keep the hash in the URL, false to update it
416         */
417        function setItemExpanded(item, expanded, keepHash) {
418            if (expanded) {
419                item.setAttribute(dataAttributes.item.expanded, "");
420                var index = that._elements["item"].indexOf(item);
421                if (!keepHash && containerUtils) {
422                    containerUtils.updateUrlHash(that, "item", index);
423                }
424                if (dataLayerEnabled) {
425                    dataLayer.push({
426                        event: "cmp:show",
427                        eventInfo: {
428                            path: "component." + getDataLayerId(item)
429                        }
430                    });
431                }
432
433            } else {
434                item.removeAttribute(dataAttributes.item.expanded);
435                if (!keepHash && containerUtils) {
436                    containerUtils.removeUrlHash();
437                }
438                if (dataLayerEnabled) {
439                    dataLayer.push({
440                        event: "cmp:hide",
441                        eventInfo: {
442                            path: "component." + getDataLayerId(item)
443                        }
444                    });
445                }
446            }
447            refreshItem(item);
448        }
449
450        /**
451         * Gets an item's expanded state.
452         *
453         * @private
454         * @param {HTMLElement} item The item for checking its expanded state
455         * @returns {Boolean} true if the item is expanded, false otherwise
456         */
457        function getItemExpanded(item) {
458            return item && item.dataset && item.dataset["cmpExpanded"] !== undefined;
459        }
460
461        /**
462         * Refreshes an item based on its expanded state.
463         *
464         * @private
465         * @param {HTMLElement} item The item to refresh
466         */
467        function refreshItem(item) {
468            var expanded = getItemExpanded(item);
469            if (expanded) {
470                expandItem(item);
471            } else {
472                collapseItem(item);
473            }
474        }
475
476        /**
477         * Refreshes all items based on their expanded state.
478         *
479         * @private
480         */
481        function refreshItems() {
482            for (var i = 0; i < that._elements["item"].length; i++) {
483                refreshItem(that._elements["item"][i]);
484            }
485        }
486
487        /**
488         * Returns all expanded items.
489         *
490         * @private
491         * @returns {HTMLElement[]} The expanded items
492         */
493        function getExpandedItems() {
494            var expandedItems = [];
495
496            for (var i = 0; i < that._elements["item"].length; i++) {
497                var item = that._elements["item"][i];
498                var expanded = getItemExpanded(item);
499                if (expanded) {
500                    expandedItems.push(item);
501                }
502            }
503
504            return expandedItems;
505        }
506
507        /**
508         * Annotates the item and its internals with
509         * the necessary style and accessibility attributes to indicate it is expanded.
510         *
511         * @private
512         * @param {HTMLElement} item The item to annotate as expanded
513         */
514        function expandItem(item) {
515            var index = that._elements["item"].indexOf(item);
516            if (index > -1) {
517                var button = that._elements["button"][index];
518                var panel = that._elements["panel"][index];
519                button.classList.add(cssClasses.button.expanded);
520                // used to fix some known screen readers issues in reading the correct state of the 'aria-expanded' attribute
521                // e.g. https://bugs.webkit.org/show_bug.cgi?id=210934
522                setTimeout(function() {
523                    button.setAttribute("aria-expanded", true);
524                }, delay);
525                panel.classList.add(cssClasses.panel.expanded);
526                panel.classList.remove(cssClasses.panel.hidden);
527                panel.setAttribute("aria-hidden", false);
528            }
529        }
530
531        /**
532         * Annotates the item and its internals with
533         * the necessary style and accessibility attributes to indicate it is not expanded.
534         *
535         * @private
536         * @param {HTMLElement} item The item to annotate as not expanded
537         */
538        function collapseItem(item) {
539            var index = that._elements["item"].indexOf(item);
540            if (index > -1) {
541                var button = that._elements["button"][index];
542                var panel = that._elements["panel"][index];
543                button.classList.remove(cssClasses.button.expanded);
544                // used to fix some known screen readers issues in reading the correct state of the 'aria-expanded' attribute
545                // e.g. https://bugs.webkit.org/show_bug.cgi?id=210934
546                setTimeout(function() {
547                    button.setAttribute("aria-expanded", false);
548                }, delay);
549                panel.classList.add(cssClasses.panel.hidden);
550                panel.classList.remove(cssClasses.panel.expanded);
551                panel.setAttribute("aria-hidden", true);
552            }
553        }
554
555        /**
556         * Focuses the button at the provided index.
557         *
558         * @private
559         * @param {Number} index The index of the button to focus
560         */
561        function focusButton(index) {
562            var button = that._elements["button"][index];
563            button.focus();
564        }
565    }
566
567    /**
568     * Reads options data from the Accordion wrapper element, defined via {@code data-cmp-*} data attributes.
569     *
570     * @private
571     * @param {HTMLElement} element The Accordion element to read options data from
572     * @returns {Object} The options read from the component data attributes
573     */
574    function readData(element) {
575        var data = element.dataset;
576        var options = [];
577        var capitalized = IS;
578        capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
579        var reserved = ["is", "hook" + capitalized];
580
581        for (var key in data) {
582            if (Object.prototype.hasOwnProperty.call(data, key)) {
583                var value = data[key];
584
585                if (key.indexOf(NS) === 0) {
586                    key = key.slice(NS.length);
587                    key = key.charAt(0).toLowerCase() + key.substring(1);
588
589                    if (reserved.indexOf(key) === -1) {
590                        options[key] = value;
591                    }
592                }
593            }
594        }
595
596        return options;
597    }
598
599    /**
600     * Parses the dataLayer string and returns the ID
601     *
602     * @private
603     * @param {HTMLElement} item the accordion item
604     * @returns {String} dataLayerId or undefined
605     */
606    function getDataLayerId(item) {
607        if (item) {
608            if (item.dataset.cmpDataLayer) {
609                return Object.keys(JSON.parse(item.dataset.cmpDataLayer))[0];
610            } else {
611                return item.id;
612            }
613        }
614        return null;
615    }
616
617    /**
618     * Document ready handler and DOM mutation observers. Initializes Accordion components as necessary.
619     *
620     * @private
621     */
622    function onDocumentReady() {
623        dataLayerEnabled = document.body.hasAttribute("data-cmp-data-layer-enabled");
624        if (dataLayerEnabled) {
625            dataLayerName = document.body.getAttribute("data-cmp-data-layer-name") || "adobeDataLayer";
626            dataLayer = window[dataLayerName] = window[dataLayerName] || [];
627        }
628
629        var elements = document.querySelectorAll(selectors.self);
630        for (var i = 0; i < elements.length; i++) {
631            new Accordion({ element: elements[i], options: readData(elements[i]) });
632        }
633
634        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
635        var body = document.querySelector("body");
636        var observer = new MutationObserver(function(mutations) {
637            mutations.forEach(function(mutation) {
638                // needed for IE
639                var nodesArray = [].slice.call(mutation.addedNodes);
640                if (nodesArray.length > 0) {
641                    nodesArray.forEach(function(addedNode) {
642                        if (addedNode.querySelectorAll) {
643                            var elementsArray = [].slice.call(addedNode.querySelectorAll(selectors.self));
644                            elementsArray.forEach(function(element) {
645                                new Accordion({ element: element, options: readData(element) });
646                            });
647                        }
648                    });
649                }
650            });
651        });
652
653        observer.observe(body, {
654            subtree: true,
655            childList: true,
656            characterData: true
657        });
658    }
659
660    if (document.readyState !== "loading") {
661        onDocumentReady();
662    } else {
663        document.addEventListener("DOMContentLoaded", onDocumentReady);
664    }
665
666    if (containerUtils) {
667        window.addEventListener("load", containerUtils.scrollToAnchor, false);
668    }
669
670}());
671
672
673/*******************************************************************************
674 * Copyright 2018 Adobe
675 *
676 * Licensed under the Apache License, Version 2.0 (the "License");
677 * you may not use this file except in compliance with the License.
678 * You may obtain a copy of the License at
679 *
680 *     http://www.apache.org/licenses/LICENSE2.0
681 *
682 * Unless required by applicable law or agreed to in writing, software
683 * distributed under the License is distributed on an "AS IS" BASIS,
684 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
685 * See the License for the specific language governing permissions and
686 * limitations under the License.
687 ******************************************************************************/
688
689/**
690 * Element.matches()
691 * https://developer.mozilla.org/enUS/docs/Web/API/Element/matches#Polyfill
692 */
693if (!Element.prototype.matches) {
694    Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
695}
696
697// eslint-disable-next-line valid-jsdoc
698/**
699 * Element.closest()
700 * https://developer.mozilla.org/enUS/docs/Web/API/Element/closest#Polyfill
701 */
702if (!Element.prototype.closest) {
703    Element.prototype.closest = function(s) {
704        "use strict";
705        var el = this;
706        if (!document.documentElement.contains(el)) {
707            return null;
708        }
709        do {
710            if (el.matches(s)) {
711                return el;
712            }
713            el = el.parentElement || el.parentNode;
714        } while (el !== null && el.nodeType === 1);
715        return null;
716    };
717}
718
719/*******************************************************************************
720 * Copyright 2018 Adobe
721 *
722 * Licensed under the Apache License, Version 2.0 (the "License");
723 * you may not use this file except in compliance with the License.
724 * You may obtain a copy of the License at
725 *
726 *     http://www.apache.org/licenses/LICENSE-2.0
727 *
728 * Unless required by applicable law or agreed to in writing, software
729 * distributed under the License is distributed on an "AS IS" BASIS,
730 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
731 * See the License for the specific language governing permissions and
732 * limitations under the License.
733 ******************************************************************************/
734/* global
735    CQ
736 */
737(function() {
738    "use strict";
739
740    var containerUtils = window.CQ && window.CQ.CoreComponents && window.CQ.CoreComponents.container && window.CQ.CoreComponents.container.utils ? window.CQ.CoreComponents.container.utils : undefined;
741    if (!containerUtils) {
742        // eslint-disable-next-line no-console
743        console.warn("Tabs: container utilities at window.CQ.CoreComponents.container.utils are not available. This can lead to missing features. Ensure the core.wcm.components.commons.site.container client library is included on the page.");
744    }
745    var dataLayerEnabled;
746    var dataLayer;
747    var dataLayerName;
748
749    var NS = "cmp";
750    var IS = "tabs";
751
752    var keyCodes = {
753        END: 35,
754        HOME: 36,
755        ARROW_LEFT: 37,
756        ARROW_UP: 38,
757        ARROW_RIGHT: 39,
758        ARROW_DOWN: 40
759    };
760
761    var selectors = {
762        self: "[data-" + NS + '-is="' + IS + '"]',
763        active: {
764            tab: "cmp-tabs__tab--active",
765            tabpanel: "cmp-tabs__tabpanel--active"
766        }
767    };
768
769    /**
770     * Tabs Configuration
771     *
772     * @typedef {Object} TabsConfig Represents a Tabs configuration
773     * @property {HTMLElement} element The HTMLElement representing the Tabs
774     * @property {Object} options The Tabs options
775     */
776
777    /**
778     * Tabs
779     *
780     * @class Tabs
781     * @classdesc An interactive Tabs component for navigating a list of tabs
782     * @param {TabsConfig} config The Tabs configuration
783     */
784    function Tabs(config) {
785        var that = this;
786
787        if (config && config.element) {
788            init(config);
789        }
790
791        /**
792         * Initializes the Tabs
793         *
794         * @private
795         * @param {TabsConfig} config The Tabs configuration
796         */
797        function init(config) {
798            that._config = config;
799
800            // prevents multiple initialization
801            config.element.removeAttribute("data-" + NS + "-is");
802
803            cacheElements(config.element);
804            that._active = getActiveIndex(that._elements["tab"]);
805
806            if (that._elements.tabpanel) {
807                refreshActive();
808                bindEvents();
809                scrollToDeepLinkIdInTabs();
810            }
811
812            if (window.Granite && window.Granite.author && window.Granite.author.MessageChannel) {
813                /*
814                 * Editor message handling:
815                 * - subscribe to "cmp.panelcontainer" message requests sent by the editor frame
816                 * - check that the message data panel container type is correct and that the id (path) matches this specific Tabs component
817                 * - if so, route the "navigate" operation to enact a navigation of the Tabs based on index data
818                 */
819                CQ.CoreComponents.MESSAGE_CHANNEL = CQ.CoreComponents.MESSAGE_CHANNEL || new window.Granite.author.MessageChannel("cqauthor", window);
820                CQ.CoreComponents.MESSAGE_CHANNEL.subscribeRequestMessage("cmp.panelcontainer", function(message) {
821                    if (message.data && message.data.type === "cmp-tabs" && message.data.id === that._elements.self.dataset["cmpPanelcontainerId"]) {
822                        if (message.data.operation === "navigate") {
823                            navigate(message.data.index);
824                        }
825                    }
826                });
827            }
828        }
829
830        /**
831         * Displays the panel containing the element that corresponds to the deep link in the URI fragment
832         * and scrolls the browser to this element.
833         */
834        function scrollToDeepLinkIdInTabs() {
835            if (containerUtils) {
836                var deepLinkItemIdx = containerUtils.getDeepLinkItemIdx(that, "tab", "tabpanel");
837                if (deepLinkItemIdx > -1) {
838                    var deepLinkItem = that._elements["tab"][deepLinkItemIdx];
839                    if (deepLinkItem && that._elements["tab"][that._active].id !== deepLinkItem.id) {
840                        navigateAndFocusTab(deepLinkItemIdx, true);
841                    }
842                    var hashId = window.location.hash.substring(1);
843                    if (hashId) {
844                        var hashItem = document.querySelector("[id='" + hashId + "']");
845                        if (hashItem) {
846                            hashItem.scrollIntoView();
847                        }
848                    }
849                }
850            }
851        }
852
853        /**
854         * Returns the index of the active tab, if no tab is active returns 0
855         *
856         * @param {Array} tabs Tab elements
857         * @returns {Number} Index of the active tab, 0 if none is active
858         */
859        function getActiveIndex(tabs) {
860            if (tabs) {
861                for (var i = 0; i < tabs.length; i++) {
862                    if (tabs[i].classList.contains(selectors.active.tab)) {
863                        return i;
864                    }
865                }
866            }
867            return 0;
868        }
869
870        /**
871         * Caches the Tabs elements as defined via the {@code data-tabs-hook="ELEMENT_NAME"} markup API
872         *
873         * @private
874         * @param {HTMLElement} wrapper The Tabs wrapper element
875         */
876        function cacheElements(wrapper) {
877            that._elements = {};
878            that._elements.self = wrapper;
879            var hooks = that._elements.self.querySelectorAll("[data-" + NS + "-hook-" + IS + "]");
880
881            for (var i = 0; i < hooks.length; i++) {
882                var hook = hooks[i];
883                if (hook.closest("." + NS + "-" + IS) === that._elements.self) { // only process own tab elements
884                    var capitalized = IS;
885                    capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
886                    var key = hook.dataset[NS + "Hook" + capitalized];
887                    if (that._elements[key]) {
888                        if (!Array.isArray(that._elements[key])) {
889                            var tmp = that._elements[key];
890                            that._elements[key] = [tmp];
891                        }
892                        that._elements[key].push(hook);
893                    } else {
894                        that._elements[key] = hook;
895                    }
896                }
897            }
898        }
899
900        /**
901         * Binds Tabs event handling
902         *
903         * @private
904         */
905        function bindEvents() {
906            window.addEventListener("hashchange", scrollToDeepLinkIdInTabs, false);
907            var tabs = that._elements["tab"];
908            if (tabs) {
909                for (var i = 0; i < tabs.length; i++) {
910                    (function(index) {
911                        tabs[i].addEventListener("click", function(event) {
912                            navigateAndFocusTab(index);
913                        });
914                        tabs[i].addEventListener("keydown", function(event) {
915                            onKeyDown(event);
916                        });
917                    })(i);
918                }
919            }
920        }
921
922        /**
923         * Handles tab keydown events
924         *
925         * @private
926         * @param {Object} event The keydown event
927         */
928        function onKeyDown(event) {
929            var index = that._active;
930            var lastIndex = that._elements["tab"].length - 1;
931
932            switch (event.keyCode) {
933                case keyCodes.ARROW_LEFT:
934                case keyCodes.ARROW_UP:
935                    event.preventDefault();
936                    if (index > 0) {
937                        navigateAndFocusTab(index - 1);
938                    }
939                    break;
940                case keyCodes.ARROW_RIGHT:
941                case keyCodes.ARROW_DOWN:
942                    event.preventDefault();
943                    if (index < lastIndex) {
944                        navigateAndFocusTab(index + 1);
945                    }
946                    break;
947                case keyCodes.HOME:
948                    event.preventDefault();
949                    navigateAndFocusTab(0);
950                    break;
951                case keyCodes.END:
952                    event.preventDefault();
953                    navigateAndFocusTab(lastIndex);
954                    break;
955                default:
956                    return;
957            }
958        }
959
960        /**
961         * Refreshes the tab markup based on the current {@code Tabs#_active} index
962         *
963         * @private
964         */
965        function refreshActive() {
966            var tabpanels = that._elements["tabpanel"];
967            var tabs = that._elements["tab"];
968
969            if (tabpanels) {
970                if (Array.isArray(tabpanels)) {
971                    for (var i = 0; i < tabpanels.length; i++) {
972                        if (i === parseInt(that._active)) {
973                            tabpanels[i].classList.add(selectors.active.tabpanel);
974                            tabpanels[i].removeAttribute("aria-hidden");
975                            tabs[i].classList.add(selectors.active.tab);
976                            tabs[i].setAttribute("aria-selected", true);
977                            tabs[i].setAttribute("tabindex", "0");
978                        } else {
979                            tabpanels[i].classList.remove(selectors.active.tabpanel);
980                            tabpanels[i].setAttribute("aria-hidden", true);
981                            tabs[i].classList.remove(selectors.active.tab);
982                            tabs[i].setAttribute("aria-selected", false);
983                            tabs[i].setAttribute("tabindex", "-1");
984                        }
985                    }
986                } else {
987                    // only one tab
988                    tabpanels.classList.add(selectors.active.tabpanel);
989                    tabs.classList.add(selectors.active.tab);
990                }
991            }
992        }
993
994        /**
995         * Focuses the element and prevents scrolling the element into view
996         *
997         * @param {HTMLElement} element Element to focus
998         */
999        function focusWithoutScroll(element) {
1000            var x = window.scrollX || window.pageXOffset;
1001            var y = window.scrollY || window.pageYOffset;
1002            element.focus();
1003            window.scrollTo(x, y);
1004        }
1005
1006        /**
1007         * Navigates to the tab at the provided index
1008         *
1009         * @private
1010         * @param {Number} index The index of the tab to navigate to
1011         */
1012        function navigate(index) {
1013            that._active = index;
1014            refreshActive();
1015        }
1016
1017        /**
1018         * Navigates to the item at the provided index and ensures the active tab gains focus
1019         *
1020         * @private
1021         * @param {Number} index The index of the item to navigate to
1022         * @param {Boolean} keepHash true to keep the hash in the URL, false to update it
1023         */
1024        function navigateAndFocusTab(index, keepHash) {
1025            var exActive = that._active;
1026            if (!keepHash && containerUtils) {
1027                containerUtils.updateUrlHash(that, "tab", index);
1028            }
1029            navigate(index);
1030            focusWithoutScroll(that._elements["tab"][index]);
1031
1032            if (dataLayerEnabled) {
1033
1034                var activeItem = getDataLayerId(that._elements.tabpanel[index]);
1035                var exActiveItem = getDataLayerId(that._elements.tabpanel[exActive]);
1036
1037                dataLayer.push({
1038                    event: "cmp:show",
1039                    eventInfo: {
1040                        path: "component." + activeItem
1041                    }
1042                });
1043
1044                dataLayer.push({
1045                    event: "cmp:hide",
1046                    eventInfo: {
1047                        path: "component." + exActiveItem
1048                    }
1049                });
1050
1051                var tabsId = that._elements.self.id;
1052                var uploadPayload = { component: {} };
1053                uploadPayload.component[tabsId] = { shownItems: [activeItem] };
1054
1055                var removePayload = { component: {} };
1056                removePayload.component[tabsId] = { shownItems: undefined };
1057
1058                dataLayer.push(removePayload);
1059                dataLayer.push(uploadPayload);
1060            }
1061        }
1062    }
1063
1064    /**
1065     * Reads options data from the Tabs wrapper element, defined via {@code data-cmp-*} data attributes
1066     *
1067     * @private
1068     * @param {HTMLElement} element The Tabs element to read options data from
1069     * @returns {Object} The options read from the component data attributes
1070     */
1071    function readData(element) {
1072        var data = element.dataset;
1073        var options = [];
1074        var capitalized = IS;
1075        capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
1076        var reserved = ["is", "hook" + capitalized];
1077
1078        for (var key in data) {
1079            if (Object.prototype.hasOwnProperty.call(data, key)) {
1080                var value = data[key];
1081
1082                if (key.indexOf(NS) === 0) {
1083                    key = key.slice(NS.length);
1084                    key = key.charAt(0).toLowerCase() + key.substring(1);
1085
1086                    if (reserved.indexOf(key) === -1) {
1087                        options[key] = value;
1088                    }
1089                }
1090            }
1091        }
1092
1093        return options;
1094    }
1095
1096    /**
1097     * Parses the dataLayer string and returns the ID
1098     *
1099     * @private
1100     * @param {HTMLElement} item the accordion item
1101     * @returns {String} dataLayerId or undefined
1102     */
1103    function getDataLayerId(item) {
1104        if (item) {
1105            if (item.dataset.cmpDataLayer) {
1106                return Object.keys(JSON.parse(item.dataset.cmpDataLayer))[0];
1107            } else {
1108                return item.id;
1109            }
1110        }
1111        return null;
1112    }
1113
1114    /**
1115     * Document ready handler and DOM mutation observers. Initializes Tabs components as necessary.
1116     *
1117     * @private
1118     */
1119    function onDocumentReady() {
1120        dataLayerEnabled = document.body.hasAttribute("data-cmp-data-layer-enabled");
1121        if (dataLayerEnabled) {
1122            dataLayerName = document.body.getAttribute("data-cmp-data-layer-name") || "adobeDataLayer";
1123            dataLayer = window[dataLayerName] = window[dataLayerName] || [];
1124        }
1125
1126        var elements = document.querySelectorAll(selectors.self);
1127        for (var i = 0; i < elements.length; i++) {
1128            new Tabs({ element: elements[i], options: readData(elements[i]) });
1129        }
1130
1131        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
1132        var body = document.querySelector("body");
1133        var observer = new MutationObserver(function(mutations) {
1134            mutations.forEach(function(mutation) {
1135                // needed for IE
1136                var nodesArray = [].slice.call(mutation.addedNodes);
1137                if (nodesArray.length > 0) {
1138                    nodesArray.forEach(function(addedNode) {
1139                        if (addedNode.querySelectorAll) {
1140                            var elementsArray = [].slice.call(addedNode.querySelectorAll(selectors.self));
1141                            elementsArray.forEach(function(element) {
1142                                new Tabs({ element: element, options: readData(element) });
1143                            });
1144                        }
1145                    });
1146                }
1147            });
1148        });
1149
1150        observer.observe(body, {
1151            subtree: true,
1152            childList: true,
1153            characterData: true
1154        });
1155    }
1156
1157    if (document.readyState !== "loading") {
1158        onDocumentReady();
1159    } else {
1160        document.addEventListener("DOMContentLoaded", onDocumentReady);
1161    }
1162
1163    if (containerUtils) {
1164        window.addEventListener("load", containerUtils.scrollToAnchor, false);
1165    }
1166
1167}());
1168
1169
1170/*******************************************************************************
1171 * Copyright 2022 Adobe
1172 *
1173 * Licensed under the Apache License, Version 2.0 (the "License");
1174 * you may not use this file except in compliance with the License.
1175 * You may obtain a copy of the License at
1176 *
1177 *     http://www.apache.org/licenses/LICENSE-2.0
1178 *
1179 * Unless required by applicable law or agreed to in writing, software
1180 * distributed under the License is distributed on an "AS IS" BASIS,
1181 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1182 * See the License for the specific language governing permissions and
1183 * limitations under the License.
1184 ******************************************************************************/
1185(function(document) {
1186    "use strict";
1187
1188    window.CMP = window.CMP || {};
1189    window.CMP.utils = (function() {
1190        var NS = "cmp";
1191
1192        /**
1193         * Reads options data from the Component wrapper element, defined via {@code data-cmp-*} data attributes
1194         *
1195         * @param {HTMLElement} element The component element to read options data from
1196         * @param {String} is The component identifier
1197         * @returns {String[]} The options read from the component data attributes
1198         */
1199        var readData = function(element, is) {
1200            var data = element.dataset;
1201            var options = [];
1202            var capitalized = is;
1203            capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
1204            var reserved = ["is", "hook" + capitalized];
1205
1206            for (var key in data) {
1207                if (Object.prototype.hasOwnProperty.call(data, key)) {
1208                    var value = data[key];
1209
1210                    if (key.indexOf(NS) === 0) {
1211                        key = key.slice(NS.length);
1212                        key = key.charAt(0).toLowerCase() + key.substring(1);
1213
1214                        if (reserved.indexOf(key) === -1) {
1215                            options[key] = value;
1216                        }
1217                    }
1218                }
1219            }
1220            return options;
1221        };
1222
1223        /**
1224         * Set up the final properties of a component by evaluating the transform function or fall back to the default value on demand
1225         * @param {String[]} options the options to transform
1226         * @param {Object} properties object of properties of property functions
1227         * @returns {Object} transformed properties
1228         */
1229        var setupProperties = function(options, properties) {
1230            var transformedProperties = {};
1231
1232            for (var key in properties) {
1233                if (Object.prototype.hasOwnProperty.call(properties, key)) {
1234                    var property = properties[key];
1235                    if (options && options[key] != null) {
1236                        if (property && typeof property.transform === "function") {
1237                            transformedProperties[key] = property.transform(options[key]);
1238                        } else {
1239                            transformedProperties[key] = options[key];
1240                        }
1241                    } else {
1242                        transformedProperties[key] = properties[key]["default"];
1243                    }
1244                }
1245            }
1246            return transformedProperties;
1247        };
1248
1249
1250        return {
1251            readData: readData,
1252            setupProperties: setupProperties
1253        };
1254    }());
1255}(window.document));
1256
1257/*******************************************************************************
1258 * Copyright 2018 Adobe
1259 *
1260 * Licensed under the Apache License, Version 2.0 (the "License");
1261 * you may not use this file except in compliance with the License.
1262 * You may obtain a copy of the License at
1263 *
1264 *     http://www.apache.org/licenses/LICENSE-2.0
1265 *
1266 * Unless required by applicable law or agreed to in writing, software
1267 * distributed under the License is distributed on an "AS IS" BASIS,
1268 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1269 * See the License for the specific language governing permissions and
1270 * limitations under the License.
1271 ******************************************************************************/
1272(function() {
1273    "use strict";
1274
1275    var containerUtils = window.CQ && window.CQ.CoreComponents && window.CQ.CoreComponents.container && window.CQ.CoreComponents.container.utils ? window.CQ.CoreComponents.container.utils : undefined;
1276    if (!containerUtils) {
1277        // eslint-disable-next-line no-console
1278        console.warn("Tabs: container utilities at window.CQ.CoreComponents.container.utils are not available. This can lead to missing features. Ensure the core.wcm.components.commons.site.container client library is included on the page.");
1279    }
1280    var dataLayerEnabled;
1281    var dataLayer;
1282    var dataLayerName;
1283
1284    var NS = "cmp";
1285    var IS = "carousel";
1286
1287    var keyCodes = {
1288        SPACE: 32,
1289        END: 35,
1290        HOME: 36,
1291        ARROW_LEFT: 37,
1292        ARROW_UP: 38,
1293        ARROW_RIGHT: 39,
1294        ARROW_DOWN: 40
1295    };
1296
1297    var selectors = {
1298        self: "[data-" + NS + '-is="' + IS + '"]'
1299    };
1300
1301    var properties = {
1302        /**
1303         * Determines whether the Carousel will automatically transition between slides
1304         *
1305         * @memberof Carousel
1306         * @type {Boolean}
1307         * @default false
1308         */
1309        "autoplay": {
1310            "default": false,
1311            "transform": function(value) {
1312                return !(value === null || typeof value === "undefined");
1313            }
1314        },
1315        /**
1316         * Duration (in milliseconds) before automatically transitioning to the next slide
1317         *
1318         * @memberof Carousel
1319         * @type {Number}
1320         * @default 5000
1321         */
1322        "delay": {
1323            "default": 5000,
1324            "transform": function(value) {
1325                value = parseFloat(value);
1326                return !isNaN(value) ? value : null;
1327            }
1328        },
1329        /**
1330         * Determines whether automatic pause on hovering the carousel is disabled
1331         *
1332         * @memberof Carousel
1333         * @type {Boolean}
1334         * @default false
1335         */
1336        "autopauseDisabled": {
1337            "default": false,
1338            "transform": function(value) {
1339                return !(value === null || typeof value === "undefined");
1340            }
1341        }
1342    };
1343
1344    /**
1345     * Carousel Configuration
1346     *
1347     * @typedef {Object} CarouselConfig Represents a Carousel configuration
1348     * @property {HTMLElement} element The HTMLElement representing the Carousel
1349     * @property {*[]} options The Carousel options
1350     */
1351
1352    /**
1353     * Carousel
1354     *
1355     * @class Carousel
1356     * @classdesc An interactive Carousel component for navigating a list of generic items
1357     * @param {CarouselConfig} config The Carousel configuration
1358     */
1359    function Carousel(config) {
1360        var that = this;
1361
1362        if (config && config.element) {
1363            init(config);
1364        }
1365
1366        /**
1367         * Initializes the Carousel
1368         *
1369         * @private
1370         * @param {CarouselConfig} config The Carousel configuration
1371         */
1372        function init(config) {
1373            that._config = config;
1374
1375            // prevents multiple initialization
1376            config.element.removeAttribute("data-" + NS + "-is");
1377
1378            setupProperties(config.options);
1379            cacheElements(config.element);
1380
1381            that._active = 0;
1382            that._paused = false;
1383
1384            if (that._elements.item) {
1385                initializeActive();
1386                bindEvents();
1387                resetAutoplayInterval();
1388                refreshPlayPauseActions();
1389                scrollToDeepLinkIdInCarousel();
1390            }
1391
1392            // TODO: This section is only relevant in edit mode and should move to the editor clientLib
1393            if (window.Granite && window.Granite.author && window.Granite.author.MessageChannel) {
1394                /*
1395                 * Editor message handling:
1396                 * - subscribe to "cmp.panelcontainer" message requests sent by the editor frame
1397                 * - check that the message data panel container type is correct and that the id (path) matches this specific Carousel component
1398                 * - if so, route the "navigate" operation to enact a navigation of the Carousel based on index data
1399                 */
1400                window.CQ = window.CQ || {};
1401                window.CQ.CoreComponents = window.CQ.CoreComponents || {};
1402                window.CQ.CoreComponents.MESSAGE_CHANNEL = window.CQ.CoreComponents.MESSAGE_CHANNEL || new window.Granite.author.MessageChannel("cqauthor", window);
1403                window.CQ.CoreComponents.MESSAGE_CHANNEL.subscribeRequestMessage("cmp.panelcontainer", function(message) {
1404                    if (message.data && message.data.type === "cmp-carousel" && message.data.id === that._elements.self.dataset["cmpPanelcontainerId"]) {
1405                        if (message.data.operation === "navigate") {
1406                            navigate(message.data.index);
1407                        }
1408                    }
1409                });
1410            }
1411        }
1412
1413        /**
1414         * Displays the slide containing the element that corresponds to the deep link in the URI fragment
1415         * and scrolls the browser to this element.
1416         */
1417        function scrollToDeepLinkIdInCarousel() {
1418            if (containerUtils) {
1419                var deepLinkItemIdx = containerUtils.getDeepLinkItemIdx(that, "item", "item");
1420                if (deepLinkItemIdx > -1) {
1421                    var deepLinkItem = that._elements["item"][deepLinkItemIdx];
1422                    if (deepLinkItem && that._elements["item"][that._active].id !== deepLinkItem.id) {
1423                        navigateAndFocusIndicator(deepLinkItemIdx, true);
1424                        // pause the carousel auto-rotation
1425                        pause();
1426                    }
1427                    var hashId = window.location.hash.substring(1);
1428                    if (hashId) {
1429                        var hashItem = document.querySelector("[id='" + hashId + "']");
1430                        if (hashItem) {
1431                            hashItem.scrollIntoView();
1432                        }
1433                    }
1434                }
1435            }
1436        }
1437
1438        /**
1439         * Caches the Carousel elements as defined via the {@code data-carousel-hook="ELEMENT_NAME"} markup API
1440         *
1441         * @private
1442         * @param {HTMLElement} wrapper The Carousel wrapper element
1443         */
1444        function cacheElements(wrapper) {
1445            that._elements = {};
1446            that._elements.self = wrapper;
1447            var hooks = that._elements.self.querySelectorAll("[data-" + NS + "-hook-" + IS + "]");
1448
1449            for (var i = 0; i < hooks.length; i++) {
1450                var hook = hooks[i];
1451                var capitalized = IS;
1452                capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
1453                var key = hook.dataset[NS + "Hook" + capitalized];
1454                if (that._elements[key]) {
1455                    if (!Array.isArray(that._elements[key])) {
1456                        var tmp = that._elements[key];
1457                        that._elements[key] = [tmp];
1458                    }
1459                    that._elements[key].push(hook);
1460                } else {
1461                    that._elements[key] = hook;
1462                }
1463            }
1464        }
1465
1466        /**
1467         * Sets up properties for the Carousel based on the passed options.
1468         *
1469         * @private
1470         * @param {Object} options The Carousel options
1471         */
1472        function setupProperties(options) {
1473            that._properties = {};
1474
1475            for (var key in properties) {
1476                if (Object.prototype.hasOwnProperty.call(properties, key)) {
1477                    var property = properties[key];
1478                    var value = null;
1479
1480                    if (options && options[key] != null) {
1481                        value = options[key];
1482
1483                        // transform the provided option
1484                        if (property && typeof property.transform === "function") {
1485                            value = property.transform(value);
1486                        }
1487                    }
1488
1489                    if (value === null) {
1490                        // value still null, take the property default
1491                        value = properties[key]["default"];
1492                    }
1493
1494                    that._properties[key] = value;
1495                }
1496            }
1497        }
1498
1499        /**
1500         * Binds Carousel event handling
1501         *
1502         * @private
1503         */
1504        function bindEvents() {
1505            window.addEventListener("hashchange", scrollToDeepLinkIdInCarousel, false);
1506            if (that._elements["previous"]) {
1507                that._elements["previous"].addEventListener("click", function() {
1508                    var index = getPreviousIndex();
1509                    navigate(index);
1510                    if (dataLayerEnabled) {
1511                        dataLayer.push({
1512                            event: "cmp:show",
1513                            eventInfo: {
1514                                path: "component." + getDataLayerId(that._elements.item[index])
1515                            }
1516                        });
1517                    }
1518                });
1519            }
1520
1521            if (that._elements["next"]) {
1522                that._elements["next"].addEventListener("click", function() {
1523                    var index = getNextIndex();
1524                    navigate(index);
1525                    if (dataLayerEnabled) {
1526                        dataLayer.push({
1527                            event: "cmp:show",
1528                            eventInfo: {
1529                                path: "component." + getDataLayerId(that._elements.item[index])
1530                            }
1531                        });
1532                    }
1533                });
1534            }
1535
1536            var indicators = that._elements["indicator"];
1537            if (indicators) {
1538                for (var i = 0; i < indicators.length; i++) {
1539                    (function(index) {
1540                        indicators[i].addEventListener("click", function(event) {
1541                            navigateAndFocusIndicator(index);
1542                            // pause the carousel auto-rotation
1543                            pause();
1544                        });
1545                    })(i);
1546                }
1547            }
1548
1549            if (that._elements["pause"]) {
1550                if (that._properties.autoplay) {
1551                    that._elements["pause"].addEventListener("click", onPauseClick);
1552                }
1553            }
1554
1555            if (that._elements["play"]) {
1556                if (that._properties.autoplay) {
1557                    that._elements["play"].addEventListener("click", onPlayClick);
1558                }
1559            }
1560
1561            that._elements.self.addEventListener("keydown", onKeyDown);
1562
1563            if (!that._properties.autopauseDisabled) {
1564                that._elements.self.addEventListener("mouseenter", onMouseEnter);
1565                that._elements.self.addEventListener("mouseleave", onMouseLeave);
1566            }
1567
1568            // for accessibility we pause animation when a element get focused
1569            var items = that._elements["item"];
1570            if (items) {
1571                for (var j = 0; j < items.length; j++) {
1572                    items[j].addEventListener("focusin", onMouseEnter);
1573                    items[j].addEventListener("focusout", onMouseLeave);
1574                }
1575            }
1576        }
1577
1578        /**
1579         * Handles carousel keydown events
1580         *
1581         * @private
1582         * @param {Object} event The keydown event
1583         */
1584        function onKeyDown(event) {
1585            var index = that._active;
1586            var lastIndex = that._elements["indicator"].length - 1;
1587
1588            switch (event.keyCode) {
1589                case keyCodes.ARROW_LEFT:
1590                case keyCodes.ARROW_UP:
1591                    event.preventDefault();
1592                    if (index > 0) {
1593                        navigateAndFocusIndicator(index - 1);
1594                    }
1595                    break;
1596                case keyCodes.ARROW_RIGHT:
1597                case keyCodes.ARROW_DOWN:
1598                    event.preventDefault();
1599                    if (index < lastIndex) {
1600                        navigateAndFocusIndicator(index + 1);
1601                    }
1602                    break;
1603                case keyCodes.HOME:
1604                    event.preventDefault();
1605                    navigateAndFocusIndicator(0);
1606                    break;
1607                case keyCodes.END:
1608                    event.preventDefault();
1609                    navigateAndFocusIndicator(lastIndex);
1610                    break;
1611                case keyCodes.SPACE:
1612                    if (that._properties.autoplay && (event.target !== that._elements["previous"] && event.target !== that._elements["next"])) {
1613                        event.preventDefault();
1614                        if (!that._paused) {
1615                            pause();
1616                        } else {
1617                            play();
1618                        }
1619                    }
1620                    if (event.target === that._elements["pause"]) {
1621                        that._elements["play"].focus();
1622                    }
1623                    if (event.target === that._elements["play"]) {
1624                        that._elements["pause"].focus();
1625                    }
1626                    break;
1627                default:
1628                    return;
1629            }
1630        }
1631
1632        /**
1633         * Handles carousel mouseenter events
1634         *
1635         * @private
1636         * @param {Object} event The mouseenter event
1637         */
1638        function onMouseEnter(event) {
1639            clearAutoplayInterval();
1640        }
1641
1642        /**
1643         * Handles carousel mouseleave events
1644         *
1645         * @private
1646         * @param {Object} event The mouseleave event
1647         */
1648        function onMouseLeave(event) {
1649            resetAutoplayInterval();
1650        }
1651
1652        /**
1653         * Handles pause element click events
1654         *
1655         * @private
1656         * @param {Object} event The click event
1657         */
1658        function onPauseClick(event) {
1659            pause();
1660            that._elements["play"].focus();
1661        }
1662
1663        /**
1664         * Handles play element click events
1665         *
1666         * @private
1667         * @param {Object} event The click event
1668         */
1669        function onPlayClick() {
1670            play();
1671            that._elements["pause"].focus();
1672        }
1673
1674        /**
1675         * Pauses the playing of the Carousel. Sets {@code Carousel#_paused} marker.
1676         * Only relevant when autoplay is enabled
1677         *
1678         * @private
1679         */
1680        function pause() {
1681            that._paused = true;
1682            clearAutoplayInterval();
1683            refreshPlayPauseActions();
1684        }
1685
1686        /**
1687         * Enables the playing of the Carousel. Sets {@code Carousel#_paused} marker.
1688         * Only relevant when autoplay is enabled
1689         *
1690         * @private
1691         */
1692        function play() {
1693            that._paused = false;
1694
1695            // If the Carousel is hovered, don't begin auto transitioning until the next mouse leave event
1696            var hovered = false;
1697            if (that._elements.self.parentElement) {
1698                hovered = that._elements.self.parentElement.querySelector(":hover") === that._elements.self;
1699            }
1700            if (that._properties.autopauseDisabled || !hovered) {
1701                resetAutoplayInterval();
1702            }
1703
1704            refreshPlayPauseActions();
1705        }
1706
1707        /**
1708         * Refreshes the play/pause action markup based on the {@code Carousel#_paused} state
1709         *
1710         * @private
1711         */
1712        function refreshPlayPauseActions() {
1713            setActionDisabled(that._elements["pause"], that._paused);
1714            setActionDisabled(that._elements["play"], !that._paused);
1715        }
1716
1717        /**
1718         * Initialize {@code Carousel#_active} based on the active item of the carousel.
1719         */
1720        function initializeActive() {
1721            var items = that._elements["item"];
1722            if (items && Array.isArray(items)) {
1723                for (var i = 0; i < items.length; i++) {
1724                    if (items[i].classList.contains("cmp-carousel__item--active")) {
1725                        that._active = i;
1726                        break;
1727                    }
1728                }
1729            }
1730        }
1731
1732        /**
1733         * Refreshes the item markup based on the current {@code Carousel#_active} index
1734         *
1735         * @private
1736         */
1737        function refreshActive() {
1738            var items = that._elements["item"];
1739            var indicators = that._elements["indicator"];
1740
1741            if (items) {
1742                if (Array.isArray(items)) {
1743                    for (var i = 0; i < items.length; i++) {
1744                        if (i === parseInt(that._active)) {
1745                            items[i].classList.add("cmp-carousel__item--active");
1746                            items[i].removeAttribute("aria-hidden");
1747                            indicators[i].classList.add("cmp-carousel__indicator--active");
1748                            indicators[i].setAttribute("aria-selected", true);
1749                            indicators[i].setAttribute("tabindex", "0");
1750                        } else {
1751                            items[i].classList.remove("cmp-carousel__item--active");
1752                            items[i].setAttribute("aria-hidden", true);
1753                            indicators[i].classList.remove("cmp-carousel__indicator--active");
1754                            indicators[i].setAttribute("aria-selected", false);
1755                            indicators[i].setAttribute("tabindex", "-1");
1756                        }
1757                    }
1758                } else {
1759                    // only one item
1760                    items.classList.add("cmp-carousel__item--active");
1761                    indicators.classList.add("cmp-carousel__indicator--active");
1762                }
1763            }
1764        }
1765
1766        /**
1767         * Focuses the element and prevents scrolling the element into view
1768         *
1769         * @param {HTMLElement} element Element to focus
1770         */
1771        function focusWithoutScroll(element) {
1772            var x = window.scrollX || window.pageXOffset;
1773            var y = window.scrollY || window.pageYOffset;
1774            element.focus();
1775            window.scrollTo(x, y);
1776        }
1777
1778        /**
1779         * Retrieves the next active index, with looping
1780         *
1781         * @private
1782         * @returns {Number} Index of the next carousel item
1783         */
1784        function getNextIndex() {
1785            return that._active === (that._elements["item"].length - 1) ? 0 : that._active + 1;
1786        }
1787
1788        /**
1789         * Retrieves the previous active index, with looping
1790         *
1791         * @private
1792         * @returns {Number} Index of the previous carousel item
1793         */
1794        function getPreviousIndex() {
1795            return that._active === 0 ? (that._elements["item"].length - 1) : that._active - 1;
1796        }
1797
1798        /**
1799         * Navigates to the item at the provided index
1800         *
1801         * @private
1802         * @param {Number} index The index of the item to navigate to
1803         * @param {Boolean} keepHash true to keep the hash in the URL, false to update it
1804         */
1805        function navigate(index, keepHash) {
1806            if (index < 0 || index > (that._elements["item"].length - 1)) {
1807                return;
1808            }
1809
1810            that._active = index;
1811            refreshActive();
1812
1813            if (!keepHash && containerUtils) {
1814                containerUtils.updateUrlHash(that, "item", index);
1815            }
1816
1817            if (dataLayerEnabled) {
1818                var carouselId = that._elements.self.id;
1819                var activeItem = getDataLayerId(that._elements.item[index]);
1820                var updatePayload = { component: {} };
1821                updatePayload.component[carouselId] = { shownItems: [activeItem] };
1822
1823                var removePayload = { component: {} };
1824                removePayload.component[carouselId] = { shownItems: undefined };
1825
1826                dataLayer.push(removePayload);
1827                dataLayer.push(updatePayload);
1828            }
1829
1830            // reset the autoplay transition interval following navigation, if not already hovering the carousel
1831            if (that._elements.self.parentElement) {
1832                if (that._elements.self.parentElement.querySelector(":hover") !== that._elements.self) {
1833                    resetAutoplayInterval();
1834                }
1835            }
1836        }
1837
1838        /**
1839         * Navigates to the item at the provided index and ensures the active indicator gains focus
1840         *
1841         * @private
1842         * @param {Number} index The index of the item to navigate to
1843         * @param {Boolean} keepHash true to keep the hash in the URL, false to update it
1844         */
1845        function navigateAndFocusIndicator(index, keepHash) {
1846            navigate(index, keepHash);
1847            focusWithoutScroll(that._elements["indicator"][index]);
1848
1849            if (dataLayerEnabled) {
1850                dataLayer.push({
1851                    event: "cmp:show",
1852                    eventInfo: {
1853                        path: "component." + getDataLayerId(that._elements.item[index])
1854                    }
1855                });
1856            }
1857        }
1858
1859        /**
1860         * Starts/resets automatic slide transition interval
1861         *
1862         * @private
1863         */
1864        function resetAutoplayInterval() {
1865            if (that._paused || !that._properties.autoplay) {
1866                return;
1867            }
1868            clearAutoplayInterval();
1869            that._autoplayIntervalId = window.setInterval(function() {
1870                if (document.visibilityState && document.hidden) {
1871                    return;
1872                }
1873                var indicators = that._elements["indicators"];
1874                if (indicators !== document.activeElement && indicators.contains(document.activeElement)) {
1875                    // if an indicator has focus, ensure we switch focus following navigation
1876                    navigateAndFocusIndicator(getNextIndex(), true);
1877                } else {
1878                    navigate(getNextIndex(), true);
1879                }
1880            }, that._properties.delay);
1881        }
1882
1883        /**
1884         * Clears/pauses automatic slide transition interval
1885         *
1886         * @private
1887         */
1888        function clearAutoplayInterval() {
1889            window.clearInterval(that._autoplayIntervalId);
1890            that._autoplayIntervalId = null;
1891        }
1892
1893        /**
1894         * Sets the disabled state for an action and toggles the appropriate CSS classes
1895         *
1896         * @private
1897         * @param {HTMLElement} action Action to disable
1898         * @param {Boolean} [disable] {@code true} to disable, {@code false} to enable
1899         */
1900        function setActionDisabled(action, disable) {
1901            if (!action) {
1902                return;
1903            }
1904            if (disable !== false) {
1905                action.disabled = true;
1906                action.classList.add("cmp-carousel__action--disabled");
1907            } else {
1908                action.disabled = false;
1909                action.classList.remove("cmp-carousel__action--disabled");
1910            }
1911        }
1912    }
1913
1914    /**
1915     * Parses the dataLayer string and returns the ID
1916     *
1917     * @private
1918     * @param {HTMLElement} item the accordion item
1919     * @returns {String} dataLayerId or undefined
1920     */
1921    function getDataLayerId(item) {
1922        if (item) {
1923            if (item.dataset.cmpDataLayer) {
1924                return Object.keys(JSON.parse(item.dataset.cmpDataLayer))[0];
1925            } else {
1926                return item.id;
1927            }
1928        }
1929        return null;
1930    }
1931
1932    /**
1933     * Document ready handler and DOM mutation observers. Initializes Carousel components as necessary.
1934     *
1935     * @private
1936     */
1937    function onDocumentReady() {
1938        dataLayerEnabled = document.body.hasAttribute("data-cmp-data-layer-enabled");
1939        if (dataLayerEnabled) {
1940            dataLayerName = document.body.getAttribute("data-cmp-data-layer-name") || "adobeDataLayer";
1941            dataLayer = window[dataLayerName] = window[dataLayerName] || [];
1942        }
1943
1944        var elements = document.querySelectorAll(selectors.self);
1945        for (var i = 0; i < elements.length; i++) {
1946            new Carousel({ element: elements[i], options: CMP.utils.readData(elements[i], IS) });
1947        }
1948
1949        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
1950        var body = document.querySelector("body");
1951        var observer = new MutationObserver(function(mutations) {
1952            mutations.forEach(function(mutation) {
1953                // needed for IE
1954                var nodesArray = [].slice.call(mutation.addedNodes);
1955                if (nodesArray.length > 0) {
1956                    nodesArray.forEach(function(addedNode) {
1957                        if (addedNode.querySelectorAll) {
1958                            var elementsArray = [].slice.call(addedNode.querySelectorAll(selectors.self));
1959                            elementsArray.forEach(function(element) {
1960                                new Carousel({ element: element, options: CMP.utils.readData(element, IS) });
1961                            });
1962                        }
1963                    });
1964                }
1965            });
1966        });
1967
1968        observer.observe(body, {
1969            subtree: true,
1970            childList: true,
1971            characterData: true
1972        });
1973    }
1974
1975    var documentReady = document.readyState !== "loading" ? Promise.resolve() : new Promise(function(resolve) {
1976        document.addEventListener("DOMContentLoaded", resolve);
1977    });
1978    Promise.all([documentReady]).then(onDocumentReady);
1979
1980    if (containerUtils) {
1981        window.addEventListener("load", containerUtils.scrollToAnchor, false);
1982    }
1983
1984}());
1985
1986
1987/*******************************************************************************
1988 * Copyright 2017 Adobe
1989 *
1990 * Licensed under the Apache License, Version 2.0 (the "License");
1991 * you may not use this file except in compliance with the License.
1992 * You may obtain a copy of the License at
1993 *
1994 *     http://www.apache.org/licenses/LICENSE-2.0
1995 *
1996 * Unless required by applicable law or agreed to in writing, software
1997 * distributed under the License is distributed on an "AS IS" BASIS,
1998 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1999 * See the License for the specific language governing permissions and
2000 * limitations under the License.
2001 ******************************************************************************/
2002if (window.Element && !Element.prototype.closest) {
2003    // eslint valid-jsdoc: "off"
2004    Element.prototype.closest =
2005        function(s) {
2006            "use strict";
2007            var matches = (this.document || this.ownerDocument).querySelectorAll(s);
2008            var el      = this;
2009            var i;
2010            do {
2011                i = matches.length;
2012                while (--i >= 0 && matches.item(i) !== el) {
2013                    // continue
2014                }
2015            } while ((i < 0) && (el = el.parentElement));
2016            return el;
2017        };
2018}
2019
2020if (window.Element && !Element.prototype.matches) {
2021    Element.prototype.matches =
2022        Element.prototype.matchesSelector ||
2023        Element.prototype.mozMatchesSelector ||
2024        Element.prototype.msMatchesSelector ||
2025        Element.prototype.oMatchesSelector ||
2026        Element.prototype.webkitMatchesSelector ||
2027        function(s) {
2028            "use strict";
2029            var matches = (this.document || this.ownerDocument).querySelectorAll(s);
2030            var i       = matches.length;
2031            while (--i >= 0 && matches.item(i) !== this) {
2032                // continue
2033            }
2034            return i > -1;
2035        };
2036}
2037
2038if (!Object.assign) {
2039    Object.assign = function(target, varArgs) { // .length of function is 2
2040        "use strict";
2041        if (target === null) {
2042            throw new TypeError("Cannot convert undefined or null to object");
2043        }
2044
2045        var to = Object(target);
2046
2047        for (var index = 1; index < arguments.length; index++) {
2048            var nextSource = arguments[index];
2049
2050            if (nextSource !== null) {
2051                for (var nextKey in nextSource) {
2052                    if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
2053                        to[nextKey] = nextSource[nextKey];
2054                    }
2055                }
2056            }
2057        }
2058        return to;
2059    };
2060}
2061
2062(function(arr) {
2063    "use strict";
2064    arr.forEach(function(item) {
2065        if (Object.prototype.hasOwnProperty.call(item, "remove")) {
2066            return;
2067        }
2068        Object.defineProperty(item, "remove", {
2069            configurable: true,
2070            enumerable: true,
2071            writable: true,
2072            value: function remove() {
2073                this.parentNode.removeChild(this);
2074            }
2075        });
2076    });
2077})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
2078
2079/*******************************************************************************
2080 * Copyright 2022 Adobe
2081 *
2082 * Licensed under the Apache License, Version 2.0 (the "License");
2083 * you may not use this file except in compliance with the License.
2084 * You may obtain a copy of the License at
2085 *
2086 *     http://www.apache.org/licenses/LICENSE-2.0
2087 *
2088 * Unless required by applicable law or agreed to in writing, software
2089 * distributed under the License is distributed on an "AS IS" BASIS,
2090 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2091 * See the License for the specific language governing permissions and
2092 * limitations under the License.
2093 ******************************************************************************/
2094(function(document) {
2095    "use strict";
2096
2097    window.CMP = window.CMP || {};
2098    window.CMP.utils = (function() {
2099        var NS = "cmp";
2100
2101        /**
2102         * Reads options data from the Component wrapper element, defined via {@code data-cmp-*} data attributes
2103         *
2104         * @param {HTMLElement} element The component element to read options data from
2105         * @param {String} is The component identifier
2106         * @returns {String[]} The options read from the component data attributes
2107         */
2108        var readData = function(element, is) {
2109            var data = element.dataset;
2110            var options = [];
2111            var capitalized = is;
2112            capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
2113            var reserved = ["is", "hook" + capitalized];
2114
2115            for (var key in data) {
2116                if (Object.prototype.hasOwnProperty.call(data, key)) {
2117                    var value = data[key];
2118
2119                    if (key.indexOf(NS) === 0) {
2120                        key = key.slice(NS.length);
2121                        key = key.charAt(0).toLowerCase() + key.substring(1);
2122
2123                        if (reserved.indexOf(key) === -1) {
2124                            options[key] = value;
2125                        }
2126                    }
2127                }
2128            }
2129            return options;
2130        };
2131
2132        /**
2133         * Set up the final properties of a component by evaluating the transform function or fall back to the default value on demand
2134         * @param {String[]} options the options to transform
2135         * @param {Object} properties object of properties of property functions
2136         * @returns {Object} transformed properties
2137         */
2138        var setupProperties = function(options, properties) {
2139            var transformedProperties = {};
2140
2141            for (var key in properties) {
2142                if (Object.prototype.hasOwnProperty.call(properties, key)) {
2143                    var property = properties[key];
2144                    if (options && options[key] != null) {
2145                        if (property && typeof property.transform === "function") {
2146                            transformedProperties[key] = property.transform(options[key]);
2147                        } else {
2148                            transformedProperties[key] = options[key];
2149                        }
2150                    } else {
2151                        transformedProperties[key] = properties[key]["default"];
2152                    }
2153                }
2154            }
2155            return transformedProperties;
2156        };
2157
2158
2159        return {
2160            readData: readData,
2161            setupProperties: setupProperties
2162        };
2163    }());
2164}(window.document));
2165
2166/*******************************************************************************
2167 * Copyright 2022 Adobe
2168 *
2169 * Licensed under the Apache License, Version 2.0 (the "License");
2170 * you may not use this file except in compliance with the License.
2171 * You may obtain a copy of the License at
2172 *
2173 *     http://www.apache.org/licenses/LICENSE-2.0
2174 *
2175 * Unless required by applicable law or agreed to in writing, software
2176 * distributed under the License is distributed on an "AS IS" BASIS,
2177 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2178 * See the License for the specific language governing permissions and
2179 * limitations under the License.
2180 ******************************************************************************/
2181(function(document) {
2182    "use strict";
2183
2184    window.CMP = window.CMP || {};
2185    window.CMP.image = window.CMP.image || {};
2186    window.CMP.image.dynamicMedia = (function() {
2187        var autoSmartCrops = {};
2188        var SRC_URI_TEMPLATE_WIDTH_VAR = "{.width}";
2189        var SRC_URI_TEMPLATE_DPR_VAR = "{dpr}";
2190        var SRC_URI_DPR_OFF = "dpr=off";
2191        var SRC_URI_DPR_ON = "dpr=on,{dpr}";
2192        var dpr = window.devicePixelRatio || 1;
2193        var config = {
2194            minWidth: 20
2195        };
2196
2197        /**
2198         * get auto smart crops from dm
2199         * @param {String} src the src uri
2200         * @returns {{}} the smart crop json object
2201         */
2202        var getAutoSmartCrops = function(src) {
2203            var request = new XMLHttpRequest();
2204            var url = src.split(SRC_URI_TEMPLATE_WIDTH_VAR)[0] + "?req=set,json";
2205            request.open("GET", url, false);
2206            request.onload = function() {
2207                if (request.status >= 200 && request.status < 400) {
2208                    // success status
2209                    var responseText = request.responseText;
2210                    var rePayload = new RegExp(/^(?:\/\*jsonp\*\/)?\s*([^()]+)\(([\s\S]+),\s*"[0-9]*"\);?$/gmi);
2211                    var rePayloadJSON = new RegExp(/^{[\s\S]*}$/gmi);
2212                    var resPayload = rePayload.exec(responseText);
2213                    var payload;
2214                    if (resPayload) {
2215                        var payloadStr = resPayload[2];
2216                        if (rePayloadJSON.test(payloadStr)) {
2217                            payload = JSON.parse(payloadStr);
2218                        }
2219
2220                    }
2221                    // check "relation" - only in case of smartcrop preset
2222                    if (payload && payload.set.relation && payload.set.relation.length > 0) {
2223                        for (var i = 0; i < payload.set.relation.length; i++) {
2224                            autoSmartCrops[parseInt(payload.set.relation[i].userdata.SmartCropWidth)] =
2225                                ":" + payload.set.relation[i].userdata.SmartCropDef;
2226                        }
2227                    }
2228                } else {
2229                    // error status
2230                }
2231            };
2232            request.send();
2233            return autoSmartCrops;
2234        };
2235
2236        /**
2237         * Build and return the srcset value based on the available auto smart crops
2238         * @param {String} src the src uri
2239         * @param {Object} smartCrops the smart crops object
2240         * @returns {String} the srcset
2241         */
2242        var getSrcSet = function(src, smartCrops) {
2243            var srcset;
2244            var keys = Object.keys(smartCrops);
2245            if (keys.length > 0) {
2246                srcset = [];
2247                for (var key in autoSmartCrops) {
2248                    srcset.push(src.replace(SRC_URI_TEMPLATE_WIDTH_VAR, smartCrops[key]) + " " + key + "w");
2249                }
2250            }
2251            return  srcset.join(",");
2252        };
2253
2254        /**
2255         * Get the optimal width based on the available sizes
2256         * @param {[Number]} sizes the available sizes
2257         * @param {Number} width the element width
2258         * @returns {String} the optimal width
2259         */
2260        function getOptimalWidth(sizes, width) {
2261            var len = sizes.length;
2262            var key = 0;
2263
2264            while ((key < len - 1) && (sizes[key] < width)) {
2265                key++;
2266            }
2267
2268            return sizes[key] !== undefined ? sizes[key].toString() : width;
2269        }
2270
2271        /**
2272         * Get the width of an element or parent element if the width is smaller than the minimum width
2273         * @param {HTMLElement} component the image component
2274         * @param {HTMLElement | Node} parent the parent element
2275         * @returns {Number} the width of the element
2276         */
2277        var getWidth = function(component, parent) {
2278            var width = component.offsetWidth;
2279            while (width < config.minWidth && parent && !component._autoWidth) {
2280                width =  parent.offsetWidth;
2281                parent = parent.parentNode;
2282            }
2283            return width;
2284        };
2285
2286        /**
2287         * Set the src and srcset attribute for a Dynamic Media Image which auto smart crops enabled.
2288         * @param {HTMLElement} component the image component
2289         * @param {{}} properties the component properties
2290         */
2291        var setDMAttributes = function(component, properties) {
2292            // for v3 we first have to turn the dpr on
2293            var src = properties.src.replace(SRC_URI_DPR_OFF, SRC_URI_DPR_ON);
2294            src = src.replace(SRC_URI_TEMPLATE_DPR_VAR, dpr);
2295            var smartCrops = {};
2296            var width;
2297            if (properties["smartcroprendition"] === "SmartCrop:Auto") {
2298                smartCrops = getAutoSmartCrops(src);
2299            }
2300            var hasWidths = (properties.widths && properties.widths.length > 0) || Object.keys(smartCrops).length > 0;
2301            if (hasWidths) {
2302                var image = component.querySelector("img");
2303                var elemWidth = getWidth(component, component.parentNode);
2304                if (properties["smartcroprendition"] === "SmartCrop:Auto") {
2305                    image.setAttribute("srcset", CMP.image.dynamicMedia.getSrcSet(src, smartCrops));
2306                    width = getOptimalWidth(Object.keys(smartCrops, elemWidth));
2307                    image.setAttribute("src", CMP.image.dynamicMedia.getSrc(src, smartCrops[width]));
2308                } else {
2309                    width = getOptimalWidth(properties.widths, elemWidth);
2310                    image.setAttribute("src", CMP.image.dynamicMedia.getSrc(src, width));
2311                }
2312            }
2313        };
2314
2315        /**
2316         * Get the src attribute based on the optimal width
2317         * @param {String} src the src uri
2318         * @param {String} width the element width
2319         * @returns {String} the final src attribute
2320         */
2321        var getSrc = function(src, width) {
2322            if (src.indexOf(SRC_URI_TEMPLATE_WIDTH_VAR) > -1) {
2323                src = src.replace(SRC_URI_TEMPLATE_WIDTH_VAR, width);
2324            }
2325            return src;
2326        };
2327
2328
2329        return {
2330            getAutoSmartCrops: getAutoSmartCrops,
2331            getSrcSet: getSrcSet,
2332            getSrc: getSrc,
2333            setDMAttributes: setDMAttributes,
2334            getWidth: getWidth
2335        };
2336    }());
2337    document.dispatchEvent(new CustomEvent("core.wcm.components.commons.site.image.dynamic-media.loaded"));
2338}(window.document));
2339
2340/*******************************************************************************
2341 * Copyright 2016 Adobe
2342 *
2343 * Licensed under the Apache License, Version 2.0 (the "License");
2344 * you may not use this file except in compliance with the License.
2345 * You may obtain a copy of the License at
2346 *
2347 *     http://www.apache.org/licenses/LICENSE-2.0
2348 *
2349 * Unless required by applicable law or agreed to in writing, software
2350 * distributed under the License is distributed on an "AS IS" BASIS,
2351 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2352 * See the License for the specific language governing permissions and
2353 * limitations under the License.
2354 ******************************************************************************/
2355(function() {
2356    "use strict";
2357
2358    var NS = "cmp";
2359    var IS = "image";
2360
2361    var EMPTY_PIXEL = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
2362    var LAZY_THRESHOLD_DEFAULT = 0;
2363    var SRC_URI_TEMPLATE_WIDTH_VAR = "{.width}";
2364    var SRC_URI_TEMPLATE_WIDTH_VAR_ASSET_DELIVERY = "width={width}";
2365    var SRC_URI_TEMPLATE_DPR_VAR = "{dpr}";
2366
2367    var selectors = {
2368        self: "[data-" + NS + '-is="' + IS + '"]',
2369        image: '[data-cmp-hook-image="image"]',
2370        map: '[data-cmp-hook-image="map"]',
2371        area: '[data-cmp-hook-image="area"]'
2372    };
2373
2374    var lazyLoader = {
2375        "cssClass": "cmp-image__image--is-loading",
2376        "style": {
2377            "height": 0,
2378            "padding-bottom": "" // will be replaced with % ratio
2379        }
2380    };
2381
2382    var properties = {
2383        /**
2384         * An array of alternative image widths (in pixels).
2385         * Used to replace a {.width} variable in the src property with an optimal width if a URI template is provided.
2386         *
2387         * @memberof Image
2388         * @type {Number[]}
2389         * @default []
2390         */
2391        "widths": {
2392            "default": [],
2393            "transform": function(value) {
2394                var widths = [];
2395                value.split(",").forEach(function(item) {
2396                    item = parseFloat(item);
2397                    if (!isNaN(item)) {
2398                        widths.push(item);
2399                    }
2400                });
2401                return widths;
2402            }
2403        },
2404        /**
2405         * Indicates whether the image should be rendered lazily.
2406         *
2407         * @memberof Image
2408         * @type {Boolean}
2409         * @default false
2410         */
2411        "lazy": {
2412            "default": false,
2413            "transform": function(value) {
2414                return !(value === null || typeof value === "undefined");
2415            }
2416        },
2417        /**
2418         * Indicates image is DynamicMedia image.
2419         *
2420         * @memberof Image
2421         * @type {Boolean}
2422         * @default false
2423         */
2424        "dmimage": {
2425            "default": false,
2426            "transform": function(value) {
2427                return !(value === null || typeof value === "undefined");
2428            }
2429        },
2430        /**
2431         * The lazy threshold.
2432         * This is the number of pixels, in advance of becoming visible, when an lazy-loading image should begin
2433         * to load.
2434         *
2435         * @memberof Image
2436         * @type {Number}
2437         * @default 0
2438         */
2439        "lazythreshold": {
2440            "default": 0,
2441            "transform": function(value) {
2442                var val =  parseInt(value);
2443                if (isNaN(val)) {
2444                    return LAZY_THRESHOLD_DEFAULT;
2445                }
2446                return val;
2447            }
2448        },
2449        /**
2450         * The image source.
2451         *
2452         * Can be a simple image source, or a URI template representation that
2453         * can be variable expanded - useful for building an image configuration with an alternative width.
2454         * e.g. '/path/image.coreimg{.width}.jpeg/1506620954214.jpeg'
2455         *
2456         * @memberof Image
2457         * @type {String}
2458         */
2459        "src": {
2460            "transform": function(value) {
2461                return decodeURIComponent(value);
2462            }
2463        }
2464    };
2465
2466    var devicePixelRatio = window.devicePixelRatio || 1;
2467
2468    function Image(config) {
2469        var that = this;
2470
2471        var smartCrops = {};
2472
2473        var useAssetDelivery = false;
2474        var srcUriTemplateWidthVar = SRC_URI_TEMPLATE_WIDTH_VAR;
2475
2476        function init(config) {
2477            // prevents multiple initialization
2478            config.element.removeAttribute("data-" + NS + "-is");
2479
2480            // check if asset delivery is used
2481            if (config.options.src && config.options.src.indexOf(SRC_URI_TEMPLATE_WIDTH_VAR_ASSET_DELIVERY) >= 0) {
2482                useAssetDelivery = true;
2483                srcUriTemplateWidthVar = SRC_URI_TEMPLATE_WIDTH_VAR_ASSET_DELIVERY;
2484            }
2485
2486            that._properties = CMP.utils.setupProperties(config.options, properties);
2487            cacheElements(config.element);
2488            // check image is DM asset; if true try to make req=set
2489            if (config.options.src && Object.prototype.hasOwnProperty.call(config.options, "dmimage") && (config.options["smartcroprendition"] === "SmartCrop:Auto")) {
2490                smartCrops = CMP.image.dynamicMedia.getAutoSmartCrops(config.options.src);
2491            }
2492
2493            if (!that._elements.noscript) {
2494                return;
2495            }
2496
2497            that._elements.container = that._elements.link ? that._elements.link : that._elements.self;
2498
2499            unwrapNoScript();
2500
2501            if (that._properties.lazy) {
2502                addLazyLoader();
2503            }
2504
2505            if (that._elements.map) {
2506                that._elements.image.addEventListener("load", onLoad);
2507            }
2508
2509            window.addEventListener("resize", onWindowResize);
2510            ["focus", "click", "load", "transitionend", "animationend", "scroll"].forEach(function(name) {
2511                document.addEventListener(name, that.update);
2512            });
2513
2514            that._elements.image.addEventListener("cmp-image-redraw", that.update);
2515
2516            that._interSectionObserver = new IntersectionObserver(function(entries, interSectionObserver) {
2517                entries.forEach(function(entry) {
2518                    if (entry.intersectionRatio > 0) {
2519                        that.update();
2520                    }
2521                });
2522            });
2523            that._interSectionObserver.observe(that._elements.self);
2524
2525            that.update();
2526        }
2527
2528        function loadImage() {
2529            var hasWidths = (that._properties.widths && that._properties.widths.length > 0) || Object.keys(smartCrops).length > 0;
2530            var replacement;
2531            if (Object.keys(smartCrops).length > 0) {
2532                var optimalWidth = getOptimalWidth(Object.keys(smartCrops), false);
2533                replacement = smartCrops[optimalWidth];
2534            } else {
2535                replacement = hasWidths ? (that._properties.dmimage ? "" : ".") + getOptimalWidth(that._properties.widths, true) : "";
2536            }
2537            if (useAssetDelivery) {
2538                replacement = replacement !== "" ? ("width=" + replacement.substring(1)) : "";
2539            }
2540            var url = that._properties.src.replace(srcUriTemplateWidthVar, replacement);
2541            url = url.replace(SRC_URI_TEMPLATE_DPR_VAR, devicePixelRatio);
2542
2543            var imgSrcAttribute = that._elements.image.getAttribute("src");
2544
2545            if (url !== imgSrcAttribute) {
2546                if (imgSrcAttribute === null || imgSrcAttribute === EMPTY_PIXEL) {
2547                    that._elements.image.setAttribute("src", url);
2548                } else {
2549                    var urlTemplateParts = that._properties.src.split(srcUriTemplateWidthVar);
2550                    // check if image src was dynamically swapped meanwhile (e.g. by Target)
2551                    var isImageRefSame = imgSrcAttribute.startsWith(urlTemplateParts[0]);
2552                    if (isImageRefSame && urlTemplateParts.length > 1) {
2553                        isImageRefSame = imgSrcAttribute.endsWith(urlTemplateParts[urlTemplateParts.length - 1]);
2554                    }
2555                    if (isImageRefSame) {
2556                        that._elements.image.setAttribute("src", url);
2557                        if (!hasWidths) {
2558                            window.removeEventListener("scroll", that.update);
2559                        }
2560                    }
2561                }
2562            }
2563            if (that._lazyLoaderShowing) {
2564                that._elements.image.addEventListener("load", removeLazyLoader);
2565            }
2566            that._interSectionObserver.unobserve(that._elements.self);
2567        }
2568
2569        function getOptimalWidth(widths, useDevicePixelRatio) {
2570            var container = that._elements.self;
2571            var containerWidth = container.clientWidth;
2572            while (containerWidth === 0 && container.parentNode) {
2573                container = container.parentNode;
2574                containerWidth = container.clientWidth;
2575            }
2576
2577            var dpr = useDevicePixelRatio ? devicePixelRatio : 1;
2578            var optimalWidth = containerWidth * dpr;
2579            var len = widths.length;
2580            var key = 0;
2581
2582            while ((key < len - 1) && (widths[key] < optimalWidth)) {
2583                key++;
2584            }
2585
2586            return widths[key].toString();
2587        }
2588
2589        function addLazyLoader() {
2590            var width = that._elements.image.getAttribute("width");
2591            var height = that._elements.image.getAttribute("height");
2592
2593            if (width && height) {
2594                var ratio = (height / width) * 100;
2595                var styles = lazyLoader.style;
2596
2597                styles["padding-bottom"] = ratio + "%";
2598
2599                for (var s in styles) {
2600                    if (Object.prototype.hasOwnProperty.call(styles, s)) {
2601                        that._elements.image.style[s] = styles[s];
2602                    }
2603                }
2604            }
2605            that._elements.image.setAttribute("src", EMPTY_PIXEL);
2606            that._elements.image.classList.add(lazyLoader.cssClass);
2607            that._lazyLoaderShowing = true;
2608        }
2609
2610        function unwrapNoScript() {
2611            var markup = decodeNoscript(that._elements.noscript.textContent.trim());
2612            var parser = new DOMParser();
2613
2614            // temporary document avoids requesting the image before removing its src
2615            var temporaryDocument = parser.parseFromString(markup, "text/html");
2616            var imageElement = temporaryDocument.querySelector(selectors.image);
2617            imageElement.removeAttribute("src");
2618            that._elements.container.insertBefore(imageElement, that._elements.noscript);
2619
2620            var mapElement = temporaryDocument.querySelector(selectors.map);
2621            if (mapElement) {
2622                that._elements.container.insertBefore(mapElement, that._elements.noscript);
2623            }
2624
2625            that._elements.noscript.parentNode.removeChild(that._elements.noscript);
2626            if (that._elements.container.matches(selectors.image)) {
2627                that._elements.image = that._elements.container;
2628            } else {
2629                that._elements.image = that._elements.container.querySelector(selectors.image);
2630            }
2631
2632            that._elements.map = that._elements.container.querySelector(selectors.map);
2633            that._elements.areas = that._elements.container.querySelectorAll(selectors.area);
2634        }
2635
2636        function removeLazyLoader() {
2637            that._elements.image.classList.remove(lazyLoader.cssClass);
2638            for (var property in lazyLoader.style) {
2639                if (Object.prototype.hasOwnProperty.call(lazyLoader.style, property)) {
2640                    that._elements.image.style[property] = "";
2641                }
2642            }
2643            that._elements.image.removeEventListener("load", removeLazyLoader);
2644            that._lazyLoaderShowing = false;
2645        }
2646
2647        function isLazyVisible() {
2648            if (that._elements.container.offsetParent === null) {
2649                return false;
2650            }
2651
2652            var wt = window.pageYOffset;
2653            var wb = wt + document.documentElement.clientHeight;
2654            var et = that._elements.container.getBoundingClientRect().top + wt;
2655            var eb = et + that._elements.container.clientHeight;
2656
2657            return eb >= wt - that._properties.lazythreshold && et <= wb + that._properties.lazythreshold;
2658        }
2659
2660        function resizeAreas() {
2661            if (that._elements.areas && that._elements.areas.length > 0) {
2662                for (var i = 0; i < that._elements.areas.length; i++) {
2663                    var width = that._elements.image.width;
2664                    var height = that._elements.image.height;
2665
2666                    if (width && height) {
2667                        var relcoords = that._elements.areas[i].dataset.cmpRelcoords;
2668                        if (relcoords) {
2669                            var relativeCoordinates = relcoords.split(",");
2670                            var coordinates = new Array(relativeCoordinates.length);
2671
2672                            for (var j = 0; j < coordinates.length; j++) {
2673                                if (j % 2 === 0) {
2674                                    coordinates[j] = parseInt(relativeCoordinates[j] * width);
2675                                } else {
2676                                    coordinates[j] = parseInt(relativeCoordinates[j] * height);
2677                                }
2678                            }
2679
2680                            that._elements.areas[i].coords = coordinates;
2681                        }
2682                    }
2683                }
2684            }
2685        }
2686
2687        function cacheElements(wrapper) {
2688            that._elements = {};
2689            that._elements.self = wrapper;
2690            var hooks = that._elements.self.querySelectorAll("[data-" + NS + "-hook-" + IS + "]");
2691
2692            for (var i = 0; i < hooks.length; i++) {
2693                var hook = hooks[i];
2694                var capitalized = IS;
2695                capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
2696                var key = hook.dataset[NS + "Hook" + capitalized];
2697                that._elements[key] = hook;
2698            }
2699        }
2700
2701        function onWindowResize() {
2702            that.update();
2703            resizeAreas();
2704        }
2705
2706        function onLoad() {
2707            resizeAreas();
2708        }
2709
2710        that.update = function() {
2711            if (that._properties.lazy) {
2712                if (isLazyVisible()) {
2713                    loadImage();
2714                }
2715            } else {
2716                loadImage();
2717            }
2718        };
2719
2720        if (config && config.element) {
2721            init(config);
2722        }
2723    }
2724
2725    function onDocumentReady() {
2726        var elements = document.querySelectorAll(selectors.self);
2727        for (var i = 0; i < elements.length; i++) {
2728            new Image({ element: elements[i], options: CMP.utils.readData(elements[i], IS) });
2729        }
2730
2731        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
2732        var body             = document.querySelector("body");
2733        var observer         = new MutationObserver(function(mutations) {
2734            mutations.forEach(function(mutation) {
2735                // needed for IE
2736                var nodesArray = [].slice.call(mutation.addedNodes);
2737                if (nodesArray.length > 0) {
2738                    nodesArray.forEach(function(addedNode) {
2739                        if (addedNode.querySelectorAll) {
2740                            var elementsArray = [].slice.call(addedNode.querySelectorAll(selectors.self));
2741                            elementsArray.forEach(function(element) {
2742                                new Image({ element: element, options: CMP.utils.readData(element, IS) });
2743                            });
2744                        }
2745                    });
2746                }
2747            });
2748        });
2749
2750        observer.observe(body, {
2751            subtree: true,
2752            childList: true,
2753            characterData: true
2754        });
2755    }
2756
2757    var documentReady = document.readyState !== "loading" ? Promise.resolve() : new Promise(function(resolve) {
2758        document.addEventListener("DOMContentLoaded", resolve);
2759    });
2760
2761    Promise.all([documentReady]).then(onDocumentReady);
2762    /*
2763        on drag & drop of the component into a parsys, noscript's content will be escaped multiple times by the editor which creates
2764        the DOM for editing; the HTML parser cannot be used here due to the multiple escaping
2765     */
2766    function decodeNoscript(text) {
2767        text = text.replace(/&(amp;)*lt;/g, "<");
2768        text = text.replace(/&(amp;)*gt;/g, ">");
2769        return text;
2770    }
2771
2772})();
2773
2774
2775/*******************************************************************************
2776 * Copyright 2017 Adobe
2777 *
2778 * Licensed under the Apache License, Version 2.0 (the "License");
2779 * you may not use this file except in compliance with the License.
2780 * You may obtain a copy of the License at
2781 *
2782 *     http://www.apache.org/licenses/LICENSE-2.0
2783 *
2784 * Unless required by applicable law or agreed to in writing, software
2785 * distributed under the License is distributed on an "AS IS" BASIS,
2786 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2787 * See the License for the specific language governing permissions and
2788 * limitations under the License.
2789 ******************************************************************************/
2790(function() {
2791    "use strict";
2792
2793    var NS = "cmp";
2794    var IS = "search";
2795
2796    var DELAY = 300; // time before fetching new results when the user is typing a search string
2797    var LOADING_DISPLAY_DELAY = 300; // minimum time during which the loading indicator is displayed
2798    var PARAM_RESULTS_OFFSET = "resultsOffset";
2799
2800    var keyCodes = {
2801        TAB: 9,
2802        ENTER: 13,
2803        ESCAPE: 27,
2804        ARROW_UP: 38,
2805        ARROW_DOWN: 40
2806    };
2807
2808    var selectors = {
2809        self: "[data-" + NS + '-is="' + IS + '"]',
2810        item: {
2811            self: "[data-" + NS + "-hook-" + IS + '="item"]',
2812            title: "[data-" + NS + "-hook-" + IS + '="itemTitle"]',
2813            focused: "." + NS + "-search__item--is-focused"
2814        }
2815    };
2816
2817    var properties = {
2818        /**
2819         * The minimum required length of the search term before results are fetched.
2820         *
2821         * @memberof Search
2822         * @type {Number}
2823         * @default 3
2824         */
2825        minLength: {
2826            "default": 3,
2827            transform: function(value) {
2828                value = parseFloat(value);
2829                return isNaN(value) ? null : value;
2830            }
2831        },
2832        /**
2833         * The maximal number of results fetched by a search request.
2834         *
2835         * @memberof Search
2836         * @type {Number}
2837         * @default 10
2838         */
2839        resultsSize: {
2840            "default": 10,
2841            transform: function(value) {
2842                value = parseFloat(value);
2843                return isNaN(value) ? null : value;
2844            }
2845        }
2846    };
2847
2848    var idCount = 0;
2849
2850    function readData(element) {
2851        var data = element.dataset;
2852        var options = [];
2853        var capitalized = IS;
2854        capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
2855        var reserved = ["is", "hook" + capitalized];
2856
2857        for (var key in data) {
2858            if (Object.prototype.hasOwnProperty.call(data, key)) {
2859                var value = data[key];
2860
2861                if (key.indexOf(NS) === 0) {
2862                    key = key.slice(NS.length);
2863                    key = key.charAt(0).toLowerCase() + key.substring(1);
2864
2865                    if (reserved.indexOf(key) === -1) {
2866                        options[key] = value;
2867                    }
2868                }
2869            }
2870        }
2871
2872        return options;
2873    }
2874
2875    function toggleShow(element, show) {
2876        if (element) {
2877            if (show !== false) {
2878                element.style.display = "block";
2879                element.setAttribute("aria-hidden", false);
2880            } else {
2881                element.style.display = "none";
2882                element.setAttribute("aria-hidden", true);
2883            }
2884        }
2885    }
2886
2887    function serialize(form) {
2888        var query = [];
2889        if (form && form.elements) {
2890            for (var i = 0; i < form.elements.length; i++) {
2891                var node = form.elements[i];
2892                if (!node.disabled && node.name) {
2893                    var param = [node.name, encodeURIComponent(node.value)];
2894                    query.push(param.join("="));
2895                }
2896            }
2897        }
2898        return query.join("&");
2899    }
2900
2901    function mark(node, regex) {
2902        if (!node || !regex) {
2903            return;
2904        }
2905
2906        // text nodes
2907        if (node.nodeType === 3) {
2908            var nodeValue = node.nodeValue;
2909            var match = regex.exec(nodeValue);
2910
2911            if (nodeValue && match) {
2912                var element = document.createElement("mark");
2913                element.className = NS + "-search__item-mark";
2914                element.appendChild(document.createTextNode(match[0]));
2915
2916                var after = node.splitText(match.index);
2917                after.nodeValue = after.nodeValue.substring(match[0].length);
2918                node.parentNode.insertBefore(element, after);
2919            }
2920        } else if (node.hasChildNodes()) {
2921            for (var i = 0; i < node.childNodes.length; i++) {
2922                // recurse
2923                mark(node.childNodes[i], regex);
2924            }
2925        }
2926    }
2927
2928    function Search(config) {
2929        if (config.element) {
2930            // prevents multiple initialization
2931            config.element.removeAttribute("data-" + NS + "-is");
2932        }
2933
2934        this._cacheElements(config.element);
2935        this._setupProperties(config.options);
2936
2937        this._action = this._elements.form.getAttribute("action");
2938        this._resultsOffset = 0;
2939        this._hasMoreResults = true;
2940
2941        this._elements.input.addEventListener("input", this._onInput.bind(this));
2942        this._elements.input.addEventListener("focus", this._onInput.bind(this));
2943        this._elements.input.addEventListener("keydown", this._onKeydown.bind(this));
2944        this._elements.clear.addEventListener("click", this._onClearClick.bind(this));
2945        document.addEventListener("click", this._onDocumentClick.bind(this));
2946        this._elements.results.addEventListener("scroll", this._onScroll.bind(this));
2947
2948        this._makeAccessible();
2949    }
2950
2951    Search.prototype._displayResults = function() {
2952        if (this._elements.input.value.length === 0) {
2953            toggleShow(this._elements.clear, false);
2954            this._cancelResults();
2955        } else if (this._elements.input.value.length < this._properties.minLength) {
2956            toggleShow(this._elements.clear, true);
2957        } else {
2958            this._updateResults();
2959            toggleShow(this._elements.clear, true);
2960        }
2961    };
2962
2963    Search.prototype._onScroll = function(event) {
2964        // fetch new results when the results to be scrolled down are less than the visible results
2965        if (this._elements.results.scrollTop + 2 * this._elements.results.clientHeight >= this._elements.results.scrollHeight) {
2966            this._resultsOffset += this._properties.resultsSize;
2967            this._displayResults();
2968        }
2969    };
2970
2971    Search.prototype._onInput = function(event) {
2972        var self = this;
2973        self._cancelResults();
2974        // start searching when the search term reaches the minimum length
2975        this._timeout = setTimeout(function() {
2976            self._displayResults();
2977        }, DELAY);
2978    };
2979
2980    Search.prototype._onKeydown = function(event) {
2981        var self = this;
2982
2983        switch (event.keyCode) {
2984            case keyCodes.TAB:
2985                if (self._resultsOpen()) {
2986                    toggleShow(self._elements.results, false);
2987                    self._elements.input.setAttribute("aria-expanded", "false");
2988                }
2989                break;
2990            case keyCodes.ENTER:
2991                event.preventDefault();
2992                if (self._resultsOpen()) {
2993                    var focused = self._elements.results.querySelector(selectors.item.focused);
2994                    if (focused) {
2995                        focused.click();
2996                    }
2997                }
2998                break;
2999            case keyCodes.ESCAPE:
3000                self._cancelResults();
3001                break;
3002            case keyCodes.ARROW_UP:
3003                if (self._resultsOpen()) {
3004                    event.preventDefault();
3005                    self._stepResultFocus(true);
3006                }
3007                break;
3008            case keyCodes.ARROW_DOWN:
3009                if (self._resultsOpen()) {
3010                    event.preventDefault();
3011                    self._stepResultFocus();
3012                } else {
3013                    // test the input and if necessary fetch and display the results
3014                    self._onInput();
3015                }
3016                break;
3017            default:
3018                return;
3019        }
3020    };
3021
3022    Search.prototype._onClearClick = function(event) {
3023        event.preventDefault();
3024        this._elements.input.value = "";
3025        toggleShow(this._elements.clear, false);
3026        toggleShow(this._elements.results, false);
3027        this._elements.input.setAttribute("aria-expanded", "false");
3028    };
3029
3030    Search.prototype._onDocumentClick = function(event) {
3031        var inputContainsTarget =  this._elements.input.contains(event.target);
3032        var resultsContainTarget = this._elements.results.contains(event.target);
3033
3034        if (!(inputContainsTarget || resultsContainTarget)) {
3035            toggleShow(this._elements.results, false);
3036            this._elements.input.setAttribute("aria-expanded", "false");
3037        }
3038    };
3039
3040    Search.prototype._resultsOpen = function() {
3041        return this._elements.results.style.display !== "none";
3042    };
3043
3044    Search.prototype._makeAccessible = function() {
3045        var id = NS + "-search-results-" + idCount;
3046        this._elements.input.setAttribute("aria-owns", id);
3047        this._elements.results.id = id;
3048        idCount++;
3049    };
3050
3051    Search.prototype._generateItems = function(data, results) {
3052        var self = this;
3053
3054        data.forEach(function(item) {
3055            var el = document.createElement("span");
3056            el.innerHTML = self._elements.itemTemplate.innerHTML;
3057            el.querySelectorAll(selectors.item.title)[0].appendChild(document.createTextNode(item.title));
3058            el.querySelectorAll(selectors.item.self)[0].setAttribute("href", self._safeHref(item.url));
3059            results.innerHTML += el.innerHTML;
3060        });
3061    };
3062
3063    Search.prototype._safeHref = function(href) {
3064        var a = document.createElement("a");
3065        a.href = href;
3066        return a.pathname;
3067    };
3068
3069    Search.prototype._markResults = function() {
3070        var nodeList = this._elements.results.querySelectorAll(selectors.item.self);
3071        var escapedTerm = this._elements.input.value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
3072        var regex = new RegExp("(" + escapedTerm + ")", "gi");
3073
3074        for (var i = this._resultsOffset - 1; i < nodeList.length; ++i) {
3075            var result = nodeList[i];
3076            mark(result, regex);
3077        }
3078    };
3079
3080    Search.prototype._stepResultFocus = function(reverse) {
3081        var results = this._elements.results.querySelectorAll(selectors.item.self);
3082        var focused = this._elements.results.querySelector(selectors.item.focused);
3083        var newFocused;
3084        var index = Array.prototype.indexOf.call(results, focused);
3085        var focusedCssClass = NS + "-search__item--is-focused";
3086
3087        if (results.length > 0) {
3088
3089            if (!reverse) {
3090                // highlight the next result
3091                if (index < 0) {
3092                    results[0].classList.add(focusedCssClass);
3093                    results[0].setAttribute("aria-selected", "true");
3094                } else if (index + 1 < results.length) {
3095                    results[index].classList.remove(focusedCssClass);
3096                    results[index].setAttribute("aria-selected", "false");
3097                    results[index + 1].classList.add(focusedCssClass);
3098                    results[index + 1].setAttribute("aria-selected", "true");
3099                }
3100
3101                // if the last visible result is partially hidden, scroll up until it's completely visible
3102                newFocused = this._elements.results.querySelector(selectors.item.focused);
3103                if (newFocused) {
3104                    var bottomHiddenHeight = newFocused.offsetTop + newFocused.offsetHeight - this._elements.results.scrollTop - this._elements.results.clientHeight;
3105                    if (bottomHiddenHeight > 0) {
3106                        this._elements.results.scrollTop += bottomHiddenHeight;
3107                    } else {
3108                        this._onScroll();
3109                    }
3110                }
3111
3112            } else {
3113                // highlight the previous result
3114                if (index >= 1) {
3115                    results[index].classList.remove(focusedCssClass);
3116                    results[index].setAttribute("aria-selected", "false");
3117                    results[index - 1].classList.add(focusedCssClass);
3118                    results[index - 1].setAttribute("aria-selected", "true");
3119                }
3120
3121                // if the first visible result is partially hidden, scroll down until it's completely visible
3122                newFocused = this._elements.results.querySelector(selectors.item.focused);
3123                if (newFocused) {
3124                    var topHiddenHeight = this._elements.results.scrollTop - newFocused.offsetTop;
3125                    if (topHiddenHeight > 0) {
3126                        this._elements.results.scrollTop -= topHiddenHeight;
3127                    }
3128                }
3129            }
3130        }
3131    };
3132
3133    Search.prototype._updateResults = function() {
3134        var self = this;
3135        if (self._hasMoreResults) {
3136            var request = new XMLHttpRequest();
3137            var url = self._action + "?" + serialize(self._elements.form) + "&" + PARAM_RESULTS_OFFSET + "=" + self._resultsOffset;
3138
3139            request.open("GET", url, true);
3140            request.onload = function() {
3141                // when the results are loaded: hide the loading indicator and display the search icon after a minimum period
3142                setTimeout(function() {
3143                    toggleShow(self._elements.loadingIndicator, false);
3144                    toggleShow(self._elements.icon, true);
3145                }, LOADING_DISPLAY_DELAY);
3146                if (request.status >= 200 && request.status < 400) {
3147                    // success status
3148                    var data = JSON.parse(request.responseText);
3149                    if (data.length > 0) {
3150                        self._generateItems(data, self._elements.results);
3151                        self._markResults();
3152                        toggleShow(self._elements.results, true);
3153                        self._elements.input.setAttribute("aria-expanded", "true");
3154                    } else {
3155                        self._hasMoreResults = false;
3156                    }
3157                    // the total number of results is not a multiple of the fetched results:
3158                    // -> we reached the end of the query
3159                    if (self._elements.results.querySelectorAll(selectors.item.self).length % self._properties.resultsSize > 0) {
3160                        self._hasMoreResults = false;
3161                    }
3162                } else {
3163                    // error status
3164                }
3165            };
3166            // when the results are loading: display the loading indicator and hide the search icon
3167            toggleShow(self._elements.loadingIndicator, true);
3168            toggleShow(self._elements.icon, false);
3169            request.send();
3170        }
3171    };
3172
3173    Search.prototype._cancelResults = function() {
3174        clearTimeout(this._timeout);
3175        this._elements.results.scrollTop = 0;
3176        this._resultsOffset = 0;
3177        this._hasMoreResults = true;
3178        this._elements.results.innerHTML = "";
3179        this._elements.input.setAttribute("aria-expanded", "false");
3180    };
3181
3182    Search.prototype._cacheElements = function(wrapper) {
3183        this._elements = {};
3184        this._elements.self = wrapper;
3185        var hooks = this._elements.self.querySelectorAll("[data-" + NS + "-hook-" + IS + "]");
3186
3187        for (var i = 0; i < hooks.length; i++) {
3188            var hook = hooks[i];
3189            var capitalized = IS;
3190            capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
3191            var key = hook.dataset[NS + "Hook" + capitalized];
3192            this._elements[key] = hook;
3193        }
3194    };
3195
3196    Search.prototype._setupProperties = function(options) {
3197        this._properties = {};
3198
3199        for (var key in properties) {
3200            if (Object.prototype.hasOwnProperty.call(properties, key)) {
3201                var property = properties[key];
3202                if (options && options[key] != null) {
3203                    if (property && typeof property.transform === "function") {
3204                        this._properties[key] = property.transform(options[key]);
3205                    } else {
3206                        this._properties[key] = options[key];
3207                    }
3208                } else {
3209                    this._properties[key] = properties[key]["default"];
3210                }
3211            }
3212        }
3213    };
3214
3215    function onDocumentReady() {
3216        var elements = document.querySelectorAll(selectors.self);
3217        for (var i = 0; i < elements.length; i++) {
3218            new Search({ element: elements[i], options: readData(elements[i]) });
3219        }
3220
3221        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
3222        var body = document.querySelector("body");
3223        var observer = new MutationObserver(function(mutations) {
3224            mutations.forEach(function(mutation) {
3225                // needed for IE
3226                var nodesArray = [].slice.call(mutation.addedNodes);
3227                if (nodesArray.length > 0) {
3228                    nodesArray.forEach(function(addedNode) {
3229                        if (addedNode.querySelectorAll) {
3230                            var elementsArray = [].slice.call(addedNode.querySelectorAll(selectors.self));
3231                            elementsArray.forEach(function(element) {
3232                                new Search({ element: element, options: readData(element) });
3233                            });
3234                        }
3235                    });
3236                }
3237            });
3238        });
3239
3240        observer.observe(body, {
3241            subtree: true,
3242            childList: true,
3243            characterData: true
3244        });
3245    }
3246
3247    if (document.readyState !== "loading") {
3248        onDocumentReady();
3249    } else {
3250        document.addEventListener("DOMContentLoaded", onDocumentReady);
3251    }
3252
3253})();
3254
3255
3256/*******************************************************************************
3257 * Copyright 2016 Adobe
3258 *
3259 * Licensed under the Apache License, Version 2.0 (the "License");
3260 * you may not use this file except in compliance with the License.
3261 * You may obtain a copy of the License at
3262 *
3263 *     http://www.apache.org/licenses/LICENSE-2.0
3264 *
3265 * Unless required by applicable law or agreed to in writing, softw
3265are
3266 * distributed under the License is distributed on an "AS IS" BASIS,
3267 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3268 * See the License for the specific language governing permissions and
3269 * limitations under the License.
3270 ******************************************************************************/
3271(function() {
3272    "use strict";
3273
3274    var NS = "cmp";
3275    var IS = "formText";
3276    var IS_DASH = "form-text";
3277    var SELF_SELECTOR = "[data-" + NS + '-is="' + IS + '"]';
3278
3279    var selectors = {
3280        self: SELF_SELECTOR,
3281        validationMessage: SELF_SELECTOR + " .cmp-form-text__validation-message"
3282    };
3283
3284    var displayValidationMessage = false;
3285
3286    var properties = {
3287        /**
3288         * A validation message to display if there is a type mismatch between the user input and expected input.
3289         *
3290         * @type {String}
3291         */
3292        constraintMessage: "",
3293        /**
3294         * A validation message to display if no input is supplied, but input is expected for the field.
3295         *
3296         * @type {String}
3297         */
3298        requiredMessage: ""
3299    };
3300
3301    function readData(element) {
3302        var data = element.dataset;
3303        var options = [];
3304        var capitalized = IS;
3305        capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
3306        var reserved = ["is", "hook" + capitalized];
3307
3308        for (var key in data) {
3309            if (Object.prototype.hasOwnProperty.call(data, key)) {
3310                var value = data[key];
3311
3312                if (key.indexOf(NS) === 0) {
3313                    key = key.slice(NS.length);
3314                    key = key.charAt(0).toLowerCase() + key.substring(1);
3315
3316                    if (reserved.indexOf(key) === -1) {
3317                        options[key] = value;
3318                    }
3319                }
3320            }
3321        }
3322
3323        return options;
3324    }
3325
3326    function FormText(config) {
3327        if (config.element) {
3328            // prevents multiple initialization
3329            config.element.removeAttribute("data-" + NS + "-is");
3330        }
3331
3332        this._cacheElements(config.element);
3333        this._setupProperties(config.options);
3334
3335        this._elements.input.addEventListener("invalid", this._onInvalid.bind(this));
3336        this._elements.input.addEventListener("input", this._onInput.bind(this));
3337        if (displayValidationMessage) {
3338            this._elements.input.checkValidity();
3339        }
3340    }
3341
3342    FormText.prototype._onInvalid = function(event) {
3343        event.target.setCustomValidity("");
3344        if (event.target.validity.typeMismatch) {
3345            if (this._properties.constraintMessage) {
3346                event.target.setCustomValidity(this._properties.constraintMessage);
3347            }
3348        } else if (event.target.validity.valueMissing) {
3349            if (this._properties.requiredMessage) {
3350                event.target.setCustomValidity(this._properties.requiredMessage);
3351            }
3352        }
3353        if (displayValidationMessage) {
3354            var validationMessage = event.target.parentElement.querySelector(".cmp-form-text__validation-message");
3355            if (validationMessage) {
3356                validationMessage.innerText = event.target.validationMessage;
3357            }
3358        }
3359    };
3360
3361    FormText.prototype._onInput = function(event) {
3362        event.target.setCustomValidity("");
3363        if (displayValidationMessage) {
3364            event.target.checkValidity();
3365        }
3366    };
3367
3368    FormText.prototype._cacheElements = function(wrapper) {
3369        this._elements = {};
3370        this._elements.self = wrapper;
3371        var hooks = this._elements.self.querySelectorAll("[data-" + NS + "-hook-" + IS_DASH + "]");
3372        for (var i = 0; i < hooks.length; i++) {
3373            var hook = hooks[i];
3374            var capitalized = IS;
3375            capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1);
3376            var key = hook.dataset[NS + "Hook" + capitalized];
3377            this._elements[key] = hook;
3378        }
3379    };
3380
3381    FormText.prototype._setupProperties = function(options) {
3382        this._properties = {};
3383
3384        for (var key in properties) {
3385            if (Object.prototype.hasOwnProperty.call(properties, key)) {
3386                var property = properties[key];
3387                if (options && options[key] != null) {
3388                    if (property && typeof property.transform === "function") {
3389                        this._properties[key] = property.transform(options[key]);
3390                    } else {
3391                        this._properties[key] = options[key];
3392                    }
3393                } else {
3394                    this._properties[key] = properties[key]["default"];
3395                }
3396            }
3397        }
3398    };
3399
3400    function onDocumentReady() {
3401        var validationMessages = document.querySelectorAll(selectors.validationMessage);
3402        if (validationMessages && validationMessages.length > 0) {
3403            displayValidationMessage = true;
3404        }
3405
3406        var elements = document.querySelectorAll(selectors.self);
3407        for (var i = 0; i < elements.length; i++) {
3408            new FormText({ element: elements[i], options: readData(elements[i]) });
3409        }
3410
3411        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
3412        var body = document.querySelector("body");
3413        var observer = new MutationObserver(function(mutations) {
3414            mutations.forEach(function(mutation) {
3415                // needed for IE
3416                var nodesArray = [].slice.call(mutation.addedNodes);
3417                if (nodesArray.length > 0) {
3418                    nodesArray.forEach(function(addedNode) {
3419                        if (addedNode.querySelectorAll) {
3420                            var elementsArray = [].slice.call(addedNode.querySelectorAll(selectors.self));
3421                            elementsArray.forEach(function(element) {
3422                                new FormText({ element: element, options: readData(element) });
3423                            });
3424                        }
3425                    });
3426                }
3427            });
3428        });
3429
3430        observer.observe(body, {
3431            subtree: true,
3432            childList: true,
3433            characterData: true
3434        });
3435    }
3436
3437    if (document.readyState !== "loading") {
3438        onDocumentReady();
3439    } else {
3440        document.addEventListener("DOMContentLoaded", onDocumentReady);
3441    }
3442
3443})();
3444
3445
3446/*******************************************************************************
3447 * Copyright 2020 Adobe
3448 *
3449 * Licensed under the Apache License, Version 2.0 (the "License");
3450 * you may not use this file except in compliance with the License.
3451 * You may obtain a copy of the License at
3452 *
3453 *     http://www.apache.org/licenses/LICENSE-2.0
3454 *
3455 * Unless required by applicable law or agreed to in writing, software
3456 * distributed under the License is distributed on an "AS IS" BASIS,
3457 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3458 * See the License for the specific language governing permissions and
3459 * limitations under the License.
3460 ******************************************************************************/
3461(function() {
3462    "use strict";
3463
3464    var NS = "cmp";
3465    var IS = "pdfviewer";
3466    var SDK_URL = "https://acrobatservices.adobe.com/view-sdk/viewer.js";
3467    var SDK_READY_EVENT = "adobe_dc_view_sdk.ready";
3468
3469    var selectors = {
3470        self: "[data-" + NS + '-is="' + IS + '"]',
3471        sdkScript: 'script[src="' + SDK_URL + '"]'
3472    };
3473
3474    function initSDK() {
3475        var sdkIncluded = document.querySelectorAll(selectors.sdkScript).length > 0;
3476        if (!window.adobe_dc_view_sdk && !sdkIncluded) {
3477            var dcv = document.createElement("script");
3478            dcv.type = "text/javascript";
3479            dcv.src = SDK_URL;
3480            document.body.appendChild(dcv);
3481        }
3482    }
3483
3484    function previewPdf(component) {
3485        // prevents multiple initialization
3486        component.removeAttribute("data-" + NS + "-is");
3487
3488        // add the view sdk to the page
3489        initSDK();
3490
3491        // manage the preview
3492        if (component.dataset && component.id) {
3493            if (window.AdobeDC && window.AdobeDC.View) {
3494                dcView(component);
3495            } else {
3496                document.addEventListener(SDK_READY_EVENT, function() {
3497                    dcView(component);
3498                });
3499            }
3500        }
3501    }
3502
3503    function dcView(component) {
3504        var adobeDCView = new window.AdobeDC.View({
3505            clientId: component.dataset.cmpClientId,
3506            divId: component.id + "-content",
3507            reportSuiteId: component.dataset.cmpReportSuiteId,
3508            locale: typeof Granite !== "undefined" && Granite && Granite.I18n ? Granite.I18n.getLocale() : navigator.language || navigator.userLanguage
3509        });
3510        adobeDCView.previewFile({
3511            content: { location: { url: component.dataset.cmpDocumentPath } },
3512            metaData: { fileName: component.dataset.cmpDocumentFileName }
3513        }, JSON.parse(component.dataset.cmpViewerConfigJson));
3514    }
3515
3516    /**
3517     * Document ready handler and DOM mutation observers. Initializes Accordion components as necessary.
3518     *
3519     * @private
3520     */
3521    function onDocumentReady() {
3522        var elements = document.querySelectorAll(selectors.self);
3523        for (var i = 0; i < elements.length; i++) {
3524            previewPdf(elements[i]);
3525        }
3526
3527        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
3528        var body = document.querySelector("body");
3529        var observer = new MutationObserver(function(mutations) {
3530            mutations.forEach(function(mutation) {
3531                // needed for IE
3532                var nodesArray = [].slice.call(mutation.addedNodes);
3533                if (nodesArray.length > 0) {
3534                    nodesArray.forEach(function(addedNode) {
3535                        if (addedNode.querySelectorAll) {
3536                            var elementsArray = [].slice.call(addedNode.querySelectorAll(selectors.self));
3537                            elementsArray.forEach(function(element) {
3538                                previewPdf(element);
3539                            });
3540                        }
3541                    });
3542                }
3543            });
3544        });
3545
3546        observer.observe(body, {
3547            subtree: true,
3548            childList: true,
3549            characterData: true
3550        });
3551
3552    }
3553
3554    if (document.readyState !== "loading") {
3555        onDocumentReady();
3556    } else {
3557        document.addEventListener("DOMContentLoaded", onDocumentReady);
3558    }
3559}());
3560
3561
3562/*! js-cookie v2.2.1 | MIT */
3563
3564!function (a) { var b; if ("function" == typeof define && define.amd && (define(a), b = !0), "object" == typeof exports && (module.exports = a(), b = !0), !b) { var c = window.Cookies, d = window.Cookies = a(); d.noConflict = function () { return window.Cookies = c, d } } }(function () { function a() { for (var a = 0, b = {}; a < arguments.length; a++) { var c = arguments[a]; for (var d in c) b[d] = c[d] } return b } function b(a) { return a.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent) } function c(d) { function e() { } function f(b, c, f) { if ("undefined" != typeof document) { f = a({ path: "/" }, e.defaults, f), "number" == typeof f.expires && (f.expires = new Date(1 * new Date + 864e5 * f.expires)), f.expires = f.expires ? f.expires.toUTCString() : ""; try { var g = JSON.stringify(c); /^[\{\[]/.test(g) && (c = g) } catch (j) { } c = d.write ? d.write(c, b) : encodeURIComponent(c + "").replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent), b = encodeURIComponent(b + "").replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
3564 var h = ""; for (var i in f) f[i] && (h += "; " + i, !0 !== f[i] && (h += "=" + f[i].split(";")[0])); return document.cookie = b + "=" + c + h } } function g(a, c) { if ("undefined" != typeof document) { for (var e = {}, f = document.cookie ? document.cookie.split("; ") : [], g = 0; g < f.length; g++) { var h = f[g].split("="), i = h.slice(1).join("="); c || '"' !== i.charAt(0) || (i = i.slice(1, -1)); try { var j = b(h[0]); if (i = (d.read || d)(i, j) || b(i), c) try { i = JSON.parse(i) } catch (k) { } if (e[j] = i, a === j) break } catch (k) { } } return a ? e[a] : e } } return e.set = f, e.get = function (a) { return g(a, !1) }, e.getJSON = function (a) { return g(a, !0) }, e.remove = function (b, c) { f(b, "", a(c, { expires: -1 })) }, e.defaults = {}, e.withConverter = c, e } return c(function () { }) });
3565$(document).ready(function () {
3566
3567	const cookieName = 'brand-portal-user';
3568	let patientCookie = 'argenxde-patient--mg';
3569	let isTrueSet = false;
3570	const patientCugElem = document?.querySelector('#patientCug');
3571	const patientCUG = patientCugElem?.dataset?.patientCug;
3572	isTrueSet = (String(patientCUG)?.toLowerCase() === 'true');
3573
3574	if (isTrueSet) {
3575		// Myargenxde Patient form
3576		const patientErrorMG = $('#patient-modal--mg .form-signin h4.form-signin-heading');
3577		const patientErrorCIDP = $('#patient-modal--cidp .form-signin h4.form-signin-heading');
3578		patientErrorMG?.hide();
3579		patientErrorCIDP?.hide();
3580
3581		$(".cmp-cug-login input[type=password]").each(function () {
3582			$(this).on("keyup", function (event) {
3583				if (event.keyCode === 13) {
3584					$(this).closest(".cmp-cug-login").find(".cug-login-button").click();
3585				}
3586			});
3587		});
3588		
3589		$(".cug-login-button").each(function (index, element) {
3590			submitPatientCUG($(element)); // wrap in jQuery object
3591		});
3592		
3593		function submitPatientCUG($patientCUGLoginBtn) {
3594			$patientCUGLoginBtn.off("click").on("click", function (e) {
3595				e.preventDefault();
3596		
3597				let $this = $(this);
3598				let formCUG = $this.closest('#patient-modal--mg');
3599				patientCookie = 'argenxde-patient--mg';
3600		
3601				if (!formCUG.length) {
3602					formCUG = $this.closest('#patient-modal--cidp');
3603					patientCookie = 'argenxde-patient--cidp';
3604				}
3605		
3606				const valid = validateForm(formCUG);
3607		
3608				if (valid) {
3609					$.ajax({
3610						type: "POST",
3611						url: $('#url').val(),
3612						data: {
3613							j_username: formCUG.find('input[type=text]').val(),
3614							j_password: formCUG.find('input[type=password]').val(),
3615							j_validate: "true"
3616						},
3617						success: function (data, textStatus, jqXHR) {
3618							const user = formCUG.find('input[type=text]').val();
3619							if(user.includes('mg')) {
3620								sessionStorage.setItem("patientLoginMethod","gmg");
3621								document.cookie = "argenxde-patient--cidp=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
3622							} else {
3623								sessionStorage.setItem("patientLoginMethod","cidp");
3624								document.cookie = "argenxde-patient--mg=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
3625							}
3626							if (user) {
3627								Cookies.set(patientCookie, user, { path: '/', expires: 0.0208 });
3628								window.location.href = getRedirectPath(formCUG.find('#redirect-url').val());
3629								sessionStorage.removeItem("redirectAfterLogin");
3630							}
3631						},
3632						error: function (XMLHttpRequest, textStatus, errorThrown) {
3633							formCUG.find('h4.form-signin-heading').show()
3634						}
3635					});
3636				} else {
3637					formCUG.find('h4.form-signin-heading').show()
3638				}
3639			});
3640		}
3641		
3642
3643		//Function to redirect to homepage after login
3644		const getRedirectPath = (redirectCUGPath) => {
3645			let redirectpath = '';
3646			const redirectUrl = sessionStorage.getItem("redirectAfterLogin");
3647			if (redirectUrl && redirectUrl !== '' && redirectUrl !== undefined) {
3648				redirectpath = redirectUrl;
3649			} else {
3650				redirectpath = redirectCUGPath
3651			}
3652			return redirectpath;
3653		}
3654
3655
3656		// Function for validating Login form
3657		const validateForm = (formCUG) => {
3658			let valid = false;
3659			if ((formCUG.find('#userId')?.attr('value')?.length > 0) && (formCUG.find("#inputPassword")?.val()?.length > 0)) {
3660				valid = true;
3661			}
3662			return valid;
3663		}
3664	} else {
3665		// Global CUG
3666		const checkCookie = () => {
3667			let user = Cookies.get(cookieName);
3668			if (user != "") {
3669				$("#userId").val(user);
3670			}
3671		}
3672		checkCookie();
3673		$("#inputPassword").keyup(function (event) {
3674			if (event.keyCode == 13) {
3675				$("#loginButton").click();
3676			}
3677		})
3678
3679		$("#loginButton").click(function (e) {
3680
3681			e.preventDefault();
3682
3683			var valid = validateForm();
3684			if (valid) {
3685				$.ajax({
3686					type: "POST",
3687					url: $('#url').val(),
3688					data: {
3689						j_username: $('#userId').val(),
3690						j_password: $("#inputPassword").val(),
3691						j_validate: "true"
3692					},
3693					success: function (data, textStatus, jqXHR) {
3694						let user = $('#userId').val();
3695						if (user != "" && user != null) {
3696							Cookies.set(cookieName, user, {
3697								path: '/'
3698							});
3699							window.location.href = getRedirectPath();
3700						}
3701
3702					},
3703					error: function (XMLHttpRequest, textStatus, errorThrown) {
3704						$("#errordiv").show().html("Invalid User Name or Password");
3705					}
3706				});
3707			} else {
3708				$("#errordiv").show().html("Please fill all the details");
3709			}
3710		});
3711
3712		//Function to redirect to a home/resource page after login
3713		const getRedirectPath = () => {
3714			const params = new URLSearchParams(window.location.search);
3715			const resource = params.get('resource');
3716			if(resource) {
3717				return resource;
3718			}
3719			const redirectpath = $('#redirect-url').val();
3720			if(redirectpath === '/') {
3721				return redirectpath;
3722			}
3723			return redirectpath + ".html";
3724		}
3725
3726
3727		// Function for validating Login form
3728		const validateForm = () => {
3729			let valid = false;
3730			if (($("#userId").val().length > 0) && ($("#inputPassword").val().length > 0)) {
3731				valid = true;
3732			}
3733			return valid;
3734		}
3735	}
3736
3737});
3738$(document).ready(function () {
3739    $( ".requestAccess" ).on( "click", requestAccess );
3740	const requestOverlay = document.querySelector('.requestaccess')
3741    function requestAccess(){
3742       requestOverlay.classList.add("show")
3743      document.documentElement.classList.add("body-scroll-lock")
3744    $(".requestaccess").show();
3745     $( ".request-access-close-btn" ).on( "click", overlayCloseBtn );
3746   }
3747    function overlayCloseBtn() {
3748        requestOverlay.classList.remove("show")
3749      document.documentElement.classList.remove("body-scroll-lock")
3750         $(".requestaccess").hide();
3751
3752
3753      }
3754});
3755$(document).ready(function () {
3756
3757    $( ".cmp-asset-download-btn" ).on( "click", downloadAssets );
3758
3759	function downloadAssets(){
3760		var paths;
3761		let urlPath = window.location.pathname;
3762		urlPath = urlPath.replace('.html','.download-folder.html');
3763		$.each($("input[name='assets']:checked"), function(index){
3764			console.log(index);
3765			let assetPath = $(this).attr('data-asset-path');
3766			if(index == 0) {
3767				paths = assetPath;
3768			} else {
3769				paths = paths + "," + assetPath;
3770			}
3771        });
3772		window.open(urlPath+'?assetPath='+paths, '_blank');
3773   }
3774});
3775$(document).ready(function () {
3776    var $isiMainWrapper = $('.cmp-isi-tray-main-wrapper');
3777    if($isiMainWrapper.length > 0){
3778        var position = $(window).scrollTop();
3779        var $isiTray = $('.cmp-isi-tray'),
3780            $window = $(window),
3781            $isiTrayCollapsed = $(".cmp-isi-tray--collapsed"),
3782            $scrollDownViewCollapse = $('.cmp-isi-tray--scrollDownView--collapsed'),
3783            $scrollDownViewPreCollapse = $('.cmp-isi-tray--scrollDownView--preCollapsed'),
3784            $isiFooter = $('#isi-page-section');
3785            $isiTrayCollapsed.addClass("expand");
3786            $preCollapsed = $('.cmp-isi-tray--pre-collapsed');
3787            $isiTrayExpanded = $('.cmp-isi-tray--expanded');
3788            $isiTrayChevronCollapsed = $(".cmp-isi-tray--chevron-collapse");
3789            $isiTrayChevronExpanded = $(".cmp-isi-tray--chevron-expand");
3790            $isiTrayBackDrop = $(".cmp-isi-tray-backdrop");
3791            $docBody = $("body");
3792        const maxHeightProp = $isiTray[0].style["max-height"];
3793        const isiTrayHeight = $isiTray.height();
3794        const initHeightSelector = $isiTray.data("initialHeightSelector");
3795        const initHeightSelectorPercentage = $isiTray.data("initialHeightSelectorPercentage");
3796        const initHeightSelectorPixel = $isiTray.data("initialHeightSelectorPixel");
3797        let inlineHeight = $isiTray[0].style["height"];
3798
3799        // authorable breakpoints functionality
3800        const breakpoints = $isiTray.data("breakpoints");
3801        const mediaQueries = [];
3802        function handleMediaQueryMatch(current) {
3803            if (current.matches) {
3804                for (let i = 0; i < mediaQueries.length; i++) {
3805                    if (mediaQueries[i].matches) {
3806                        inlineHeight = breakpoints[i].breakpointHeight;
3807                        $isiTray.css("height", breakpoints[i].breakpointHeight);
3808                    }
3809                }
3810            }
3811        }
3812        if (breakpoints && breakpoints.length) {
3813            for (let i = 0; i < breakpoints.length; i++) {
3814                mediaQueries.push(window.matchMedia(`(min-width: ${breakpoints[i].mediaQueryMin}) and (max-width: ${breakpoints[i].mediaQueryMax}) and (min-height: ${breakpoints[i].mediaQueryMinHeight}) and (max-height: ${breakpoints[i].mediaQueryMaxHeight})`));
3815                handleMediaQueryMatch(mediaQueries[i]);
3816                mediaQueries[i].addListener(handleMediaQueryMatch);
3817                if ($(window).width() > parseInt(breakpoints[breakpoints.length - 1].mediaQueryMax)) {
3818                    if (initHeightSelector == "percentage") {
3819                        setTimeout(function(){
3820                            inlineHeight = initHeightSelectorPercentage;
3821                            $isiTray.css("height", initHeightSelectorPercentage);
3822                        }, 0);
3823                    } else {
3824                        setTimeout(function(){
3825                            inlineHeight = initHeightSelectorPixel;
3826                            $isiTray.css("height", initHeightSelectorPixel);
3827                        }, 0);
3828                    }
3829                    break;
3830                }
3831            }
3832            console.log(mediaQueries);
3833        } else {
3834            if (initHeightSelector == "percentage") {
3835                $isiTray.css("height", initHeightSelectorPercentage);
3836            } else {
3837                $isiTray.css("height", initHeightSelectorPixel);
3838            }
3839        }
3840
3841        // check for cookie
3842        const cookieName = "argenx-isi-tray-collapsed";
3843        const cookieValue = Cookies.get(cookieName);
3844
3845        $(document).on('click', '.show-isi-tray', expandTray);
3846
3847        $(".cmp-isi-tray--chevron-expand, .cmp-isi-tray--main-heading").on("click", expandTray);
3848        $isiTrayChevronCollapsed.on("click", collapseTray);
3849
3850        // function that checks if ISI tray cookie is set - if so, collapse ISI tray.
3851        function checkISIcookie () {
3852            if (cookieValue) {
3853                collapseTray();
3854            }
3855        }
3856
3857        function expandTray() {
3858            $isiTrayCollapsed.attr("aria-expanded","true");
3859            // check to see if ISI tray has defined inline height from fully pre-collapsed state - if so, remove
3860            $isiTray.css("height", "");
3861
3862            $isiTray.addClass("pre-collapsed-hide");
3863
3864            if ($isiTray.hasClass("expanded-hide")) {
3865                $isiTray.removeClass("expanded-hide");
3866            }
3867
3868            $isiTrayExpanded.show('fast');
3869            $isiTrayChevronExpanded.hide();
3870            $isiTrayChevronCollapsed.show();
3871            $isiTrayBackDrop.show();
3872            $isiTrayCollapsed.removeClass("expand");
3873            $isiTrayCollapsed.addClass("collapse");
3874            $isiTray.addClass("allow-scroll");
3875            $docBody.addClass("isi-tray-active");
3876            if ($isiTray[0].style["max-height"]) {
3877                $isiTray.css("max-height", "");
3878            }
3879            detectTransitionEnd("expand");
3880        }
3881
3882        function collapseTray() {
3883            $isiTrayCollapsed.attr("aria-expanded","false");
3884            $isiTray.removeClass("pre-collapsed-hide");
3885            $isiTray.css("height", inlineHeight);
3886
3887            $isiTrayChevronCollapsed.hide();
3888
3889            // check to see if cookie is set - if not, set it
3890            if (!cookieValue) {
3891                Cookies.set(cookieName, "collapsed", { expires: 30, path: '/' });
3892            }
3893
3894            if ($isiTrayCollapsed.hasClass("collapse") && $preCollapsed.hasClass("not-collapsible")) {
3895                $preCollapsed.show();
3896                $isiTray.removeClass("pre-collapsed-hide");
3897            } else {
3898                if ($preCollapsed.hasClass("not-collapsible")) {
3899                    $preCollapsed.removeClass("not-collapsible").addClass("collapsible");
3900                }
3901            }
3902
3903            $isiTray.addClass("expanded-hide");
3904
3905            $isiTrayChevronExpanded.show();
3906            $isiTrayBackDrop.hide();
3907            $isiTrayCollapsed.removeClass("collapse");
3908            $isiTrayCollapsed.addClass("expand");
3909            $isiTray.removeClass("allow-scroll");
3910            $isiTray.removeClass("set-to-top");
3911            $docBody.removeClass("isi-tray-active");
3912
3913            if (typeof maxHeightProp !== "undefined") {
3914                $isiTray.css("max-height", maxHeightProp);
3915            }
3916
3917            if ($docBody.hasClass("hero-banner-animating") || $docBody.hasClass("hero-banner-before")) {
3918                $isiTray.addClass("offset-collapse");
3919            }
3920
3921            if (!$preCollapsed.hasClass("collapsible")) {
3922                $preCollapsed.show();
3923            }
3924            detectTransitionEnd("collapse");
3925        }
3926
3927        // detecting end of transition to apply scroll class
3928        function detectTransitionEnd(identifier) {
3929            $(".cmp-isi-tray").on("transitionend webkitTransitionEnd oTransitionEnd", function(event) {
3930                if (identifier == "expand") {
3931                    $isiTray.addClass("set-to-top");
3932                } else {
3933                    $isiTray.removeClass("set-to-top");
3934                }
3935            });
3936        }
3937
3938        function isiTrayVisibleFunc() {
3939            if ($isiFooter.length > 0 && $isiTray.length > 0) {
3940                if (!$isiTray.hasClass("allow-scroll")) {
3941                    if ($window.scrollTop() >= ($isiFooter.offset().top - $window.height() + $isiTray.height())) {
3942                        $isiTray.addClass("stuck");
3943                        const offset = $isiFooter.offset().top;
3944                        $isiTray.css("top", offset +"px");
3945                    }
3946                }
3947            }
3948        }
3949        function setScrollDownView() {
3950            var scroll = $(window).scrollTop();
3951            if (scroll > position) {
3952                if ($scrollDownViewCollapse.length > 0) {
3953                    $isiTrayExpanded.hide('fast');
3954                    $isiTrayChevronExpanded.show();
3955                    $isiTrayBackDrop.hide();
3956                    $isiTrayCollapsed.removeClass("collapse");
3957                    $isiTrayCollapsed.addClass("expand");
3958                }
3959                else {
3960                    $isiTrayExpanded.hide('fast');
3961                    $isiTrayBackDrop.hide();
3962                    $isiTrayCollapsed.removeClass("collapse");
3963                    $isiTrayCollapsed.addClass("expand");
3964                    if ($isiTray.hasClass("offset-collapse")) {
3965                        $isiTray.removeClass("offset-collapse");
3966                    }
3967                }
3968
3969            } else {
3970                if (scroll <= (parseInt($isiFooter.offset().top, 10) - $window.height() + $isiTray.height())) {
3971                    $isiTray.removeClass("stuck");
3972                    $isiTray.css("top", "");
3973                    if (!$preCollapsed.hasClass("collapsible")) {
3974                        $preCollapsed.show("slow");
3975                    }
3976                }
3977            }
3978            position = scroll;
3979        }
3980        checkISIcookie();
3981        $window.on('resize scroll', isiTrayVisibleFunc);
3982        $window.on('scroll', setScrollDownView);
3983        }
3984    });
3985$(document).ready(function () {
3986
3987	const showMobileDropdown = () => {
3988
3989		$('.cmp-standard-header__mobile-hamburger-menu').hide();
3990
3991		$('.cmp-standard-header__mobile-close-button, .cmp-standard-header__nav, .backdrop').show();
3992		$('body').css({
3993			'overflow': 'hidden'
3994		});
3995	};
3996
3997	const hideMobileDropdown = () => {
3998		$('.cmp-standard-header__mobile-close-button, .cmp-standard-header__nav, .backdrop').hide();
3999		$('.cmp-standard-header__mobile-hamburger-menu').show();
4000		$('body').css({
4001			'overflow': 'auto'
4002		});
4003
4004	};
4005
4006	const isMobile = () => {
4007		return window.innerWidth < 767
4008	};
4009
4010	const resetHeader = () => {;
4011		if (isMobile()) {
4012
4013			$('.cmp-standard-header__mobile').show();
4014			$('.cmp-standard-header__nav').hide();
4015
4016		} else {
4017
4018			$('.cmp-standard-header__mobile').hide();
4019			$('.cmp-standard-header__nav').show();
4020		}
4021
4022
4023	}
4024
4025	$('.cmp-standard-header__mobile-hamburger-menu').on('click', showMobileDropdown);
4026	$('.cmp-standard-header__mobile-close-button').on('click', hideMobileDropdown);
4027
4028
4029	window.addEventListener('resize', resetHeader);
4030
4031});
4032$(document).ready(function () {
4033    if ($('.cmp-site-locator').length) {
4034        let cards = $();
4035        // Create the script tag, set the appropriate attributes
4036		const GOOGLE_API_KEY = $(".googleMapsApiKey").val();
4037        let script = document.createElement('script');
4038        script.src = `https://maps.googleapis.com/maps/api/js?key=${GOOGLE_API_KEY}&callback=initMap`;
4039        script.async = true;
4040        // Attach your callback function to the `window` object
4041        window.initMap = function () {
4042            // JS API is loaded and available
4043        };
4044
4045
4046        const submitBtn = $('.cmp-site-locator--submit-button');
4047        //Cookie to store the zip code
4048        const cookieName = 'site-locator-zip';
4049        //Cookie to store the result flag
4050        const validResultsFlag = 'site-locator-results';
4051        let cookieValue = Cookies.get(cookieName);
4052        let validResultsFlagVal = Cookies.get(validResultsFlag);
4053        if (cookieValue !== null && cookieValue !== undefined && validResultsFlagVal !== null && validResultsFlagVal !== undefined && validResultsFlagVal == 'valid') {
4054            $("#zipCode").val(cookieValue);
4055            submitBtn.removeAttr('disabled');
4056            setTimeout(function () {
4057                submitBtn.trigger("click");
4058            }, 50);
4059        }
4060
4061
4062        // Append the 'script' element to 'head'
4063        document.head.appendChild(script);
4064
4065        //Component html elements
4066        const outerResultsArea = $('.cmp-site-locator--output-results-area');
4067        const cardResultsArea = $('.cmp-site-locator--card-results-area');
4068        const mapArea = $('.cmp-site-locator--map-area');
4069        const sysErrorMsg = $('.cmp-site-locator--system-error-message');
4070        const inValidResults = $('.cmp-site-locator--invalid-results-message');
4071        const noValidResults = $('.cmp-site-locator--no-valid-message');
4072        const zipCodeInput = $('#zipCode');
4073        const loadMoreBtn = $('.cmp-site-locator--load-more-btn');
4074        const loadMoreBtnWrapper = $('.cmp-site-locator--load-more');
4075        const resultsCount = $('.cmp-site-locator--results-count');
4076        const siteLocatorForm = $('#cmp-site-locator--form');
4077
4078
4079        //This function is called when an ajax call is made and adds the loading screen to the cards and map area
4080        $(document).ajaxStart(function () {
4081            outerResultsArea.css("display", "flex");
4082            cardResultsArea.addClass('loading');
4083            mapArea.addClass('loading');
4084            sysErrorMsg.add(inValidResults).add(noValidResults).add(resultsCount).add(loadMoreBtnWrapper).add(sysErrorMsg).hide();
4085        });
4086
4087        //This function is where the site data is loaded
4088        const getSiteData = (zip) => {
4089            const disStr = siteLocatorForm.data("distanceArray");
4090            const queryString = `.site-data.html?zipCode=${zip}&distance=${disStr}`;
4091            let urlPath = window.location.pathname;
4092            if (urlPath.includes(".html") == true) {
4093                urlPath = urlPath.replace('.html', queryString);
4094            } else {
4095                urlPath = urlPath + queryString;
4096            }
4097            if (siteLocatorForm.data("setCookie") == true) {
4098                Cookies.set(cookieName, zip, { expires: 1, path: '/' });
4099            }
4100
4101            $.ajax({
4102                method: "GET",
4103                url: urlPath,
4104                dataType: "json"
4105            })
4106                .done(data => {
4107                    // Show the locations when there are sites
4108                    if (data != null && data.sites?.length) {
4109                        Cookies.set(validResultsFlag, data.status, { expires: 1, path: '/' });
4110                        //For each data.sites array a card div will be created in ascending order
4111                        const newSitesData = data.sites.sort((c1, c2) => c1.distance - c2.distance);
4112                        for (i = 0; i < data.sites.length; i++) {
4113                            cards = cards.add(createCard(i, newSitesData));
4114                        }
4115                        if (window.innerWidth < 768) {
4116                            getMobileCards(cards);
4117                        } else {
4118                            cardResultsArea.removeClass('loading').append(cards);
4119                            initMap(newSitesData);
4120                        }
4121                    } else if (data != null && data.status == 'invalid') {
4122                        Cookies.set(validResultsFlag, data.status, { expires: 1, path: '/' });
4123                        // showing the invalid results when the zip code is not valid (Not in USA)
4124                        cardResultsArea.removeClass('loading');
4125                        if (window.innerWidth < 768) {
4126                            inValidResults.show();
4127                        } else {
4128                            cardResultsArea.find(".cmp-site-locator--invalid-results-message").show();
4129                            initDefaultMap("invalid-zipcode");
4130                        }
4131
4132                    } else {
4133                        Cookies.set(validResultsFlag, 'invalid', { expires: 1, path: '/' });
4134                        // showing the no valid results when the zip code is in USA but has no locations
4135                        cardResultsArea.removeClass('loading');
4136                        if (window.innerWidth < 768) {
4137                            noValidResults.show();
4138                        } else {
4139                            cardResultsArea.find(".cmp-site-locator--no-valid-message").show();
4140                        }
4141                        if (typeof data.latitude !== "undefined" && typeof data.longitude !== "undefined") {
4142                            initDefaultMap("no-results", data);
4143                        }
4144                    }
4145                })
4146                .fail(function (jqXHR, textStatus) {
4147                    Cookies.set(validResultsFlag, 'error', { expires: 1, path: '/' });
4148                    cardResultsArea.removeClass('loading');
4149                    if (window.innerWidth < 768) {
4150                        sysErrorMsg.show();
4151                    } else {
4152                        cardResultsArea.find(".cmp-site-locator--system-error-message").show();
4153                        initDefaultMap("invalid-zipcode");
4154                    }
4155                });
4156        }
4157
4158        // Function to call cards on mobile devices with load more logic
4159        const getMobileCards = (cards) => {
4160            const cardsLength = cards.length;
4161            const defaultCardIncrement = $(".cmp-site-locator").data("mobileCardsNum");
4162            let mobileCardsNum = $(".cmp-site-locator").data("mobileCardsNum");
4163            if (cardsLength > mobileCardsNum) {
4164                cardResultsArea.removeClass('loading').append(cards.slice(0, mobileCardsNum));
4165                let countString;
4166                countString = `Showing ${mobileCardsNum} of ${cardsLength}`;
4167                resultsCount.html(countString);
4168                resultsCount.show();
4169                loadMoreBtnWrapper.show();
4170                loadMoreBtn.click(() => {
4171                    mobileCardsNum = (mobileCardsNum + defaultCardIncrement <= cardsLength) ? mobileCardsNum + defaultCardIncrement : cardsLength;
4172                    cardResultsArea.append(cards.slice(0, mobileCardsNum));
4173                    let cardToInViewNumber = mobileCardsNum - defaultCardIncrement;
4174                    let cardInView = cards[cardToInViewNumber];
4175                    cardInView.scrollIntoView({ behavior: 'smooth', block: 'start' });
4176                    countString = `Showing ${mobileCardsNum} of ${cardsLength}`;
4177                    resultsCount.html(countString);
4178                    if (mobileCardsNum == cardsLength) {
4179                        loadMoreBtn.attr('disabled', 'disabled');
4180                        loadMoreBtn.hide();
4181                    }
4182                });
4183            } else {
4184                cardResultsArea.removeClass('loading').append(cards);
4185            }
4186
4187        }
4188
4189        //Function to return directions on google maps
4190
4191        const getDirections = (address, city, state) => {
4192            return `https://www.google.com/maps/place/${address}+${city}+${state}`;
4193        }
4194
4195        const formatPhoneNumber = (number) => {
4196            if (number) {
4197                return number.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
4198            }
4199            return "";
4200        }
4201
4202        //This function is where the card div is dynamically created
4203        const createCard = (i, sites) => {
4204            let card = "";
4205            if (typeof sites[i].name !== "undefined") {
4206                card += '<div class="cmp-site-locator--card" id="' + sites[i].external_Id + '"><h3 class="cmp-site-locator--card-title">' + (sites[i].name ? sites[i].name : 'No name provided') + '</h3>';
4207            }
4208
4209            if (typeof sites[i].distance !== "undefined") {
4210                card += '<div class="cmp-site-locator--card-miles">' + Math.round(sites[i].distance) + ' miles</div>';
4211            }
4212
4213            if (typeof sites[i].address !== "undefined") {
4214                card += '<div class="cmp-site-locator--card-address-area">';
4215                card += '<div class="cmp-site-locator--card-address">' + sites[i].address + ',</div>&nbsp;';
4216            }
4217
4218            if (typeof sites[i].addressLine2 !== "undefined") {
4219                card += '<div class="cmp-site-locator--card-address-line2">' + sites[i].addressLine2 + ' </div>&nbsp;';
4220            }
4221
4222            if (typeof sites[i].city !== "undefined") {
4223                card += '<div class="cmp-site-locator--card-city-name">' + sites[i].city + ', </div>&nbsp;';
4224            }
4225
4226            if (typeof sites[i].state !== "undefined") {
4227                card += '<div class="cmp-site-locator--card-state">' + sites[i].state + ', </div>&nbsp;';
4228            }
4229
4230            if (typeof sites[i].postal_code !== "undefined") {
4231                card += '<div class="cmp-site-locator--card-zipcode">' + sites[i].postal_code + '</div></div>';
4232            }
4233
4234            if (typeof sites[i].phone !== "undefined") {
4235                card += '<div class="cmp-site-locator--card-phone"><a href="tel:' + sites[i].phone + '">' + formatPhoneNumber(sites[i].phone) + '</a></div>';
4236            }
4237            card += '<div class="cmp-site-locator--card-map-link"><a href="' + getDirections(sites[i].address, sites[i].city, sites[i].state) + '" target="_blank">';
4238            card += $('.cmp-site-locator--card-map-link-value').html() + '</a></div></div>';
4239
4240            return $(card);
4241
4242
4243        }
4244        //This function checks if a correct zipcode was entered
4245        const isZipCodeValid = (zip) => {
4246            regexp = /^\d{5}
4246$/;
4247            if (regexp.test(zip)) {
4248                return true;
4249            }
4250            return false;
4251        }
4252        //This function has the card results area load independently of the page
4253        const updateSearchResults = () => {
4254            cardResultsArea.load(" .cmp-site-locator--card-results-area > *");
4255            return new Promise(resolve => setTimeout(resolve, 1000));
4256        }
4257        //Checks if the cards array is empty to prevent cards showing up twice
4258        const isEmptyCards = (cards) => {
4259            return cards && Object.keys(cards).length === 0 && cards.constructor === Object;
4260        }
4261
4262        //this is the first function called when someone presses the search button
4263        const getLocation = async () => {
4264
4265            let zipcode = zipCodeInput.val();
4266            if (isZipCodeValid(zipcode)) {
4267                //This checks if the cards is not empty.
4268                if (!isEmptyCards()) {
4269                    cards = {};
4270                    cards = $();
4271                }
4272                await updateSearchResults();
4273                await getSiteData(zipcode);
4274            } else {
4275                sysErrorMsg.add(noValidResults).hide();
4276                if (window.innerWidth < 768) {
4277                    outerResultsArea.hide();
4278                    inValidResults.show();
4279                } else {
4280                    cardResultsArea.find(".cmp-site-locator--invalid-results-message").show();
4281                    cardResultsArea.find(".cmp-site-locator--no-valid-message").hide();
4282                    const existingCards = cardResultsArea.find(".cmp-site-locator--card");
4283                    if (existingCards.length) {
4284                        existingCards.remove();
4285                    }
4286                }
4287                initDefaultMap("invalid-zipcode");
4288            }
4289        }
4290
4291        //This function to validate input to only take numbers
4292        const inputKeyValidator = e => {
4293            const ASCIICode = (e.which) ? e.which : e.keyCode;
4294            if (ASCIICode > 31 && (ASCIICode < 48 || ASCIICode > 57))
4295                return false;
4296            return true;
4297        }
4298
4299        //This function to validate if the zip code matches the regex
4300        const validateInput = () => {
4301            let zipcode = zipCodeInput.val();
4302            if (isZipCodeValid(zipcode)) {
4303                submitBtn.removeAttr('disabled');
4304                return true;
4305            }
4306            submitBtn.attr('disabled', 'disabled');
4307            return false;
4308        }
4309
4310        // Once the user clicks submit it will call getLocation function
4311        submitBtn.click(getLocation);
4312
4313        // Once the user clicks enter it will cal getLocation function
4314        zipCodeInput.keydown(function (e) {
4315            if (e.keyCode == 13) {
4316                e.preventDefault();
4317                getLocation();
4318            }
4319        });
4320
4321        // Calling validations on key press and keyup
4322        zipCodeInput.keypress(e => inputKeyValidator(e));
4323        zipCodeInput.keyup(validateInput);
4324
4325
4326        //this function is where the map is loaded and the markers are placed
4327        const initMap = (sites) => {
4328            let map, marker, i;
4329            mapArea.removeClass('loading invalid-map');
4330            const mapStyle = [
4331                {
4332                    "featureType": "poi.business",
4333                    "stylers": [
4334                        {
4335                            "visibility": "off"
4336                        }
4337                    ]
4338                },
4339                {
4340                    "featureType": "poi.park",
4341                    "elementType": "labels.text",
4342                    "stylers": [
4343                        {
4344                            "visibility": "off"
4345                        }
4346                    ]
4347                }
4348            ];
4349
4350            const city = {
4351                lat: sites[0].latitude,
4352                lng: sites[0].longitude
4353            };
4354            map = new google.maps.Map(document.getElementById('map-canvas'), {
4355                center: city,
4356                styles: mapStyle,
4357                disableDefaultUI: true,
4358            });
4359
4360            var latlngbounds = new google.maps.LatLngBounds();
4361            for (i = 0; i < sites.length; i++) {
4362                marker = new google.maps.Marker({
4363                    position: new google.maps.LatLng(sites[i].latitude, sites[i].longitude),
4364                    map: map,
4365                    store_id: sites[i].external_Id,
4366                });
4367
4368                onCardMarkerHover(map, marker, sites[i].name, sites[i].external_Id);
4369                latlngbounds.extend(marker.position);
4370            }
4371
4372
4373            google.maps.event.addListenerOnce(map, 'bounds_changed', function () {
4374                this.setZoom(map.getZoom() - 1);
4375                if (this.getZoom() > 15) {
4376                    this.setZoom(15);
4377                }
4378            });
4379
4380            map.fitBounds(latlngbounds);
4381
4382        }
4383
4384        // This function will render a Google map zoomed-out of the U.S.
4385        const initDefaultMap = (error, data) => {
4386
4387            mapArea.removeClass('loading');
4388
4389            const mapStyleBlurred = [
4390                {
4391                    featureType: "all",
4392                    elementType: "all",
4393                    stylers: [
4394                        { saturation: -100 }
4395                    ]
4396                },
4397                {
4398                    "featureType": "poi.business",
4399                    "stylers": [
4400                        {
4401                            "visibility": "off"
4402                        }
4403                    ]
4404                },
4405                {
4406                    "featureType": "poi.park",
4407                    "elementType": "labels.text",
4408                    "stylers": [
4409                        {
4410                            "visibility": "off"
4411                        }
4412                    ]
4413                }
4414            ];
4415
4416            const mapStyle = [
4417                {
4418                    "featureType": "poi.business",
4419                    "stylers": [
4420                        {
4421                            "visibility": "off"
4422                        }
4423                    ]
4424                },
4425                {
4426                    "featureType": "poi.park",
4427                    "elementType": "labels.text",
4428                    "stylers": [
4429                        {
4430                            "visibility": "off"
4431                        }
4432                    ]
4433                }
4434            ];
4435
vendor: 16,896 bytes, lines 4436-5076
4436            if (error == "invalid-zipcode") {
4437                const defaultLat = 39.8097343; // for center of U.S.
4438                const defaultLng = -98.5556199; // for center of U.S.
4439                if (!mapArea.hasClass("invalid-map")) {
4440                    mapArea.addClass("invalid-map");
4441                }
4442                const city = {
4443                    lat: defaultLat,
4444                    lng: defaultLng
4445                };
4446
4447                map = new google.maps.Map(document.getElementById('map-canvas'), {
4448                    center: city,
4449                    styles: error == "invalid-zipcode" ? mapStyleBlurred : mapStyle,
4450                    disableDefaultUI: true,
4451                    zoom: 4
4452                });
4453            } else {
4454                if (mapArea.hasClass("invalid-map")) {
4455                    mapArea.removeClass("invalid-map");
4456                }
4457                const city = {
4458                    lat: data.latitude,
4459                    lng: data.longitude
4460                };
4461
4462                map = new google.maps.Map(document.getElementById('map-canvas'), {
4463                    center: city,
4464                    styles: mapStyle,
4465                    disableDefaultUI: true,
4466                    zoom: 15
4467                });
4468            }
4469        }
4470
4471        //this function is where the information above the marker is displayed
4472        let prevInfoWindow = false;
4473        const onCardMarkerHover = (map, marker, name, externalId) => {
4474            const infoWindow = new google.maps.InfoWindow({
4475                content: name
4476            });
4477            const cardElement = document.getElementById(externalId);
4478
4479            google.maps.event.addListener(marker, 'click', function () {
4480                cardElement.parentNode.scrollTop = cardElement.offsetTop;
4481                cardElement.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
4482                const previouslyActive = $(cardElement).closest(".cmp-site-locator--card-results-area").find(".cmp-site-locator--card.active");
4483                if (previouslyActive.length && prevInfoWindow) {
4484                    prevInfoWindow.close();
4485                    previouslyActive.removeClass("active");
4486                    if (previouslyActive.hasClass("clicked")) {
4487                        previouslyActive.removeClass("clicked");
4488                    }
4489                }
4490                prevInfoWindow = infoWindow;
4491                infoWindow.open(map, marker);
4492                cardElement.classList.add("active");
4493                cardElement.classList.add("clicked");
4494            });
4495
4496            google.maps.event.addListener(marker, 'mouseover', function () {
4497                infoWindow.open(map, marker);
4498                cardElement.classList.add("active");
4499            });
4500
4501            google.maps.event.addListener(marker, 'mouseout', function () {
4502                if (!$(cardElement).hasClass("clicked")) {
4503                    infoWindow.close();
4504                    cardElement.classList.remove("active");
4505                }
4506            });
4507
4508            cardElement.addEventListener('click', function () {
4509                const previouslyActive = $(cardElement).closest(".cmp-site-locator--card-results-area").find(".cmp-site-locator--card.active");
4510                if (previouslyActive.length && prevInfoWindow) {
4511                    prevInfoWindow.close();
4512                    previouslyActive.removeClass("active");
4513                    if (previouslyActive.hasClass("clicked")) {
4514                        previouslyActive.removeClass("clicked");
4515                    }
4516                }
4517                prevInfoWindow = infoWindow;
4518                infoWindow.open(map, marker);
4519                cardElement.classList.add("active");
4520                cardElement.classList.add("clicked");
4521            });
4522
4523            cardElement.addEventListener('mouseover', function () {
4524                infoWindow.open(map, marker);
4525                cardElement.classList.add("active");
4526            });
4527            cardElement.addEventListener('mouseout', function () {
4528                if (!$(cardElement).hasClass("clicked")) {
4529                    infoWindow.close();
4530                    cardElement.classList.remove("active");
4531                }
4532            });
4533        }
4534    }
4535});
4536// https://d3js.org Version 4.13.0. Copyright 2018 Mike Bostock.
4537(function (global, factory) {
4538	typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4539	typeof define === 'function' && define.amd ? define(['exports'], factory) :
4540	(factory((global.d3 = global.d3 || {})));
4541}(this, (function (exports) { 'use strict';
4542
4543var version = "4.13.0";
4544
4545function ascending(a, b) {
4546  return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
4547}
4548
4549function bisector(compare) {
4550  if (compare.length === 1) compare = ascendingComparator(compare);
4551  return {
4552    left: function(a, x, lo, hi) {
4553      if (lo == null) lo = 0;
4554      if (hi == null) hi = a.length;
4555      while (lo < hi) {
4556        var mid = lo + hi >>> 1;
4557        if (compare(a[mid], x) < 0) lo = mid + 1;
4558        else hi = mid;
4559      }
4560      return lo;
4561    },
4562    right: function(a, x, lo, hi) {
4563      if (lo == null) lo = 0;
4564      if (hi == null) hi = a.length;
4565      while (lo < hi) {
4566        var mid = lo + hi >>> 1;
4567        if (compare(a[mid], x) > 0) hi = mid;
4568        else lo = mid + 1;
4569      }
4570      return lo;
4571    }
4572  };
4573}
4574
4575function ascendingComparator(f) {
4576  return function(d, x) {
4577    return ascending(f(d), x);
4578  };
4579}
4580
4581var ascendingBisect = bisector(ascending);
4582var bisectRight = ascendingBisect.right;
4583var bisectLeft = ascendingBisect.left;
4584
4585function pairs(array, f) {
4586  if (f == null) f = pair;
4587  var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
4588  while (i < n) pairs[i] = f(p, p = array[++i]);
4589  return pairs;
4590}
4591
4592function pair(a, b) {
4593  return [a, b];
4594}
4595
4596function cross(values0, values1, reduce) {
4597  var n0 = values0.length,
4598      n1 = values1.length,
4599      values = new Array(n0 * n1),
4600      i0,
4601      i1,
4602      i,
4603      value0;
4604
4605  if (reduce == null) reduce = pair;
4606
4607  for (i0 = i = 0; i0 < n0; ++i0) {
4608    for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
4609      values[i] = reduce(value0, values1[i1]);
4610    }
4611  }
4612
4613  return values;
4614}
4615
4616function descending(a, b) {
4617  return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
4618}
4619
4620function number(x) {
4621  return x === null ? NaN : +x;
4622}
4623
4624function variance(values, valueof) {
4625  var n = values.length,
4626      m = 0,
4627      i = -1,
4628      mean = 0,
4629      value,
4630      delta,
4631      sum = 0;
4632
4633  if (valueof == null) {
4634    while (++i < n) {
4635      if (!isNaN(value = number(values[i]))) {
4636        delta = value - mean;
4637        mean += delta / ++m;
4638        sum += delta * (value - mean);
4639      }
4640    }
4641  }
4642
4643  else {
4644    while (++i < n) {
4645      if (!isNaN(value = number(valueof(values[i], i, values)))) {
4646        delta = value - mean;
4647        mean += delta / ++m;
4648        sum += delta * (value - mean);
4649      }
4650    }
4651  }
4652
4653  if (m > 1) return sum / (m - 1);
4654}
4655
4656function deviation(array, f) {
4657  var v = variance(array, f);
4658  return v ? Math.sqrt(v) : v;
4659}
4660
4661function extent(values, valueof) {
4662  var n = values.length,
4663      i = -1,
4664      value,
4665      min,
4666      max;
4667
4668  if (valueof == null) {
4669    while (++i < n) { // Find the first comparable value.
4670      if ((value = values[i]) != null && value >= value) {
4671        min = max = value;
4672        while (++i < n) { // Compare the remaining values.
4673          if ((value = values[i]) != null) {
4674            if (min > value) min = value;
4675            if (max < value) max = value;
4676          }
4677        }
4678      }
4679    }
4680  }
4681
4682  else {
4683    while (++i < n) { // Find the first comparable value.
4684      if ((value = valueof(values[i], i, values)) != null && value >= value) {
4685        min = max = value;
4686        while (++i < n) { // Compare the remaining values.
4687          if ((value = valueof(values[i], i, values)) != null) {
4688            if (min > value) min = value;
4689            if (max < value) max = value;
4690          }
4691        }
4692      }
4693    }
4694  }
4695
4696  return [min, max];
4697}
4698
4699var array = Array.prototype;
4700
4701var slice = array.slice;
4702var map = array.map;
4703
4704function constant(x) {
4705  return function() {
4706    return x;
4707  };
4708}
4709
4710function identity(x) {
4711  return x;
4712}
4713
4714function sequence(start, stop, step) {
4715  start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
4716
4717  var i = -1,
4718      n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
4719      range = new Array(n);
4720
4721  while (++i < n) {
4722    range[i] = start + i * step;
4723  }
4724
4725  return range;
4726}
4727
4728var e10 = Math.sqrt(50);
4729var e5 = Math.sqrt(10);
4730var e2 = Math.sqrt(2);
4731
4732function ticks(start, stop, count) {
4733  var reverse,
4734      i = -1,
4735      n,
4736      ticks,
4737      step;
4738
4739  stop = +stop, start = +start, count = +count;
4740  if (start === stop && count > 0) return [start];
4741  if (reverse = stop < start) n = start, start = stop, stop = n;
4742  if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
4743
4744  if (step > 0) {
4745    start = Math.ceil(start / step);
4746    stop = Math.floor(stop / step);
4747    ticks = new Array(n = Math.ceil(stop - start + 1));
4748    while (++i < n) ticks[i] = (start + i) * step;
4749  } else {
4750    start = Math.floor(start * step);
4751    stop = Math.ceil(stop * step);
4752    ticks = new Array(n = Math.ceil(start - stop + 1));
4753    while (++i < n) ticks[i] = (start - i) / step;
4754  }
4755
4756  if (reverse) ticks.reverse();
4757
4758  return ticks;
4759}
4760
4761function tickIncrement(start, stop, count) {
4762  var step = (stop - start) / Math.max(0, count),
4763      power = Math.floor(Math.log(step) / Math.LN10),
4764      error = step / Math.pow(10, power);
4765  return power >= 0
4766      ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
4767      : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
4768}
4769
4770function tickStep(start, stop, count) {
4771  var step0 = Math.abs(stop - start) / Math.max(0, count),
4772      step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
4773      error = step0 / step1;
4774  if (error >= e10) step1 *= 10;
4775  else if (error >= e5) step1 *= 5;
4776  else if (error >= e2) step1 *= 2;
4777  return stop < start ? -step1 : step1;
4778}
4779
4780function sturges(values) {
4781  return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
4782}
4783
4784function histogram() {
4785  var value = identity,
4786      domain = extent,
4787      threshold = sturges;
4788
4789  function histogram(data) {
4790    var i,
4791        n = data.length,
4792        x,
4793        values = new Array(n);
4794
4795    for (i = 0; i < n; ++i) {
4796      values[i] = value(data[i], i, data);
4797    }
4798
4799    var xz = domain(values),
4800        x0 = xz[0],
4801        x1 = xz[1],
4802        tz = threshold(values, x0, x1);
4803
4804    // Convert number of thresholds into uniform thresholds.
4805    if (!Array.isArray(tz)) {
4806      tz = tickStep(x0, x1, tz);
4807      tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
4808    }
4809
4810    // Remove any thresholds outside the domain.
4811    var m = tz.length;
4812    while (tz[0] <= x0) tz.shift(), --m;
4813    while (tz[m - 1] > x1) tz.pop(), --m;
4814
4815    var bins = new Array(m + 1),
4816        bin;
4817
4818    // Initialize bins.
4819    for (i = 0; i <= m; ++i) {
4820      bin = bins[i] = [];
4821      bin.x0 = i > 0 ? tz[i - 1] : x0;
4822      bin.x1 = i < m ? tz[i] : x1;
4823    }
4824
4825    // Assign data to bins by value, ignoring any outside the domain.
4826    for (i = 0; i < n; ++i) {
4827      x = values[i];
4828      if (x0 <= x && x <= x1) {
4829        bins[bisectRight(tz, x, 0, m)].push(data[i]);
4830      }
4831    }
4832
4833    return bins;
4834  }
4835
4836  histogram.value = function(_) {
4837    return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
4838  };
4839
4840  histogram.domain = function(_) {
4841    return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
4842  };
4843
4844  histogram.thresholds = function(_) {
4845    return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
4846  };
4847
4848  return histogram;
4849}
4850
4851function threshold(values, p, valueof) {
4852  if (valueof == null) valueof = number;
4853  if (!(n = values.length)) return;
4854  if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
4855  if (p >= 1) return +valueof(values[n - 1], n - 1, values);
4856  var n,
4857      i = (n - 1) * p,
4858      i0 = Math.floor(i),
4859      value0 = +valueof(values[i0], i0, values),
4860      value1 = +valueof(values[i0 + 1], i0 + 1, values);
4861  return value0 + (value1 - value0) * (i - i0);
4862}
4863
4864function freedmanDiaconis(values, min, max) {
4865  values = map.call(values, number).sort(ascending);
4866  return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
4867}
4868
4869function scott(values, min, max) {
4870  return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
4871}
4872
4873function max(values, valueof) {
4874  var n = values.length,
4875      i = -1,
4876      value,
4877      max;
4878
4879  if (valueof == null) {
4880    while (++i < n) { // Find the first comparable value.
4881      if ((value = values[i]) != null && value >= value) {
4882        max = value;
4883        while (++i < n) { // Compare the remaining values.
4884          if ((value = values[i]) != null && value > max) {
4885            max = value;
4886          }
4887        }
4888      }
4889    }
4890  }
4891
4892  else {
4893    while (++i < n) { // Find the first comparable value.
4894      if ((value = valueof(values[i], i, values)) != null && value >= value) {
4895        max = value;
4896        while (++i < n) { // Compare the remaining values.
4897          if ((value = valueof(values[i], i, values)) != null && value > max) {
4898            max = value;
4899          }
4900        }
4901      }
4902    }
4903  }
4904
4905  return max;
4906}
4907
4908function mean(values, valueof) {
4909  var n = values.length,
4910      m = n,
4911      i = -1,
4912      value,
4913      sum = 0;
4914
4915  if (valueof == null) {
4916    while (++i < n) {
4917      if (!isNaN(value = number(values[i]))) sum += value;
4918      else --m;
4919    }
4920  }
4921
4922  else {
4923    while (++i < n) {
4924      if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
4925      else --m;
4926    }
4927  }
4928
4929  if (m) return sum / m;
4930}
4931
4932function median(values, valueof) {
4933  var n = values.length,
4934      i = -1,
4935      value,
4936      numbers = [];
4937
4938  if (valueof == null) {
4939    while (++i < n) {
4940      if (!isNaN(value = number(values[i]))) {
4941        numbers.push(value);
4942      }
4943    }
4944  }
4945
4946  else {
4947    while (++i < n) {
4948      if (!isNaN(value = number(valueof(values[i], i, values)))) {
4949        numbers.push(value);
4950      }
4951    }
4952  }
4953
4954  return threshold(numbers.sort(ascending), 0.5);
4955}
4956
4957function merge(arrays) {
4958  var n = arrays.length,
4959      m,
4960      i = -1,
4961      j = 0,
4962      merged,
4963      array;
4964
4965  while (++i < n) j += arrays[i].length;
4966  merged = new Array(j);
4967
4968  while (--n >= 0) {
4969    array = arrays[n];
4970    m = array.length;
4971    while (--m >= 0) {
4972      merged[--j] = array[m];
4973    }
4974  }
4975
4976  return merged;
4977}
4978
4979function min(values, valueof) {
4980  var n = values.length,
4981      i = -1,
4982      value,
4983      min;
4984
4985  if (valueof == null) {
4986    while (++i < n) { // Find the first comparable value.
4987      if ((value = values[i]) != null && value >= value) {
4988        min = value;
4989        while (++i < n) { // Compare the remaining values.
4990          if ((value = values[i]) != null && min > value) {
4991            min = value;
4992          }
4993        }
4994      }
4995    }
4996  }
4997
4998  else {
4999    while (++i < n) { // Find the first comparable value.
5000      if ((value = valueof(values[i], i, values)) != null && value >= value) {
5001        min = value;
5002        while (++i < n) { // Compare the remaining values.
5003          if ((value = valueof(values[i], i, values)) != null && min > value) {
5004            min = value;
5005          }
5006        }
5007      }
5008    }
5009  }
5010
5011  return min;
5012}
5013
5014function permute(array, indexes) {
5015  var i = indexes.length, permutes = new Array(i);
5016  while (i--) permutes[i] = array[indexes[i]];
5017  return permutes;
5018}
5019
5020function scan(values, compare) {
5021  if (!(n = values.length)) return;
5022  var n,
5023      i = 0,
5024      j = 0,
5025      xi,
5026      xj = values[j];
5027
5028  if (compare == null) compare = ascending;
5029
5030  while (++i < n) {
5031    if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
5032      xj = xi, j = i;
5033    }
5034  }
5035
5036  if (compare(xj, xj) === 0) return j;
5037}
5038
5039function shuffle(array, i0, i1) {
5040  var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
5041      t,
5042      i;
5043
5044  while (m) {
5045    i = Math.random() * m-- | 0;
5046    t = array[m + i0];
5047    array[m + i0] = array[i + i0];
5048    array[i + i0] = t;
5049  }
5050
5051  return array;
5052}
5053
5054function sum(values, valueof) {
5055  var n = values.length,
5056      i = -1,
5057      value,
5058      sum = 0;
5059
5060  if (valueof == null) {
5061    while (++i < n) {
5062      if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
5063    }
5064  }
5065
5066  else {
5067    while (++i < n) {
5068      if (value = +valueof(values[i], i, values)) sum += value;
5069    }
5070  }
5071
5072  return sum;
5073}
5074
5075function transpose(matrix) {
5076  if (!(n = matrix.length)) return [];
vendor: 6,265 bytes, lines 5077-5298
5077  for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
5078    for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
5079      row[j] = matrix[j][i];
5080    }
5081  }
5082  return transpose;
5083}
5084
5085function length(d) {
5086  return d.length;
5087}
5088
5089function zip() {
5090  return transpose(arguments);
5091}
5092
5093var slice$1 = Array.prototype.slice;
5094
5095function identity$1(x) {
5096  return x;
5097}
5098
5099var top = 1;
5100var right = 2;
5101var bottom = 3;
5102var left = 4;
5103var epsilon = 1e-6;
5104
5105function translateX(x) {
5106  return "translate(" + (x + 0.5) + ",0)";
5107}
5108
5109function translateY(y) {
5110  return "translate(0," + (y + 0.5) + ")";
5111}
5112
5113function number$1(scale) {
5114  return function(d) {
5115    return +scale(d);
5116  };
5117}
5118
5119function center(scale) {
5120  var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
5121  if (scale.round()) offset = Math.round(offset);
5122  return function(d) {
5123    return +scale(d) + offset;
5124  };
5125}
5126
5127function entering() {
5128  return !this.__axis;
5129}
5130
5131function axis(orient, scale) {
5132  var tickArguments = [],
5133      tickValues = null,
5134      tickFormat = null,
5135      tickSizeInner = 6,
5136      tickSizeOuter = 6,
5137      tickPadding = 3,
5138      k = orient === top || orient === left ? -1 : 1,
5139      x = orient === left || orient === right ? "x" : "y",
5140      transform = orient === top || orient === bottom ? translateX : translateY;
5141
5142  function axis(context) {
5143    var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
5144        format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
5145        spacing = Math.max(tickSizeInner, 0) + tickPadding,
5146        range = scale.range(),
5147        range0 = +range[0] + 0.5,
5148        range1 = +range[range.length - 1] + 0.5,
5149        position = (scale.bandwidth ? center : number$1)(scale.copy()),
5150        selection = context.selection ? context.selection() : context,
5151        path = selection.selectAll(".domain").data([null]),
5152        tick = selection.selectAll(".tick").data(values, scale).order(),
5153        tickExit = tick.exit(),
5154        tickEnter = tick.enter().append("g").attr("class", "tick"),
5155        line = tick.select("line"),
5156        text = tick.select("text");
5157
5158    path = path.merge(path.enter().insert("path", ".tick")
5159        .attr("class", "domain")
5160        .attr("stroke", "#000"));
5161
5162    tick = tick.merge(tickEnter);
5163
5164    line = line.merge(tickEnter.append("line")
5165        .attr("stroke", "#000")
5166        .attr(x + "2", k * tickSizeInner));
5167
5168    text = text.merge(tickEnter.append("text")
5169        .attr("fill", "#000")
5170        .attr(x, k * spacing)
5171        .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
5172
5173    if (context !== selection) {
5174      path = path.transition(context);
5175      tick = tick.transition(context);
5176      line = line.transition(context);
5177      text = text.transition(context);
5178
5179      tickExit = tickExit.transition(context)
5180          .attr("opacity", epsilon)
5181          .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
5182
5183      tickEnter
5184          .attr("opacity", epsilon)
5185          .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
5186    }
5187
5188    tickExit.remove();
5189
5190    path
5191        .attr("d", orient === left || orient == right
5192            ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
5193            : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
5194
5195    tick
5196        .attr("opacity", 1)
5197        .attr("transform", function(d) { return transform(position(d)); });
5198
5199    line
5200        .attr(x + "2", k * tickSizeInner);
5201
5202    text
5203        .attr(x, k * spacing)
5204        .text(format);
5205
5206    selection.filter(entering)
5207        .attr("fill", "none")
5208        .attr("font-size", 10)
5209        .attr("font-family", "sans-serif")
5210        .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
5211
5212    selection
5213        .each(function() { this.__axis = position; });
5214  }
5215
5216  axis.scale = function(_) {
5217    return arguments.length ? (scale = _, axis) : scale;
5218  };
5219
5220  axis.ticks = function() {
5221    return tickArguments = slice$1.call(arguments), axis;
5222  };
5223
5224  axis.tickArguments = function(_) {
5225    return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
5226  };
5227
5228  axis.tickValues = function(_) {
5229    return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
5230  };
5231
5232  axis.tickFormat = function(_) {
5233    return arguments.length ? (tickFormat = _, axis) : tickFormat;
5234  };
5235
5236  axis.tickSize = function(_) {
5237    return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
5238  };
5239
5240  axis.tickSizeInner = function(_) {
5241    return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
5242  };
5243
5244  axis.tickSizeOuter = function(_) {
5245    return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
5246  };
5247
5248  axis.tickPadding = function(_) {
5249    return arguments.length ? (tickPadding = +_, axis) : tickPadding;
5250  };
5251
5252  return axis;
5253}
5254
5255function axisTop(scale) {
5256  return axis(top, scale);
5257}
5258
5259function axisRight(scale) {
5260  return axis(right, scale);
5261}
5262
5263function axisBottom(scale) {
5264  return axis(bottom, scale);
5265}
5266
5267function axisLeft(scale) {
5268  return axis(left, scale);
5269}
5270
5271var noop = {value: function() {}};
5272
5273function dispatch() {
5274  for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
5275    if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
5276    _[t] = [];
5277  }
5278  return new Dispatch(_);
5279}
5280
5281function Dispatch(_) {
5282  this._ = _;
5283}
5284
5285function parseTypenames(typenames, types) {
5286  return typenames.trim().split(/^|\s+/).map(function(t) {
5287    var name = "", i = t.indexOf(".");
5288    if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
5289    if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
5290    return {type: t, name: name};
5291  });
5292}
5293
5294Dispatch.prototype = dispatch.prototype = {
5295  constructor: Dispatch,
5296  on: function(typename, callback) {
5297    var _ = this._,
5298        T = parseTypenames(typename + "", _),
vendor: 4,650 bytes, lines 5299-5450
5299        t,
5300        i = -1,
5301        n = T.length;
5302
5303    // If no callback was specified, return the callback of the given type and name.
5304    if (arguments.length < 2) {
5305      while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
5306      return;
5307    }
5308
5309    // If a type was specified, set the callback for the given type and name.
5310    // Otherwise, if a null callback was specified, remove callbacks of the given name.
5311    if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
5312    while (++i < n) {
5313      if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
5314      else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
5315    }
5316
5317    return this;
5318  },
5319  copy: function() {
5320    var copy = {}, _ = this._;
5321    for (var t in _) copy[t] = _[t].slice();
5322    return new Dispatch(copy);
5323  },
5324  call: function(type, that) {
5325    if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
5326    if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
5327    for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
5328  },
5329  apply: function(type, that, args) {
5330    if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
5331    for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
5332  }
5333};
5334
5335function get(type, name) {
5336  for (var i = 0, n = type.length, c; i < n; ++i) {
5337    if ((c = type[i]).name === name) {
5338      return c.value;
5339    }
5340  }
5341}
5342
5343function set(type, name, callback) {
5344  for (var i = 0, n = type.length; i < n; ++i) {
5345    if (type[i].name === name) {
5346      type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
5347      break;
5348    }
5349  }
5350  if (callback != null) type.push({name: name, value: callback});
5351  return type;
5352}
5353
5354var xhtml = "http://www.w3.org/1999/xhtml";
5355
5356var namespaces = {
5357  svg: "http://www.w3.org/2000/svg",
5358  xhtml: xhtml,
5359  xlink: "http://www.w3.org/1999/xlink",
5360  xml: "http://www.w3.org/XML/1998/namespace",
5361  xmlns: "http://www.w3.org/2000/xmlns/"
5362};
5363
5364function namespace(name) {
5365  var prefix = name += "", i = prefix.indexOf(":");
5366  if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
5367  return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
5368}
5369
5370function creatorInherit(name) {
5371  return function() {
5372    var document = this.ownerDocument,
5373        uri = this.namespaceURI;
5374    return uri === xhtml && document.documentElement.namespaceURI === xhtml
5375        ? document.createElement(name)
5376        : document.createElementNS(uri, name);
5377  };
5378}
5379
5380function creatorFixed(fullname) {
5381  return function() {
5382    return this.ownerDocument.createElementNS(fullname.space, fullname.local);
5383  };
5384}
5385
5386function creator(name) {
5387  var fullname = namespace(name);
5388  return (fullname.local
5389      ? creatorFixed
5390      : creatorInherit)(fullname);
5391}
5392
5393function none() {}
5394
5395function selector(selector) {
5396  return selector == null ? none : function() {
5397    return this.querySelector(selector);
5398  };
5399}
5400
5401function selection_select(select) {
5402  if (typeof select !== "function") select = selector(select);
5403
5404  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
5405    for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
5406      if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
5407        if ("__data__" in node) subnode.__data__ = node.__data__;
5408        subgroup[i] = subnode;
5409      }
5410    }
5411  }
5412
5413  return new Selection(subgroups, this._parents);
5414}
5415
5416function empty$1() {
5417  return [];
5418}
5419
5420function selectorAll(selector) {
5421  return selector == null ? empty$1 : function() {
5422    return this.querySelectorAll(selector);
5423  };
5424}
5425
5426function selection_selectAll(select) {
5427  if (typeof select !== "function") select = selectorAll(select);
5428
5429  for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
5430    for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
5431      if (node = group[i]) {
5432        subgroups.push(select.call(node, node.__data__, i, group));
5433        parents.push(node);
5434      }
5435    }
5436  }
5437
5438  return new Selection(subgroups, parents);
5439}
5440
5441var matcher = function(selector) {
5442  return function() {
5443    return this.matches(selector);
5444  };
5445};
5446
5447if (typeof document !== "undefined") {
5448  var element = document.documentElement;
5449  if (!element.matches) {
5450    var vendorMatches = element.webkitMatchesSelector
5451        || element.msMatchesSelector
5452        || element.mozMatchesSelector
5453        || element.oMatchesSelector;
5454    matcher = function(selector) {
5455      return function() {
5456        return vendorMatches.call(this, selector);
5457      };
5458    };
5459  }
5460}
5461
5462var matcher$1 = matcher;
5463
5464function selection_filter(match) {
5465  if (typeof match !== "function") match = matcher$1(match);
5466
5467  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
5468    for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
5469      if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
5470        subgroup.push(node);
5471      }
5472    }
5473  }
5474
5475  return new Selection(subgroups, this._parents);
5476}
5477
5478function sparse(update) {
5479  return new Array(update.length);
5480}
5481
5482function selection_enter() {
5483  return new Selection(this._enter || this._groups.map(sparse), this._parents);
5484}
5485
5486function EnterNode(parent, datum) {
5487  this.ownerDocument = parent.ownerDocument;
5488  this.namespaceURI = parent.namespaceURI;
5489  this._next = null;
5490  this._parent = parent;
5491  this.__data__ = datum;
5492}
5493
5494EnterNode.prototype = {
5495  constructor: EnterNode,
5496  appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
5497  insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
5498  querySelector: function(selector) { return this._parent.querySelector(selector); },
5499  querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
5500};
5501
5502function constant$1(x) {
5503  return function() {
5504    return x;
5505  };
5506}
5507
5508var keyPrefix = "$"; // Protect against keys like “__proto__”.
5509
5510function bindIndex(parent, group, enter, update, exit, data) {
5511  var i = 0,
5512      node,
5513      groupLength = group.length,
5514      dataLength = data.length;
5515
5516  // Put any non-null nodes that fit into update.
5517  // Put any null nodes into enter.
5518  // Put any remaining data into enter.
5519  for (; i < dataLength; ++i) {
5520    if (node = group[i]) {
5521      node.__data__ = data[i];
5522      update[i] = node;
5523    } else {
5524      enter[i] = new EnterNode(parent, data[i]);
5525    }
5526  }
5527
5528  // Put any non-null nodes that don’t fit into exit.
5529  for (; i < groupLength; ++i) {
5530    if (node = group[i]) {
5531      exit[i] = node;
5532    }
5533  }
5534}
5535
5536function bindKey(parent, group, enter, update, exit, data, key) {
5537  var i,
5538      node,
5539      nodeByKeyValue = {},
5540      groupLength = group.length,
5541      dataLength = data.length,
5542      keyValues = new Array(groupLength),
5543      keyValue;
5544
5545  // Compute the key for each node.
5546  // If multiple nodes have the same key, the duplicates are added to exit.
5547  for (i = 0; i < groupLength; ++i) {
5548    if (node = group[i]) {
5549      keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
5550      if (keyValue in nodeByKeyValue) {
5551        exit[i] = node;
5552      } else {
5553        nodeByKeyValue[keyValue] = node;
5554      }
5555    }
5556  }
5557
5558  // Compute the key for each datum.
5559  // If there a node associated with this key, join and add it to update.
5560  // If there is not (or the key is a duplicate), add it to enter.
5561  for (i = 0; i < dataLength; ++i) {
5562    keyValue = keyPrefix + key.call(parent, data[i], i, data);
5563    if (node = nodeByKeyValue[keyValue]) {
5564      update[i] = node;
5565      node.__data__ = data[i];
5566      nodeByKeyValue[keyValue] = null;
5567    } else {
5568      enter[i] = new EnterNode(parent, data[i]);
5569    }
5570  }
5571
5572  // Add any remaining nodes that were not bound to data to exit.
5573  for (i = 0; i < groupLength; ++i) {
5574    if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
5575      exit[i] = node;
5576    }
5577  }
5578}
5579
5580function selection_data(value, key) {
5581  if (!value) {
5582    data = new Array(this.size()), j = -1;
5583    this.each(function(d) { data[++j] = d; });
5584    return data;
5585  }
5586
5587  var bind = key ? bindKey : bindIndex,
5588      parents = this._parents,
5589      groups = this._groups;
5590
5591  if (typeof value !== "function") value = constant$1(value);
5592
5593  for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
5594    var parent = parents[j],
5595        group = groups[j],
5596        groupLength = group.length,
5597        data = value.call(parent, parent && parent.__data__, j, parents),
5598        dataLength = data.length,
5599        enterGroup = enter[j] = new Array(dataLength),
5600        updateGroup = update[j] = new Array(dataLength),
5601        exitGroup = exit[j] = new Array(groupLength);
5602
5603    bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
5604
5605    // Now connect the enter nodes to their following update node, such that
5606    // appendChild can insert the materialized enter node before this node,
5607    // rather than at the end of the parent node.
5608    for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
5609      if (previous = enterGroup[i0]) {
5610        if (i0 >= i1) i1 = i0 + 1;
5611        while (!(next = updateGroup[i1]) && ++i1 < dataLength);
5612        previous._next = next || null;
5613      }
5614    }
5615  }
5616
5617  update = new Selection(update, parents);
5618  update._enter = enter;
5619  update._exit = exit;
5620  return update;
5621}
5622
5623function selection_exit() {
5624  return new Selection(this._exit || this._groups.map(sparse), this._parents);
5625}
5626
5627function selection_merge(selection$$1) {
5628
5629  for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
5630    for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
5631      if (node = group0[i] || group1[i]) {
5632        merge[i] = node;
5633      }
5634    }
5635  }
5636
5637  for (; j < m0; ++j) {
5638    merges[j] = groups0[j];
5639  }
5640
5641  return new Selection(merges, this._parents);
5642}
5643
5644function selection_order() {
5645
5646  for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
5647    for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
5648      if (node = group[i]) {
5649        if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
5650        next = node;
5651      }
5652    }
5653  }
5654
5655  return this;
5656}
5657
5658function selection_sort(compare) {
5659  if (!compare) compare = ascending$1;
5660
5661  function compareNode(a, b) {
5662    return a && b ? compare(a.__data__, b.__data__) : !a - !b;
5663  }
5664
5665  for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
5666    for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
5667      if (node = group[i]) {
5668        sortgroup[i] = node;
5669      }
5670    }
5671    sortgroup.sort(compareNode);
5672  }
5673
5674  return new Selection(sortgroups, this._parents).order();
5675}
5676
5677function ascending$1(a, b) {
5678  return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
5679}
5680
5681function selection_call() {
5682  var callback = arguments[0];
5683  arguments[0] = this;
5684  callback.apply(null, arguments);
5685  return this;
5686}
5687
5688function selection_nodes() {
5689  var nodes = new Array(this.size()), i = -1;
5690  this.each(function() { nodes[++i] = this; });
5691  return nodes;
5692}
5693
5694function selection_node() {
5695
5696  for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
5697    for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
5698      var node = group[i];
5699      if (node) return node;
5700    }
5701  }
5702
5703  return null;
5704}
5705
5706function selection_size() {
5707  var size = 0;
5708  this.each(function() { ++size; });
vendor: 7,453 bytes, lines 5708-6025
5708
5709  return size;
5710}
5711
5712function selection_empty() {
5713  return !this.node();
5714}
5715
5716function selection_each(callback) {
5717
5718  for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
5719    for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
5720      if (node = group[i]) callback.call(node, node.__data__, i, group);
5721    }
5722  }
5723
5724  return this;
5725}
5726
5727function attrRemove(name) {
5728  return function() {
5729    this.removeAttribute(name);
5730  };
5731}
5732
5733function attrRemoveNS(fullname) {
5734  return function() {
5735    this.removeAttributeNS(fullname.space, fullname.local);
5736  };
5737}
5738
5739function attrConstant(name, value) {
5740  return function() {
5741    this.setAttribute(name, value);
5742  };
5743}
5744
5745function attrConstantNS(fullname, value) {
5746  return function() {
5747    this.setAttributeNS(fullname.space, fullname.local, value);
5748  };
5749}
5750
5751function attrFunction(name, value) {
5752  return function() {
5753    var v = value.apply(this, arguments);
5754    if (v == null) this.removeAttribute(name);
5755    else this.setAttribute(name, v);
5756  };
5757}
5758
5759function attrFunctionNS(fullname, value) {
5760  return function() {
5761    var v = value.apply(this, arguments);
5762    if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
5763    else this.setAttributeNS(fullname.space, fullname.local, v);
5764  };
5765}
5766
5767function selection_attr(name, value) {
5768  var fullname = namespace(name);
5769
5770  if (arguments.length < 2) {
5771    var node = this.node();
5772    return fullname.local
5773        ? node.getAttributeNS(fullname.space, fullname.local)
5774        : node.getAttribute(fullname);
5775  }
5776
5777  return this.each((value == null
5778      ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
5779      ? (fullname.local ? attrFunctionNS : attrFunction)
5780      : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
5781}
5782
5783function defaultView(node) {
5784  return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
5785      || (node.document && node) // node is a Window
5786      || node.defaultView; // node is a Document
5787}
5788
5789function styleRemove(name) {
5790  return function() {
5791    this.style.removeProperty(name);
5792  };
5793}
5794
5795function styleConstant(name, value, priority) {
5796  return function() {
5797    this.style.setProperty(name, value, priority);
5798  };
5799}
5800
5801function styleFunction(name, value, priority) {
5802  return function() {
5803    var v = value.apply(this, arguments);
5804    if (v == null) this.style.removeProperty(name);
5805    else this.style.setProperty(name, v, priority);
5806  };
5807}
5808
5809function selection_style(name, value, priority) {
5810  return arguments.length > 1
5811      ? this.each((value == null
5812            ? styleRemove : typeof value === "function"
5813            ? styleFunction
5814            : styleConstant)(name, value, priority == null ? "" : priority))
5815      : styleValue(this.node(), name);
5816}
5817
5818function styleValue(node, name) {
5819  return node.style.getPropertyValue(name)
5820      || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
5821}
5822
5823function propertyRemove(name) {
5824  return function() {
5825    delete this[name];
5826  };
5827}
5828
5829function propertyConstant(name, value) {
5830  return function() {
5831    this[name] = value;
5832  };
5833}
5834
5835function propertyFunction(name, value) {
5836  return function() {
5837    var v = value.apply(this, arguments);
5838    if (v == null) delete this[name];
5839    else this[name] = v;
5840  };
5841}
5842
5843function selection_property(name, value) {
5844  return arguments.length > 1
5845      ? this.each((value == null
5846          ? propertyRemove : typeof value === "function"
5847          ? propertyFunction
5848          : propertyConstant)(name, value))
5849      : this.node()[name];
5850}
5851
5852function classArray(string) {
5853  return string.trim().split(/^|\s+/);
5854}
5855
5856function classList(node) {
5857  return node.classList || new ClassList(node);
5858}
5859
5860function ClassList(node) {
5861  this._node = node;
5862  this._names = classArray(node.getAttribute("class") || "");
5863}
5864
5865ClassList.prototype = {
5866  add: function(name) {
5867    var i = this._names.indexOf(name);
5868    if (i < 0) {
5869      this._names.push(name);
5870      this._node.setAttribute("class", this._names.join(" "));
5871    }
5872  },
5873  remove: function(name) {
5874    var i = this._names.indexOf(name);
5875    if (i >= 0) {
5876      this._names.splice(i, 1);
5877      this._node.setAttribute("class", this._names.join(" "));
5878    }
5879  },
5880  contains: function(name) {
5881    return this._names.indexOf(name) >= 0;
5882  }
5883};
5884
5885function classedAdd(node, names) {
5886  var list = classList(node), i = -1, n = names.length;
5887  while (++i < n) list.add(names[i]);
5888}
5889
5890function classedRemove(node, names) {
5891  var list = classList(node), i = -1, n = names.length;
5892  while (++i < n) list.remove(names[i]);
5893}
5894
5895function classedTrue(names) {
5896  return function() {
5897    classedAdd(this, names);
5898  };
5899}
5900
5901function classedFalse(names) {
5902  return function() {
5903    classedRemove(this, names);
5904  };
5905}
5906
5907function classedFunction(names, value) {
5908  return function() {
5909    (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
5910  };
5911}
5912
5913function selection_classed(name, value) {
5914  var names = classArray(name + "");
5915
5916  if (arguments.length < 2) {
5917    var list = classList(this.node()), i = -1, n = names.length;
5918    while (++i < n) if (!list.contains(names[i])) return false;
5919    return true;
5920  }
5921
5922  return this.each((typeof value === "function"
5923      ? classedFunction : value
5924      ? classedTrue
5925      : classedFalse)(names, value));
5926}
5927
5928function textRemove() {
5929  this.textContent = "";
5930}
5931
5932function textConstant(value) {
5933  return function() {
5934    this.textContent = value;
5935  };
5936}
5937
5938function textFunction(value) {
5939  return function() {
5940    var v = value.apply(this, arguments);
5941    this.textContent = v == null ? "" : v;
5942  };
5943}
5944
5945function selection_text(value) {
5946  return arguments.length
5947      ? this.each(value == null
5948          ? textRemove : (typeof value === "function"
5949          ? textFunction
5950          : textConstant)(value))
5951      : this.node().textContent;
5952}
5953
5954function htmlRemove() {
5955  this.innerHTML = "";
5956}
5957
5958function htmlConstant(value) {
5959  return function() {
5960    this.innerHTML = value;
5961  };
5962}
5963
5964function htmlFunction(value) {
5965  return function() {
5966    var v = value.apply(this, arguments);
5967    this.innerHTML = v == null ? "" : v;
5968  };
5969}
5970
5971function selection_html(value) {
5972  return arguments.length
5973      ? this.each(value == null
5974          ? htmlRemove : (typeof value === "function"
5975          ? htmlFunction
5976          : htmlConstant)(value))
5977      : this.node().innerHTML;
5978}
5979
5980function raise() {
5981  if (this.nextSibling) this.parentNode.appendChild(this);
5982}
5983
5984function selection_raise() {
5985  return this.each(raise);
5986}
5987
5988function lower() {
5989  if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
5990}
5991
5992function selection_lower() {
5993  return this.each(lower);
5994}
5995
5996function selection_append(name) {
5997  var create = typeof name === "function" ? name : creator(name);
5998  return this.select(function() {
5999    return this.appendChild(create.apply(this, arguments));
6000  });
6001}
6002
6003function constantNull() {
6004  return null;
6005}
6006
6007function selection_insert(name, before) {
6008  var create = typeof name === "function" ? name : creator(name),
6009      select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
6010  return this.select(function() {
6011    return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
6012  });
6013}
6014
6015function remove() {
6016  var parent = this.parentNode;
6017  if (parent) parent.removeChild(this);
6018}
6019
6020function selection_remove() {
6021  return this.each(remove);
6022}
6023
6024function selection_cloneShallow() {
6025  
vendor: 3,281 bytes, lines 6025-6134
6025return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
6026}
6027
6028function selection_cloneDeep() {
6029  return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
6030}
6031
6032function selection_clone(deep) {
6033  return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
6034}
6035
6036function selection_datum(value) {
6037  return arguments.length
6038      ? this.property("__data__", value)
6039      : this.node().__data__;
6040}
6041
6042var filterEvents = {};
6043
6044exports.event = null;
6045
6046if (typeof document !== "undefined") {
6047  var element$1 = document.documentElement;
6048  if (!("onmouseenter" in element$1)) {
6049    filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
6050  }
6051}
6052
6053function filterContextListener(listener, index, group) {
6054  listener = contextListener(listener, index, group);
6055  return function(event) {
6056    var related = event.relatedTarget;
6057    if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
6058      listener.call(this, event);
6059    }
6060  };
6061}
6062
6063function contextListener(listener, index, group) {
6064  return function(event1) {
6065    var event0 = exports.event; // Events can be reentrant (e.g., focus).
6066    exports.event = event1;
6067    try {
6068      listener.call(this, this.__data__, index, group);
6069    } finally {
6070      exports.event = event0;
6071    }
6072  };
6073}
6074
6075function parseTypenames$1(typenames) {
6076  return typenames.trim().split(/^|\s+/).map(function(t) {
6077    var name = "", i = t.indexOf(".");
6078    if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
6079    return {type: t, name: name};
6080  });
6081}
6082
6083function onRemove(typename) {
6084  return function() {
6085    var on = this.__on;
6086    if (!on) return;
6087    for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
6088      if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
6089        this.removeEventListener(o.type, o.listener, o.capture);
6090      } else {
6091        on[++i] = o;
6092      }
6093    }
6094    if (++i) on.length = i;
6095    else delete this.__on;
6096  };
6097}
6098
6099function onAdd(typename, value, capture) {
6100  var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
6101  return function(d, i, group) {
6102    var on = this.__on, o, listener = wrap(value, i, group);
6103    if (on) for (var j = 0, m = on.length; j < m; ++j) {
6104      if ((o = on[j]).type === typename.type && o.name === typename.name) {
6105        this.removeEventListener(o.type, o.listener, o.capture);
6106        this.addEventListener(o.type, o.listener = listener, o.capture = capture);
6107        o.value = value;
6108        return;
6109      }
6110    }
6111    this.addEventListener(typename.type, listener, capture);
6112    o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
6113    if (!on) this.__on = [o];
6114    else on.push(o);
6115  };
6116}
6117
6118function selection_on(typename, value, capture) {
6119  var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
6120
6121  if (arguments.length < 2) {
6122    var on = this.node().__on;
6123    if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
6124      for (i = 0, o = on[j]; i < n; ++i) {
6125        if ((t = typenames[i]).type === o.type && t.name === o.name) {
6126          return o.value;
6127        }
6128      }
6129    }
6130    return;
6131  }
6132
6133  on = value ? onAdd : onRemove;
6134  if (capture == null) capture = false;
6135  for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
6136  return this;
6137}
6138
6139function customEvent(event1, listener, that, args) {
6140  var event0 = exports.event;
6141  event1.sourceEvent = exports.event;
6142  exports.event = event1;
6143  try {
6144    return listener.apply(that, args);
6145  } finally {
6146    exports.event = event0;
6147  }
6148}
6149
6150function dispatchEvent(node, type, params) {
6151  var window = defaultView(node),
6152      event = window.CustomEvent;
6153
6154  if (typeof event === "function") {
6155    event = new event(type, params);
6156  } else {
6157    event = window.document.createEvent("Event");
6158    if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
6159    else event.initEvent(type, false, false);
6160  }
6161
6162  node.dispatchEvent(event);
6163}
6164
6165function dispatchConstant(type, params) {
6166  return function() {
6167    return dispatchEvent(this, type, params);
6168  };
6169}
6170
6171function dispatchFunction(type, params) {
6172  return function() {
6173    return dispatchEvent(this, type, params.apply(this, arguments));
6174  };
6175}
6176
6177function selection_dispatch(type, params) {
6178  return this.each((typeof params === "function"
6179      ? dispatchFunction
6180      : dispatchConstant)(type, params));
6181}
6182
6183var root = [null];
6184
6185function Selection(groups, parents) {
6186  this._groups = groups;
6187  this._parents = parents;
6188}
6189
6190function selection() {
6191  return new Selection([[document.documentElement]], root);
6192}
6193
6194Selection.prototype = selection.prototype = {
6195  constructor: Selection,
6196  select: selection_select,
6197  selectAll: selection_selectAll,
6198  filter: selection_filter,
6199  data: selection_data,
6200  enter: selection_enter,
6201  exit: selection_exit,
6202  merge: selection_merge,
6203  order: selection_order,
6204  sort: selection_sort,
6205  call: selection_call,
6206  nodes: selection_nodes,
6207  node: selection_node,
6208  size: selection_size,
6209  empty: selection_empty,
6210  each: selection_each,
6211  attr: selection_attr,
6212  style: selection_style,
6213  property: selection_property,
6214  classed: selection_classed,
6215  text: selection_text,
6216  html: selection_html,
6217  raise: selection_raise,
6218  lower: selection_lower,
6219  append: selection_append,
6220  insert: selection_insert,
6221  remove: selection_remove,
6222  clone: selection_clone,
6223  datum: selection_datum,
6224  on: selection_on,
6225  dispatch: selection_dispatch
6226};
6227
6228function select(selector) {
6229  return typeof selector === "string"
6230      ? new Selection([[document.querySelector(selector)]], [document.documentElement])
6231      : new Selection([[selector]], root);
6232}
6233
6234function create(name) {
6235  return select(creator(name).call(document.documentElement));
6236}
6237
6238var nextId = 0;
6239
6240function local$1() {
6241  return new Local;
6242}
6243
6244function Local() {
6245  this._ = "@" + (++nextId).toString(36);
6246}
6247
6248Local.prototype = local$1.prototype = {
6249  constructor: Local,
6250  get: function(node) {
6251    var id = this._;
6252    while (!(id in node)) if (!(node = node.parentNode)) return;
6253    return node[id];
6254  },
6255  set: function(node, value) {
6256    return node[this._] = value;
6257  },
6258  remove: function(node) {
6259    return this._ in node && delete node[this._];
6260  },
6261  toString: function() {
6262    return this._;
6263  }
6264};
6265
6266function sourceEvent() {
6267  var current = exports.event, source;
6268  while (source = current.sourceEvent) current = source;
6269  return current;
6270}
6271
6272function point(node, event) {
6273  var svg = node.ownerSVGElement || node;
6274
6275  if (svg.createSVGPoint) {
6276    var point = svg.createSVGPoint();
6277    point.x = event.clientX, point.y = event.clientY;
6278    point = point.matrixTransform(node.getScreenCTM().inverse());
6279    return [point.x, point.y];
6280  }
6281
6282  var rect = node.getBoundingClientRect();
6283  return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
6284}
6285
6286function mouse(node) {
6287  var event = sourceEvent();
6288  if (event.changedTouches) event = event.changedTouches[0];
6289  return point(node, event);
6290}
6291
6292function selectAll(selector) {
6293  return typeof selector === "string"
6294      ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
6295      : new Selection([selector == null ? [] : selector], root);
6296}
6297
6298function touch(node, touches, identifier) {
6299  if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
6300
6301  for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
6302    if ((touch = touches[i]).identifier === identifier) {
6303      return point(node, touch);
6304    }
6305  }
6306
6307  return null;
6308}
6309
6310function touches(node, touches) {
6311  if (touches == null) touches = sourceEvent().touches;
6312
6313  for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
6314    points[i] = point(node, touches[i]);
6315  }
6316
6317  return points;
6318}
6319
6320function nopropagation() {
6321  exports.event.stopImmediatePropagation();
6322}
6323
6324function noevent() {
6325  exports.event.preventDefault();
6326  exports.event.stopImmediatePropagation();
6327}
6328
6329function dragDisable(view) {
6330  var root = view.document.documentElement,
6331      selection = select(view).on("dragstart.drag", noevent, true);
6332  if ("onselectstart" in root) {
6333    selection.on("selectstart.drag", noevent, true);
6334  } else {
6335    root.__noselect = root.style.MozUserSelect;
6336    root.style.MozUserSelect = "none";
6337  }
6338}
6339
6340function yesdrag(view, noclick) {
6341  var root = view.document.documentElement,
6342      selection = select(view).on("dragstart.drag", null);
6343  if (noclick) {
6344    selection.on("click.drag", noevent, true);
6345    setTimeout(function() { selection.on("click.drag", null); }, 0);
6346  }
6347  if ("onselectstart" in root) {
6348    selection.on("selectstart.drag", null);
6349  } else {
6350    root.style.MozUserSelect = root.__noselect;
6351    delete root.__noselect;
6352  }
6353}
6354
6355function constant$2(x) {
6356  return function() {
6357    return x;
6358  };
6359}
6360
6361function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
6362  this.target = target;
6363  this.type = type;
6364  this.subject = subject;
6365  this.identifier = id;
6366  this.active = active;
6367  this.x = x;
6368  this.y = y;
6369  this.dx = dx;
6370  this.dy = dy;
6371  this._ = dispatch;
6372}
6373
6374DragEvent.prototype.on = function() {
6375  var value = this._.on.apply(this._, arguments);
6376  return value === this._ ? this : value;
6377};
6378
6379// Ignore right-click, since that should open the context menu.
6380function defaultFilter$1() {
6381  return !exports.event.button;
6382}
6383
6384function defaultContainer() {
6385  return this.parentNode;
6386}
6387
6388function defaultSubject(d) {
6389  return d == null ? {x: exports.event.x, y: exports.event.y} : d;
6390}
6391
6392function defaultTouchable() {
6393  return "ontouchstart" in this;
6394}
6395
6396function drag() {
6397  var filter = defaultFilter$1,
6398      container = defaultContainer,
6399      subject = defaultSubject,
6400      touchable = defaultTouchable,
6401      gestures = {},
6402      listeners = dispatch("start", "drag", "end"),
6403      active = 0,
6404      mousedownx,
6405      mousedowny,
6406      mousemoving,
6407      touchending,
6408      clickDistance2 = 0;
6409
6410  function drag(selection) {
6411    selection
6412        .on("mousedown.drag", mousedowned)
6413      .filter(touchable)
6414        .on("touchstart.drag", touchstarted)
6415        .on("touchmove.drag", touchmoved)
6416        .on("touchend.drag touchcancel.drag", touchended)
6417        .style("touch-action", "none")
6418        .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
6419  }
6420
6421  function mousedowned() {
6422    if (touchending || !filter.apply(this, arguments)) return;
6423    var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
6424    if (!gesture) return;
6425    select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
6426    dragDisable(exports.event.view);
6427    nopropagation();
6428    mousemoving = false;
6429    mousedownx = exports.event.clientX;
6430    mousedowny = exports.event.clientY;
6431    gesture("start");
6432  }
6433
6434  function mousemoved() {
6435    noevent();
6436    if (!mousemoving) {
6437      var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
6438      mousemoving = dx * dx + dy * dy > clickDistance2;
6439    }
6440    gestures.mouse("drag");
6441  }
6442
6443  function mouseupped() {
6444    select(exports.event.view).on("mousemove.drag mouseup.drag", null);
6445    yesdrag(exports.event.view, mousemoving);
6446    noevent();
6447    gestures.mouse("end");
6448  }
6449
6450  function touchstarted() {
6451    if (!filter.apply(this, arguments)) return;
6452    var touches = exports.event.changedTouches,
6453        c = container.apply(this, arguments),
6454        n = touches.length, i, gesture;
6455
6456    for (i = 0; i < n; ++i) {
6457      if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
6458        nopropagation();
6459        gesture("start");
6460      }
6461    }
6462  }
6463
6464  function touchmoved() {
6465    var touches = exports.event.changedTouches,
6466        n = touches.length, i, gesture;
6467
6468    for (i = 0; i < n; ++i) {
6469      if (gesture = gestures[touches[i].identifier]) {
6470        noevent();
6471        gesture("drag");
6472      }
6473    }
6474  }
6475
6476  function touchended() {
6477    var touches = exports.event.changedTouches,
6478        n = touches.length, i, gesture;
6479
6480    if (touchending) clearTimeout(touchending);
6481    touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
6482    for (i = 0; i < n; ++i) {
6483      if (gesture = gestures[touches[i].identifier]) {
6484        nopropagation();
6485        gesture("end");
6486      }
6487    }
6488  }
6489
6490  function beforestart(id, container, point, that, args) {
6491    var p = point(container, id), s, dx, dy,
6492        sublisteners = listeners.copy();
6493
6494    if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
6495      if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
6496      dx = s.x - p[0] || 0;
6497      dy = s.y - p[1] || 0;
6498      return true;
6499    })) return;
6500
6501    return function gesture(type) {
6502      var p0 = p, n;
6503      switch (type) {
6504        case "start": gestures[id] = gesture, n = active++; break;
6505        case "end": delete gestures[id], --active; // nobreak
6506        case "drag": p = point(container, id), n = active; break;
6507      }
6508      customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
6509    };
6510  }
6511
6512  drag.filter = function(_) {
6513    return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
6514  };
6515
6516  drag.container = function(_) {
6517    return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
6518  };
6519
6520  drag.subject = function(_) {
6521    return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
6522  };
6523
6524  drag.touchable = function(_) {
6525    return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
6526  };
6527
6528  drag.on = function() {
6529    var value = listeners.on.apply(listeners, arguments);
6530    return value === listeners ? drag : value;
6531  };
6532
6533  drag.clickDistance = function(_) {
6534    return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
6535  };
6536
6537  return drag;
6538}
6539
6540function define(constructor, factory, prototype) {
6541  constructor.prototype = factory.prototype = prototype;
6542  prototype.constructor = constructor;
6543}
6544
6545function extend(parent, definition) {
6546  var prototype = Object.create(parent.prototype);
6547  for (var key in definition) prototype[key] = definition[key];
6548  return prototype;
6549}
6550
6551function Color() {}
6552
6553var darker = 0.7;
6554var brighter = 1 / darker;
6555
6556var reI = "\\s*([+-]?\\d+)\\s*";
6557var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
6558var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
6559var reHex3 = /^#([0-9a-f]{3})$/;
6560var reHex6 = /^#([0-9a-f]{6})$/;
6561var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
6562var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
6563var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
6564var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
6565var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
6566var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
6567
6568var named = {
6569  aliceblue: 0xf0f8ff,
6570  antiquewhite: 0xfaebd7,
6571  aqua: 0x00ffff,
6572  aquamarine: 0x7fffd4,
6573  azure: 0xf0ffff,
6574  beige: 0xf5f5dc,
6575  bisque: 0xffe4c4,
6576  black: 0x000000,
6577  blanchedalmond: 0xffebcd,
6578  blue: 0x0000ff,
6579  blueviolet: 0x8a2be2,
6580  brown: 0xa52a2a,
6581  burlywood: 0xdeb887,
6582  cadetblue: 0x5f9ea0,
6583  chartreuse: 0x7fff00,
6584  chocolate: 0xd2691e,
6585  coral: 0xff7f50,
6586  cornflowerblue: 0x6495ed,
6587  cornsilk: 0xfff8dc,
6588  crimson: 0xdc143c,
6589  cyan: 0x00ffff,
6590  darkblue: 0x00008b,
6591  darkcyan: 0x008b8b,
6592  darkgoldenrod: 0xb8860b,
6593  darkgray: 0xa9a9a9,
6594  darkgreen: 0x006400,
6595  darkgrey: 0xa9a9a9,
6596  darkkhaki: 0xbdb76b,
6597  darkmagenta: 0x8b008b,
6598  darkolivegreen: 0x556b2f,
6599  darkorange: 0xff8c00,
6600  darkorchid: 0x9932cc,
6601  darkred: 0x8b0000,
6602  darksalmon: 0xe9967a,
6603  darkseagreen: 0x8fbc8f,
6604  darkslateblue: 0x483d8b,
6605  darkslategray: 0x2f4f4f,
6606  darkslategrey: 0x2f4f4f,
6607  darkturquoise: 0x00ced1,
6608  darkviolet: 0x9400d3,
6609  deeppink: 0xff1493,
6610  deepskyblue: 0x00bfff,
6611  dimgray: 0x696969,
6612  dimgrey: 0x696969,
6613  dodgerblue: 0x1e90ff,
6614  firebrick: 0xb22222,
6615  floralwhite: 0xfffaf0,
6616  forestgreen: 0x228b22,
6617  fuchsia: 0xff00ff,
6618  gainsboro: 0xdcdcdc,
6619  ghostwhite: 0xf8f8ff,
6620  gold: 0xffd700,
6621  goldenrod: 0xdaa520,
6622  gray: 0x808080,
6623  green: 0x008000,
6624  greenyellow: 0xadff2f,
6625  grey: 0x808080,
6626  honeydew: 0xf0fff0,
6627  hotpink: 0xff69b4,
6628  indianred: 0xcd5c5c,
6629  indigo: 0x4b0082,
6630  ivory: 0xfffff0,
6631  khaki: 0xf0e68c,
6632  lavender: 0xe6e6fa,
6633  lavenderblush: 0xfff0f5,
6634  lawngreen: 0x7cfc00,
6635  lemonchiffon: 0xfffacd,
6636  lightblue: 0xadd8e6,
6637  lightcoral: 0xf08080,
6638  lightcyan: 0xe0ffff,
6639  lightgoldenrodyellow: 0xfafad2,
6640  lightgray: 0xd3d3d3,
6641  lightgreen: 0x90ee90,
6642  lightgrey: 0xd3d3d3,
6643  lightpink: 0xffb6c1,
6644  lightsalmon: 0xffa07a,
6645  lightseagreen: 0x20b2aa,
6646  lightskyblue: 0x87cefa,
6647  lightslategray: 0x778899,
6648  lightslategrey: 0x778899,
6649  lightsteelblue: 0xb0c4de,
6650  lightyellow: 0xffffe0,
6651  lime: 0x00ff00,
6652  limegreen: 0x32cd32,
6653  linen: 0xfaf0e6,
6654  magenta: 0xff00ff,
6655  maroon: 0x800000,
6656  mediumaquamarine: 0x66cdaa,
6657  mediumblue: 0x0000cd,
6658  mediumorchid: 0xba55d3,
6659  mediumpurple: 0x9370db,
6660  mediumseagreen: 0x3cb371,
6661  mediumslateblue: 0x7b68ee,
6662  mediumspringgreen: 0x00fa9a,
6663  mediumturquoise: 0x48d1cc,
6664  mediumvioletred: 0xc71585,
6665  midnightblue: 0x191970,
6666  mintcream: 0xf5fffa,
6667  mistyrose: 0xffe4e1,
6668  moccasin: 0xffe4b5,
6669  navajowhite: 0xffdead,
6670  navy: 0x000080,
6671  oldlace: 0xfdf5e6,
6672  olive: 0x808000,
6673  olivedrab: 0x6b8e23,
6674  orange: 0xffa500,
6675  orangered: 0xff4500,
6676  orchid: 0xda70d6,
6677  palegoldenrod: 0xeee8aa,
6678  palegreen: 0x98fb98,
6679  paleturquoise: 0xafeeee,
6680  palevioletred: 0xdb7093,
6681  papayawhip: 0xffefd5,
6682  peachpuff: 0xffdab9,
6683  peru: 0xcd853f,
6684  pink: 0xffc0cb,
6685  plum: 0xdda0dd,
6686  powderblue: 0xb0e0e6,
6687  purple: 0x800080,
6688  rebeccapurple: 0x663399,
6689  red: 0xff0000,
6690  rosybrown: 0xbc8f8f,
6691  royalblue: 0x4169e1,
6692  saddlebrown: 0x8b4513,
6693  salmon: 0xfa8072,
6694  sandybrown: 0xf4a460,
6695  seagreen: 0x2e8b57,
6696  seashell: 0xfff5ee,
6697  sienna: 0xa0522d,
6698  silver: 0xc0c0c0,
6699  skyblue: 0x87ceeb,
6700  slateblue: 0x6a5acd,
6701  slategray: 0x708090,
6702  slategrey: 0x708090,
6703  snow: 0xfffafa,
6704  springgreen: 0x00ff7f,
6705  steelblue: 0x4682b4,
6706  tan: 0xd2b48c,
6707  teal: 0x008080,
6708  thistle: 0xd8bfd8,
6709  tomato: 0xff6347,
6710  turquoise: 0x40e0d0,
6711  violet: 0xee82ee,
6712  wheat: 0xf5deb3,
6713  white: 0xffffff,
6714  whitesmoke: 0xf5f5f5,
6715  yellow: 0xffff00,
6716  yellowgreen: 0x9acd32
6717};
6718
6719define(Color, color, {
6720  displayable: function() {
6721    return this.rgb().displayable();
6722  },
6723  toString: function() {
6724    return this.rgb() + "";
6725  }
6726});
6727
6728function color(format) {
6729  var m;
6730  format = (format + "").trim().toLowerCase();
6731  return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
6732      : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
6733      : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
6734      : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 25
vendor: 4,591 bytes, lines 6734-6892
67345 / 100, 1) // rgb(100%, 0%, 0%)
6735      : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
6736      : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
6737      : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
6738      : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
6739      : named.hasOwnProperty(format) ? rgbn(named[format])
6740      : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
6741      : null;
6742}
6743
6744function rgbn(n) {
6745  return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
6746}
6747
6748function rgba(r, g, b, a) {
6749  if (a <= 0) r = g = b = NaN;
6750  return new Rgb(r, g, b, a);
6751}
6752
6753function rgbConvert(o) {
6754  if (!(o instanceof Color)) o = color(o);
6755  if (!o) return new Rgb;
6756  o = o.rgb();
6757  return new Rgb(o.r, o.g, o.b, o.opacity);
6758}
6759
6760function rgb(r, g, b, opacity) {
6761  return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
6762}
6763
6764function Rgb(r, g, b, opacity) {
6765  this.r = +r;
6766  this.g = +g;
6767  this.b = +b;
6768  this.opacity = +opacity;
6769}
6770
6771define(Rgb, rgb, extend(Color, {
6772  brighter: function(k) {
6773    k = k == null ? brighter : Math.pow(brighter, k);
6774    return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
6775  },
6776  darker: function(k) {
6777    k = k == null ? darker : Math.pow(darker, k);
6778    return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
6779  },
6780  rgb: function() {
6781    return this;
6782  },
6783  displayable: function() {
6784    return (0 <= this.r && this.r <= 255)
6785        && (0 <= this.g && this.g <= 255)
6786        && (0 <= this.b && this.b <= 255)
6787        && (0 <= this.opacity && this.opacity <= 1);
6788  },
6789  toString: function() {
6790    var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
6791    return (a === 1 ? "rgb(" : "rgba(")
6792        + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
6793        + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
6794        + Math.max(0, Math.min(255, Math.round(this.b) || 0))
6795        + (a === 1 ? ")" : ", " + a + ")");
6796  }
6797}));
6798
6799function hsla(h, s, l, a) {
6800  if (a <= 0) h = s = l = NaN;
6801  else if (l <= 0 || l >= 1) h = s = NaN;
6802  else if (s <= 0) h = NaN;
6803  return new Hsl(h, s, l, a);
6804}
6805
6806function hslConvert(o) {
6807  if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
6808  if (!(o instanceof Color)) o = color(o);
6809  if (!o) return new Hsl;
6810  if (o instanceof Hsl) return o;
6811  o = o.rgb();
6812  var r = o.r / 255,
6813      g = o.g / 255,
6814      b = o.b / 255,
6815      min = Math.min(r, g, b),
6816      max = Math.max(r, g, b),
6817      h = NaN,
6818      s = max - min,
6819      l = (max + min) / 2;
6820  if (s) {
6821    if (r === max) h = (g - b) / s + (g < b) * 6;
6822    else if (g === max) h = (b - r) / s + 2;
6823    else h = (r - g) / s + 4;
6824    s /= l < 0.5 ? max + min : 2 - max - min;
6825    h *= 60;
6826  } else {
6827    s = l > 0 && l < 1 ? 0 : h;
6828  }
6829  return new Hsl(h, s, l, o.opacity);
6830}
6831
6832function hsl(h, s, l, opacity) {
6833  return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
6834}
6835
6836function Hsl(h, s, l, opacity) {
6837  this.h = +h;
6838  this.s = +s;
6839  this.l = +l;
6840  this.opacity = +opacity;
6841}
6842
6843define(Hsl, hsl, extend(Color, {
6844  brighter: function(k) {
6845    k = k == null ? brighter : Math.pow(brighter, k);
6846    return new Hsl(this.h, this.s, this.l * k, this.opacity);
6847  },
6848  darker: function(k) {
6849    k = k == null ? darker : Math.pow(darker, k);
6850    return new Hsl(this.h, this.s, this.l * k, this.opacity);
6851  },
6852  rgb: function() {
6853    var h = this.h % 360 + (this.h < 0) * 360,
6854        s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
6855        l = this.l,
6856        m2 = l + (l < 0.5 ? l : 1 - l) * s,
6857        m1 = 2 * l - m2;
6858    return new Rgb(
6859      hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
6860      hsl2rgb(h, m1, m2),
6861      hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
6862      this.opacity
6863    );
6864  },
6865  displayable: function() {
6866    return (0 <= this.s && this.s <= 1 || isNaN(this.s))
6867        && (0 <= this.l && this.l <= 1)
6868        && (0 <= this.opacity && this.opacity <= 1);
6869  }
6870}));
6871
6872/* From FvD 13.37, CSS Color Module Level 3 */
6873function hsl2rgb(h, m1, m2) {
6874  return (h < 60 ? m1 + (m2 - m1) * h / 60
6875      : h < 180 ? m2
6876      : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
6877      : m1) * 255;
6878}
6879
6880var deg2rad = Math.PI / 180;
6881var rad2deg = 180 / Math.PI;
6882
6883var Kn = 18;
6884var Xn = 0.950470;
6885var Yn = 1;
6886var Zn = 1.088830;
6887var t0 = 4 / 29;
6888var t1 = 6 / 29;
6889var t2 = 3 * t1 * t1;
6890var t3 = t1 * t1 * t1;
6891
6892function labConvert(o) {
vendor: 10,821 bytes, lines 6893-7308
6893  if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
6894  if (o instanceof Hcl) {
6895    var h = o.h * deg2rad;
6896    return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
6897  }
6898  if (!(o instanceof Rgb)) o = rgbConvert(o);
6899  var b = rgb2xyz(o.r),
6900      a = rgb2xyz(o.g),
6901      l = rgb2xyz(o.b),
6902      x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
6903      y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
6904      z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
6905  return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
6906}
6907
6908function lab(l, a, b, opacity) {
6909  return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
6910}
6911
6912function Lab(l, a, b, opacity) {
6913  this.l = +l;
6914  this.a = +a;
6915  this.b = +b;
6916  this.opacity = +opacity;
6917}
6918
6919define(Lab, lab, extend(Color, {
6920  brighter: function(k) {
6921    return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
6922  },
6923  darker: function(k) {
6924    return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
6925  },
6926  rgb: function() {
6927    var y = (this.l + 16) / 116,
6928        x = isNaN(this.a) ? y : y + this.a / 500,
6929        z = isNaN(this.b) ? y : y - this.b / 200;
6930    y = Yn * lab2xyz(y);
6931    x = Xn * lab2xyz(x);
6932    z = Zn * lab2xyz(z);
6933    return new Rgb(
6934      xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
6935      xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
6936      xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
6937      this.opacity
6938    );
6939  }
6940}));
6941
6942function xyz2lab(t) {
6943  return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
6944}
6945
6946function lab2xyz(t) {
6947  return t > t1 ? t * t * t : t2 * (t - t0);
6948}
6949
6950function xyz2rgb(x) {
6951  return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
6952}
6953
6954function rgb2xyz(x) {
6955  return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
6956}
6957
6958function hclConvert(o) {
6959  if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
6960  if (!(o instanceof Lab)) o = labConvert(o);
6961  var h = Math.atan2(o.b, o.a) * rad2deg;
6962  return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
6963}
6964
6965function hcl(h, c, l, opacity) {
6966  return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
6967}
6968
6969function Hcl(h, c, l, opacity) {
6970  this.h = +h;
6971  this.c = +c;
6972  this.l = +l;
6973  this.opacity = +opacity;
6974}
6975
6976define(Hcl, hcl, extend(Color, {
6977  brighter: function(k) {
6978    return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
6979  },
6980  darker: function(k) {
6981    return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
6982  },
6983  rgb: function() {
6984    return labConvert(this).rgb();
6985  }
6986}));
6987
6988var A = -0.14861;
6989var B = +1.78277;
6990var C = -0.29227;
6991var D = -0.90649;
6992var E = +1.97294;
6993var ED = E * D;
6994var EB = E * B;
6995var BC_DA = B * C - D * A;
6996
6997function cubehelixConvert(o) {
6998  if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
6999  if (!(o instanceof Rgb)) o = rgbConvert(o);
7000  var r = o.r / 255,
7001      g = o.g / 255,
7002      b = o.b / 255,
7003      l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
7004      bl = b - l,
7005      k = (E * (g - l) - C * bl) / D,
7006      s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
7007      h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
7008  return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
7009}
7010
7011function cubehelix(h, s, l, opacity) {
7012  return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
7013}
7014
7015function Cubehelix(h, s, l, opacity) {
7016  this.h = +h;
7017  this.s = +s;
7018  this.l = +l;
7019  this.opacity = +opacity;
7020}
7021
7022define(Cubehelix, cubehelix, extend(Color, {
7023  brighter: function(k) {
7024    k = k == null ? brighter : Math.pow(brighter, k);
7025    return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
7026  },
7027  darker: function(k) {
7028    k = k == null ? darker : Math.pow(darker, k);
7029    return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
7030  },
7031  rgb: function() {
7032    var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
7033        l = +this.l,
7034        a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
7035        cosh = Math.cos(h),
7036        sinh = Math.sin(h);
7037    return new Rgb(
7038      255 * (l + a * (A * cosh + B * sinh)),
7039      255 * (l + a * (C * cosh + D * sinh)),
7040      255 * (l + a * (E * cosh)),
7041      this.opacity
7042    );
7043  }
7044}));
7045
7046function basis(t1, v0, v1, v2, v3) {
7047  var t2 = t1 * t1, t3 = t2 * t1;
7048  return ((1 - 3 * t1 + 3 * t2 - t3) * v0
7049      + (4 - 6 * t2 + 3 * t3) * v1
7050      + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
7051      + t3 * v3) / 6;
7052}
7053
7054function basis$1(values) {
7055  var n = values.length - 1;
7056  return function(t) {
7057    var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
7058        v1 = values[i],
7059        v2 = values[i + 1],
7060        v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
7061        v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
7062    return basis((t - i / n) * n, v0, v1, v2, v3);
7063  };
7064}
7065
7066function basisClosed(values) {
7067  var n = values.length;
7068  return function(t) {
7069    var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
7070        v0 = values[(i + n - 1) % n],
7071        v1 = values[i % n],
7072        v2 = values[(i + 1) % n],
7073        v3 = values[(i + 2) % n];
7074    return basis((t - i / n) * n, v0, v1, v2, v3);
7075  };
7076}
7077
7078function constant$3(x) {
7079  return function() {
7080    return x;
7081  };
7082}
7083
7084function linear(a, d) {
7085  return function(t) {
7086    return a + t * d;
7087  };
7088}
7089
7090function exponential(a, b, y) {
7091  return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
7092    return Math.pow(a + t * b, y);
7093  };
7094}
7095
7096function hue(a, b) {
7097  var d = b - a;
7098  return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
7099}
7100
7101function gamma(y) {
7102  return (y = +y) === 1 ? nogamma : function(a, b) {
7103    return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
7104  };
7105}
7106
7107function nogamma(a, b) {
7108  var d = b - a;
7109  return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
7110}
7111
7112var interpolateRgb = (function rgbGamma(y) {
7113  var color$$1 = gamma(y);
7114
7115  function rgb$$1(start, end) {
7116    var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
7117        g = color$$1(start.g, end.g),
7118        b = color$$1(start.b, end.b),
7119        opacity = nogamma(start.opacity, end.opacity);
7120    return function(t) {
7121      start.r = r(t);
7122      start.g = g(t);
7123      start.b = b(t);
7124      start.opacity = opacity(t);
7125      return start + "";
7126    };
7127  }
7128
7129  rgb$$1.gamma = rgbGamma;
7130
7131  return rgb$$1;
7132})(1);
7133
7134function rgbSpline(spline) {
7135  return function(colors) {
7136    var n = colors.length,
7137        r = new Array(n),
7138        g = new Array(n),
7139        b = new Array(n),
7140        i, color$$1;
7141    for (i = 0; i < n; ++i) {
7142      color$$1 = rgb(colors[i]);
7143      r[i] = color$$1.r || 0;
7144      g[i] = color$$1.g || 0;
7145      b[i] = color$$1.b || 0;
7146    }
7147    r = spline(r);
7148    g = spline(g);
7149    b = spline(b);
7150    color$$1.opacity = 1;
7151    return function(t) {
7152      color$$1.r = r(t);
7153      color$$1.g = g(t);
7154      color$$1.b = b(t);
7155      return color$$1 + "";
7156    };
7157  };
7158}
7159
7160var rgbBasis = rgbSpline(basis$1);
7161var rgbBasisClosed = rgbSpline(basisClosed);
7162
7163function array$1(a, b) {
7164  var nb = b ? b.length : 0,
7165      na = a ? Math.min(nb, a.length) : 0,
7166      x = new Array(na),
7167      c = new Array(nb),
7168      i;
7169
7170  for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
7171  for (; i < nb; ++i) c[i] = b[i];
7172
7173  return function(t) {
7174    for (i = 0; i < na; ++i) c[i] = x[i](t);
7175    return c;
7176  };
7177}
7178
7179function date(a, b) {
7180  var d = new Date;
7181  return a = +a, b -= a, function(t) {
7182    return d.setTime(a + b * t), d;
7183  };
7184}
7185
7186function reinterpolate(a, b) {
7187  return a = +a, b -= a, function(t) {
7188    return a + b * t;
7189  };
7190}
7191
7192function object(a, b) {
7193  var i = {},
7194      c = {},
7195      k;
7196
7197  if (a === null || typeof a !== "object") a = {};
7198  if (b === null || typeof b !== "object") b = {};
7199
7200  for (k in b) {
7201    if (k in a) {
7202      i[k] = interpolateValue(a[k], b[k]);
7203    } else {
7204      c[k] = b[k];
7205    }
7206  }
7207
7208  return function(t) {
7209    for (k in i) c[k] = i[k](t);
7210    return c;
7211  };
7212}
7213
7214var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
7215var reB = new RegExp(reA.source, "g");
7216
7217function zero(b) {
7218  return function() {
7219    return b;
7220  };
7221}
7222
7223function one(b) {
7224  return function(t) {
7225    return b(t) + "";
7226  };
7227}
7228
7229function interpolateString(a, b) {
7230  var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
7231      am, // current match in a
7232      bm, // current match in b
7233      bs, // string preceding current number in b, if any
7234      i = -1, // index in s
7235      s = [], // string constants and placeholders
7236      q = []; // number interpolators
7237
7238  // Coerce inputs to strings.
7239  a = a + "", b = b + "";
7240
7241  // Interpolate pairs of numbers in a & b.
7242  while ((am = reA.exec(a))
7243      && (bm = reB.exec(b))) {
7244    if ((bs = bm.index) > bi) { // a string precedes the next number in b
7245      bs = b.slice(bi, bs);
7246      if (s[i]) s[i] += bs; // coalesce with previous string
7247      else s[++i] = bs;
7248    }
7249    if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
7250      if (s[i]) s[i] += bm; // coalesce with previous string
7251      else s[++i] = bm;
7252    } else { // interpolate non-matching numbers
7253      s[++i] = null;
7254      q.push({i: i, x: reinterpolate(am, bm)});
7255    }
7256    bi = reB.lastIndex;
7257  }
7258
7259  // Add remains of b.
7260  if (bi < b.length) {
7261    bs = b.slice(bi);
7262    if (s[i]) s[i] += bs; // coalesce with previous string
7263    else s[++i] = bs;
7264  }
7265
7266  // Special optimization for only a single match.
7267  // Otherwise, interpolate each of the numbers and rejoin the string.
7268  return s.length < 2 ? (q[0]
7269      ? one(q[0].x)
7270      : zero(b))
7271      : (b = q.length, function(t) {
7272          for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
7273          return s.join("");
7274        });
7275}
7276
7277function interpolateValue(a, b) {
7278  var t = typeof b, c;
7279  return b == null || t === "boolean" ? constant$3(b)
7280      : (t === "number" ? reinterpolate
7281      : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
7282      : b instanceof color ? interpolateRgb
7283      : b instanceof Date ? date
7284      : Array.isArray(b) ? array$1
7285      : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
7286      : reinterpolate)(a, b);
7287}
7288
7289function interpolateRound(a, b) {
7290  return a = +a, b -= a, function(t) {
7291    return Math.round(a + b * t);
7292  };
7293}
7294
7295var degrees = 180 / Math.PI;
7296
7297var identity$2 = {
7298  translateX: 0,
7299  translateY: 0,
7300  rotate: 0,
7301  skewX: 0,
7302  scaleX: 1,
7303  scaleY: 1
7304};
7305
7306function decompose(a, b, c, d, e, f) {
7307  var scaleX, scaleY, skewX;
7308  if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
vendor: 8,677 bytes, lines 7309-7635
7309  if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
7310  if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
7311  if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
7312  return {
7313    translateX: e,
7314    translateY: f,
7315    rotate: Math.atan2(b, a) * degrees,
7316    skewX: Math.atan(skewX) * degrees,
7317    scaleX: scaleX,
7318    scaleY: scaleY
7319  };
7320}
7321
7322var cssNode;
7323var cssRoot;
7324var cssView;
7325var svgNode;
7326
7327function parseCss(value) {
7328  if (value === "none") return identity$2;
7329  if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
7330  cssNode.style.transform = value;
7331  value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
7332  cssRoot.removeChild(cssNode);
7333  value = value.slice(7, -1).split(",");
7334  return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
7335}
7336
7337function parseSvg(value) {
7338  if (value == null) return identity$2;
7339  if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
7340  svgNode.setAttribute("transform", value);
7341  if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
7342  value = value.matrix;
7343  return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
7344}
7345
7346function interpolateTransform(parse, pxComma, pxParen, degParen) {
7347
7348  function pop(s) {
7349    return s.length ? s.pop() + " " : "";
7350  }
7351
7352  function translate(xa, ya, xb, yb, s, q) {
7353    if (xa !== xb || ya !== yb) {
7354      var i = s.push("translate(", null, pxComma, null, pxParen);
7355      q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
7356    } else if (xb || yb) {
7357      s.push("translate(" + xb + pxComma + yb + pxParen);
7358    }
7359  }
7360
7361  function rotate(a, b, s, q) {
7362    if (a !== b) {
7363      if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
7364      q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
7365    } else if (b) {
7366      s.push(pop(s) + "rotate(" + b + degParen);
7367    }
7368  }
7369
7370  function skewX(a, b, s, q) {
7371    if (a !== b) {
7372      q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
7373    } else if (b) {
7374      s.push(pop(s) + "skewX(" + b + degParen);
7375    }
7376  }
7377
7378  function scale(xa, ya, xb, yb, s, q) {
7379    if (xa !== xb || ya !== yb) {
7380      var i = s.push(pop(s) + "scale(", null, ",", null, ")");
7381      q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
7382    } else if (xb !== 1 || yb !== 1) {
7383      s.push(pop(s) + "scale(" + xb + "," + yb + ")");
7384    }
7385  }
7386
7387  return function(a, b) {
7388    var s = [], // string constants and placeholders
7389        q = []; // number interpolators
7390    a = parse(a), b = parse(b);
7391    translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
7392    rotate(a.rotate, b.rotate, s, q);
7393    skewX(a.skewX, b.skewX, s, q);
7394    scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
7395    a = b = null; // gc
7396    return function(t) {
7397      var i = -1, n = q.length, o;
7398      while (++i < n) s[(o = q[i]).i] = o.x(t);
7399      return s.join("");
7400    };
7401  };
7402}
7403
7404var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
7405var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
7406
7407var rho = Math.SQRT2;
7408var rho2 = 2;
7409var rho4 = 4;
7410var epsilon2 = 1e-12;
7411
7412function cosh(x) {
7413  return ((x = Math.exp(x)) + 1 / x) / 2;
7414}
7415
7416function sinh(x) {
7417  return ((x = Math.exp(x)) - 1 / x) / 2;
7418}
7419
7420function tanh(x) {
7421  return ((x = Math.exp(2 * x)) - 1) / (x + 1);
7422}
7423
7424// p0 = [ux0, uy0, w0]
7425// p1 = [ux1, uy1, w1]
7426function interpolateZoom(p0, p1) {
7427  var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
7428      ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
7429      dx = ux1 - ux0,
7430      dy = uy1 - uy0,
7431      d2 = dx * dx + dy * dy,
7432      i,
7433      S;
7434
7435  // Special case for u0 ≅ u1.
7436  if (d2 < epsilon2) {
7437    S = Math.log(w1 / w0) / rho;
7438    i = function(t) {
7439      return [
7440        ux0 + t * dx,
7441        uy0 + t * dy,
7442        w0 * Math.exp(rho * t * S)
7443      ];
7444    };
7445  }
7446
7447  // General case.
7448  else {
7449    var d1 = Math.sqrt(d2),
7450        b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
7451        b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
7452        r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
7453        r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
7454    S = (r1 - r0) / rho;
7455    i = function(t) {
7456      var s = t * S,
7457          coshr0 = cosh(r0),
7458          u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
7459      return [
7460        ux0 + u * dx,
7461        uy0 + u * dy,
7462        w0 * coshr0 / cosh(rho * s + r0)
7463      ];
7464    };
7465  }
7466
7467  i.duration = S * 1000;
7468
7469  return i;
7470}
7471
7472function hsl$1(hue$$1) {
7473  return function(start, end) {
7474    var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
7475        s = nogamma(start.s, end.s),
7476        l = nogamma(start.l, end.l),
7477        opacity = nogamma(start.opacity, end.opacity);
7478    return function(t) {
7479      start.h = h(t);
7480      start.s = s(t);
7481      start.l = l(t);
7482      start.opacity = opacity(t);
7483      return start + "";
7484    };
7485  }
7486}
7487
7488var hsl$2 = hsl$1(hue);
7489var hslLong = hsl$1(nogamma);
7490
7491function lab$1(start, end) {
7492  var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
7493      a = nogamma(start.a, end.a),
7494      b = nogamma(start.b, end.b),
7495      opacity = nogamma(start.opacity, end.opacity);
7496  return function(t) {
7497    start.l = l(t);
7498    start.a = a(t);
7499    start.b = b(t);
7500    start.opacity = opacity(t);
7501    return start + "";
7502  };
7503}
7504
7505function hcl$1(hue$$1) {
7506  return function(start, end) {
7507    var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
7508        c = nogamma(start.c, end.c),
7509        l = nogamma(start.l, end.l),
7510        opacity = nogamma(start.opacity, end.opacity);
7511    return function(t) {
7512      start.h = h(t);
7513      start.c = c(t);
7514      start.l = l(t);
7515      start.opacity = opacity(t);
7516      return start + "";
7517    };
7518  }
7519}
7520
7521var hcl$2 = hcl$1(hue);
7522var hclLong = hcl$1(nogamma);
7523
7524function cubehelix$1(hue$$1) {
7525  return (function cubehelixGamma(y) {
7526    y = +y;
7527
7528    function cubehelix$$1(start, end) {
7529      var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
7530          s = nogamma(start.s, end.s),
7531          l = nogamma(start.l, end.l),
7532          opacity = nogamma(start.opacity, end.opacity);
7533      return function(t) {
7534        start.h = h(t);
7535        start.s = s(t);
7536        start.l = l(Math.pow(t, y));
7537        start.opacity = opacity(t);
7538        return start + "";
7539      };
7540    }
7541
7542    cubehelix$$1.gamma = cubehelixGamma;
7543
7544    return cubehelix$$1;
7545  })(1);
7546}
7547
7548var cubehelix$2 = cubehelix$1(hue);
7549var cubehelixLong = cubehelix$1(nogamma);
7550
7551function quantize(interpolator, n) {
7552  var samples = new Array(n);
7553  for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
7554  return samples;
7555}
7556
7557var frame = 0;
7558var timeout = 0;
7559var interval = 0;
7560var pokeDelay = 1000;
7561var taskHead;
7562var taskTail;
7563var clockLast = 0;
7564var clockNow = 0;
7565var clockSkew = 0;
7566var clock = typeof performance === "object" && performance.now ? performance : Date;
7567var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
7568
7569function now() {
7570  return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
7571}
7572
7573function clearNow() {
7574  clockNow = 0;
7575}
7576
7577function Timer() {
7578  this._call =
7579  this._time =
7580  this._next = null;
7581}
7582
7583Timer.prototype = timer.prototype = {
7584  constructor: Timer,
7585  restart: function(callback, delay, time) {
7586    if (typeof callback !== "function") throw new TypeError("callback is not a function");
7587    time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
7588    if (!this._next && taskTail !== this) {
7589      if (taskTail) taskTail._next = this;
7590      else taskHead = this;
7591      taskTail = this;
7592    }
7593    this._call = callback;
7594    this._time = time;
7595    sleep();
7596  },
7597  stop: function() {
7598    if (this._call) {
7599      this._call = null;
7600      this._time = Infinity;
7601      sleep();
7602    }
7603  }
7604};
7605
7606function timer(callback, delay, time) {
7607  var t = new Timer;
7608  t.restart(callback, delay, time);
7609  return t;
7610}
7611
7612function timerFlush() {
7613  now(); // Get the current time, if not already set.
7614  ++frame; // Pretend we’ve set an alarm, if we haven’t already.
7615  var t = taskHead, e;
7616  while (t) {
7617    if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
7618    t = t._next;
7619  }
7620  --frame;
7621}
7622
7623function wake() {
7624  clockNow = (clockLast = clock.now()) + clockSkew;
7625  frame = timeout = 0;
7626  try {
7627    timerFlush();
7628  } finally {
7629    frame = 0;
7630    nap();
7631    clockNow = 0;
7632  }
7633}
7634
7635function poke() {
vendor: 8,746 bytes, lines 7636-7944
7636  var now = clock.now(), delay = now - clockLast;
7637  if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
7638}
7639
7640function nap() {
7641  var t0, t1 = taskHead, t2, time = Infinity;
7642  while (t1) {
7643    if (t1._call) {
7644      if (time > t1._time) time = t1._time;
7645      t0 = t1, t1 = t1._next;
7646    } else {
7647      t2 = t1._next, t1._next = null;
7648      t1 = t0 ? t0._next = t2 : taskHead = t2;
7649    }
7650  }
7651  taskTail = t0;
7652  sleep(time);
7653}
7654
7655function sleep(time) {
7656  if (frame) return; // Soonest alarm already set, or will be.
7657  if (timeout) timeout = clearTimeout(timeout);
7658  var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
7659  if (delay > 24) {
7660    if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
7661    if (interval) interval = clearInterval(interval);
7662  } else {
7663    if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
7664    frame = 1, setFrame(wake);
7665  }
7666}
7667
7668function timeout$1(callback, delay, time) {
7669  var t = new Timer;
7670  delay = delay == null ? 0 : +delay;
7671  t.restart(function(elapsed) {
7672    t.stop();
7673    callback(elapsed + delay);
7674  }, delay, time);
7675  return t;
7676}
7677
7678function interval$1(callback, delay, time) {
7679  var t = new Timer, total = delay;
7680  if (delay == null) return t.restart(callback, delay, time), t;
7681  delay = +delay, time = time == null ? now() : +time;
7682  t.restart(function tick(elapsed) {
7683    elapsed += total;
7684    t.restart(tick, total += delay, time);
7685    callback(elapsed);
7686  }, delay, time);
7687  return t;
7688}
7689
7690var emptyOn = dispatch("start", "end", "interrupt");
7691var emptyTween = [];
7692
7693var CREATED = 0;
7694var SCHEDULED = 1;
7695var STARTING = 2;
7696var STARTED = 3;
7697var RUNNING = 4;
7698var ENDING = 5;
7699var ENDED = 6;
7700
7701function schedule(node, name, id, index, group, timing) {
7702  var schedules = node.__transition;
7703  if (!schedules) node.__transition = {};
7704  else if (id in schedules) return;
7705  create$1(node, id, {
7706    name: name,
7707    index: index, // For context during callback.
7708    group: group, // For context during callback.
7709    on: emptyOn,
7710    tween: emptyTween,
7711    time: timing.time,
7712    delay: timing.delay,
7713    duration: timing.duration,
7714    ease: timing.ease,
7715    timer: null,
7716    state: CREATED
7717  });
7718}
7719
7720function init(node, id) {
7721  var schedule = get$1(node, id);
7722  if (schedule.state > CREATED) throw new Error("too late; already scheduled");
7723  return schedule;
7724}
7725
7726function set$1(node, id) {
7727  var schedule = get$1(node, id);
7728  if (schedule.state > STARTING) throw new Error("too late; already started");
7729  return schedule;
7730}
7731
7732function get$1(node, id) {
7733  var schedule = node.__transition;
7734  if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
7735  return schedule;
7736}
7737
7738function create$1(node, id, self) {
7739  var schedules = node.__transition,
7740      tween;
7741
7742  // Initialize the self timer when the transition is created.
7743  // Note the actual delay is not known until the first callback!
7744  schedules[id] = self;
7745  self.timer = timer(schedule, 0, self.time);
7746
7747  function schedule(elapsed) {
7748    self.state = SCHEDULED;
7749    self.timer.restart(start, self.delay, self.time);
7750
7751    // If the elapsed delay is less than our first sleep, start immediately.
7752    if (self.delay <= elapsed) start(elapsed - self.delay);
7753  }
7754
7755  function start(elapsed) {
7756    var i, j, n, o;
7757
7758    // If the state is not SCHEDULED, then we previously errored on start.
7759    if (self.state !== SCHEDULED) return stop();
7760
7761    for (i in schedules) {
7762      o = schedules[i];
7763      if (o.name !== self.name) continue;
7764
7765      // While this element already has a starting transition during this frame,
7766      // defer starting an interrupting transition until that transition has a
7767      // chance to tick (and possibly end); see d3/d3-transition#54!
7768      if (o.state === STARTED) return timeout$1(start);
7769
7770      // Interrupt the active transition, if any.
7771      // Dispatch the interrupt event.
7772      if (o.state === RUNNING) {
7773        o.state = ENDED;
7774        o.timer.stop();
7775        o.on.call("interrupt", node, node.__data__, o.index, o.group);
7776        delete schedules[i];
7777      }
7778
7779      // Cancel any pre-empted transitions. No interrupt event is dispatched
7780      // because the cancelled transitions never started. Note that this also
7781      // removes this transition from the pending list!
7782      else if (+i < id) {
7783        o.state = ENDED;
7784        o.timer.stop();
7785        delete schedules[i];
7786      }
7787    }
7788
7789    // Defer the first tick to end of the current frame; see d3/d3#1576.
7790    // Note the transition may be canceled after start and before the first tick!
7791    // Note this must be scheduled before the start event; see d3/d3-transition#16!
7792    // Assuming this is successful, subsequent callbacks go straight to tick.
7793    timeout$1(function() {
7794      if (self.state === STARTED) {
7795        self.state = RUNNING;
7796        self.timer.restart(tick, self.delay, self.time);
7797        tick(elapsed);
7798      }
7799    });
7800
7801    // Dispatch the start event.
7802    // Note this must be done before the tween are initialized.
7803    self.state = STARTING;
7804    self.on.call("start", node, node.__data__, self.index, self.group);
7805    if (self.state !== STARTING) return; // interrupted
7806    self.state = STARTED;
7807
7808    // Initialize the tween, deleting null tween.
7809    tween = new Array(n = self.tween.length);
7810    for (i = 0, j = -1; i < n; ++i) {
7811      if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
7812        tween[++j] = o;
7813      }
7814    }
7815    tween.length = j + 1;
7816  }
7817
7818  function tick(elapsed) {
7819    var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
7820        i = -1,
7821        n = tween.length;
7822
7823    while (++i < n) {
7824      tween[i].call(null, t);
7825    }
7826
7827    // Dispatch the end event.
7828    if (self.state === ENDING) {
7829      self.on.call("end", node, node.__data__, self.index, self.group);
7830      stop();
7831    }
7832  }
7833
7834  function stop() {
7835    self.state = ENDED;
7836    self.timer.stop();
7837    delete schedules[id];
7838    for (var i in schedules) return; // eslint-disable-line no-unused-vars
7839    delete node.__transition;
7840  }
7841}
7842
7843function interrupt(node, name) {
7844  var schedules = node.__transition,
7845      schedule$$1,
7846      active,
7847      empty = true,
7848      i;
7849
7850  if (!schedules) return;
7851
7852  name = name == null ? null : name + "";
7853
7854  for (i in schedules) {
7855    if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
7856    active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
7857    schedule$$1.state = ENDED;
7858    schedule$$1.timer.stop();
7859    if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
7860    delete schedules[i];
7861  }
7862
7863  if (empty) delete node.__transition;
7864}
7865
7866function selection_interrupt(name) {
7867  return this.each(function() {
7868    interrupt(this, name);
7869  });
7870}
7871
7872function tweenRemove(id, name) {
7873  var tween0, tween1;
7874  return function() {
7875    var schedule$$1 = set$1(this, id),
7876        tween = schedule$$1.tween;
7877
7878    // If this node shared tween with the previous node,
7879    // just assign the updated shared tween and we’re done!
7880    // Otherwise, copy-on-write.
7881    if (tween !== tween0) {
7882      tween1 = tween0 = tween;
7883      for (var i = 0, n = tween1.length; i < n; ++i) {
7884        if (tween1[i].name === name) {
7885          tween1 = tween1.slice();
7886          tween1.splice(i, 1);
7887          break;
7888        }
7889      }
7890    }
7891
7892    schedule$$1.tween = tween1;
7893  };
7894}
7895
7896function tweenFunction(id, name, value) {
7897  var tween0, tween1;
7898  if (typeof value !== "function") throw new Error;
7899  return function() {
7900    var schedule$$1 = set$1(this, id),
7901        tween = schedule$$1.tween;
7902
7903    // If this node shared tween with the previous node,
7904    // just assign the updated shared tween and we’re done!
7905    // Otherwise, copy-on-write.
7906    if (tween !== tween0) {
7907      tween1 = (tween0 = tween).slice();
7908      for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
7909        if (tween1[i].name === name) {
7910          tween1[i] = t;
7911          break;
7912        }
7913      }
7914      if (i === n) tween1.push(t);
7915    }
7916
7917    schedule$$1.tween = tween1;
7918  };
7919}
7920
7921function transition_tween(name, value) {
7922  var id = this._id;
7923
7924  name += "";
7925
7926  if (arguments.length < 2) {
7927    var tween = get$1(this.node(), id).tween;
7928    for (var i = 0, n = tween.length, t; i < n; ++i) {
7929      if ((t = tween[i]).name === name) {
7930        return t.value;
7931      }
7932    }
7933    return null;
7934  }
7935
7936  return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
7937}
7938
7939function tweenValue(transition, name, value) {
7940  var id = transition._id;
7941
7942  transition.each(function() {
7943    var schedule$$1 = set$1(this, id);
7944    (schedule$$1.value || (schedule$$1.value = {}
vendor: 7,638 bytes, lines 7944-8205
7944))[name] = value.apply(this, arguments);
7945  });
7946
7947  return function(node) {
7948    return get$1(node, id).value[name];
7949  };
7950}
7951
7952function interpolate(a, b) {
7953  var c;
7954  return (typeof b === "number" ? reinterpolate
7955      : b instanceof color ? interpolateRgb
7956      : (c = color(b)) ? (b = c, interpolateRgb)
7957      : interpolateString)(a, b);
7958}
7959
7960function attrRemove$1(name) {
7961  return function() {
7962    this.removeAttribute(name);
7963  };
7964}
7965
7966function attrRemoveNS$1(fullname) {
7967  return function() {
7968    this.removeAttributeNS(fullname.space, fullname.local);
7969  };
7970}
7971
7972function attrConstant$1(name, interpolate$$1, value1) {
7973  var value00,
7974      interpolate0;
7975  return function() {
7976    var value0 = this.getAttribute(name);
7977    return value0 === value1 ? null
7978        : value0 === value00 ? interpolate0
7979        : interpolate0 = interpolate$$1(value00 = value0, value1);
7980  };
7981}
7982
7983function attrConstantNS$1(fullname, interpolate$$1, value1) {
7984  var value00,
7985      interpolate0;
7986  return function() {
7987    var value0 = this.getAttributeNS(fullname.space, fullname.local);
7988    return value0 === value1 ? null
7989        : value0 === value00 ? interpolate0
7990        : interpolate0 = interpolate$$1(value00 = value0, value1);
7991  };
7992}
7993
7994function attrFunction$1(name, interpolate$$1, value) {
7995  var value00,
7996      value10,
7997      interpolate0;
7998  return function() {
7999    var value0, value1 = value(this);
8000    if (value1 == null) return void this.removeAttribute(name);
8001    value0 = this.getAttribute(name);
8002    return value0 === value1 ? null
8003        : value0 === value00 && value1 === value10 ? interpolate0
8004        : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8005  };
8006}
8007
8008function attrFunctionNS$1(fullname, interpolate$$1, value) {
8009  var value00,
8010      value10,
8011      interpolate0;
8012  return function() {
8013    var value0, value1 = value(this);
8014    if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
8015    value0 = this.getAttributeNS(fullname.space, fullname.local);
8016    return value0 === value1 ? null
8017        : value0 === value00 && value1 === value10 ? interpolate0
8018        : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8019  };
8020}
8021
8022function transition_attr(name, value) {
8023  var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
8024  return this.attrTween(name, typeof value === "function"
8025      ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
8026      : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
8027      : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
8028}
8029
8030function attrTweenNS(fullname, value) {
8031  function tween() {
8032    var node = this, i = value.apply(node, arguments);
8033    return i && function(t) {
8034      node.setAttributeNS(fullname.space, fullname.local, i(t));
8035    };
8036  }
8037  tween._value = value;
8038  return tween;
8039}
8040
8041function attrTween(name, value) {
8042  function tween() {
8043    var node = this, i = value.apply(node, arguments);
8044    return i && function(t) {
8045      node.setAttribute(name, i(t));
8046    };
8047  }
8048  tween._value = value;
8049  return tween;
8050}
8051
8052function transition_attrTween(name, value) {
8053  var key = "attr." + name;
8054  if (arguments.length < 2) return (key = this.tween(key)) && key._value;
8055  if (value == null) return this.tween(key, null);
8056  if (typeof value !== "function") throw new Error;
8057  var fullname = namespace(name);
8058  return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
8059}
8060
8061function delayFunction(id, value) {
8062  return function() {
8063    init(this, id).delay = +value.apply(this, arguments);
8064  };
8065}
8066
8067function delayConstant(id, value) {
8068  return value = +value, function() {
8069    init(this, id).delay = value;
8070  };
8071}
8072
8073function transition_delay(value) {
8074  var id = this._id;
8075
8076  return arguments.length
8077      ? this.each((typeof value === "function"
8078          ? delayFunction
8079          : delayConstant)(id, value))
8080      : get$1(this.node(), id).delay;
8081}
8082
8083function durationFunction(id, value) {
8084  return function() {
8085    set$1(this, id).duration = +value.apply(this, arguments);
8086  };
8087}
8088
8089function durationConstant(id, value) {
8090  return value = +value, function() {
8091    set$1(this, id).duration = value;
8092  };
8093}
8094
8095function transition_duration(value) {
8096  var id = this._id;
8097
8098  return arguments.length
8099      ? this.each((typeof value === "function"
8100          ? durationFunction
8101          : durationConstant)(id, value))
8102      : get$1(this.node(), id).duration;
8103}
8104
8105function easeConstant(id, value) {
8106  if (typeof value !== "function") throw new Error;
8107  return function() {
8108    set$1(this, id).ease = value;
8109  };
8110}
8111
8112function transition_ease(value) {
8113  var id = this._id;
8114
8115  return arguments.length
8116      ? this.each(easeConstant(id, value))
8117      : get$1(this.node(), id).ease;
8118}
8119
8120function transition_filter(match) {
8121  if (typeof match !== "function") match = matcher$1(match);
8122
8123  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
8124    for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
8125      if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
8126        subgroup.push(node);
8127      }
8128    }
8129  }
8130
8131  return new Transition(subgroups, this._parents, this._name, this._id);
8132}
8133
8134function transition_merge(transition$$1) {
8135  if (transition$$1._id !== this._id) throw new Error;
8136
8137  for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
8138    for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
8139      if (node = group0[i] || group1[i]) {
8140        merge[i] = node;
8141      }
8142    }
8143  }
8144
8145  for (; j < m0; ++j) {
8146    merges[j] = groups0[j];
8147  }
8148
8149  return new Transition(merges, this._parents, this._name, this._id);
8150}
8151
8152function start(name) {
8153  return (name + "").trim().split(/^|\s+/).every(function(t) {
8154    var i = t.indexOf(".");
8155    if (i >= 0) t = t.slice(0, i);
8156    return !t || t === "start";
8157  });
8158}
8159
8160function onFunction(id, name, listener) {
8161  var on0, on1, sit = start(name) ? init : set$1;
8162  return function() {
8163    var schedule$$1 = sit(this, id),
8164        on = schedule$$1.on;
8165
8166    // If this node shared a dispatch with the previous node,
8167    // just assign the updated shared dispatch and we’re done!
8168    // Otherwise, copy-on-write.
8169    if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
8170
8171    schedule$$1.on = on1;
8172  };
8173}
8174
8175function transition_on(name, listener) {
8176  var id = this._id;
8177
8178  return arguments.length < 2
8179      ? get$1(this.node(), id).on.on(name)
8180      : this.each(onFunction(id, name, listener));
8181}
8182
8183function removeFunction(id) {
8184  return function() {
8185    var parent = this.parentNode;
8186    for (var i in this.__transition) if (+i !== id) return;
8187    if (parent) parent.removeChild(this);
8188  };
8189}
8190
8191function transition_remove() {
8192  return this.on("end.remove", removeFunction(this._id));
8193}
8194
8195function transition_select(select) {
8196  var name = this._name,
8197      id = this._id;
8198
8199  if (typeof select !== "function") select = selector(select);
8200
8201  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
8202    for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
8203      if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
8204        if ("__data__" in node) subnode.__data__ = node.__data__;
8205        subgroup[i] = subnode;
vendor: 7,134 bytes, lines 8206-8500
8206        schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
8207      }
8208    }
8209  }
8210
8211  return new Transition(subgroups, this._parents, name, id);
8212}
8213
8214function transition_selectAll(select) {
8215  var name = this._name,
8216      id = this._id;
8217
8218  if (typeof select !== "function") select = selectorAll(select);
8219
8220  for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
8221    for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
8222      if (node = group[i]) {
8223        for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
8224          if (child = children[k]) {
8225            schedule(child, name, id, k, children, inherit);
8226          }
8227        }
8228        subgroups.push(children);
8229        parents.push(node);
8230      }
8231    }
8232  }
8233
8234  return new Transition(subgroups, parents, name, id);
8235}
8236
8237var Selection$1 = selection.prototype.constructor;
8238
8239function transition_selection() {
8240  return new Selection$1(this._groups, this._parents);
8241}
8242
8243function styleRemove$1(name, interpolate$$1) {
8244  var value00,
8245      value10,
8246      interpolate0;
8247  return function() {
8248    var value0 = styleValue(this, name),
8249        value1 = (this.style.removeProperty(name), styleValue(this, name));
8250    return value0 === value1 ? null
8251        : value0 === value00 && value1 === value10 ? interpolate0
8252        : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8253  };
8254}
8255
8256function styleRemoveEnd(name) {
8257  return function() {
8258    this.style.removeProperty(name);
8259  };
8260}
8261
8262function styleConstant$1(name, interpolate$$1, value1) {
8263  var value00,
8264      interpolate0;
8265  return function() {
8266    var value0 = styleValue(this, name);
8267    return value0 === value1 ? null
8268        : value0 === value00 ? interpolate0
8269        : interpolate0 = interpolate$$1(value00 = value0, value1);
8270  };
8271}
8272
8273function styleFunction$1(name, interpolate$$1, value) {
8274  var value00,
8275      value10,
8276      interpolate0;
8277  return function() {
8278    var value0 = styleValue(this, name),
8279        value1 = value(this);
8280    if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
8281    return value0 === value1 ? null
8282        : value0 === value00 && value1 === value10 ? interpolate0
8283        : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8284  };
8285}
8286
8287function transition_style(name, value, priority) {
8288  var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
8289  return value == null ? this
8290          .styleTween(name, styleRemove$1(name, i))
8291          .on("end.style." + name, styleRemoveEnd(name))
8292      : this.styleTween(name, typeof value === "function"
8293          ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
8294          : styleConstant$1(name, i, value + ""), priority);
8295}
8296
8297function styleTween(name, value, priority) {
8298  function tween() {
8299    var node = this, i = value.apply(node, arguments);
8300    return i && function(t) {
8301      node.style.setProperty(name, i(t), priority);
8302    };
8303  }
8304  tween._value = value;
8305  return tween;
8306}
8307
8308function transition_styleTween(name, value, priority) {
8309  var key = "style." + (name += "");
8310  if (arguments.length < 2) return (key = this.tween(key)) && key._value;
8311  if (value == null) return this.tween(key, null);
8312  if (typeof value !== "function") throw new Error;
8313  return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
8314}
8315
8316function textConstant$1(value) {
8317  return function() {
8318    this.textContent = value;
8319  };
8320}
8321
8322function textFunction$1(value) {
8323  return function() {
8324    var value1 = value(this);
8325    this.textContent = value1 == null ? "" : value1;
8326  };
8327}
8328
8329function transition_text(value) {
8330  return this.tween("text", typeof value === "function"
8331      ? textFunction$1(tweenValue(this, "text", value))
8332      : textConstant$1(value == null ? "" : value + ""));
8333}
8334
8335function transition_transition() {
8336  var name = this._name,
8337      id0 = this._id,
8338      id1 = newId();
8339
8340  for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
8341    for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
8342      if (node = group[i]) {
8343        var inherit = get$1(node, id0);
8344        schedule(node, name, id1, i, group, {
8345          time: inherit.time + inherit.delay + inherit.duration,
8346          delay: 0,
8347          duration: inherit.duration,
8348          ease: inherit.ease
8349        });
8350      }
8351    }
8352  }
8353
8354  return new Transition(groups, this._parents, name, id1);
8355}
8356
8357var id = 0;
8358
8359function Transition(groups, parents, name, id) {
8360  this._groups = groups;
8361  this._parents = parents;
8362  this._name = name;
8363  this._id = id;
8364}
8365
8366function transition(name) {
8367  return selection().transition(name);
8368}
8369
8370function newId() {
8371  return ++id;
8372}
8373
8374var selection_prototype = selection.prototype;
8375
8376Transition.prototype = transition.prototype = {
8377  constructor: Transition,
8378  select: transition_select,
8379  selectAll: transition_selectAll,
8380  filter: transition_filter,
8381  merge: transition_merge,
8382  selection: transition_selection,
8383  transition: transition_transition,
8384  call: selection_prototype.call,
8385  nodes: selection_prototype.nodes,
8386  node: selection_prototype.node,
8387  size: selection_prototype.size,
8388  empty: selection_prototype.empty,
8389  each: selection_prototype.each,
8390  on: transition_on,
8391  attr: transition_attr,
8392  attrTween: transition_attrTween,
8393  style: transition_style,
8394  styleTween: transition_styleTween,
8395  text: transition_text,
8396  remove: transition_remove,
8397  tween: transition_tween,
8398  delay: transition_delay,
8399  duration: transition_duration,
8400  ease: transition_ease
8401};
8402
8403function linear$1(t) {
8404  return +t;
8405}
8406
8407function quadIn(t) {
8408  return t * t;
8409}
8410
8411function quadOut(t) {
8412  return t * (2 - t);
8413}
8414
8415function quadInOut(t) {
8416  return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
8417}
8418
8419function cubicIn(t) {
8420  return t * t * t;
8421}
8422
8423function cubicOut(t) {
8424  return --t * t * t + 1;
8425}
8426
8427function cubicInOut(t) {
8428  return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
8429}
8430
8431var exponent = 3;
8432
8433var polyIn = (function custom(e) {
8434  e = +e;
8435
8436  function polyIn(t) {
8437    return Math.pow(t, e);
8438  }
8439
8440  polyIn.exponent = custom;
8441
8442  return polyIn;
8443})(exponent);
8444
8445var polyOut = (function custom(e) {
8446  e = +e;
8447
8448  function polyOut(t) {
8449    return 1 - Math.pow(1 - t, e);
8450  }
8451
8452  polyOut.exponent = custom;
8453
8454  return polyOut;
8455})(exponent);
8456
8457var polyInOut = (function custom(e) {
8458  e = +e;
8459
8460  function polyInOut(t) {
8461    return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
8462  }
8463
8464  polyInOut.exponent = custom;
8465
8466  return polyInOut;
8467})(exponent);
8468
8469var pi = Math.PI;
8470var halfPi = pi / 2;
8471
8472function sinIn(t) {
8473  return 1 - Math.cos(t * halfPi);
8474}
8475
8476function sinOut(t) {
8477  return Math.sin(t * halfPi);
8478}
8479
8480function sinInOut(t) {
8481  return (1 - Math.cos(pi * t)) / 2;
8482}
8483
8484function expIn(t) {
8485  return Math.pow(2, 10 * t - 10);
8486}
8487
8488function expOut(t) {
8489  return 1 - Math.pow(2, -10 * t);
8490}
8491
8492function expInOut(t) {
8493  return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
8494}
8495
8496function circleIn(t) {
8497  return 1 - Math.sqrt(1 - t * t);
8498}
8499
8500function circleOut(t) {
8501  return Math.sqrt(1 - --t * t);
8502}
8503
8504function circleInOut(t) {
8505  return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
8506}
8507
8508var b1 = 4 / 11;
8509var b2 = 6 / 11;
8510var b3 = 8 / 11;
8511var b4 = 3 / 4;
8512var b5 = 9 / 11;
8513var b6 = 10 / 11;
8514var b7 = 15 / 16;
8515var b8 = 21 / 22;
8516var b9 = 63 / 64;
8517var b0 = 1 / b1 / b1;
8518
8519function bounceIn(t) {
8520  return 1 - bounceOut(1 - t);
8521}
8522
8523function bounceOut(t) {
8524  return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
8525}
8526
8527function bounceInOut(t) {
8528  return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
8529}
8530
8531var overshoot = 1.70158;
8532
8533var backIn = (function custom(s) {
8534  s = +s;
8535
8536  function backIn(t) {
8537    return t * t * ((s + 1) * t - s);
8538  }
8539
8540  backIn.overshoot = custom;
8541
8542  return backIn;
8543})(overshoot);
8544
8545var backOut = (function custom(s) {
8546  s = +s;
8547
8548  function backOut(t) {
8549    return --t * t * ((s + 1) * t + s) + 1;
8550  }
8551
8552  backOut.overshoot = custom;
8553
8554  return backOut;
8555})(overshoot);
8556
8557var backInOut = (function custom(s) {
8558  s = +s;
8559
8560  function backInOut(t) {
8561    return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
8562  }
8563
8564  backInOut.overshoot = custom;
8565
8566  return backInOut;
8567})(overshoot);
8568
8569var tau = 2 * Math.PI;
8570var amplitude = 1;
8571var period = 0.3;
8572
8573var elasticIn = (function custom(a, p) {
8574  var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
8575
8576  function elasticIn(t) {
8577    return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
8578  }
8579
8580  elasticIn.amplitude = function(a) { return custom(a, p * tau); };
8581  elasticIn.period = function(p) { return custom(a, p); };
8582
8583  return elasticIn;
8584})(amplitude, period);
8585
8586var elasticOut = (function custom(a, p) {
8587  var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
8588
8589  function elasticOut(t) {
8590    return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
8591  }
8592
8593  elasticOut.amplitude = function(a) { return custom(a, p * tau); };
8594  elasticOut.period = function(p) { return custom(a, p); };
8595
8596  return elasticOut;
8597})(amplitude, period);
8598
8599var elasticInOut = (function custom(a, p) {
8600  var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
8601
8602  function elasticInOut(t) {
8603    return ((t = t * 2 - 1) < 0
8604        ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
8605        : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
8606  }
8607
8608  elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
8609  elasticInOut.period = function(p) { return custom(a, p); };
8610
8611  return elasticInOut;
8612})(amplitude, period);
8613
8614var defaultTiming = {
8615  time: null, // Set on use.
8616  delay: 0,
8617  duration: 250,
8618  ease: cubicInOut
8619};
8620
8621function inherit(node, id) {
8622  var timing;
8623  while (!(timing = node.__transition) || !(timing = timing[id])) {
8624    if (!(node = node.parentNode)) {
8625      return defaultTiming.time = now(), defaultTiming;
8626    }
8627  }
8628  return timing;
8629}
8630
8631function selection_transition(name) {
8632  var id,
8633      timing;
8634
8635  if (name instanceof Transition) {
8636    id = name._id, name = name._name;
8637  } else {
8638    id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
8639  }
8640
8641  for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
8642    for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
8643      if (node = group[i]) {
8644        schedule(node, name, id, i, group, timing || inherit(node, id));
8645      }
8646    }
8647  }
8648
8649  return new Transition(groups, this._parents, name, id);
8650}
8651
8652selection.prototype.interrupt = selection_interrupt;
8653selection.prototype.transition = selection_transition;
8654
8655var root$1 = [null];
8656
8657function active(node, name) {
8658  var schedules = node.__transition,
8659      schedule$$1,
8660      i;
8661
8662  if (schedules) {
8663    name = name == null ? null : name + "";
8664    for (i in schedules) {
8665      if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
8666        return new Transition([[node]], root$1, name, +i);
8667      }
8668    }
8669  }
8670
8671  return null;
8672}
8673
8674function constant$4(x) {
8675  return function() {
8676    return x;
8677  };
8678}
8679
8680function BrushEvent(target, type, selection) {
8681  this.target = target;
8682  this.type = type;
8683  this.selection = selection;
8684}
8685
8686function nopropagation$1() {
8687  exports.event.stopImmediatePropagation();
8688}
8689
8690function noevent$1() {
8691  exports.event.preventDefault();
8692  exports.event.stopImmediatePropagation();
8693}
8694
8695var MODE_DRAG = {name: "drag"};
8696var MODE_SPACE = {name: "space"};
8697var MODE_HANDLE = {name: "handle"};
8698var MODE_CENTER = {name: "center"};
8699
8700var X = {
8701  name: "x",
8702  handles: ["e", "w"].map(type),
8703  input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
8704  output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
8705};
8706
8707var Y = {
8708  name: "y",
8709  handles: ["n", "s"].map(type),
8710  input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
8711  output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
8712};
8713
8714var XY = {
8715  name: "xy",
8716  handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
8717  input: function(xy) { return xy; },
8718  output: function(xy) { return xy; }
8719};
8720
8721var cursors = {
8722  overlay: "crosshair",
8723  selection: "move",
8724  n: "ns-resize",
8725  e: "ew-resize",
8726  s: "ns-resize",
8727  w: "ew-resize",
8728  nw: "nwse-resize",
8729  ne: "nesw-resize",
8730  se: "nwse-resize",
8731  sw: "nesw-resize"
8732};
8733
8734var flipX = {
8735  e: "w",
8736  w: "e",
8737  nw: "ne",
8738  ne: "nw",
8739  se: "sw",
8740  sw: "se"
8741};
8742
8743var flipY = {
8744  n: "s",
8745  s: "n",
8746  nw: "sw",
8747  ne: "se",
8748  se: "ne",
8749  sw: "nw"
8750};
8751
8752var signsX = {
8753  overlay: +1,
8754  selection: +1,
8755  n: null,
8756  e: +1,
8757  s: null,
8758  w: -1,
8759  nw: -1,
8760  ne: +1,
8761  se: +1,
8762  sw: -1
8763};
8764
8765var signsY = {
8766  overlay: +1,
8767  selection: +1,
8768  n: -1,
8769  e: null,
8770  s: +1,
8771  w: null,
8772  nw: -1,
8773  ne: -1,
8774  se: +1,
8775  sw: +1
8776};
8777
8778function type(t) {
8779  return {type: t};
8780}
8781
8782// Ignore right-click, since that should open the context menu.
8783function defaultFilter() {
8784  return !exports.event.button;
8785}
8786
8787function defaultExtent() {
8788  var svg = this.ownerSVGElement || this;
vendor: 4,235 bytes, lines 8789-8925
8789  return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
8790}
8791
8792// Like d3.local, but with the name “__brush” rather than auto-generated.
8793function local(node) {
8794  while (!node.__brush) if (!(node = node.parentNode)) return;
8795  return node.__brush;
8796}
8797
8798function empty(extent) {
8799  return extent[0][0] === extent[1][0]
8800      || extent[0][1] === extent[1][1];
8801}
8802
8803function brushSelection(node) {
8804  var state = node.__brush;
8805  return state ? state.dim.output(state.selection) : null;
8806}
8807
8808function brushX() {
8809  return brush$1(X);
8810}
8811
8812function brushY() {
8813  return brush$1(Y);
8814}
8815
8816function brush() {
8817  return brush$1(XY);
8818}
8819
8820function brush$1(dim) {
8821  var extent = defaultExtent,
8822      filter = defaultFilter,
8823      listeners = dispatch(brush, "start", "brush", "end"),
8824      handleSize = 6,
8825      touchending;
8826
8827  function brush(group) {
8828    var overlay = group
8829        .property("__brush", initialize)
8830      .selectAll(".overlay")
8831      .data([type("overlay")]);
8832
8833    overlay.enter().append("rect")
8834        .attr("class", "overlay")
8835        .attr("pointer-events", "all")
8836        .attr("cursor", cursors.overlay)
8837      .merge(overlay)
8838        .each(function() {
8839          var extent = local(this).extent;
8840          select(this)
8841              .attr("x", extent[0][0])
8842              .attr("y", extent[0][1])
8843              .attr("width", extent[1][0] - extent[0][0])
8844              .attr("height", extent[1][1] - extent[0][1]);
8845        });
8846
8847    group.selectAll(".selection")
8848      .data([type("selection")])
8849      .enter().append("rect")
8850        .attr("class", "selection")
8851        .attr("cursor", cursors.selection)
8852        .attr("fill", "#777")
8853        .attr("fill-opacity", 0.3)
8854        .attr("stroke", "#fff")
8855        .attr("shape-rendering", "crispEdges");
8856
8857    var handle = group.selectAll(".handle")
8858      .data(dim.handles, function(d) { return d.type; });
8859
8860    handle.exit().remove();
8861
8862    handle.enter().append("rect")
8863        .attr("class", function(d) { return "handle handle--" + d.type; })
8864        .attr("cursor", function(d) { return cursors[d.type]; });
8865
8866    group
8867        .each(redraw)
8868        .attr("fill", "none")
8869        .attr("pointer-events", "all")
8870        .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
8871        .on("mousedown.brush touchstart.brush", started);
8872  }
8873
8874  brush.move = function(group, selection) {
8875    if (group.selection) {
8876      group
8877          .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
8878          .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
8879          .tween("brush", function() {
8880            var that = this,
8881                state = that.__brush,
8882                emit = emitter(that, arguments),
8883                selection0 = state.selection,
8884                selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
8885                i = interpolateValue(selection0, selection1);
8886
8887            function tween(t) {
8888              state.selection = t === 1 && empty(selection1) ? null : i(t);
8889              redraw.call(that);
8890              emit.brush();
8891            }
8892
8893            return selection0 && selection1 ? tween : tween(1);
8894          });
8895    } else {
8896      group
8897          .each(function() {
8898            var that = this,
8899                args = arguments,
8900                state = that.__brush,
8901                selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
8902                emit = emitter(that, args).beforestart();
8903
8904            interrupt(that);
8905            state.selection = selection1 == null || empty(selection1) ? null : selection1;
8906            redraw.call(that);
8907            emit.start().brush().end();
8908          });
8909    }
8910  };
8911
8912  function redraw() {
8913    var group = select(this),
8914        selection = local(this).selection;
8915
8916    if (selection) {
8917      group.selectAll(".selection")
8918          .style("display", null)
8919          .attr("x", selection[0][0])
8920          .attr("y", selection[0][1])
8921          .attr("width", selection[1][0] - selection[0][0])
8922          .attr("height", selection[1][1] - selection[0][1]);
8923
8924      group.selectAll(".handle")
8925          .style("display", null)
8926          .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
8927          .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
8928          .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
8929          .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
8930    }
8931
8932    else {
8933      group.selectAll(".selection,.handle")
8934          .style("display", "none")
8935          .attr("x", null)
8936          .attr("y", null)
8937          .attr("width", null)
8938          .attr("height", null);
8939    }
8940  }
8941
8942  function emitter(that, args) {
8943    return that.__brush.emitter || new Emitter(that, args);
8944  }
8945
8946  function Emitter(that, args) {
8947    this.that = that;
8948    this.args = args;
8949    this.state = that.__brush;
8950    this.active = 0;
8951  }
8952
8953  Emitter.prototype = {
8954    beforestart: function() {
8955      if (++this.active === 1) this.state.emitter = this, this.starting = true;
8956      return this;
8957    },
8958    start: function() {
8959      if (this.starting) this.starting = false, this.emit("start");
8960      return this;
8961    },
8962    brush: function() {
8963      this.emit("brush");
8964      return this;
8965    },
8966    end: function() {
8967      if (--this.active === 0) delete this.state.emitter, this.emit("end");
8968      return this;
8969    },
8970    emit: function(type) {
8971      customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
8972    }
8973  };
8974
8975  function started() {
8976    if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
8977    else if (touchending) return;
8978    if (!filter.apply(this, arguments)) return;
8979
8980    var that = this,
8981        type = exports.event.target.__data__.type,
8982        mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
8983        signX = dim === Y ? null : signsX[type],
8984        signY = dim === X ? null : signsY[type],
8985        state = local(that),
8986        extent = state.extent,
8987        selection = state.selection,
8988        W = extent[0][0], w0, w1,
8989        N = extent[0][1], n0, n1,
8990        E = extent[1][0], e0, e1,
8991        S = extent[1][1], s0, s1,
8992        dx,
8993        dy,
8994        moving,
8995        shifting = signX && signY && exports.event.shiftKey,
8996        lockX,
8997        lockY,
8998        point0 = mouse(that),
8999        point = point0,
9000        emit = emitter(that, arguments).beforestart();
9001
9002    if (type === "overlay") {
9003      state.selection = selection = [
9004        [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
9005        [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
9006      ];
9007    } else {
9008      w0 = selection[0][0];
9009      n0 = selection[0][1];
9010      e0 = selection[1][0];
9011      s0 = selection[1][1];
9012    }
9013
9014    w1 = w0;
9015    n1 = n0;
9016    e1 = e0;
9017    s1 = s0;
9018
9019    var group = select(that)
9020        .attr("pointer-events", "none");
9021
9022    var overlay = group.selectAll(".overlay")
9023        .attr("cursor", cursors[type]);
9024
9025    if (exports.event.touches) {
9026      group
9027          .on("touchmove.brush", moved, true)
9028          .on("touchend.brush touchcancel.brush", ended, true);
9029    } else {
9030      var view = select(exports.event.view)
9031          .on("keydown.brush", keydowned, true)
9032          .on("keyup.brush", keyupped, true)
9033          .on("mousemove.brush", moved, true)
9034          .on("mouseup.brush", ended, true);
9035
9036      dragDisable(exports.event.view);
9037    }
9038
9039    nopropagation$1();
9040    interrupt(that);
9041    redraw.call(that);
9042    emit.start();
9043
9044    function moved() {
9045      var point1 = mouse(that);
9046      if (shifting && !lockX && !lockY) {
9047        if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
9048        else lockX = true;
9049      }
9050      point = point1;
9051      moving = true;
9052      noevent$1();
9053      move();
9054    }
9055
9056    function move() {
9057      var t;
9058
9059      dx = point[0] - point0[0];
9060      dy = point[1] - point0[1];
9061
9062      switch (mode) {
9063        case MODE_SPACE:
9064        case MODE_DRAG: {
9065          if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
9066          if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
9067          break;
9068        }
9069        case MODE_HANDLE: {
9070          if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)
9070), w1 = w0 + dx, e1 = e0;
9071          else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
9072          if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
9073          else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
9074          break;
9075        }
9076        case MODE_CENTER: {
9077          if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
9078          if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
9079          break;
9080        }
9081      }
9082
9083      if (e1 < w1) {
9084        signX *= -1;
9085        t = w0, w0 = e0, e0 = t;
9086        t = w1, w1 = e1, e1 = t;
9087        if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
9088      }
9089
9090      if (s1 < n1) {
9091        signY *= -1;
9092        t = n0, n0 = s0, s0 = t;
9093        t = n1, n1 = s1, s1 = t;
9094        if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
9095      }
9096
9097      if (state.selection) selection = state.selection; // May be set by brush.move!
9098      if (lockX) w1 = selection[0][0], e1 = selection[1][0];
9099      if (lockY) n1 = selection[0][1], s1 = selection[1][1];
9100
9101      if (selection[0][0] !== w1
9102          || selection[0][1] !== n1
9103          || selection[1][0] !== e1
9104          || selection[1][1] !== s1) {
9105        state.selection = [[w1, n1], [e1, s1]];
9106        redraw.call(that);
9107        emit.brush();
9108      }
9109    }
9110
9111    function ended() {
9112      nopropagation$1();
9113      if (exports.event.touches) {
9114        if (exports.event.touches.length) return;
9115        if (touchending) clearTimeout(touchending);
9116        touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
9117        group.on("touchmove.brush touchend.brush touchcancel.brush", null);
9118      } else {
9119        yesdrag(exports.event.view, moving);
9120        view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
9121      }
9122      group.attr("pointer-events", "all");
9123      overlay.attr("cursor", cursors.overlay);
9124      if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
9125      if (empty(selection)) state.selection = null, redraw.call(that);
9126      emit.end();
9127    }
9128
9129    function keydowned() {
9130      switch (exports.event.keyCode) {
9131        case 16: { // SHIFT
9132          shifting = signX && signY;
9133          break;
9134        }
9135        case 18: { // ALT
9136          if (mode === MODE_HANDLE) {
9137            if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
9138            if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
9139            mode = MODE_CENTER;
9140            move();
9141          }
9142          break;
9143        }
9144        case 32: { // SPACE; takes priority over ALT
9145          if (mode === MODE_HANDLE || mode === MODE_CENTER) {
9146            if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
9147            if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
9148            mode = MODE_SPACE;
9149            overlay.attr("cursor", cursors.selection);
9150            move();
9151          }
9152          break;
9153        }
9154        default: return;
9155      }
9156      noevent$1();
9157    }
9158
9159    function keyupped() {
9160      switch (exports.event.keyCode) {
9161        case 16: { // SHIFT
9162          if (shifting) {
9163            lockX = lockY = shifting = false;
9164            move();
9165          }
9166          break;
9167        }
9168        case 18: { // ALT
9169          if (mode === MODE_CENTER) {
9170            if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
9171            if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
9172            mode = MODE_HANDLE;
9173            move();
9174          }
9175          break;
9176        }
9177        case 32: { // SPACE
9178          if (mode === MODE_SPACE) {
9179            if (exports.event.altKey) {
9180              if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
9181              if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
9182              mode = MODE_CENTER;
9183            } else {
9184              if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
9185              if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
9186              mode = MODE_HANDLE;
9187            }
9188            overlay.attr("cursor", cursors[type]);
9189            move();
9190          }
9191          break;
9192        }
9193        default: return;
9194      }
9195      noevent$1();
9196    }
9197  }
9198
9199  function initialize() {
9200    var state = this.__brush || {selection: null};
9201    state.extent = extent.apply(this, arguments);
9202    state.dim = dim;
9203    return state;
9204  }
9205
9206  brush.extent = function(_) {
9207    return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
9208  };
9209
9210  brush.filter = function(_) {
9211    return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
9212  };
9213
9214  brush.handleSize = function(_) {
9215    return arguments.length ? (handleSize = +_, brush) : handleSize;
9216  };
9217
9218  brush.on = function() {
9219    var value = listeners.on.apply(listeners, arguments);
9220    return value === listeners ? brush : value;
9221  };
9222
9223  return brush;
9224}
9225
9226var cos = Math.cos;
9227var sin = Math.sin;
9228var pi$1 = Math.PI;
9229var halfPi$1 = pi$1 / 2;
9230var tau$1 = pi$1 * 2;
9231var max$1 = Math.max;
9232
9233function compareValue(compare) {
9234  return function(a, b) {
9235    return compare(
9236      a.source.value + a.target.value,
9237      b.source.value + b.target.value
9238    );
9239  };
9240}
9241
9242function chord() {
9243  var padAngle = 0,
9244      sortGroups = null,
9245      sortSubgroups = null,
9246      sortChords = null;
9247
9248  function chord(matrix) {
9249    var n = matrix.length,
9250        groupSums = [],
9251        groupIndex = sequence(n),
9252        subgroupIndex = [],
9253        chords = [],
9254        groups = chords.groups = new Array(n),
9255        subgroups = new Array(n * n),
9256        k,
9257        x,
9258        x0,
9259        dx,
9260        i,
9261        j;
9262
9263    // Compute the sum.
9264    k = 0, i = -1; while (++i < n) {
9265      x = 0, j = -1; while (++j < n) {
9266        x += matrix[i][j];
9267      }
9268      groupSums.push(x);
9269      subgroupIndex.push(sequence(n));
9270      k += x;
9271    }
9272
9273    // Sort groups…
9274    if (sortGroups) groupIndex.sort(function(a, b) {
9275      return sortGroups(groupSums[a], groupSums[b]);
9276    });
9277
9278    // Sort subgroups…
9279    if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
9280      d.sort(function(a, b) {
9281        return sortSubgroups(matrix[i][a], matrix[i][b]);
9282      });
9283    });
9284
9285    // Convert the sum to scaling factor for [0, 2pi].
9286    // TODO Allow start and end angle to be specified?
9287    // TODO Allow padding to be specified as percentage?
9288    k = max$1(0, tau$1 - padAngle * n) / k;
9289    dx = k ? padAngle : tau$1 / n;
9290
9291    // Compute the start and end angle for each group and subgroup.
9292    // Note: Opera has a bug reordering object literal properties!
9293    x = 0, i = -1; while (++i < n) {
9294      x0 = x, j = -1; while (++j < n) {
9295        var di = groupIndex[i],
9296            dj = subgroupIndex[di][j],
9297            v = matrix[di][dj],
9298            a0 = x,
9299            a1 = x += v * k;
9300        subgroups[dj * n + di] = {
9301          index: di,
9302          subindex: dj,
9303          startAngle: a0,
9304          endAngle: a1,
9305          value: v
9306        };
9307      }
9308      groups[di] = {
9309        index: di,
9310        startAngle: x0,
9311        endAngle: x,
9312        value: groupSums[di]
9313      };
9314      x += dx;
9315    }
9316
9317    // Generate chords for each (non-empty) subgroup-subgroup link.
9318    i = -1; while (++i < n) {
9319      j = i - 1; while (++j < n) {
9320        var source = subgroups[j * n + i],
9321            target = subgroups[i * n + j];
9322        if (source.value || target.value) {
9323          chords.push(source.value < target.value
9324              ? {source: target, target: source}
9325              : {source: source, target: target});
9326        }
9327      }
9328    }
9329
9330    return sortChords ? chords.sort(sortChords) : chords;
9331  }
9332
9333  chord.padAngle = function(_) {
9334    return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
9335  };
9336
9337  chord.sortGroups = function(_) {
9338    return arguments.length ? (sortGroups = _, chord) : sortGroups;
9339  };
9340
9341  chord.sortSubgroups = function(_) {
9342    return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
9343  };
9344
9345  chord.sortChords = function(_) {
9346    return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
9347  };
9348
9349  return chord;
9350}
9351
9352var slice$2 = Array.prototype.slice;
9353
9354function constant$5(x) {
9355  return function() {
9356    return x;
9357  };
9358}
9359
9360var pi$2 = Math.PI;
9361var tau$2 = 2 * pi$2;
9362var epsilon$1 = 1e-6;
9363var tauEpsilon = tau$2 - epsilon$1;
9364
9365function Path() {
9366  this._x0 = this._y0 = // start of current subpath
9367  this._x1 = this._y1 = null; // end of current subpath
9368  this._ = "";
9369}
9370
9371function path() {
9372  return new Path;
9373}
9374
9375Path.prototype = path.prototype = {
9376  constructor: Path,
9377  moveTo: function(x, y) {
9378    this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
9379  },
9380  closePath: function() {
9381    if (this._x1 !== null) {
9382      this._x1 = this._x0, this._y1 = this._y0;
9383      this._ += "Z";
9384    }
9385  },
9386  lineTo: function(x, y) {
9387    this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
9388  },
9389  quadraticCurveTo: function(x1, y1, x, y) {
9390    this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
9391  },
9392  bezierCurveTo: function(x1, y1, x2, y2, x, y) {
9393    this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
9394  },
9395  arcTo: function(x1, y1, x2, y2, r) {
9396    x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
9397    var x0 = this._x1,
9398        y0 = this._y1,
9399        x21 = x2 - x1,
9400        y21 = y2 - y1,
9401        x01 = x0 - x1,
9402        y01 = y0 - y1,
9403        l01_2 = x01 * x01 + y01 * y01;
9404
9405    // Is the radius negative? Error.
9406    if (r < 0) throw new Error("negative radius: " + r);
9407
9408    // Is this path empty? Move to (x1,y1).
9409    if (this._x1 === null) {
9410      this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
9411    }
9412
9413    // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
9414    else if (!(l01_2 > epsilon$1)) {}
9415
9416    // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
9417    // Equivalently, is (x1,y1) coincident with (x2,y2)?
9418    // Or, is the radius zero? Line to (x1,y1).
9419    else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
9420      this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
9421    }
9422
9423    // Otherwise, draw an arc!
9424    else {
9425      var x20 = x2 - x0,
9426          y20 = y2 - y0,
9427          l21_2 = x21 * x21 + y21 * y21,
9428          l20_2 = x20 * x20 + y20 * y20,
9429          l21 = Math.sqrt(l21_2),
9430          l01 = Math.sqrt(l01_2),
9431          l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
9432          t01 = l / l01,
9433          t21 = l / l21;
9434
9435      // If the start tangent is not coincident with (x0,y0), line to.
9436      if (Math.abs(t01 - 1) > epsilon$1) {
9437        this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
9438      }
9439
9440      this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
9441    }
9442  },
9443  arc: function(x, y, r, a0, a1, ccw) {
9444    x = +x, y = +y, r = +r;
9445    var dx = r * Math.cos(a0),
9446        dy = r * Math.sin(a0),
9447        x0 = x + dx,
9448        y0 = y + dy,
9449        cw = 1 ^ ccw,
9450        da = ccw ? a0 - a1 : a1 - a0;
9451
9452    // Is the radius negative? Error.
9453    if (r < 0) throw new Error("negative radius: " + r);
9454
9455    // Is this path empty? Move to (x0,y0).
9456    if (this._x1 === null) {
9457      this._ += "M" + x0 + "," + y0;
9458    }
9459
9460    // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
9461    else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
9462      this._ += "L" + x0 + "," + y0;
9463    }
9464
9465    // Is this arc empty? We’re done.
9466    if (!r) return;
9467
9468    // Does the angle go the wrong way? Flip the direction.
9469    if (da < 0) da = da % tau$2 + tau$2;
9470
9471    // Is this a complete circle? Draw two arcs to complete the circle.
9472    if (da > tauEpsilon) {
9473      this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
9474    }
9475
9476    // Is this arc non-empty? Draw an arc!
9477    else if (da > epsilon$1) {
9478      this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
9479    }
9480  },
9481  rect: function(x, y, w, h) {
9482    this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
9483  },
9484  toString: function() {
9485    return this._;
9486  }
9487};
9488
9489function defaultSource(d) {
9490  return d.source;
9491}
9492
9493function defaultTarget(d) {
9494  return d.target;
9495}
9496
9497function defaultRadius(d) {
9498  return d.radius;
9499}
9500
9501function defaultStartAngle(d) {
9502  return d.startAngle;
9503}
9504
9505function defaultEndAngle(d) {
9506  return d.endAngle;
9507}
9508
9509function ribbon() {
9510  var source = defaultSource,
9511      target = defaultTarget,
9512      radius = defaultRadius,
9513      startAngle = defaultStartAngle,
9514      endAngle = defaultEndAngle,
9515      context = null;
9516
9517  function ribbon() {
9518    var buffer,
9519        argv = slice$2.call(arguments),
9520        s = source.apply(this, argv),
9521        t = target.apply(this, argv),
9522        sr = +radius.apply(this, (argv[0] = s, argv)),
9523        sa0 = startAngle.apply(this, argv) - halfPi$1,
9524        sa1 = endAngle.apply(this, argv) - halfPi$1,
9525        sx0 = sr * cos(sa0),
9526        sy0 = sr * sin(sa0),
9527        tr = +radius.apply(this, (argv[0] = t, argv)),
9528        ta0 = startAngle.apply(this, argv) - halfPi$1,
9529        ta1 = endAngle.apply(this, argv) - halfPi$1;
9530
9531    if (!context) context = buffer = path();
9532
9533    context.moveTo(sx0, sy0);
9534    context.arc(0, 0, sr, sa0, sa1);
9535    if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
9536      context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
9537      context.arc(0, 0, tr, ta0, ta1);
9538    }
9539    context.quadraticCurveTo(0, 0, sx0, sy0);
9540    context.closePath();
9541
9542    if (buffer) return context = null, buffer + "" || null;
9543  }
9544
9545  ribbon.radius = function(_) {
9546    return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radiu
vendor: 4,540 bytes, lines 9546-9713
9546s;
9547  };
9548
9549  ribbon.startAngle = function(_) {
9550    return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
9551  };
9552
9553  ribbon.endAngle = function(_) {
9554    return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
9555  };
9556
9557  ribbon.source = function(_) {
9558    return arguments.length ? (source = _, ribbon) : source;
9559  };
9560
9561  ribbon.target = function(_) {
9562    return arguments.length ? (target = _, ribbon) : target;
9563  };
9564
9565  ribbon.context = function(_) {
9566    return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
9567  };
9568
9569  return ribbon;
9570}
9571
9572var prefix = "$";
9573
9574function Map() {}
9575
9576Map.prototype = map$1.prototype = {
9577  constructor: Map,
9578  has: function(key) {
9579    return (prefix + key) in this;
9580  },
9581  get: function(key) {
9582    return this[prefix + key];
9583  },
9584  set: function(key, value) {
9585    this[prefix + key] = value;
9586    return this;
9587  },
9588  remove: function(key) {
9589    var property = prefix + key;
9590    return property in this && delete this[property];
9591  },
9592  clear: function() {
9593    for (var property in this) if (property[0] === prefix) delete this[property];
9594  },
9595  keys: function() {
9596    var keys = [];
9597    for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
9598    return keys;
9599  },
9600  values: function() {
9601    var values = [];
9602    for (var property in this) if (property[0] === prefix) values.push(this[property]);
9603    return values;
9604  },
9605  entries: function() {
9606    var entries = [];
9607    for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
9608    return entries;
9609  },
9610  size: function() {
9611    var size = 0;
9612    for (var property in this) if (property[0] === prefix) ++size;
9613    return size;
9614  },
9615  empty: function() {
9616    for (var property in this) if (property[0] === prefix) return false;
9617    return true;
9618  },
9619  each: function(f) {
9620    for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
9621  }
9622};
9623
9624function map$1(object, f) {
9625  var map = new Map;
9626
9627  // Copy constructor.
9628  if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
9629
9630  // Index array by numeric index or specified key function.
9631  else if (Array.isArray(object)) {
9632    var i = -1,
9633        n = object.length,
9634        o;
9635
9636    if (f == null) while (++i < n) map.set(i, object[i]);
9637    else while (++i < n) map.set(f(o = object[i], i, object), o);
9638  }
9639
9640  // Convert object to map.
9641  else if (object) for (var key in object) map.set(key, object[key]);
9642
9643  return map;
9644}
9645
9646function nest() {
9647  var keys = [],
9648      sortKeys = [],
9649      sortValues,
9650      rollup,
9651      nest;
9652
9653  function apply(array, depth, createResult, setResult) {
9654    if (depth >= keys.length) {
9655      if (sortValues != null) array.sort(sortValues);
9656      return rollup != null ? rollup(array) : array;
9657    }
9658
9659    var i = -1,
9660        n = array.length,
9661        key = keys[depth++],
9662        keyValue,
9663        value,
9664        valuesByKey = map$1(),
9665        values,
9666        result = createResult();
9667
9668    while (++i < n) {
9669      if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
9670        values.push(value);
9671      } else {
9672        valuesByKey.set(keyValue, [value]);
9673      }
9674    }
9675
9676    valuesByKey.each(function(values, key) {
9677      setResult(result, key, apply(values, depth, createResult, setResult));
9678    });
9679
9680    return result;
9681  }
9682
9683  function entries(map, depth) {
9684    if (++depth > keys.length) return map;
9685    var array, sortKey = sortKeys[depth - 1];
9686    if (rollup != null && depth >= keys.length) array = map.entries();
9687    else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
9688    return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
9689  }
9690
9691  return nest = {
9692    object: function(array) { return apply(array, 0, createObject, setObject); },
9693    map: function(array) { return apply(array, 0, createMap, setMap); },
9694    entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
9695    key: function(d) { keys.push(d); return nest; },
9696    sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
9697    sortValues: function(order) { sortValues = order; return nest; },
9698    rollup: function(f) { rollup = f; return nest; }
9699  };
9700}
9701
9702function createObject() {
9703  return {};
9704}
9705
9706function setObject(object, key, value) {
9707  object[key] = value;
9708}
9709
9710function createMap() {
9711  return map$1();
9712}
9713
9714function setMap(map, key, value) {
9715  map.set(key, value);
9716}
9717
9718function Set() {}
9719
9720var proto = map$1.prototype;
9721
9722Set.prototype = set$2.prototype = {
9723  constructor: Set,
9724  has: proto.has,
9725  add: function(value) {
9726    value += "";
9727    this[prefix + value] = value;
9728    return this;
9729  },
9730  remove: proto.remove,
9731  clear: proto.clear,
9732  values: proto.keys,
9733  size: proto.size,
9734  empty: proto.empty,
9735  each: proto.each
9736};
9737
9738function set$2(object, f) {
9739  var set = new Set;
9740
9741  // Copy constructor.
9742  if (object instanceof Set) object.each(function(value) { set.add(value); });
9743
9744  // Otherwise, assume it’s an array.
9745  else if (object) {
9746    var i = -1, n = object.length;
9747    if (f == null) while (++i < n) set.add(object[i]);
9748    else while (++i < n) set.add(f(object[i], i, object));
9749  }
9750
9751  return set;
9752}
9753
9754function keys(map) {
9755  var keys = [];
9756  for (var key in map) keys.push(key);
9757  return keys;
9758}
9759
9760function values(map) {
9761  var values = [];
9762  for (var key in map) values.push(map[key]);
9763  return values;
9764}
9765
9766function entries(map) {
9767  var entries = [];
9768  for (var key in map) entries.push({key: key, value: map[key]});
9769  return entries;
9770}
9771
9772var EOL = {};
9773var EOF = {};
9774var QUOTE = 34;
9775var NEWLINE = 10;
9776var RETURN = 13;
9777
9778function objectConverter(columns) {
9779  return new Function("d", "return {" + columns.map(function(name, i) {
9780    return JSON.stringify(name) + ": d[" + i + "]";
9781  }).join(",") + "}");
9782}
9783
9784function customConverter(columns, f) {
9785  var object = objectConverter(columns);
9786  return function(row, i) {
9787    return f(object(row), i, columns);
9788  };
9789}
9790
9791// Compute unique columns in order of discovery.
9792function inferColumns(rows) {
9793  var columnSet = Object.create(null),
9794      columns = [];
9795
9796  rows.forEach(function(row) {
9797    for (var column in row) {
9798      if (!(column in columnSet)) {
9799        columns.push(columnSet[column] = column);
9800      }
9801    }
9802  });
9803
9804  return columns;
9805}
9806
9807function dsv(delimiter) {
9808  var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
9809      DELIMITER = delimiter.charCodeAt(0);
9810
9811  function parse(text, f) {
9812    var convert, columns, rows = parseRows(text, function(row, i) {
9813      if (convert) return convert(row, i - 1);
9814      columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
9815    });
9816    rows.columns = columns || [];
9817    return rows;
9818  }
9819
9820  function parseRows(text, f) {
9821    var rows = [], // output rows
9822        N = text.length,
9823        I = 0, // current character index
9824        n = 0, // current line number
9825        t, // current token
9826        eof = N <= 0, // current token followed by EOF?
9827        eol = false; // current token followed by EOL?
9828
9829    // Strip the trailing newline.
9830    if (text.charCodeAt(N - 1) === NEWLINE) --N;
9831    if (text.charCodeAt(N - 1) === RETURN) --N;
9832
9833    function token() {
9834      if (eof) return EOF;
9835      if (eol) return eol = false, EOL;
9836
9837      // Unescape quotes.
9838      var i, j = I, c;
9839      if (text.charCodeAt(j) === QUOTE) {
9840        while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
9841        if ((i = I) >= N) eof = true;
9842        else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
9843        else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
9844        return text.slice(j + 1, i - 1).replace(/""/g, "\"");
9845      }
9846
9847      // Find next delimiter or newline.
9848      while (I < N) {
9849        if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
9850        else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
9851        else if (c !== DELIMITER) continue;
9852        return text.slice(j, i);
9853      }
9854
9855      // Return last token before EOF.
9856      return eof = true, text.slice(j, N);
9857    }
9858
9859    while ((t = token()) !== EOF) {
9860      var row = [];
9861      while (t !== EOL && t !== EOF) row.push(t), t = token();
9862      if (f && (row = f(row, n++)) == null) continue;
9863      rows.push(row);
9864    }
9865
9866    return rows;
9867  }
9868
9869  function format(rows, columns) {
9870    if (columns == null) columns = inferColumns(rows);
9871    return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
9872      return columns.map(function(column) {
9873        return formatValue(row[column]);
9874      }).join(delimiter);
9875    })).join("\n");
9876  }
9877
9878  function formatRows(rows) {
9879    return rows.map(formatRow).join("\n");
9880  }
9881
9882  function formatRow(row) {
9883    return row.map(formatValue).join(delimiter);
9884  }
9885
9886  function formatValue(text) {
9887    return text == null ? ""
9888        : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
9889        : text;
9890  }
9891
9892  return {
9893    parse: parse,
9894    parseRows: parseRows,
9895    format: format,
9896    formatRows: formatRows
9897  };
9898}
9899
9900var csv = dsv(",");
9901
9902var csvParse = csv.parse;
9903var csvParseRows = csv.parseRows;
9904var csvFormat = csv.format;
9905var csvFormatRows = csv.formatRows;
9906
9907var tsv = dsv("\t");
9908
9909var tsvParse = tsv.parse;
9910var tsvParseRows = tsv.parseRows;
9911var tsvFormat = tsv.format;
9912var tsvFormatRows = tsv.formatRows;
9913
9914function center$1(x, y) {
9915  var nodes;
9916
9917  if (x == null) x = 0;
9918  if (y == null) y = 0;
9919
9920  function force() {
9921    var i,
9922        n = nodes.length,
9923        node,
9924        sx = 0,
9925        sy = 0;
9926
9927    for (i = 0; i < n; ++i) {
9928      node = nodes[i], sx += node.x, sy += node.y;
9929    }
9930
9931    for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
9932      node = nodes[i], node.x -= sx, node.y -= sy;
9933    }
9934  }
9935
9936  force.initialize = function(_) {
9937    nodes = _;
9938  };
9939
9940  force.x = function(_) {
9941    return arguments.length ? (x = +_, force) : x;
9942  };
9943
9944  force.y = function(_) {
9945    return arguments.length ? (y = +_, force) : y;
9946  };
9947
9948  return force;
9949}
9950
9951function constant$6(x) {
9952  return function() {
9953    return x;
9954  };
9955}
9956
9957function jiggle() {
9958  return (Math.random() - 0.5) * 1e-6;
9959}
9960
9961function tree_add(d) {
9962  var x = +this._x.call(null, d),
9963      y = +this._y.call(null, d);
9964  return add(this.cover(x, y), x, y, d);
9965}
9966
9967function add(tree, x, y, d) {
9968  if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
9969
9970  var parent,
9971      node = tree._root,
9972      leaf = {data: d},
9973      x0 = tree._x0,
9974      y0 = tree._y0,
9975      x1 = tree._x1,
9976      y1 = tree._y1,
9977      xm,
9978      ym,
9979      xp,
9980      yp,
9981      right,
9982      bottom,
9983      i,
9984      j;
9985
9986  // If the tree is empty, initialize the root as a leaf.
9987  if (!node) return tree._root = leaf, tree;
9988
9989  // Find the existing leaf for the new point, or add it.
9990  while (node.length) {
9991    if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
9992    if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
9993    if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
9994  }
9995
9996  // Is the new point is exactly coincident with the existing point?
9997  xp = +tree._x.call(null, node.data);
9998  yp = +tree._y.call(null, node.data);
9999  if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
10000
10001  // Otherwise, split the leaf node until the old and new point are separated.
10002  do {
10003    parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
10004    if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
10005    if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
10006  } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
10007  return parent[j] = node, parent[i] = leaf, tree;
10008}
10009
10010function addAll(data) {
10011  var d, i, n = data.length,
10012      x,
10013      y,
10014      xz = new Array(n),
10015      yz = new Array(n),
10016      x0 = Infinity,
10017      y0 = Infinity,
10018      x1 = -Infinity,
10019      y1 = -Infinity;
10020
10021  // Compute the points and their extent.
10022  for (i = 0; i < n; ++i) {
10023    if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
10024    xz[i] = x;
10025    yz[i] = y;
10026    if (x < x0) x0 = x;
10027    if (x > x1) x1 = x;
10028    if (y < y0) y0 = y;
10029    if (y > y1) y1 = y;
10030  }
10031
10032  // If there were no (valid) points, inherit the existing extent.
10033  if (x1 < x0) x0 = this._x0, x1 = this._x1;
10034  if (y1 < y0) y0 = this._y0, y1 = this._y1;
10035
10036  // Expand the tree to cover the new points.
10037  this.cover(x0, y0).cover(x1, y1);
10038
10039  // Add the new points.
10040  for (i = 0; i < n; ++i) {
10041    add(this, xz[i], yz[i], data[i]);
10042  }
10043
10044  return this;
10045}
10046
10047function tree_cover(x, y) {
10048  if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
10049
10050  var x0 = this._x0,
10051      y0 = this._y0,
10052      x1 = this._x1,
10053      y1 = this._y1;
10054
10055  // If the quadtree has no extent, initialize them.
10056  // Integer extent are necessary so that if we later double the extent,
10057  // the existing quadrant boundaries don’t change due to floating point error!
10058  if (isNaN(x0)) {
10059    x1 = (x0 = Math.floor(x)) + 1;
10060    y1 = (y0 = Math.floor(y)) + 1;
10061  }
10062
10063  // Otherwise, double repeatedly to cover.
10064  else if (x0 > x || x > x1 || y0 > y || y > y1) {
10065    var z = x1 - x0,
10066        node = this._root,
10067        parent,
10068        i;
10069
10070    switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
10071      case 0: {
10072        do parent = new Array(4), parent[i] = node, node = parent;
10073        while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
10074        break;
10075      }
10076      case 1: {
10077        do parent = new Array(4), parent[i] = node, node = parent;
10078        while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
10079        break;
10080      }
10081      case 2: {
10082        do parent = new Array(4), parent[i] = node, node = parent;
10083        while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
10084        break;
10085      }
10086      case 3: {
10087        do parent = new Array(4), parent[i] = node, node = parent;
10088        while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
10089        break;
10090      }
10091    }
10092
10093    if (this._root && this._root.length) this._root = node;
10094  }
10095
10096  // If the quadtree covers the point already, just return.
10097  else return this;
10098
10099  this._x0 = x0;
10100  this._y0 = y0;
10101  this._x1 = x1;
10102  this._y1 = y1;
10103  return this;
10104}
10105
10106function tree_data() {
10107  var data = [];
10108  this.visit(function(node) {
10109    if (!node.length) do data.push(node.data); while (node = node.next)
10110  });
10111  return data;
10112}
10113
10114function tree_extent(_) {
10115  return arguments.length
10116      ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
10117      : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
10118}
10119
10120function Quad(node, x0, y0, x1, y1) {
10121  this.node = node;
10122  this.x0 = x0;
10123  this.y0 = y0;
10124  this.x1 = x1;
10125  this.y1 = y1;
10126}
10127
10128function tree_find(x, y, radius) {
10129  var data,
10130      x0 = this._x0,
10131      y0 = this._y0,
10132      x1,
10133      y1,
10134      x2,
10135      y2,
10136      x3 = this._x1,
10137      y3 = this._y1,
10138      quads = [],
10139      node = this._root,
10140      q,
10141      i;
10142
10143  if (node) quads.push(new Quad(node, x0, y0, x3, y3));
10144  if (radius == null) radius = Infinity;
10145  else {
vendor: 22,175 bytes, lines 10146-10981
10146    x0 = x - radius, y0 = y - radius;
10147    x3 = x + radius, y3 = y + radius;
10148    radius *= radius;
10149  }
10150
10151  while (q = quads.pop()) {
10152
10153    // Stop searching if this quadrant can’t contain a closer node.
10154    if (!(node = q.node)
10155        || (x1 = q.x0) > x3
10156        || (y1 = q.y0) > y3
10157        || (x2 = q.x1) < x0
10158        || (y2 = q.y1) < y0) continue;
10159
10160    // Bisect the current quadrant.
10161    if (node.length) {
10162      var xm = (x1 + x2) / 2,
10163          ym = (y1 + y2) / 2;
10164
10165      quads.push(
10166        new Quad(node[3], xm, ym, x2, y2),
10167        new Quad(node[2], x1, ym, xm, y2),
10168        new Quad(node[1], xm, y1, x2, ym),
10169        new Quad(node[0], x1, y1, xm, ym)
10170      );
10171
10172      // Visit the closest quadrant first.
10173      if (i = (y >= ym) << 1 | (x >= xm)) {
10174        q = quads[quads.length - 1];
10175        quads[quads.length - 1] = quads[quads.length - 1 - i];
10176        quads[quads.length - 1 - i] = q;
10177      }
10178    }
10179
10180    // Visit this point. (Visiting coincident points isn’t necessary!)
10181    else {
10182      var dx = x - +this._x.call(null, node.data),
10183          dy = y - +this._y.call(null, node.data),
10184          d2 = dx * dx + dy * dy;
10185      if (d2 < radius) {
10186        var d = Math.sqrt(radius = d2);
10187        x0 = x - d, y0 = y - d;
10188        x3 = x + d, y3 = y + d;
10189        data = node.data;
10190      }
10191    }
10192  }
10193
10194  return data;
10195}
10196
10197function tree_remove(d) {
10198  if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
10199
10200  var parent,
10201      node = this._root,
10202      retainer,
10203      previous,
10204      next,
10205      x0 = this._x0,
10206      y0 = this._y0,
10207      x1 = this._x1,
10208      y1 = this._y1,
10209      x,
10210      y,
10211      xm,
10212      ym,
10213      right,
10214      bottom,
10215      i,
10216      j;
10217
10218  // If the tree is empty, initialize the root as a leaf.
10219  if (!node) return this;
10220
10221  // Find the leaf node for the point.
10222  // While descending, also retain the deepest parent with a non-removed sibling.
10223  if (node.length) while (true) {
10224    if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
10225    if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
10226    if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
10227    if (!node.length) break;
10228    if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
10229  }
10230
10231  // Find the point to remove.
10232  while (node.data !== d) if (!(previous = node, node = node.next)) return this;
10233  if (next = node.next) delete node.next;
10234
10235  // If there are multiple coincident points, remove just the point.
10236  if (previous) return next ? previous.next = next : delete previous.next, this;
10237
10238  // If this is the root point, remove it.
10239  if (!parent) return this._root = next, this;
10240
10241  // Remove this leaf.
10242  next ? parent[i] = next : delete parent[i];
10243
10244  // If the parent now contains exactly one leaf, collapse superfluous parents.
10245  if ((node = parent[0] || parent[1] || parent[2] || parent[3])
10246      && node === (parent[3] || parent[2] || parent[1] || parent[0])
10247      && !node.length) {
10248    if (retainer) retainer[j] = node;
10249    else this._root = node;
10250  }
10251
10252  return this;
10253}
10254
10255function removeAll(data) {
10256  for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
10257  return this;
10258}
10259
10260function tree_root() {
10261  return this._root;
10262}
10263
10264function tree_size() {
10265  var size = 0;
10266  this.visit(function(node) {
10267    if (!node.length) do ++size; while (node = node.next)
10268  });
10269  return size;
10270}
10271
10272function tree_visit(callback) {
10273  var quads = [], q, node = this._root, child, x0, y0, x1, y1;
10274  if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
10275  while (q = quads.pop()) {
10276    if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
10277      var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
10278      if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
10279      if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
10280      if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
10281      if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
10282    }
10283  }
10284  return this;
10285}
10286
10287function tree_visitAfter(callback) {
10288  var quads = [], next = [], q;
10289  if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
10290  while (q = quads.pop()) {
10291    var node = q.node;
10292    if (node.length) {
10293      var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
10294      if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
10295      if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
10296      if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
10297      if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
10298    }
10299    next.push(q);
10300  }
10301  while (q = next.pop()) {
10302    callback(q.node, q.x0, q.y0, q.x1, q.y1);
10303  }
10304  return this;
10305}
10306
10307function defaultX(d) {
10308  return d[0];
10309}
10310
10311function tree_x(_) {
10312  return arguments.length ? (this._x = _, this) : this._x;
10313}
10314
10315function defaultY(d) {
10316  return d[1];
10317}
10318
10319function tree_y(_) {
10320  return arguments.length ? (this._y = _, this) : this._y;
10321}
10322
10323function quadtree(nodes, x, y) {
10324  var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
10325  return nodes == null ? tree : tree.addAll(nodes);
10326}
10327
10328function Quadtree(x, y, x0, y0, x1, y1) {
10329  this._x = x;
10330  this._y = y;
10331  this._x0 = x0;
10332  this._y0 = y0;
10333  this._x1 = x1;
10334  this._y1 = y1;
10335  this._root = undefined;
10336}
10337
10338function leaf_copy(leaf) {
10339  var copy = {data: leaf.data}, next = copy;
10340  while (leaf = leaf.next) next = next.next = {data: leaf.data};
10341  return copy;
10342}
10343
10344var treeProto = quadtree.prototype = Quadtree.prototype;
10345
10346treeProto.copy = function() {
10347  var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
10348      node = this._root,
10349      nodes,
10350      child;
10351
10352  if (!node) return copy;
10353
10354  if (!node.length) return copy._root = leaf_copy(node), copy;
10355
10356  nodes = [{source: node, target: copy._root = new Array(4)}];
10357  while (node = nodes.pop()) {
10358    for (var i = 0; i < 4; ++i) {
10359      if (child = node.source[i]) {
10360        if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
10361        else node.target[i] = leaf_copy(child);
10362      }
10363    }
10364  }
10365
10366  return copy;
10367};
10368
10369treeProto.add = tree_add;
10370treeProto.addAll = addAll;
10371treeProto.cover = tree_cover;
10372treeProto.data = tree_data;
10373treeProto.extent = tree_extent;
10374treeProto.find = tree_find;
10375treeProto.remove = tree_remove;
10376treeProto.removeAll = removeAll;
10377treeProto.root = tree_root;
10378treeProto.size = tree_size;
10379treeProto.visit = tree_visit;
10380treeProto.visitAfter = tree_visitAfter;
10381treeProto.x = tree_x;
10382treeProto.y = tree_y;
10383
10384function x(d) {
10385  return d.x + d.vx;
10386}
10387
10388function y(d) {
10389  return d.y + d.vy;
10390}
10391
10392function collide(radius) {
10393  var nodes,
10394      radii,
10395      strength = 1,
10396      iterations = 1;
10397
10398  if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
10399
10400  function force() {
10401    var i, n = nodes.length,
10402        tree,
10403        node,
10404        xi,
10405        yi,
10406        ri,
10407        ri2;
10408
10409    for (var k = 0; k < iterations; ++k) {
10410      tree = quadtree(nodes, x, y).visitAfter(prepare);
10411      for (i = 0; i < n; ++i) {
10412        node = nodes[i];
10413        ri = radii[node.index], ri2 = ri * ri;
10414        xi = node.x + node.vx;
10415        yi = node.y + node.vy;
10416        tree.visit(apply);
10417      }
10418    }
10419
10420    function apply(quad, x0, y0, x1, y1) {
10421      var data = quad.data, rj = quad.r, r = ri + rj;
10422      if (data) {
10423        if (data.index > node.index) {
10424          var x = xi - data.x - data.vx,
10425              y = yi - data.y - data.vy,
10426              l = x * x + y * y;
10427          if (l < r * r) {
10428            if (x === 0) x = jiggle(), l += x * x;
10429            if (y === 0) y = jiggle(), l += y * y;
10430            l = (r - (l = Math.sqrt(l))) / l * strength;
10431            node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
10432            node.vy += (y *= l) * r;
10433            data.vx -= x * (r = 1 - r);
10434            data.vy -= y * r;
10435          }
10436        }
10437        return;
10438      }
10439      return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
10440    }
10441  }
10442
10443  function prepare(quad) {
10444    if (quad.data) return quad.r = radii[quad.data.index];
10445    for (var i = quad.r = 0; i < 4; ++i) {
10446      if (quad[i] && quad[i].r > quad.r) {
10447        quad.r = quad[i].r;
10448      }
10449    }
10450  }
10451
10452  function initialize() {
10453    if (!nodes) return;
10454    var i, n = nodes.length, node;
10455    radii = new Array(n);
10456    for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
10457  }
10458
10459  force.initialize = function(_) {
10460    nodes = _;
10461    initialize();
10462  };
10463
10464  force.iterations = function(_) {
10465    return arguments.length ? (iterations = +_, force) : iterations;
10466  };
10467
10468  force.strength = function(_) {
10469    return arguments.length ? (strength = +_, force) : strength;
10470  };
10471
10472  force.radius = function(_) {
10473    return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
10474  };
10475
10476  return force;
10477}
10478
10479function index(d) {
10480  return d.index;
10481}
10482
10483function find(nodeById, nodeId) {
10484  var node = nodeById.get(nodeId);
10485  if (!node) throw new Error("missing: " + nodeId);
10486  return node;
10487}
10488
10489function link(links) {
10490  var id = index,
10491      strength = defaultStrength,
10492      strengths,
10493      distance = constant$6(30),
10494      distances,
10495      nodes,
10496      count,
10497      bias,
10498      iterations = 1;
10499
10500  if (links == null) links = [];
10501
10502  function defaultStrength(link) {
10503    return 1 / Math.min(count[link.source.index], count[link.target.index]);
10504  }
10505
10506  function force(alpha) {
10507    for (var k = 0, n = links.length; k < iterations; ++k) {
10508      for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
10509        link = links[i], source = link.source, target = link.target;
10510        x = target.x + target.vx - source.x - source.vx || jiggle();
10511        y = target.y + target.vy - source.y - source.vy || jiggle();
10512        l = Math.sqrt(x * x + y * y);
10513        l = (l - distances[i]) / l * alpha * strengths[i];
10514        x *= l, y *= l;
10515        target.vx -= x * (b = bias[i]);
10516        target.vy -= y * b;
10517        source.vx += x * (b = 1 - b);
10518        source.vy += y * b;
10519      }
10520    }
10521  }
10522
10523  function initialize() {
10524    if (!nodes) return;
10525
10526    var i,
10527        n = nodes.length,
10528        m = links.length,
10529        nodeById = map$1(nodes, id),
10530        link;
10531
10532    for (i = 0, count = new Array(n); i < m; ++i) {
10533      link = links[i], link.index = i;
10534      if (typeof link.source !== "object") link.source = find(nodeById, link.source);
10535      if (typeof link.target !== "object") link.target = find(nodeById, link.target);
10536      count[link.source.index] = (count[link.source.index] || 0) + 1;
10537      count[link.target.index] = (count[link.target.index] || 0) + 1;
10538    }
10539
10540    for (i = 0, bias = new Array(m); i < m; ++i) {
10541      link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
10542    }
10543
10544    strengths = new Array(m), initializeStrength();
10545    distances = new Array(m), initializeDistance();
10546  }
10547
10548  function initializeStrength() {
10549    if (!nodes) return;
10550
10551    for (var i = 0, n = links.length; i < n; ++i) {
10552      strengths[i] = +strength(links[i], i, links);
10553    }
10554  }
10555
10556  function initializeDistance() {
10557    if (!nodes) return;
10558
10559    for (var i = 0, n = links.length; i < n; ++i) {
10560      distances[i] = +distance(links[i], i, links);
10561    }
10562  }
10563
10564  force.initialize = function(_) {
10565    nodes = _;
10566    initialize();
10567  };
10568
10569  force.links = function(_) {
10570    return arguments.length ? (links = _, initialize(), force) : links;
10571  };
10572
10573  force.id = function(_) {
10574    return arguments.length ? (id = _, force) : id;
10575  };
10576
10577  force.iterations = function(_) {
10578    return arguments.length ? (iterations = +_, force) : iterations;
10579  };
10580
10581  force.strength = function(_) {
10582    return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
10583  };
10584
10585  force.distance = function(_) {
10586    return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
10587  };
10588
10589  return force;
10590}
10591
10592function x$1(d) {
10593  return d.x;
10594}
10595
10596function y$1(d) {
10597  return d.y;
10598}
10599
10600var initialRadius = 10;
10601var initialAngle = Math.PI * (3 - Math.sqrt(5));
10602
10603function simulation(nodes) {
10604  var simulation,
10605      alpha = 1,
10606      alphaMin = 0.001,
10607      alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
10608      alphaTarget = 0,
10609      velocityDecay = 0.6,
10610      forces = map$1(),
10611      stepper = timer(step),
10612      event = dispatch("tick", "end");
10613
10614  if (nodes == null) nodes = [];
10615
10616  function step() {
10617    tick();
10618    event.call("tick", simulation);
10619    if (alpha < alphaMin) {
10620      stepper.stop();
10621      event.call("end", simulation);
10622    }
10623  }
10624
10625  function tick() {
10626    var i, n = nodes.length, node;
10627
10628    alpha += (alphaTarget - alpha) * alphaDecay;
10629
10630    forces.each(function(force) {
10631      force(alpha);
10632    });
10633
10634    for (i = 0; i < n; ++i) {
10635      node = nodes[i];
10636      if (node.fx == null) node.x += node.vx *= velocityDecay;
10637      else node.x = node.fx, node.vx = 0;
10638      if (node.fy == null) node.y += node.vy *= velocityDecay;
10639      else node.y = node.fy, node.vy = 0;
10640    }
10641  }
10642
10643  function initializeNodes() {
10644    for (var i = 0, n = nodes.length, node; i < n; ++i) {
10645      node = nodes[i], node.index = i;
10646      if (isNaN(node.x) || isNaN(node.y)) {
10647        var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
10648        node.x = radius * Math.cos(angle);
10649        node.y = radius * Math.sin(angle);
10650      }
10651      if (isNaN(node.vx) || isNaN(node.vy)) {
10652        node.vx = node.vy = 0;
10653      }
10654    }
10655  }
10656
10657  function initializeForce(force) {
10658    if (force.initialize) force.initialize(nodes);
10659    return force;
10660  }
10661
10662  initializeNodes();
10663
10664  return simulation = {
10665    tick: tick,
10666
10667    restart: function() {
10668      return stepper.restart(step), simulation;
10669    },
10670
10671    stop: function() {
10672      return stepper.stop(), simulation;
10673    },
10674
10675    nodes: function(_) {
10676      return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
10677    },
10678
10679    alpha: function(_) {
10680      return arguments.length ? (alpha = +_, simulation) : alpha;
10681    },
10682
10683    alphaMin: function(_) {
10684      return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
10685    },
10686
10687    alphaDecay: function(_) {
10688      return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
10689    },
10690
10691    alphaTarget: function(_) {
10692      return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
10693    },
10694
10695    velocityDecay: function(_) {
10696      return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
10697    },
10698
10699    force: function(name, _) {
10700      return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
10701    },
10702
10703    find: function(x, y, radius) {
10704      var i = 0,
10705          n = nodes.length,
10706          dx,
10707          dy,
10708          d2,
10709          node,
10710          closest;
10711
10712      if (radius == null) radius = Infinity;
10713      else radius *= radius;
10714
10715      for (i = 0; i < n; ++i) {
10716        node = nodes[i];
10717        dx = x - node.x;
10718        dy = y - node.y;
10719        d2 = dx * dx + dy * dy;
10720        if (d2 < radius) closest = node, radius = d2;
10721      }
10722
10723      return closest;
10724    },
10725
10726    on: function(name, _) {
10727      return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
10728    }
10729  };
10730}
10731
10732function manyBody() {
10733  var nodes,
10734      node,
10735      alpha,
10736      strength = constant$6(-30),
10737      strengths,
10738      distanceMin2 = 1,
10739      distanceMax2 = Infinity,
10740      theta2 = 0.81;
10741
10742  function force(_) {
10743    var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
10744    for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
10745  }
10746
10747  function initialize() {
10748    if (!nodes) return;
10749    var i, n = nodes.length, node;
10750    strengths = new Array(n);
10751    for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
10752  }
10753
10754  function accumulate(quad) {
10755    var strength = 0, q, c, weight = 0, x, y, i;
10756
10757    // For internal nodes, accumulate forces from child quadrants.
10758    if (quad.length) {
10759      for (x = y = i = 0; i < 4; ++i) {
10760        if ((q = quad[i]) && (c = Math.abs(q.value))) {
10761          strength += q.value, weight += c, x += c * q.x, y += c * q.y;
10762        }
10763      }
10764      quad.x = x / weight;
10765      quad.y = y / weight;
10766    }
10767
10768    // For leaf nodes, accumulate forces from coincident quadrants.
10769    else {
10770      q = quad;
10771      q.x = q.data.x;
10772      q.y = q.data.y;
10773      do strength += strengths[q.data.index];
10774      while (q = q.next);
10775    }
10776
10777    quad.value = strength;
10778  }
10779
10780  function apply(quad, x1, _, x2) {
10781    if (!quad.value) return true;
10782
10783    var x = quad.x - node.x,
10784        y = quad.y - node.y,
10785        w = x2 - x1,
10786        l = x * x + y * y;
10787
10788    // Apply the Barnes-Hut approximation if possible.
10789    // Limit forces for very close nodes; randomize direction if coincident.
10790    if (w * w / theta2 < l) {
10791      if (l < distanceMax2) {
10792        if (x === 0) x = jiggle(), l += x * x;
10793        if (y === 0) y = jiggle(), l += y * y;
10794        if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
10795        node.vx += x * quad.value * alpha / l;
10796        node.vy += y * quad.value * alpha / l;
10797      }
10798      return true;
10799    }
10800
10801    // Otherwise, process points directly.
10802    else if (quad.length || l >= distanceMax2) return;
10803
10804    // Limit forces for very close nodes; randomize direction if coincident.
10805    if (quad.data !== node || quad.next) {
10806      if (x === 0) x = jiggle(), l += x * x;
10807      if (y === 0) y = jiggle(), l += y * y;
10808      if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
10809    }
10810
10811    do if (quad.data !== node) {
10812      w = strengths[quad.data.index] * alpha / l;
10813      node.vx += x * w;
10814      node.vy += y * w;
10815    } while (quad = quad.next);
10816  }
10817
10818  force.initialize = function(_) {
10819    nodes = _;
10820    initialize();
10821  };
10822
10823  force.strength = function(_) {
10824    return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
10825  };
10826
10827  force.distanceMin = function(_) {
10828    return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
10829  };
10830
10831  force.distanceMax = function(_) {
10832    return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
10833  };
10834
10835  force.theta = function(_) {
10836    return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
10837  };
10838
10839  return force;
10840}
10841
10842function radial(radius, x, y) {
10843  var nodes,
10844      strength = constant$6(0.1),
10845      strengths,
10846      radiuses;
10847
10848  if (typeof radius !== "function") radius = constant$6(+radius);
10849  if (x == null) x = 0;
10850  if (y == null) y = 0;
10851
10852  function force(alpha) {
10853    for (var i = 0, n = nodes.length; i < n; ++i) {
10854      var node = nodes[i],
10855          dx = node.x - x || 1e-6,
10856          dy = node.y - y || 1e-6,
10857          r = Math.sqrt(dx * dx + dy * dy),
10858          k = (radiuses[i] - r) * strengths[i] * alpha / r;
10859      node.vx += dx * k;
10860      node.vy += dy * k;
10861    }
10862  }
10863
10864  function initialize() {
10865    if (!nodes) return;
10866    var i, n = nodes.length;
10867    strengths = new Array(n);
10868    radiuses = new Array(n);
10869    for (i = 0; i < n; ++i) {
10870      radiuses[i] = +radius(nodes[i], i, nodes);
10871      strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
10872    }
10873  }
10874
10875  force.initialize = function(_) {
10876    nodes = _, initialize();
10877  };
10878
10879  force.strength = function(_) {
10880    return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
10881  };
10882
10883  force.radius = function(_) {
10884    return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
10885  };
10886
10887  force.x = function(_) {
10888    return arguments.length ? (x = +_, force) : x;
10889  };
10890
10891  force.y = function(_) {
10892    return arguments.length ? (y = +_, force) : y;
10893  };
10894
10895  return force;
10896}
10897
10898function x$2(x) {
10899  var strength = constant$6(0.1),
10900      nodes,
10901      strengths,
10902      xz;
10903
10904  if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
10905
10906  function force(alpha) {
10907    for (var i = 0, n = nodes.length, node; i < n; ++i) {
10908      node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
10909    }
10910  }
10911
10912  function initialize() {
10913    if (!nodes) return;
10914    var i, n = nodes.length;
10915    strengths = new Array(n);
10916    xz = new Array(n);
10917    for (i = 0; i < n; ++i) {
10918      strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
10919    }
10920  }
10921
10922  force.initialize = function(_) {
10923    nodes = _;
10924    initialize();
10925  };
10926
10927  force.strength = function(_) {
10928    return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
10929  };
10930
10931  force.x = function(_) {
10932    return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
10933  };
10934
10935  return force;
10936}
10937
10938function y$2(y) {
10939  var strength = constant$6(0.1),
10940      nodes,
10941      strengths,
10942      yz;
10943
10944  if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
10945
10946  function force(alpha) {
10947    for (var i = 0, n = nodes.length, node; i < n; ++i) {
10948      node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
10949    }
10950  }
10951
10952  function initialize() {
10953    if (!nodes) return;
10954    var i, n = nodes.length;
10955    strengths = new Array(n);
10956    yz = new Array(n);
10957    for (i = 0; i < n; ++i) {
10958      strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
10959    }
10960  }
10961
10962  force.initialize = function(_) {
10963    nodes = _;
10964    initialize();
10965  };
10966
10967  force.strength = function(_) {
10968    return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
10969  };
10970
10971  force.y = function(_) {
10972    return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
10973  };
10974
10975  return force;
10976}
10977
10978// Computes the decimal coefficient and exponent of the specified number x with
10979// significant digits p, where x is positive and p is in [1, 21] or undefined.
10980// For example, formatDecimal(1.23) returns ["123", 0].
10981function formatDecimal(x, p) {
10982  if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
10983  var i, coefficient = x.slice(0, i);
10984
10985  // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
10986  // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
10987  return [
10988    coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
10989    +x.slice(i + 1)
10990  ];
10991}
10992
10993function exponent$1(x) {
10994  return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
10995}
10996
10997function formatGroup(grouping, thousands) {
10998  return function(value, width) {
10999    var i = value.length,
11000        t = [],
11001        j = 0,
11002        g = grouping[0],
11003        length = 0;
11004
11005    while (i > 0 && g > 0) {
11006      if (length + g + 1 > width) g = Math.max(1, width - length);
11007      t.push(value.substring(i -= g, i + g));
11008      if ((length += g + 1) > width) break;
11009      g = grouping[j = (j + 1) % grouping.length];
11010    }
11011
11012    return t.reverse().join(thousands);
11013  };
11014}
11015
11016function formatNumerals(numerals) {
11017  return function(value) {
11018    return value.replace(/[0-9]/g, function(i) {
11019      return numerals[+i];
11020    });
11021  };
11022}
11023
11024function formatDefault(x, p) {
11025  x = x.toPrecision(p);
11026
11027  out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
11028    switch (x[i]) {
11029      case ".": i0 = i1 = i; break;
11030      case "0": if (i0 === 0) i0 = i; i1 = i; break;
11031      case "e": break out;
11032      default: if (i0 > 0) i0 = 0; break;
11033    }
11034  }
11035
11036  return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
11037}
11038
11039var prefixExponent;
11040
11041function formatPrefixAuto(x, p) {
11042  var d = formatDecimal(x, p);
11043  if (!d) return x + "";
11044  var coefficient = d[0],
11045      exponent = d[1],
11046      i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
11047      n = coefficient.length;
11048  return i === n ? coefficient
11049      : i > n ? coefficient + new Array(i - n + 1).join("0")
11050      : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
11051      : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
11052}
11053
11054function formatRounded(x, p) {
11055  var d = formatDecimal(x, p);
11056  if (!d) return x + "";
11057  var coefficient = d[0],
11058      exponent = d[1];
11059  return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
11060      : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
11061      : coefficient + new Array(exponent - coefficient.length + 2).join("0");
11062}
11063
11064var formatTypes = {
11065  "": formatDefault,
11066  "%": function(x, p) { return (x * 100).toFixed(p); },
11067  "b": function(x) { return Math.round(x).toString(2); },
11068  "c": function(x) { return x + ""; },
11069  "d": function(x) { return Math.round(x).toString(10); },
11070  "e": function(x, p) { return x.toExponential(p); },
11071  "f": function(x, p) { return x.toFixed(p); },
11072  "g": function(x, p) { return x.toPrecision(p); },
11073  "o": function(x) { return Math.round(x).toString(8); },
11074  "p": function(x, p) { return formatRounded(x * 100, p); },
11075  "r": formatRounded,
11076  "s": formatPrefixAuto,
11077  "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
11078  "x": function(x) { return Math.round(x).toString(16); }
11079};
11080
11081// [[fill]align][sign][symbol][0][width][,][.precision][type]
11082var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
11083
11084function formatSpecifier(specifier) {
11085  return new FormatSpecifier(specifier);
11086}
11087
11088formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
11089
11090function FormatSpecifier(specifier) {
11091  if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
11092
11093  var match,
11094      fill = match[1] || " ",
11095      align = match[2] || ">",
11096      sign = match[3] || "-",
11097      symbol = match[4] || "",
11098      zero = !!match[5],
11099      width = match[6] && +match[6],
11100      comma = !!match[7],
11101      precision = match[8] && +match[8].slice(1),
11102      type = match[9] || "";
11103
11104  // The "n" type is an alias for ",g".
11105  if (type === "n") comma = true, type = "g";
11106
11107  // Map invalid types to the default format.
11108  else if (!formatTypes[type]) type = "";
11109
11110  // If zero fill is specified, padding goes after sign and before digits.
11111  if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
11112
11113  this.fill = fill;
11114  this.align = align;
11115  this.sign = sign;
11116  this.symbol = symbol;
11117  this.zero = zero;
11118  this.width = width;
11119  this.comma = comma;
11120  this.precision = precision;
11121  this.type = type;
11122}
11123
11124FormatSpecifier.prototype.toString = function() {
11125  return this.fill
11126      + this.align
11127      + this.sign
11128      + this.symbol
11129      + (this.zero ? "0" : "")
11130      + (this.width == null ? "" : Math.max(1, this.width | 0))
11131      + (this.comma ? "," : "")
11132      + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
11133      + this.type;
11134};
11135
11136function identity$3(x) {
11137  return x;
11138}
11139
11140var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
11141
11142function formatLocale(locale) {
11143  var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
11144      currency = locale.currency,
11145      decimal = locale.decimal,
11146      numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
11147      percent = locale.percent || "%";
11148
11149  function newFormat(specifier) {
11150    specifier = formatSpecifier(specifier);
11151
11152    var fill = specifier.fill,
11153        align = specifier.align,
11154        sign = specifier.sign,
11155        symbol = specifier.symbol,
11156        zero = specifier.zero,
11157        width = specifier.width,
11158        comma = specifier.comma,
11159        precision = specifier.precision,
vendor: 5,278 bytes, lines 11160-11318
11160        type = specifier.type;
11161
11162    // Compute the prefix and suffix.
11163    // For SI-prefix, the suffix is lazily computed.
11164    var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
11165        suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
11166
11167    // What format function should we use?
11168    // Is this an integer type?
11169    // Can this type generate exponential notation?
11170    var formatType = formatTypes[type],
11171        maybeSuffix = !type || /[defgprs%]/.test(type);
11172
11173    // Set the default precision if not specified,
11174    // or clamp the specified precision to the supported range.
11175    // For significant precision, it must be in [1, 21].
11176    // For fixed precision, it must be in [0, 20].
11177    precision = precision == null ? (type ? 6 : 12)
11178        : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
11179        : Math.max(0, Math.min(20, precision));
11180
11181    function format(value) {
11182      var valuePrefix = prefix,
11183          valueSuffix = suffix,
11184          i, n, c;
11185
11186      if (type === "c") {
11187        valueSuffix = formatType(value) + valueSuffix;
11188        value = "";
11189      } else {
11190        value = +value;
11191
11192        // Perform the initial formatting.
11193        var valueNegative = value < 0;
11194        value = formatType(Math.abs(value), precision);
11195
11196        // If a negative value rounds to zero during formatting, treat as positive.
11197        if (valueNegative && +value === 0) valueNegative = false;
11198
11199        // Compute the prefix and suffix.
11200        valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
11201        valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
11202
11203        // Break the formatted value into the integer “value” part that can be
11204        // grouped, and fractional or exponential “suffix” part that is not.
11205        if (maybeSuffix) {
11206          i = -1, n = value.length;
11207          while (++i < n) {
11208            if (c = value.charCodeAt(i), 48 > c || c > 57) {
11209              valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
11210              value = value.slice(0, i);
11211              break;
11212            }
11213          }
11214        }
11215      }
11216
11217      // If the fill character is not "0", grouping is applied before padding.
11218      if (comma && !zero) value = group(value, Infinity);
11219
11220      // Compute the padding.
11221      var length = valuePrefix.length + value.length + valueSuffix.length,
11222          padding = length < width ? new Array(width - length + 1).join(fill) : "";
11223
11224      // If the fill character is "0", grouping is applied after padding.
11225      if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
11226
11227      // Reconstruct the final output based on the desired alignment.
11228      switch (align) {
11229        case "<": value = valuePrefix + value + valueSuffix + padding; break;
11230        case "=": value = valuePrefix + padding + value + valueSuffix; break;
11231        case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
11232        default: value = padding + valuePrefix + value + valueSuffix; break;
11233      }
11234
11235      return numerals(value);
11236    }
11237
11238    format.toString = function() {
11239      return specifier + "";
11240    };
11241
11242    return format;
11243  }
11244
11245  function formatPrefix(specifier, value) {
11246    var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
11247        e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
11248        k = Math.pow(10, -e),
11249        prefix = prefixes[8 + e / 3];
11250    return function(value) {
11251      return f(k * value) + prefix;
11252    };
11253  }
11254
11255  return {
11256    format: newFormat,
11257    formatPrefix: formatPrefix
11258  };
11259}
11260
11261var locale;
11262
11263
11264
11265defaultLocale({
11266  decimal: ".",
11267  thousands: ",",
11268  grouping: [3],
11269  currency: ["$", ""]
11270});
11271
11272function defaultLocale(definition) {
11273  locale = formatLocale(definition);
11274  exports.format = locale.format;
11275  exports.formatPrefix = locale.formatPrefix;
11276  return locale;
11277}
11278
11279function precisionFixed(step) {
11280  return Math.max(0, -exponent$1(Math.abs(step)));
11281}
11282
11283function precisionPrefix(step, value) {
11284  return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
11285}
11286
11287function precisionRound(step, max) {
11288  step = Math.abs(step), max = Math.abs(max) - step;
11289  return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
11290}
11291
11292// Adds floating point numbers with twice the normal precision.
11293// Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
11294// Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
11295// 305–363 (1997).
11296// Code adapted from GeographicLib by Charles F. F. Karney,
11297// http://geographiclib.sourceforge.net/
11298
11299function adder() {
11300  return new Adder;
11301}
11302
11303function Adder() {
11304  this.reset();
11305}
11306
11307Adder.prototype = {
11308  constructor: Adder,
11309  reset: function() {
11310    this.s = // rounded value
11311    this.t = 0; // exact error
11312  },
11313  add: function(y) {
11314    add$1(temp, y, this.t);
11315    add$1(this, temp.s, this.s);
11316    if (this.s) this.t += temp.t;
11317    else this.s = temp.t;
11318  },
vendor: 26,596 bytes, lines 11319-12253
11319  valueOf: function() {
11320    return this.s;
11321  }
11322};
11323
11324var temp = new Adder;
11325
11326function add$1(adder, a, b) {
11327  var x = adder.s = a + b,
11328      bv = x - a,
11329      av = x - bv;
11330  adder.t = (a - av) + (b - bv);
11331}
11332
11333var epsilon$2 = 1e-6;
11334var epsilon2$1 = 1e-12;
11335var pi$3 = Math.PI;
11336var halfPi$2 = pi$3 / 2;
11337var quarterPi = pi$3 / 4;
11338var tau$3 = pi$3 * 2;
11339
11340var degrees$1 = 180 / pi$3;
11341var radians = pi$3 / 180;
11342
11343var abs = Math.abs;
11344var atan = Math.atan;
11345var atan2 = Math.atan2;
11346var cos$1 = Math.cos;
11347var ceil = Math.ceil;
11348var exp = Math.exp;
11349
11350var log = Math.log;
11351var pow = Math.pow;
11352var sin$1 = Math.sin;
11353var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
11354var sqrt = Math.sqrt;
11355var tan = Math.tan;
11356
11357function acos(x) {
11358  return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
11359}
11360
11361function asin(x) {
11362  return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
11363}
11364
11365function haversin(x) {
11366  return (x = sin$1(x / 2)) * x;
11367}
11368
11369function noop$1() {}
11370
11371function streamGeometry(geometry, stream) {
11372  if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
11373    streamGeometryType[geometry.type](geometry, stream);
11374  }
11375}
11376
11377var streamObjectType = {
11378  Feature: function(object, stream) {
11379    streamGeometry(object.geometry, stream);
11380  },
11381  FeatureCollection: function(object, stream) {
11382    var features = object.features, i = -1, n = features.length;
11383    while (++i < n) streamGeometry(features[i].geometry, stream);
11384  }
11385};
11386
11387var streamGeometryType = {
11388  Sphere: function(object, stream) {
11389    stream.sphere();
11390  },
11391  Point: function(object, stream) {
11392    object = object.coordinates;
11393    stream.point(object[0], object[1], object[2]);
11394  },
11395  MultiPoint: function(object, stream) {
11396    var coordinates = object.coordinates, i = -1, n = coordinates.length;
11397    while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
11398  },
11399  LineString: function(object, stream) {
11400    streamLine(object.coordinates, stream, 0);
11401  },
11402  MultiLineString: function(object, stream) {
11403    var coordinates = object.coordinates, i = -1, n = coordinates.length;
11404    while (++i < n) streamLine(coordinates[i], stream, 0);
11405  },
11406  Polygon: function(object, stream) {
11407    streamPolygon(object.coordinates, stream);
11408  },
11409  MultiPolygon: function(object, stream) {
11410    var coordinates = object.coordinates, i = -1, n = coordinates.length;
11411    while (++i < n) streamPolygon(coordinates[i], stream);
11412  },
11413  GeometryCollection: function(object, stream) {
11414    var geometries = object.geometries, i = -1, n = geometries.length;
11415    while (++i < n) streamGeometry(geometries[i], stream);
11416  }
11417};
11418
11419function streamLine(coordinates, stream, closed) {
11420  var i = -1, n = coordinates.length - closed, coordinate;
11421  stream.lineStart();
11422  while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
11423  stream.lineEnd();
11424}
11425
11426function streamPolygon(coordinates, stream) {
11427  var i = -1, n = coordinates.length;
11428  stream.polygonStart();
11429  while (++i < n) streamLine(coordinates[i], stream, 1);
11430  stream.polygonEnd();
11431}
11432
11433function geoStream(object, stream) {
11434  if (object && streamObjectType.hasOwnProperty(object.type)) {
11435    streamObjectType[object.type](object, stream);
11436  } else {
11437    streamGeometry(object, stream);
11438  }
11439}
11440
11441var areaRingSum = adder();
11442
11443var areaSum = adder();
11444var lambda00;
11445var phi00;
11446var lambda0;
11447var cosPhi0;
11448var sinPhi0;
11449
11450var areaStream = {
11451  point: noop$1,
11452  lineStart: noop$1,
11453  lineEnd: noop$1,
11454  polygonStart: function() {
11455    areaRingSum.reset();
11456    areaStream.lineStart = areaRingStart;
11457    areaStream.lineEnd = areaRingEnd;
11458  },
11459  polygonEnd: function() {
11460    var areaRing = +areaRingSum;
11461    areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
11462    this.lineStart = this.lineEnd = this.point = noop$1;
11463  },
11464  sphere: function() {
11465    areaSum.add(tau$3);
11466  }
11467};
11468
11469function areaRingStart() {
11470  areaStream.point = areaPointFirst;
11471}
11472
11473function areaRingEnd() {
11474  areaPoint(lambda00, phi00);
11475}
11476
11477function areaPointFirst(lambda, phi) {
11478  areaStream.point = areaPoint;
11479  lambda00 = lambda, phi00 = phi;
11480  lambda *= radians, phi *= radians;
11481  lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
11482}
11483
11484function areaPoint(lambda, phi) {
11485  lambda *= radians, phi *= radians;
11486  phi = phi / 2 + quarterPi; // half the angular distance from south pole
11487
11488  // Spherical excess E for a spherical triangle with vertices: south pole,
11489  // previous point, current point.  Uses a formula derived from Cagnoli’s
11490  // theorem.  See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
11491  var dLambda = lambda - lambda0,
11492      sdLambda = dLambda >= 0 ? 1 : -1,
11493      adLambda = sdLambda * dLambda,
11494      cosPhi = cos$1(phi),
11495      sinPhi = sin$1(phi),
11496      k = sinPhi0 * sinPhi,
11497      u = cosPhi0 * cosPhi + k * cos$1(adLambda),
11498      v = k * sdLambda * sin$1(adLambda);
11499  areaRingSum.add(atan2(v, u));
11500
11501  // Advance the previous points.
11502  lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
11503}
11504
11505function area(object) {
11506  areaSum.reset();
11507  geoStream(object, areaStream);
11508  return areaSum * 2;
11509}
11510
11511function spherical(cartesian) {
11512  return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
11513}
11514
11515function cartesian(spherical) {
11516  var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
11517  return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
11518}
11519
11520function cartesianDot(a, b) {
11521  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
11522}
11523
11524function cartesianCross(a, b) {
11525  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]];
11526}
11527
11528// TODO return a
11529function cartesianAddInPlace(a, b) {
11530  a[0] += b[0], a[1] += b[1], a[2] += b[2];
11531}
11532
11533function cartesianScale(vector, k) {
11534  return [vector[0] * k, vector[1] * k, vector[2] * k];
11535}
11536
11537// TODO return d
11538function cartesianNormalizeInPlace(d) {
11539  var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
11540  d[0] /= l, d[1] /= l, d[2] /= l;
11541}
11542
11543var lambda0$1;
11544var phi0;
11545var lambda1;
11546var phi1;
11547var lambda2;
11548var lambda00$1;
11549var phi00$1;
11550var p0;
11551var deltaSum = adder();
11552var ranges;
11553var range;
11554
11555var boundsStream = {
11556  point: boundsPoint,
11557  lineStart: boundsLineStart,
11558  lineEnd: boundsLineEnd,
11559  polygonStart: function() {
11560    boundsStream.point = boundsRingPoint;
11561    boundsStream.lineStart = boundsRingStart;
11562    boundsStream.lineEnd = boundsRingEnd;
11563    deltaSum.reset();
11564    areaStream.polygonStart();
11565  },
11566  polygonEnd: function() {
11567    areaStream.polygonEnd();
11568    boundsStream.point = boundsPoint;
11569    boundsStream.lineStart = boundsLineStart;
11570    boundsStream.lineEnd = boundsLineEnd;
11571    if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
11572    else if (deltaSum > epsilon$2) phi1 = 90;
11573    else if (deltaSum < -epsilon$2) phi0 = -90;
11574    range[0] = lambda0$1, range[1] = lambda1;
11575  }
11576};
11577
11578function boundsPoint(lambda, phi) {
11579  ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
11580  if (phi < phi0) phi0 = phi;
11581  if (phi > phi1) phi1 = phi;
11582}
11583
11584function linePoint(lambda, phi) {
11585  var p = cartesian([lambda * radians, phi * radians]);
11586  if (p0) {
11587    var normal = cartesianCross(p0, p),
11588        equatorial = [normal[1], -normal[0], 0],
11589        inflection = cartesianCross(equatorial, normal);
11590    cartesianNormalizeInPlace(inflection);
11591    inflection = spherical(inflection);
11592    var delta = lambda - lambda2,
11593        sign$$1 = delta > 0 ? 1 : -1,
11594        lambdai = inflection[0] * degrees$1 * sign$$1,
11595        phii,
11596        antimeridian = abs(delta) > 180;
11597    if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
11598      phii = inflection[1] * degrees$1;
11599      if (phii > phi1) phi1 = phii;
11600    } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
11601      phii = -inflection[1] * degrees$1;
11602      if (phii < phi0) phi0 = phii;
11603    } else {
11604      if (phi < phi0) phi0 = phi;
11605      if (phi > phi1) phi1 = phi;
11606    }
11607    if (antimeridian) {
11608      if (lambda < lambda2) {
11609        if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
11610      } else {
11611        if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
11612      }
11613    } else {
11614      if (lambda1 >= lambda0$1) {
11615        if (lambda < lambda0$1) lambda0$1 = lambda;
11616        if (lambda > lambda1) lambda1 = lambda;
11617      } else {
11618        if (lambda > lambda2) {
11619          if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
11620        } else {
11621          if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
11622        }
11623      }
11624    }
11625  } else {
11626    ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
11627  }
11628  if (phi < phi0) phi0 = phi;
11629  if (phi > phi1) phi1 = phi;
11630  p0 = p, lambda2 = lambda;
11631}
11632
11633function boundsLineStart() {
11634  boundsStream.point = linePoint;
11635}
11636
11637function boundsLineEnd() {
11638  range[0] = lambda0$1, range[1] = lambda1;
11639  boundsStream.point = boundsPoint;
11640  p0 = null;
11641}
11642
11643function boundsRingPoint(lambda, phi) {
11644  if (p0) {
11645    var delta = lambda - lambda2;
11646    deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
11647  } else {
11648    lambda00$1 = lambda, phi00$1 = phi;
11649  }
11650  areaStream.point(lambda, phi);
11651  linePoint(lambda, phi);
11652}
11653
11654function boundsRingStart() {
11655  areaStream.lineStart();
11656}
11657
11658function boundsRingEnd() {
11659  boundsRingPoint(lambda00$1, phi00$1);
11660  areaStream.lineEnd();
11661  if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
11662  range[0] = lambda0$1, range[1] = lambda1;
11663  p0 = null;
11664}
11665
11666// Finds the left-right distance between two longitudes.
11667// This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
11668// the distance between ±180° to be 360°.
11669function angle(lambda0, lambda1) {
11670  return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
11671}
11672
11673function rangeCompare(a, b) {
11674  return a[0] - b[0];
11675}
11676
11677function rangeContains(range, x) {
11678  return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
11679}
11680
11681function bounds(feature) {
11682  var i, n, a, b, merged, deltaMax, delta;
11683
11684  phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
11685  ranges = [];
11686  geoStream(feature, boundsStream);
11687
11688  // First, sort ranges by their minimum longitudes.
11689  if (n = ranges.length) {
11690    ranges.sort(rangeCompare);
11691
11692    // Then, merge any ranges that overlap.
11693    for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
11694      b = ranges[i];
11695      if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
11696        if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
11697        if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
11698      } else {
11699        merged.push(a = b);
11700      }
11701    }
11702
11703    // Finally, find the largest gap between the merged ranges.
11704    // The final bounding box will be the inverse of this gap.
11705    for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
11706      b = merged[i];
11707      if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
11708    }
11709  }
11710
11711  ranges = range = null;
11712
11713  return lambda0$1 === Infinity || phi0 === Infinity
11714      ? [[NaN, NaN], [NaN, NaN]]
11715      : [[lambda0$1, phi0], [lambda1, phi1]];
11716}
11717
11718var W0;
11719var W1;
11720var X0;
11721var Y0;
11722var Z0;
11723var X1;
11724var Y1;
11725var Z1;
11726var X2;
11727var Y2;
11728var Z2;
11729var lambda00$2;
11730var phi00$2;
11731var x0;
11732var y0;
11733var z0; // previous point
11734
11735var centroidStream = {
11736  sphere: noop$1,
11737  point: centroidPoint,
11738  lineStart: centroidLineStart,
11739  lineEnd: centroidLineEnd,
11740  polygonStart: function() {
11741    centroidStream.lineStart = centroidRingStart;
11742    centroidStream.lineEnd = centroidRingEnd;
11743  },
11744  polygonEnd: function() {
11745    centroidStream.lineStart = centroidLineStart;
11746    centroidStream.lineEnd = centroidLineEnd;
11747  }
11748};
11749
11750// Arithmetic mean of Cartesian vectors.
11751function centroidPoint(lambda, phi) {
11752  lambda *= radians, phi *= radians;
11753  var cosPhi = cos$1(phi);
11754  centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
11755}
11756
11757function centroidPointCartesian(x, y, z) {
11758  ++W0;
11759  X0 += (x - X0) / W0;
11760  Y0 += (y - Y0) / W0;
11761  Z0 += (z - Z0) / W0;
11762}
11763
11764function centroidLineStart() {
11765  centroidStream.point = centroidLinePointFirst;
11766}
11767
11768function centroidLinePointFirst(lambda, phi) {
11769  lambda *= radians, phi *= radians;
11770  var cosPhi = cos$1(phi);
11771  x0 = cosPhi * cos$1(lambda);
11772  y0 = cosPhi * sin$1(lambda);
11773  z0 = sin$1(phi);
11774  centroidStream.point = centroidLinePoint;
11775  centroidPointCartesian(x0, y0, z0);
11776}
11777
11778function centroidLinePoint(lambda, phi) {
11779  lambda *= radians, phi *= radians;
11780  var cosPhi = cos$1(phi),
11781      x = cosPhi * cos$1(lambda),
11782      y = cosPhi * sin$1(lambda),
11783      z = sin$1(phi),
11784      w = atan2(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);
11785  W1 += w;
11786  X1 += w * (x0 + (x0 = x));
11787  Y1 += w * (y0 + (y0 = y));
11788  Z1 += w * (z0 + (z0 = z));
11789  centroidPointCartesian(x0, y0, z0);
11790}
11791
11792function centroidLineEnd() {
11793  centroidStream.point = centroidPoint;
11794}
11795
11796// See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
11797// J. Applied Mechanics 42, 239 (1975).
11798function centroidRingStart() {
11799  centroidStream.point = centroidRingPointFirst;
11800}
11801
11802function centroidRingEnd() {
11803  centroidRingPoint(lambda00$2, phi00$2);
11804  centroidStream.point = centroidPoint;
11805}
11806
11807function centroidRingPointFirst(lambda, phi) {
11808  lambda00$2 = lambda, phi00$2 = phi;
11809  lambda *= radians, phi *= radians;
11810  centroidStream.point = centroidRingPoint;
11811  var cosPhi = cos$1(phi);
11812  x0 = cosPhi * cos$1(lambda);
11813  y0 = cosPhi * sin$1(lambda);
11814  z0 = sin$1(phi);
11815  centroidPointCartesian(x0, y0, z0);
11816}
11817
11818function centroidRingPoint(lambda, phi) {
11819  lambda *= radians, phi *= radians;
11820  var cosPhi = cos$1(phi),
11821      x = cosPhi * cos$1(lambda),
11822      y = cosPhi * sin$1(lambda),
11823      z = sin$1(phi),
11824      cx = y0 * z - z0 * y,
11825      cy = z0 * x - x0 * z,
11826      cz = x0 * y - y0 * x,
11827      m = sqrt(cx * cx + cy * cy + cz * cz),
11828      w = asin(m), // line weight = angle
11829      v = m && -w / m; // area weight multiplier
11830  X2 += v * cx;
11831  Y2 += v * cy;
11832  Z2 += v * cz;
11833  W1 += w;
11834  X1 += w * (x0 + (x0 = x));
11835  Y1 += w * (y0 + (y0 = y));
11836  Z1 += w * (z0 + (z0 = z));
11837  centroidPointCartesian(x0, y0, z0);
11838}
11839
11840function centroid(object) {
11841  W0 = W1 =
11842  X0 = Y0 = Z0 =
11843  X1 = Y1 = Z1 =
11844  X2 = Y2 = Z2 = 0;
11845  geoStream(object, centroidStream);
11846
11847  var x = X2,
11848      y = Y2,
11849      z = Z2,
11850      m = x * x + y * y + z * z;
11851
11852  // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
11853  if (m < epsilon2$1) {
11854    x = X1, y = Y1, z = Z1;
11855    // If the feature has zero length, fall back to arithmetic mean of point vectors.
11856    if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
11857    m = x * x + y * y + z * z;
11858    // If the feature still has an undefined ccentroid, then return.
11859    if (m < epsilon2$1) return [NaN, NaN];
11860  }
11861
11862  return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
11863}
11864
11865function constant$7(x) {
11866  return function() {
11867    return x;
11868  };
11869}
11870
11871function compose(a, b) {
11872
11873  function compose(x, y) {
11874    return x = a(x, y), b(x[0], x[1]);
11875  }
11876
11877  if (a.invert && b.invert) compose.invert = function(x, y) {
11878    return x = b.invert(x, y), x && a.invert(x[0], x[1]);
11879  };
11880
11881  return compose;
11882}
11883
11884function rotationIdentity(lambda, phi) {
11885  return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
11886}
11887
11888rotationIdentity.invert = rotationIdentity;
11889
11890function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
11891  return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
11892    : rotationLambda(deltaLambda))
11893    : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
11894    : rotationIdentity);
11895}
11896
11897function forwardRotationLambda(deltaLambda) {
11898  return function(lambda, phi) {
11899    return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
11900  };
11901}
11902
11903function rotationLambda(deltaLambda) {
11904  var rotation = forwardRotationLambda(deltaLambda);
11905  rotation.invert = forwardRotationLambda(-deltaLambda);
11906  return rotation;
11907}
11908
11909function rotationPhiGamma(deltaPhi, deltaGamma) {
11910  var cosDeltaPhi = cos$1(deltaPhi),
11911      sinDeltaPhi = sin$1(deltaPhi),
11912      cosDeltaGamma = cos$1(deltaGamma),
11913      sinDeltaGamma = sin$1(deltaGamma);
11914
11915  function rotation(lambda, phi) {
11916    var cosPhi = cos$1(phi),
11917        x = cos$1(lambda) * cosPhi,
11918        y = sin$1(lambda) * cosPhi,
11919        z = sin$1(phi),
11920        k = z * cosDeltaPhi + x * sinDeltaPhi;
11921    return [
11922      atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
11923      asin(k * cosDeltaGamma + y * sinDeltaGamma)
11924    ];
11925  }
11926
11927  rotation.invert = function(lambda, phi) {
11928    var cosPhi = cos$1(phi),
11929        x = cos$1(lambda) * cosPhi,
11930        y = sin$1(lambda) * cosPhi,
11931        z = sin$1(phi),
11932        k = z * cosDeltaGamma - y * sinDeltaGamma;
11933    return [
11934      atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
11935      asin(k * cosDeltaPhi - x * sinDeltaPhi)
11936    ];
11937  };
11938
11939  return rotation;
11940}
11941
11942function rotation(rotate) {
11943  rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
11944
11945  function forward(coordinates) {
11946    coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
11947    return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
11948  }
11949
11950  forward.invert = function(coordinates) {
11951    coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
11952    return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
11953  };
11954
11955  return forward;
11956}
11957
11958// Generates a circle centered at [0°, 0°], with a given radius and precision.
11959function circleStream(stream, radius, delta, direction, t0, t1) {
11960  if (!delta) return;
11961  var cosRadius = cos$1(radius),
11962      sinRadius = sin$1(radius),
11963      step = direction * delta;
11964  if (t0 == null) {
11965    t0 = radius + direction * tau$3;
11966    t1 = radius - step / 2;
11967  } else {
11968    t0 = circleRadius(cosRadius, t0);
11969    t1 = circleRadius(cosRadius, t1);
11970    if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
11971  }
11972  for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
11973    point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
11974    stream.point(point[0], point[1]);
11975  }
11976}
11977
11978// Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
11979function circleRadius(cosRadius, point) {
11980  point = cartesian(point), point[0] -= cosRadius;
11981  cartesianNormalizeInPlace(point);
11982  var radius = acos(-point[1]);
11983  return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
11984}
11985
11986function circle() {
11987  var center = constant$7([0, 0]),
11988      radius = constant$7(90),
11989      precision = constant$7(6),
11990      ring,
11991      rotate,
11992      stream = {point: point};
11993
11994  function point(x, y) {
11995    ring.push(x = rotate(x, y));
11996    x[0] *= degrees$1, x[1] *= degrees$1;
11997  }
11998
11999  function circle() {
12000    var c = center.apply(this, arguments),
12001        r = radius.apply(this, arguments) * radians,
12002        p = precision.apply(this, arguments) * radians;
12003    ring = [];
12004    rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
12005    circleStream(stream, r, p, 1);
12006    c = {type: "Polygon", coordinates: [ring]};
12007    ring = rotate = null;
12008    return c;
12009  }
12010
12011  circle.center = function(_) {
12012    return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
12013  };
12014
12015  circle.radius = function(_) {
12016    return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
12017  };
12018
12019  circle.precision = function(_) {
12020    return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
12021  };
12022
12023  return circle;
12024}
12025
12026function clipBuffer() {
12027  var lines = [],
12028      line;
12029  return {
12030    point: function(x, y) {
12031      line.push([x, y]);
12032    },
12033    lineStart: function() {
12034      lines.push(line = []);
12035    },
12036    lineEnd: noop$1,
12037    rejoin: function() {
12038      if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
12039    },
12040    result: function() {
12041      var result = lines;
12042      lines = [];
12043      line = null;
12044      return result;
12045    }
12046  };
12047}
12048
12049function pointEqual(a, b) {
12050  return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
12051}
12052
12053function Intersection(point, points, other, entry) {
12054  this.x = point;
12055  this.z = points;
12056  this.o = other; // another intersection
12057  this.e = entry; // is an entry?
12058  this.v = false; // visited
12059  this.n = this.p = null; // next & previous
12060}
12061
12062// A generalized polygon clipping algorithm: given a polygon that has been cut
12063// into its visible line segments, and rejoins the segments by interpolating
12064// along the clip edge.
12065function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
12066  var subject = [],
12067      clip = [],
12068      i,
12069      n;
12070
12071  segments.forEach(function(segment) {
12072    if ((n = segment.length - 1) <= 0) return;
12073    var n, p0 = segment[0], p1 = segment[n], x;
12074
12075    // If the first and last points of a segment are coincident, then treat as a
12076    // closed ring. TODO if all rings are closed, then the winding order of the
12077    // exterior ring should be checked.
12078    if (pointEqual(p0, p1)) {
12079      stream.lineStart();
12080      for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
12081      stream.lineEnd();
12082      return;
12083    }
12084
12085    subject.push(x = new Intersection(p0, segment, null, true));
12086    clip.push(x.o = new Intersection(p0, null, x, false));
12087    subject.push(x = new Intersection(p1, segment, null, false));
12088    clip.push(x.o = new Intersection(p1, null, x, true));
12089  });
12090
12091  if (!subject.length) return;
12092
12093  clip.sort(compareIntersection);
12094  link$1(subject);
12095  link$1(clip);
12096
12097  for (i = 0, n = clip.length; i < n; ++i) {
12098    clip[i].e = startInside = !startInside;
12099  }
12100
12101  var start = subject[0],
12102      points,
12103      point;
12104
12105  while (1) {
12106    // Find first unvisited intersection.
12107    var current = start,
12108        isSubject = true;
12109    while (current.v) if ((current = current.n) === start) return;
12110    points = current.z;
12111    stream.lineStart();
12112    do {
12113      current.v = current.o.v = true;
12114      if (current.e) {
12115        if (isSubject) {
12116          for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
12117        } else {
12118          interpolate(current.x, current.n.x, 1, stream);
12119        }
12120        current = current.n;
12121      } else {
12122        if (isSubject) {
12123          points = current.p.z;
12124          for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
12125        } else {
12126          interpolate(current.x, current.p.x, -1, stream);
12127        }
12128        current = current.p;
12129      }
12130      current = current.o;
12131      points = current.z;
12132      isSubject = !isSubject;
12133    } while (!current.v);
12134    stream.lineEnd();
12135  }
12136}
12137
12138function link$1(array) {
12139  if (!(n = array.length)) return;
12140  var n,
12141      i = 0,
12142      a = array[0],
12143      b;
12144  while (++i < n) {
12145    a.n = b = array[i];
12146    b.p = a;
12147    a = b;
12148  }
12149  a.n = b = array[0];
12150  b.p = a;
12151}
12152
12153var sum$1 = adder();
12154
12155function polygonContains(polygon, point) {
12156  var lambda = point[0],
12157      phi = point[1],
12158      normal = [sin$1(lambda), -cos$1(lambda), 0],
12159      angle = 0,
12160      winding = 0;
12161
12162  sum$1.reset();
12163
12164  for (var i = 0, n = polygon.length; i < n; ++i) {
12165    if (!(m = (ring = polygon[i]).length)) continue;
12166    var ring,
12167        m,
12168        point0 = ring[m - 1],
12169        lambda0 = point0[0],
12170        phi0 = point0[1] / 2 + quarterPi,
12171        sinPhi0 = sin$1(phi0),
12172        cosPhi0 = cos$1(phi0);
12173
12174    for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
12175      var point1 = ring[j],
12176          lambda1 = point1[0],
12177          phi1 = point1[1] / 2 + quarterPi,
12178          sinPhi1 = sin$1(phi1),
12179          cosPhi1 = cos$1(phi1),
12180          delta = lambda1 - lambda0,
12181          sign$$1 = delta >= 0 ? 1 : -1,
12182          absDelta = sign$$1 * delta,
12183          antimeridian = absDelta > pi$3,
12184          k = sinPhi0 * sinPhi1;
12185
12186      sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
12187      angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
12188
12189      // Are the longitudes either side of the point’s meridian (lambda),
12190      // and are the latitudes smaller than the parallel (phi)?
12191      if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
12192        var arc = cartesianCross(cartesian(point0), cartesian(point1));
12193        cartesianNormalizeInPlace(arc);
12194        var intersection = cartesianCross(normal, arc);
12195        cartesianNormalizeInPlace(intersection);
12196        var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
12197        if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
12198          winding += antimeridian ^ delta >= 0 ? 1 : -1;
12199        }
12200      }
12201    }
12202  }
12203
12204  // First, determine whether the South pole is inside or outside:
12205  //
12206  // It is inside if:
12207  // * the polygon winds around it in a clockwise direction.
12208  // * the polygon does not (cumulatively) wind around it, but has a negative
12209  //   (counter-clockwise) area.
12210  //
12211  // Second, count the (signed) number of times a segment crosses a lambda
12212  // from the point to the South pole.  If it is zero, then the point is the
12213  // same side as the South pole.
12214
12215  return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
12216}
12217
12218function clip(pointVisible, clipLine, interpolate, start) {
12219  return function(sink) {
12220    var line = clipLine(sink),
12221        ringBuffer = clipBuffer(),
12222        ringSink = clipLine(ringBuffer),
12223        polygonStarted = false,
12224        polygon,
12225        segments,
12226        ring;
12227
12228    var clip = {
12229      point: point,
12230      lineStart: lineStart,
12231      lineEnd: lineEnd,
12232      polygonStart: function() {
12233        clip.point = pointRing;
12234        clip.lineStart = ringStart;
12235        clip.lineEnd = ringEnd;
12236        segments = [];
12237        polygon = [];
12238      },
12239      polygonEnd: function() {
12240        clip.point = point;
12241        clip.lineStart = lineStart;
12242        clip.lineEnd = lineEnd;
12243        segments = merge(segments);
12244        var startInside = polygonContains(polygon, start);
12245        if (segments.length) {
12246          if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
12247          clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
12248        } else if (startInside) {
12249          if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
12250          sink.lineStart();
12251          interpolate(null, null, 1, sink);
12252          sink.lineEnd();
12253        }
vendor: 6,038 bytes, lines 12254-12460
12254        if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
12255        segments = polygon = null;
12256      },
12257      sphere: function() {
12258        sink.polygonStart();
12259        sink.lineStart();
12260        interpolate(null, null, 1, sink);
12261        sink.lineEnd();
12262        sink.polygonEnd();
12263      }
12264    };
12265
12266    function point(lambda, phi) {
12267      if (pointVisible(lambda, phi)) sink.point(lambda, phi);
12268    }
12269
12270    function pointLine(lambda, phi) {
12271      line.point(lambda, phi);
12272    }
12273
12274    function lineStart() {
12275      clip.point = pointLine;
12276      line.lineStart();
12277    }
12278
12279    function lineEnd() {
12280      clip.point = point;
12281      line.lineEnd();
12282    }
12283
12284    function pointRing(lambda, phi) {
12285      ring.push([lambda, phi]);
12286      ringSink.point(lambda, phi);
12287    }
12288
12289    function ringStart() {
12290      ringSink.lineStart();
12291      ring = [];
12292    }
12293
12294    function ringEnd() {
12295      pointRing(ring[0][0], ring[0][1]);
12296      ringSink.lineEnd();
12297
12298      var clean = ringSink.clean(),
12299          ringSegments = ringBuffer.result(),
12300          i, n = ringSegments.length, m,
12301          segment,
12302          point;
12303
12304      ring.pop();
12305      polygon.push(ring);
12306      ring = null;
12307
12308      if (!n) return;
12309
12310      // No intersections.
12311      if (clean & 1) {
12312        segment = ringSegments[0];
12313        if ((m = segment.length - 1) > 0) {
12314          if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
12315          sink.lineStart();
12316          for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
12317          sink.lineEnd();
12318        }
12319        return;
12320      }
12321
12322      // Rejoin connected segments.
12323      // TODO reuse ringBuffer.rejoin()?
12324      if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
12325
12326      segments.push(ringSegments.filter(validSegment));
12327    }
12328
12329    return clip;
12330  };
12331}
12332
12333function validSegment(segment) {
12334  return segment.length > 1;
12335}
12336
12337// Intersections are sorted along the clip edge. For both antimeridian cutting
12338// and circle clipping, the same comparison is used.
12339function compareIntersection(a, b) {
12340  return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
12341       - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
12342}
12343
12344var clipAntimeridian = clip(
12345  function() { return true; },
12346  clipAntimeridianLine,
12347  clipAntimeridianInterpolate,
12348  [-pi$3, -halfPi$2]
12349);
12350
12351// Takes a line and cuts into visible segments. Return values: 0 - there were
12352// intersections or the line was empty; 1 - no intersections; 2 - there were
12353// intersections, and the first and last segments should be rejoined.
12354function clipAntimeridianLine(stream) {
12355  var lambda0 = NaN,
12356      phi0 = NaN,
12357      sign0 = NaN,
12358      clean; // no intersections
12359
12360  return {
12361    lineStart: function() {
12362      stream.lineStart();
12363      clean = 1;
12364    },
12365    point: function(lambda1, phi1) {
12366      var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
12367          delta = abs(lambda1 - lambda0);
12368      if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
12369        stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
12370        stream.point(sign0, phi0);
12371        stream.lineEnd();
12372        stream.lineStart();
12373        stream.point(sign1, phi0);
12374        stream.point(lambda1, phi0);
12375        clean = 0;
12376      } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
12377        if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
12378        if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
12379        phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
12380        stream.point(sign0, phi0);
12381        stream.lineEnd();
12382        stream.lineStart();
12383        stream.point(sign1, phi0);
12384        clean = 0;
12385      }
12386      stream.point(lambda0 = lambda1, phi0 = phi1);
12387      sign0 = sign1;
12388    },
12389    lineEnd: function() {
12390      stream.lineEnd();
12391      lambda0 = phi0 = NaN;
12392    },
12393    clean: function() {
12394      return 2 - clean; // if intersections, rejoin first and last segments
12395    }
12396  };
12397}
12398
12399function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
12400  var cosPhi0,
12401      cosPhi1,
12402      sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
12403  return abs(sinLambda0Lambda1) > epsilon$2
12404      ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
12405          - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
12406          / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
12407      : (phi0 + phi1) / 2;
12408}
12409
12410function clipAntimeridianInterpolate(from, to, direction, stream) {
12411  var phi;
12412  if (from == null) {
12413    phi = direction * halfPi$2;
12414    stream.point(-pi$3, phi);
12415    stream.point(0, phi);
12416    stream.point(pi$3, phi);
12417    stream.point(pi$3, 0);
12418    stream.point(pi$3, -phi);
12419    stream.point(0, -phi);
12420    stream.point(-pi$3, -phi);
12421    stream.point(-pi$3, 0);
12422    stream.point(-pi$3, phi);
12423  } else if (abs(from[0] - to[0]) > epsilon$2) {
12424    var lambda = from[0] < to[0] ? pi$3 : -pi$3;
12425    phi = direction * lambda / 2;
12426    stream.point(-lambda, phi);
12427    stream.point(0, phi);
12428    stream.point(lambda, phi);
12429  } else {
12430    stream.point(to[0], to[1]);
12431  }
12432}
12433
12434function clipCircle(radius) {
12435  var cr = cos$1(radius),
12436      delta = 6 * radians,
12437      smallRadius = cr > 0,
12438      notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
12439
12440  function interpolate(from, to, direction, stream) {
12441    circleStream(stream, radius, delta, direction, from, to);
12442  }
12443
12444  function visible(lambda, phi) {
12445    return cos$1(lambda) * cos$1(phi) > cr;
12446  }
12447
12448  // Takes a line and cuts into visible segments. Return values used for polygon
12449  // clipping: 0 - there were intersections or the line was empty; 1 - no
12450  // intersections 2 - there were intersections, and the first and last segments
12451  // should be rejoined.
12452  function clipLine(stream) {
12453    var point0, // previous point
12454        c0, // code for previous point
12455        v0, // visibility of previous point
12456        v00, // visibility of first point
12457        clean; // no intersections
12458    return {
12459      lineStart: function() {
12460        v00 = v0 = false;
vendor: 12,273 bytes, lines 12461-12893
12461        clean = 1;
12462      },
12463      point: function(lambda, phi) {
12464        var point1 = [lambda, phi],
12465            point2,
12466            v = visible(lambda, phi),
12467            c = smallRadius
12468              ? v ? 0 : code(lambda, phi)
12469              : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
12470        if (!point0 && (v00 = v0 = v)) stream.lineStart();
12471        // Handle degeneracies.
12472        // TODO ignore if not clipping polygons.
12473        if (v !== v0) {
12474          point2 = intersect(point0, point1);
12475          if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
12476            point1[0] += epsilon$2;
12477            point1[1] += epsilon$2;
12478            v = visible(point1[0], point1[1]);
12479          }
12480        }
12481        if (v !== v0) {
12482          clean = 0;
12483          if (v) {
12484            // outside going in
12485            stream.lineStart();
12486            point2 = intersect(point1, point0);
12487            stream.point(point2[0], point2[1]);
12488          } else {
12489            // inside going out
12490            point2 = intersect(point0, point1);
12491            stream.point(point2[0], point2[1]);
12492            stream.lineEnd();
12493          }
12494          point0 = point2;
12495        } else if (notHemisphere && point0 && smallRadius ^ v) {
12496          var t;
12497          // If the codes for two points are different, or are both zero,
12498          // and there this segment intersects with the small circle.
12499          if (!(c & c0) && (t = intersect(point1, point0, true))) {
12500            clean = 0;
12501            if (smallRadius) {
12502              stream.lineStart();
12503              stream.point(t[0][0], t[0][1]);
12504              stream.point(t[1][0], t[1][1]);
12505              stream.lineEnd();
12506            } else {
12507              stream.point(t[1][0], t[1][1]);
12508              stream.lineEnd();
12509              stream.lineStart();
12510              stream.point(t[0][0], t[0][1]);
12511            }
12512          }
12513        }
12514        if (v && (!point0 || !pointEqual(point0, point1))) {
12515          stream.point(point1[0], point1[1]);
12516        }
12517        point0 = point1, v0 = v, c0 = c;
12518      },
12519      lineEnd: function() {
12520        if (v0) stream.lineEnd();
12521        point0 = null;
12522      },
12523      // Rejoin first and last segments if there were intersections and the first
12524      // and last points were visible.
12525      clean: function() {
12526        return clean | ((v00 && v0) << 1);
12527      }
12528    };
12529  }
12530
12531  // Intersects the great circle between a and b with the clip circle.
12532  function intersect(a, b, two) {
12533    var pa = cartesian(a),
12534        pb = cartesian(b);
12535
12536    // We have two planes, n1.p = d1 and n2.p = d2.
12537    // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
12538    var n1 = [1, 0, 0], // normal
12539        n2 = cartesianCross(pa, pb),
12540        n2n2 = cartesianDot(n2, n2),
12541        n1n2 = n2[0], // cartesianDot(n1, n2),
12542        determinant = n2n2 - n1n2 * n1n2;
12543
12544    // Two polar points.
12545    if (!determinant) return !two && a;
12546
12547    var c1 =  cr * n2n2 / determinant,
12548        c2 = -cr * n1n2 / determinant,
12549        n1xn2 = cartesianCross(n1, n2),
12550        A = cartesianScale(n1, c1),
12551        B = cartesianScale(n2, c2);
12552    cartesianAddInPlace(A, B);
12553
12554    // Solve |p(t)|^2 = 1.
12555    var u = n1xn2,
12556        w = cartesianDot(A, u),
12557        uu = cartesianDot(u, u),
12558        t2 = w * w - uu * (cartesianDot(A, A) - 1);
12559
12560    if (t2 < 0) return;
12561
12562    var t = sqrt(t2),
12563        q = cartesianScale(u, (-w - t) / uu);
12564    cartesianAddInPlace(q, A);
12565    q = spherical(q);
12566
12567    if (!two) return q;
12568
12569    // Two intersection points.
12570    var lambda0 = a[0],
12571        lambda1 = b[0],
12572        phi0 = a[1],
12573        phi1 = b[1],
12574        z;
12575
12576    if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
12577
12578    var delta = lambda1 - lambda0,
12579        polar = abs(delta - pi$3) < epsilon$2,
12580        meridian = polar || delta < epsilon$2;
12581
12582    if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
12583
12584    // Check that the first point is between a and b.
12585    if (meridian
12586        ? polar
12587          ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
12588          : phi0 <= q[1] && q[1] <= phi1
12589        : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
12590      var q1 = cartesianScale(u, (-w + t) / uu);
12591      cartesianAddInPlace(q1, A);
12592      return [q, spherical(q1)];
12593    }
12594  }
12595
12596  // Generates a 4-bit vector representing the location of a point relative to
12597  // the small circle's bounding box.
12598  function code(lambda, phi) {
12599    var r = smallRadius ? radius : pi$3 - radius,
12600        code = 0;
12601    if (lambda < -r) code |= 1; // left
12602    else if (lambda > r) code |= 2; // right
12603    if (phi < -r) code |= 4; // below
12604    else if (phi > r) code |= 8; // above
12605    return code;
12606  }
12607
12608  return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
12609}
12610
12611function clipLine(a, b, x0, y0, x1, y1) {
12612  var ax = a[0],
12613      ay = a[1],
12614      bx = b[0],
12615      by = b[1],
12616      t0 = 0,
12617      t1 = 1,
12618      dx = bx - ax,
12619      dy = by - ay,
12620      r;
12621
12622  r = x0 - ax;
12623  if (!dx && r > 0) return;
12624  r /= dx;
12625  if (dx < 0) {
12626    if (r < t0) return;
12627    if (r < t1) t1 = r;
12628  } else if (dx > 0) {
12629    if (r > t1) return;
12630    if (r > t0) t0 = r;
12631  }
12632
12633  r = x1 - ax;
12634  if (!dx && r < 0) return;
12635  r /= dx;
12636  if (dx < 0) {
12637    if (r > t1) return;
12638    if (r > t0) t0 = r;
12639  } else if (dx > 0) {
12640    if (r < t0) return;
12641    if (r < t1) t1 = r;
12642  }
12643
12644  r = y0 - ay;
12645  if (!dy && r > 0) return;
12646  r /= dy;
12647  if (dy < 0) {
12648    if (r < t0) return;
12649    if (r < t1) t1 = r;
12650  } else if (dy > 0) {
12651    if (r > t1) return;
12652    if (r > t0) t0 = r;
12653  }
12654
12655  r = y1 - ay;
12656  if (!dy && r < 0) return;
12657  r /= dy;
12658  if (dy < 0) {
12659    if (r > t1) return;
12660    if (r > t0) t0 = r;
12661  } else if (dy > 0) {
12662    if (r < t0) return;
12663    if (r < t1) t1 = r;
12664  }
12665
12666  if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
12667  if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
12668  return true;
12669}
12670
12671var clipMax = 1e9;
12672var clipMin = -clipMax;
12673
12674// TODO Use d3-polygon’s polygonContains here for the ring check?
12675// TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
12676
12677function clipRectangle(x0, y0, x1, y1) {
12678
12679  function visible(x, y) {
12680    return x0 <= x && x <= x1 && y0 <= y && y <= y1;
12681  }
12682
12683  function interpolate(from, to, direction, stream) {
12684    var a = 0, a1 = 0;
12685    if (from == null
12686        || (a = corner(from, direction)) !== (a1 = corner(to, direction))
12687        || comparePoint(from, to) < 0 ^ direction > 0) {
12688      do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
12689      while ((a = (a + direction + 4) % 4) !== a1);
12690    } else {
12691      stream.point(to[0], to[1]);
12692    }
12693  }
12694
12695  function corner(p, direction) {
12696    return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
12697        : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
12698        : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
12699        : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
12700  }
12701
12702  function compareIntersection(a, b) {
12703    return comparePoint(a.x, b.x);
12704  }
12705
12706  function comparePoint(a, b) {
12707    var ca = corner(a, 1),
12708        cb = corner(b, 1);
12709    return ca !== cb ? ca - cb
12710        : ca === 0 ? b[1] - a[1]
12711        : ca === 1 ? a[0] - b[0]
12712        : ca === 2 ? a[1] - b[1]
12713        : b[0] - a[0];
12714  }
12715
12716  return function(stream) {
12717    var activeStream = stream,
12718        bufferStream = clipBuffer(),
12719        segments,
12720        polygon,
12721        ring,
12722        x__, y__, v__, // first point
12723        x_, y_, v_, // previous point
12724        first,
12725        clean;
12726
12727    var clipStream = {
12728      point: point,
12729      lineStart: lineStart,
12730      lineEnd: lineEnd,
12731      polygonStart: polygonStart,
12732      polygonEnd: polygonEnd
12733    };
12734
12735    function point(x, y) {
12736      if (visible(x, y)) activeStream.point(x, y);
12737    }
12738
12739    function polygonInside() {
12740      var winding = 0;
12741
12742      for (var i = 0, n = polygon.length; i < n; ++i) {
12743        for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
12744          a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
12745          if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
12746          else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
12747        }
12748      }
12749
12750      return winding;
12751    }
12752
12753    // Buffer geometry within a polygon and then clip it en masse.
12754    function polygonStart() {
12755      activeStream = bufferStream, segments = [], polygon = [], clean = true;
12756    }
12757
12758    function polygonEnd() {
12759      var startInside = polygonInside(),
12760          cleanInside = clean && startInside,
12761          visible = (segments = merge(segments)).length;
12762      if (cleanInside || visible) {
12763        stream.polygonStart();
12764        if (cleanInside) {
12765          stream.lineStart();
12766          interpolate(null, null, 1, stream);
12767          stream.lineEnd();
12768        }
12769        if (visible) {
12770          clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
12771        }
12772        stream.polygonEnd();
12773      }
12774      activeStream = stream, segments = polygon = ring = null;
12775    }
12776
12777    function lineStart() {
12778      clipStream.point = linePoint;
12779      if (polygon) polygon.push(ring = []);
12780      first = true;
12781      v_ = false;
12782      x_ = y_ = NaN;
12783    }
12784
12785    // TODO rather than special-case polygons, simply handle them separately.
12786    // Ideally, coincident intersection points should be jittered to avoid
12787    // clipping issues.
12788    function lineEnd() {
12789      if (segments) {
12790        linePoint(x__, y__);
12791        if (v__ && v_) bufferStream.rejoin();
12792        segments.push(bufferStream.result());
12793      }
12794      clipStream.point = point;
12795      if (v_) activeStream.lineEnd();
12796    }
12797
12798    function linePoint(x, y) {
12799      var v = visible(x, y);
12800      if (polygon) ring.push([x, y]);
12801      if (first) {
12802        x__ = x, y__ = y, v__ = v;
12803        first = false;
12804        if (v) {
12805          activeStream.lineStart();
12806          activeStream.point(x, y);
12807        }
12808      } else {
12809        if (v && v_) activeStream.point(x, y);
12810        else {
12811          var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
12812              b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
12813          if (clipLine(a, b, x0, y0, x1, y1)) {
12814            if (!v_) {
12815              activeStream.lineStart();
12816              activeStream.point(a[0], a[1]);
12817            }
12818            activeStream.point(b[0], b[1]);
12819            if (!v) activeStream.lineEnd();
12820            clean = false;
12821          } else if (v) {
12822            activeStream.lineStart();
12823            activeStream.point(x, y);
12824            clean = false;
12825          }
12826        }
12827      }
12828      x_ = x, y_ = y, v_ = v;
12829    }
12830
12831    return clipStream;
12832  };
12833}
12834
12835function extent$1() {
12836  var x0 = 0,
12837      y0 = 0,
12838      x1 = 960,
12839      y1 = 500,
12840      cache,
12841      cacheStream,
12842      clip;
12843
12844  return clip = {
12845    stream: function(stream) {
12846      return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
12847    },
12848    extent: function(_) {
12849      return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
12850    }
12851  };
12852}
12853
12854var lengthSum = adder();
12855var lambda0$2;
12856var sinPhi0$1;
12857var cosPhi0$1;
12858
12859var lengthStream = {
12860  sphere: noop$1,
12861  point: noop$1,
12862  lineStart: lengthLineStart,
12863  lineEnd: noop$1,
12864  polygonStart: noop$1,
12865  polygonEnd: noop$1
12866};
12867
12868function lengthLineStart() {
12869  lengthStream.point = lengthPointFirst;
12870  lengthStream.lineEnd = lengthLineEnd;
12871}
12872
12873function lengthLineEnd() {
12874  lengthStream.point = lengthStream.lineEnd = noop$1;
12875}
12876
12877function lengthPointFirst(lambda, phi) {
12878  lambda *= radians, phi *= radians;
12879  lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
12880  lengthStream.point = lengthPoint;
12881}
12882
12883function lengthPoint(lambda, phi) {
12884  lambda *= radians, phi *= radians;
12885  var sinPhi = sin$1(phi),
12886      cosPhi = cos$1(phi),
12887      delta = abs(lambda - lambda0$2),
12888      cosDelta = cos$1(delta),
12889      sinDelta = sin$1(delta),
12890      x = cosPhi * sinDelta,
12891      y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
12892      z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
12893  lengthSum.add(atan2(sqrt(x * x + y * y), z));
vendor: 5,011 bytes, lines 12894-13059
12894  lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
12895}
12896
12897function length$1(object) {
12898  lengthSum.reset();
12899  geoStream(object, lengthStream);
12900  return +lengthSum;
12901}
12902
12903var coordinates = [null, null];
12904var object$1 = {type: "LineString", coordinates: coordinates};
12905
12906function distance(a, b) {
12907  coordinates[0] = a;
12908  coordinates[1] = b;
12909  return length$1(object$1);
12910}
12911
12912var containsObjectType = {
12913  Feature: function(object, point) {
12914    return containsGeometry(object.geometry, point);
12915  },
12916  FeatureCollection: function(object, point) {
12917    var features = object.features, i = -1, n = features.length;
12918    while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
12919    return false;
12920  }
12921};
12922
12923var containsGeometryType = {
12924  Sphere: function() {
12925    return true;
12926  },
12927  Point: function(object, point) {
12928    return containsPoint(object.coordinates, point);
12929  },
12930  MultiPoint: function(object, point) {
12931    var coordinates = object.coordinates, i = -1, n = coordinates.length;
12932    while (++i < n) if (containsPoint(coordinates[i], point)) return true;
12933    return false;
12934  },
12935  LineString: function(object, point) {
12936    return containsLine(object.coordinates, point);
12937  },
12938  MultiLineString: function(object, point) {
12939    var coordinates = object.coordinates, i = -1, n = coordinates.length;
12940    while (++i < n) if (containsLine(coordinates[i], point)) return true;
12941    return false;
12942  },
12943  Polygon: function(object, point) {
12944    return containsPolygon(object.coordinates, point);
12945  },
12946  MultiPolygon: function(object, point) {
12947    var coordinates = object.coordinates, i = -1, n = coordinates.length;
12948    while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
12949    return false;
12950  },
12951  GeometryCollection: function(object, point) {
12952    var geometries = object.geometries, i = -1, n = geometries.length;
12953    while (++i < n) if (containsGeometry(geometries[i], point)) return true;
12954    return false;
12955  }
12956};
12957
12958function containsGeometry(geometry, point) {
12959  return geometry && containsGeometryType.hasOwnProperty(geometry.type)
12960      ? containsGeometryType[geometry.type](geometry, point)
12961      : false;
12962}
12963
12964function containsPoint(coordinates, point) {
12965  return distance(coordinates, point) === 0;
12966}
12967
12968function containsLine(coordinates, point) {
12969  var ab = distance(coordinates[0], coordinates[1]),
12970      ao = distance(coordinates[0], point),
12971      ob = distance(point, coordinates[1]);
12972  return ao + ob <= ab + epsilon$2;
12973}
12974
12975function containsPolygon(coordinates, point) {
12976  return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
12977}
12978
12979function ringRadians(ring) {
12980  return ring = ring.map(pointRadians), ring.pop(), ring;
12981}
12982
12983function pointRadians(point) {
12984  return [point[0] * radians, point[1] * radians];
12985}
12986
12987function contains(object, point) {
12988  return (object && containsObjectType.hasOwnProperty(object.type)
12989      ? containsObjectType[object.type]
12990      : containsGeometry)(object, point);
12991}
12992
12993function graticuleX(y0, y1, dy) {
12994  var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
12995  return function(x) { return y.map(function(y) { return [x, y]; }); };
12996}
12997
12998function graticuleY(x0, x1, dx) {
12999  var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
13000  return function(y) { return x.map(function(x) { return [x, y]; }); };
13001}
13002
13003function graticule() {
13004  var x1, x0, X1, X0,
13005      y1, y0, Y1, Y0,
13006      dx = 10, dy = dx, DX = 90, DY = 360,
13007      x, y, X, Y,
13008      precision = 2.5;
13009
13010  function graticule() {
13011    return {type: "MultiLineString", coordinates: lines()};
13012  }
13013
13014  function lines() {
13015    return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
13016        .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
13017        .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
13018        .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
13019  }
13020
13021  graticule.lines = function() {
13022    return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
13023  };
13024
13025  graticule.outline = function() {
13026    return {
13027      type: "Polygon",
13028      coordinates: [
13029        X(X0).concat(
13030        Y(Y1).slice(1),
13031        X(X1).reverse().slice(1),
13032        Y(Y0).reverse().slice(1))
13033      ]
13034    };
13035  };
13036
13037  graticule.extent = function(_) {
13038    if (!arguments.length) return graticule.extentMinor();
13039    return graticule.extentMajor(_).extentMinor(_);
13040  };
13041
13042  graticule.extentMajor = function(_) {
13043    if (!arguments.length) return [[X0, Y0], [X1, Y1]];
13044    X0 = +_[0][0], X1 = +_[1][0];
13045    Y0 = +_[0][1], Y1 = +_[1][1];
13046    if (X0 > X1) _ = X0, X0 = X1, X1 = _;
13047    if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
13048    return graticule.precision(precision);
13049  };
13050
13051  graticule.extentMinor = function(_) {
13052    if (!arguments.length) return [[x0, y0], [x1, y1]];
13053    x0 = +_[0][0], x1 = +_[1][0];
13054    y0 = +_[0][1], y1 = +_[1][1];
13055    if (x0 > x1) _ = x0, x0 = x1, x1 = _;
13056    if (y0 > y1) _ = y0, y0 = y1, y1 = _;
13057    return graticule.precision(precision);
13058  };
13059
vendor: 20,774 bytes, lines 13060-13855
13060  graticule.step = function(_) {
13061    if (!arguments.length) return graticule.stepMinor();
13062    return graticule.stepMajor(_).stepMinor(_);
13063  };
13064
13065  graticule.stepMajor = function(_) {
13066    if (!arguments.length) return [DX, DY];
13067    DX = +_[0], DY = +_[1];
13068    return graticule;
13069  };
13070
13071  graticule.stepMinor = function(_) {
13072    if (!arguments.length) return [dx, dy];
13073    dx = +_[0], dy = +_[1];
13074    return graticule;
13075  };
13076
13077  graticule.precision = function(_) {
13078    if (!arguments.length) return precision;
13079    precision = +_;
13080    x = graticuleX(y0, y1, 90);
13081    y = graticuleY(x0, x1, precision);
13082    X = graticuleX(Y0, Y1, 90);
13083    Y = graticuleY(X0, X1, precision);
13084    return graticule;
13085  };
13086
13087  return graticule
13088      .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
13089      .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
13090}
13091
13092function graticule10() {
13093  return graticule()();
13094}
13095
13096function interpolate$1(a, b) {
13097  var x0 = a[0] * radians,
13098      y0 = a[1] * radians,
13099      x1 = b[0] * radians,
13100      y1 = b[1] * radians,
13101      cy0 = cos$1(y0),
13102      sy0 = sin$1(y0),
13103      cy1 = cos$1(y1),
13104      sy1 = sin$1(y1),
13105      kx0 = cy0 * cos$1(x0),
13106      ky0 = cy0 * sin$1(x0),
13107      kx1 = cy1 * cos$1(x1),
13108      ky1 = cy1 * sin$1(x1),
13109      d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
13110      k = sin$1(d);
13111
13112  var interpolate = d ? function(t) {
13113    var B = sin$1(t *= d) / k,
13114        A = sin$1(d - t) / k,
13115        x = A * kx0 + B * kx1,
13116        y = A * ky0 + B * ky1,
13117        z = A * sy0 + B * sy1;
13118    return [
13119      atan2(y, x) * degrees$1,
13120      atan2(z, sqrt(x * x + y * y)) * degrees$1
13121    ];
13122  } : function() {
13123    return [x0 * degrees$1, y0 * degrees$1];
13124  };
13125
13126  interpolate.distance = d;
13127
13128  return interpolate;
13129}
13130
13131function identity$4(x) {
13132  return x;
13133}
13134
13135var areaSum$1 = adder();
13136var areaRingSum$1 = adder();
13137var x00;
13138var y00;
13139var x0$1;
13140var y0$1;
13141
13142var areaStream$1 = {
13143  point: noop$1,
13144  lineStart: noop$1,
13145  lineEnd: noop$1,
13146  polygonStart: function() {
13147    areaStream$1.lineStart = areaRingStart$1;
13148    areaStream$1.lineEnd = areaRingEnd$1;
13149  },
13150  polygonEnd: function() {
13151    areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
13152    areaSum$1.add(abs(areaRingSum$1));
13153    areaRingSum$1.reset();
13154  },
13155  result: function() {
13156    var area = areaSum$1 / 2;
13157    areaSum$1.reset();
13158    return area;
13159  }
13160};
13161
13162function areaRingStart$1() {
13163  areaStream$1.point = areaPointFirst$1;
13164}
13165
13166function areaPointFirst$1(x, y) {
13167  areaStream$1.point = areaPoint$1;
13168  x00 = x0$1 = x, y00 = y0$1 = y;
13169}
13170
13171function areaPoint$1(x, y) {
13172  areaRingSum$1.add(y0$1 * x - x0$1 * y);
13173  x0$1 = x, y0$1 = y;
13174}
13175
13176function areaRingEnd$1() {
13177  areaPoint$1(x00, y00);
13178}
13179
13180var x0$2 = Infinity;
13181var y0$2 = x0$2;
13182var x1 = -x0$2;
13183var y1 = x1;
13184
13185var boundsStream$1 = {
13186  point: boundsPoint$1,
13187  lineStart: noop$1,
13188  lineEnd: noop$1,
13189  polygonStart: noop$1,
13190  polygonEnd: noop$1,
13191  result: function() {
13192    var bounds = [[x0$2, y0$2], [x1, y1]];
13193    x1 = y1 = -(y0$2 = x0$2 = Infinity);
13194    return bounds;
13195  }
13196};
13197
13198function boundsPoint$1(x, y) {
13199  if (x < x0$2) x0$2 = x;
13200  if (x > x1) x1 = x;
13201  if (y < y0$2) y0$2 = y;
13202  if (y > y1) y1 = y;
13203}
13204
13205// TODO Enforce positive area for exterior, negative area for interior?
13206
13207var X0$1 = 0;
13208var Y0$1 = 0;
13209var Z0$1 = 0;
13210var X1$1 = 0;
13211var Y1$1 = 0;
13212var Z1$1 = 0;
13213var X2$1 = 0;
13214var Y2$1 = 0;
13215var Z2$1 = 0;
13216var x00$1;
13217var y00$1;
13218var x0$3;
13219var y0$3;
13220
13221var centroidStream$1 = {
13222  point: centroidPoint$1,
13223  lineStart: centroidLineStart$1,
13224  lineEnd: centroidLineEnd$1,
13225  polygonStart: function() {
13226    centroidStream$1.lineStart = centroidRingStart$1;
13227    centroidStream$1.lineEnd = centroidRingEnd$1;
13228  },
13229  polygonEnd: function() {
13230    centroidStream$1.point = centroidPoint$1;
13231    centroidStream$1.lineStart = centroidLineStart$1;
13232    centroidStream$1.lineEnd = centroidLineEnd$1;
13233  },
13234  result: function() {
13235    var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
13236        : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
13237        : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
13238        : [NaN, NaN];
13239    X0$1 = Y0$1 = Z0$1 =
13240    X1$1 = Y1$1 = Z1$1 =
13241    X2$1 = Y2$1 = Z2$1 = 0;
13242    return centroid;
13243  }
13244};
13245
13246function centroidPoint$1(x, y) {
13247  X0$1 += x;
13248  Y0$1 += y;
13249  ++Z0$1;
13250}
13251
13252function centroidLineStart$1() {
13253  centroidStream$1.point = centroidPointFirstLine;
13254}
13255
13256function centroidPointFirstLine(x, y) {
13257  centroidStream$1.point = centroidPointLine;
13258  centroidPoint$1(x0$3 = x, y0$3 = y);
13259}
13260
13261function centroidPointLine(x, y) {
13262  var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
13263  X1$1 += z * (x0$3 + x) / 2;
13264  Y1$1 += z * (y0$3 + y) / 2;
13265  Z1$1 += z;
13266  centroidPoint$1(x0$3 = x, y0$3 = y);
13267}
13268
13269function centroidLineEnd$1() {
13270  centroidStream$1.point = centroidPoint$1;
13271}
13272
13273function centroidRingStart$1() {
13274  centroidStream$1.point = centroidPointFirstRing;
13275}
13276
13277function centroidRingEnd$1() {
13278  centroidPointRing(x00$1, y00$1);
13279}
13280
13281function centroidPointFirstRing(x, y) {
13282  centroidStream$1.point = centroidPointRing;
13283  centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
13284}
13285
13286function centroidPointRing(x, y) {
13287  var dx = x - x0$3,
13288      dy = y - y0$3,
13289      z = sqrt(dx * dx + dy * dy);
13290
13291  X1$1 += z * (x0$3 + x) / 2;
13292  Y1$1 += z * (y0$3 + y) / 2;
13293  Z1$1 += z;
13294
13295  z = y0$3 * x - x0$3 * y;
13296  X2$1 += z * (x0$3 + x);
13297  Y2$1 += z * (y0$3 + y);
13298  Z2$1 += z * 3;
13299  centroidPoint$1(x0$3 = x, y0$3 = y);
13300}
13301
13302function PathContext(context) {
13303  this._context = context;
13304}
13305
13306PathContext.prototype = {
13307  _radius: 4.5,
13308  pointRadius: function(_) {
13309    return this._radius = _, this;
13310  },
13311  polygonStart: function() {
13312    this._line = 0;
13313  },
13314  polygonEnd: function() {
13315    this._line = NaN;
13316  },
13317  lineStart: function() {
13318    this._point = 0;
13319  },
13320  lineEnd: function() {
13321    if (this._line === 0) this._context.closePath();
13322    this._point = NaN;
13323  },
13324  point: function(x, y) {
13325    switch (this._point) {
13326      case 0: {
13327        this._context.moveTo(x, y);
13328        this._point = 1;
13329        break;
13330      }
13331      case 1: {
13332        this._context.lineTo(x, y);
13333        break;
13334      }
13335      default: {
13336        this._context.moveTo(x + this._radius, y);
13337        this._context.arc(x, y, this._radius, 0, tau$3);
13338        break;
13339      }
13340    }
13341  },
13342  result: noop$1
13343};
13344
13345var lengthSum$1 = adder();
13346var lengthRing;
13347var x00$2;
13348var y00$2;
13349var x0$4;
13350var y0$4;
13351
13352var lengthStream$1 = {
13353  point: noop$1,
13354  lineStart: function() {
13355    lengthStream$1.point = lengthPointFirst$1;
13356  },
13357  lineEnd: function() {
13358    if (lengthRing) lengthPoint$1(x00$2, y00$2);
13359    lengthStream$1.point = noop$1;
13360  },
13361  polygonStart: function() {
13362    lengthRing = true;
13363  },
13364  polygonEnd: function() {
13365    lengthRing = null;
13366  },
13367  result: function() {
13368    var length = +lengthSum$1;
13369    lengthSum$1.reset();
13370    return length;
13371  }
13372};
13373
13374function lengthPointFirst$1(x, y) {
13375  lengthStream$1.point = lengthPoint$1;
13376  x00$2 = x0$4 = x, y00$2 = y0$4 = y;
13377}
13378
13379function lengthPoint$1(x, y) {
13380  x0$4 -= x, y0$4 -= y;
13381  lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
13382  x0$4 = x, y0$4 = y;
13383}
13384
13385function PathString() {
13386  this._string = [];
13387}
13388
13389PathString.prototype = {
13390  _radius: 4.5,
13391  _circle: circle$1(4.5),
13392  pointRadius: function(_) {
13393    if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
13394    return this;
13395  },
13396  polygonStart: function() {
13397    this._line = 0;
13398  },
13399  polygonEnd: function() {
13400    this._line = NaN;
13401  },
13402  lineStart: function() {
13403    this._point = 0;
13404  },
13405  lineEnd: function() {
13406    if (this._line === 0) this._string.push("Z");
13407    this._point = NaN;
13408  },
13409  point: function(x, y) {
13410    switch (this._point) {
13411      case 0: {
13412        this._string.push("M", x, ",", y);
13413        this._point = 1;
13414        break;
13415      }
13416      case 1: {
13417        this._string.push("L", x, ",", y);
13418        break;
13419      }
13420      default: {
13421        if (this._circle == null) this._circle = circle$1(this._radius);
13422        this._string.push("M", x, ",", y, this._circle);
13423        break;
13424      }
13425    }
13426  },
13427  result: function() {
13428    if (this._string.length) {
13429      var result = this._string.join("");
13430      this._string = [];
13431      return result;
13432    } else {
13433      return null;
13434    }
13435  }
13436};
13437
13438function circle$1(radius) {
13439  return "m0," + radius
13440      + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
13441      + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
13442      + "z";
13443}
13444
13445function index$1(projection, context) {
13446  var pointRadius = 4.5,
13447      projectionStream,
13448      contextStream;
13449
13450  function path(object) {
13451    if (object) {
13452      if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
13453      geoStream(object, projectionStream(contextStream));
13454    }
13455    return contextStream.result();
13456  }
13457
13458  path.area = function(object) {
13459    geoStream(object, projectionStream(areaStream$1));
13460    return areaStream$1.result();
13461  };
13462
13463  path.measure = function(object) {
13464    geoStream(object, projectionStream(lengthStream$1));
13465    return lengthStream$1.result();
13466  };
13467
13468  path.bounds = function(object) {
13469    geoStream(object, projectionStream(boundsStream$1));
13470    return boundsStream$1.result();
13471  };
13472
13473  path.centroid = function(object) {
13474    geoStream(object, projectionStream(centroidStream$1));
13475    return centroidStream$1.result();
13476  };
13477
13478  path.projection = function(_) {
13479    return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
13480  };
13481
13482  path.context = function(_) {
13483    if (!arguments.length) return context;
13484    contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
13485    if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
13486    return path;
13487  };
13488
13489  path.pointRadius = function(_) {
13490    if (!arguments.length) return pointRadius;
13491    pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
13492    return path;
13493  };
13494
13495  return path.projection(projection).context(context);
13496}
13497
13498function transform(methods) {
13499  return {
13500    stream: transformer(methods)
13501  };
13502}
13503
13504function transformer(methods) {
13505  return function(stream) {
13506    var s = new TransformStream;
13507    for (var key in methods) s[key] = methods[key];
13508    s.stream = stream;
13509    return s;
13510  };
13511}
13512
13513function TransformStream() {}
13514
13515TransformStream.prototype = {
13516  constructor: TransformStream,
13517  point: function(x, y) { this.stream.point(x, y); },
13518  sphere: function() { this.stream.sphere(); },
13519  lineStart: function() { this.stream.lineStart(); },
13520  lineEnd: function() { this.stream.lineEnd(); },
13521  polygonStart: function() { this.stream.polygonStart(); },
13522  polygonEnd: function() { this.stream.polygonEnd(); }
13523};
13524
13525function fit(projection, fitBounds, object) {
13526  var clip = projection.clipExtent && projection.clipExtent();
13527  projection.scale(150).translate([0, 0]);
13528  if (clip != null) projection.clipExtent(null);
13529  geoStream(object, projection.stream(boundsStream$1));
13530  fitBounds(boundsStream$1.result());
13531  if (clip != null) projection.clipExtent(clip);
13532  return projection;
13533}
13534
13535function fitExtent(projection, extent, object) {
13536  return fit(projection, function(b) {
13537    var w = extent[1][0] - extent[0][0],
13538        h = extent[1][1] - extent[0][1],
13539        k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
13540        x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
13541        y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
13542    projection.scale(150 * k).translate([x, y]);
13543  }, object);
13544}
13545
13546function fitSize(projection, size, object) {
13547  return fitExtent(projection, [[0, 0], size], object);
13548}
13549
13550function fitWidth(projection, width, object) {
13551  return fit(projection, function(b) {
13552    var w = +width,
13553        k = w / (b[1][0] - b[0][0]),
13554        x = (w - k * (b[1][0] + b[0][0])) / 2,
13555        y = -k * b[0][1];
13556    projection.scale(150 * k).translate([x, y]);
13557  }, object);
13558}
13559
13560function fitHeight(projection, height, object) {
13561  return fit(projection, function(b) {
13562    var h = +height,
13563        k = h / (b[1][1] - b[0][1]),
13564        x = -k * b[0][0],
13565        y = (h - k * (b[1][1] + b[0][1])) / 2;
13566    projection.scale(150 * k).translate([x, y]);
13567  }, object);
13568}
13569
13570var maxDepth = 16;
13571var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
13572
13573function resample(project, delta2) {
13574  return +delta2 ? resample$1(project, delta2) : resampleNone(project);
13575}
13576
13577function resampleNone(project) {
13578  return transformer({
13579    point: function(x, y) {
13580      x = project(x, y);
13581      this.stream.point(x[0], x[1]);
13582    }
13583  });
13584}
13585
13586function resample$1(project, delta2) {
13587
13588  function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
13589    var dx = x1 - x0,
13590        dy = y1 - y0,
13591        d2 = dx * dx + dy * dy;
13592    if (d2 > 4 * delta2 && depth--) {
13593      var a = a0 + a1,
13594          b = b0 + b1,
13595          c = c0 + c1,
13596          m = sqrt(a * a + b * b + c * c),
13597          phi2 = asin(c /= m),
13598          lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
13599          p = project(lambda2, phi2),
13600          x2 = p[0],
13601          y2 = p[1],
13602          dx2 = x2 - x0,
13603          dy2 = y2 - y0,
13604          dz = dy * dx2 - dx * dy2;
13605      if (dz * dz / d2 > delta2 // perpendicular projected distance
13606          || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
13607          || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
13608        resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
13609        stream.point(x2, y2);
13610        resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
13611      }
13612    }
13613  }
13614  return function(stream) {
13615    var lambda00, x00, y00, a00, b00, c00, // first point
13616        lambda0, x0, y0, a0, b0, c0; // previous point
13617
13618    var resampleStream = {
13619      point: point,
13620      lineStart: lineStart,
13621      lineEnd: lineEnd,
13622      polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
13623      polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
13624    };
13625
13626    function point(x, y) {
13627      x = project(x, y);
13628      stream.point(x[0], x[1]);
13629    }
13630
13631    function lineStart() {
13632      x0 = NaN;
13633      resampleStream.point = linePoint;
13634      stream.lineStart();
13635    }
13636
13637    function linePoint(lambda, phi) {
13638      var c = cartesian([lambda, phi]), p = project(lambda, phi);
13639      resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
13640      stream.point(x0, y0);
13641    }
13642
13643    function lineEnd() {
13644      resampleStream.point = point;
13645      stream.lineEnd();
13646    }
13647
13648    function ringStart() {
13649      lineStart();
13650      resampleStream.point = ringPoint;
13651      resampleStream.lineEnd = ringEnd;
13652    }
13653
13654    function ringPoint(lambda, phi) {
13655      linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
13656      resampleStream.point = linePoint;
13657    }
13658
13659    function ringEnd() {
13660      resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
13661      resampleStream.lineEnd = lineEnd;
13662      lineEnd();
13663    }
13664
13665    return resampleStream;
13666  };
13667}
13668
13669var transformRadians = transformer({
13670  point: function(x, y) {
13671    this.stream.point(x * radians, y * radians);
13672  }
13673});
13674
13675function transformRotate(rotate) {
13676  return transformer({
13677    point: function(x, y) {
13678      var r = rotate(x, y);
13679      return this.stream.point(r[0], r[1]);
13680    }
13681  });
13682}
13683
13684function projection(project) {
13685  return projectionMutator(function() { return project; })();
13686}
13687
13688function projectionMutator(projectAt) {
13689  var project,
13690      k = 150, // scale
13691      x = 480, y = 250, // translate
13692      dx, dy, lambda = 0, phi = 0, // center
13693      deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
13694      theta = null, preclip = clipAntimeridian, // clip angle
13695      x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
13696      delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
13697      cache,
13698      cacheStream;
13699
13700  function projection(point) {
13701    point = projectRotate(point[0] * radians, point[1] * radians);
13702    return [point[0] * k + dx, dy - point[1] * k];
13703  }
13704
13705  function invert(point) {
13706    point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
13707    return point && [point[0] * degrees$1, point[1] * degrees$1];
13708  }
13709
13710  function projectTransform(x, y) {
13711    return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
13712  }
13713
13714  projection.stream = function(stream) {
13715    return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
13716  };
13717
13718  projection.preclip = function(_) {
13719    return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
13720  };
13721
13722  projection.postclip = function(_) {
13723    return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
13724  };
13725
13726  projection.clipAngle = function(_) {
13727    return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
13728  };
13729
13730  projection.clipExtent = function(_) {
13731    return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
13732  };
13733
13734  projection.scale = function(_) {
13735    return arguments.length ? (k = +_, recenter()) : k;
13736  };
13737
13738  projection.translate = function(_) {
13739    return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
13740  };
13741
13742  projection.center = function(_) {
13743    return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
13744  };
13745
13746  projection.rotate = function(_) {
13747    return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees$1, deltaPhi * degrees$1, deltaGamma * degrees$1];
13748  };
13749
13750  projection.precision = function(_) {
13751    return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
13752  };
13753
13754  projection.fitExtent = function(extent, object) {
13755    return fitExtent(projection, extent, object);
13756  };
13757
13758  projection.fitSize = function(size, object) {
13759    return fitSize(projection, size, object);
13760  };
13761
13762  projection.fitWidth = function(width, object) {
13763    return fitWidth(projection, width, object);
13764  };
13765
13766  projection.fitHeight = function(height, object) {
13767    return fitHeight(projection, height, object);
13768  };
13769
13770  function recenter() {
13771    projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
13772    var center = project(lambda, phi);
13773    dx = x - center[0] * k;
13774    dy = y + center[1] * k;
13775    return reset();
13776  }
13777
13778  function reset() {
13779    cache = cacheStream = null;
13780    return projection;
13781  }
13782
13783  return function() {
13784    project = projectAt.apply(this, arguments);
13785    projection.invert = project.invert && invert;
13786    return recenter();
13787  };
13788}
13789
13790function conicProjection(projectAt) {
13791  var phi0 = 0,
13792      phi1 = pi$3 / 3,
13793      m = projectionMutator(projectAt),
13794      p = m(phi0, phi1);
13795
13796  p.parallels = function(_) {
13797    return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
13798  };
13799
13800  return p;
13801}
13802
13803function cylindricalEqualAreaRaw(phi0) {
13804  var cosPhi0 = cos$1(phi0);
13805
13806  function forward(lambda, phi) {
13807    return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
13808  }
13809
13810  forward.invert = function(x, y) {
13811    return [x / cosPhi0, asin(y * cosPhi0)];
13812  };
13813
13814  return forward;
13815}
13816
13817function conicEqualAreaRaw(y0, y1) {
13818  var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
13819
13820  // Are the parallels symmetrical around the Equator?
13821  if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
13822
13823  var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
13824
13825  function project(x, y) {
13826    var r = sqrt(c - 2 * n * sin$1(y)) / n;
13827    return [r * sin$1(x *= n), r0 - r * cos$1(x)];
13828  }
13829
13830  project.invert = function(x, y) {
13831    var r0y = r0 - y;
13832    return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
13833  };
13834
13835  return project;
13836}
13837
13838function conicEqualArea() {
13839  return conicProjection(conicEqualAreaRaw)
13840      .scale(155.424)
13841      .center([0, 33.6442]);
13842}
13843
13844function albers() {
13845  return conicEqualArea()
13846      .parallels([29.5, 45.5])
13847      .scale(1070)
13848      .translate([480, 250])
13849      .rotate([96, 0])
13850      .center([-0.6, 38.7]);
13851}
13852
13853// The projections must have mutually exclusive clip regions on the sphere,
13854// as this will avoid emitting interleaving lines and polygons.
13855function multiplex(streams) {
vendor: 5,849 bytes, lines 13856-14046
13856  var n = streams.length;
13857  return {
13858    point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
13859    sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
13860    lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
13861    lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
13862    polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
13863    polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
13864  };
13865}
13866
13867// A composite projection for the United States, configured by default for
13868// 960×500. The projection also works quite well at 960×600 if you change the
13869// scale to 1285 and adjust the translate accordingly. The set of standard
13870// parallels for each region comes from USGS, which is published here:
13871// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
13872function albersUsa() {
13873  var cache,
13874      cacheStream,
13875      lower48 = albers(), lower48Point,
13876      alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
13877      hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
13878      point, pointStream = {point: function(x, y) { point = [x, y]; }};
13879
13880  function albersUsa(coordinates) {
13881    var x = coordinates[0], y = coordinates[1];
13882    return point = null, (lower48Point.point(x, y), point)
13883        || (alaskaPoint.point(x, y), point)
13884        || (hawaiiPoint.point(x, y), point);
13885  }
13886
13887  albersUsa.invert = function(coordinates) {
13888    var k = lower48.scale(),
13889        t = lower48.translate(),
13890        x = (coordinates[0] - t[0]) / k,
13891        y = (coordinates[1] - t[1]) / k;
13892    return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
13893        : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
13894        : lower48).invert(coordinates);
13895  };
13896
13897  albersUsa.stream = function(stream) {
13898    return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
13899  };
13900
13901  albersUsa.precision = function(_) {
13902    if (!arguments.length) return lower48.precision();
13903    lower48.precision(_), alaska.precision(_), hawaii.precision(_);
13904    return reset();
13905  };
13906
13907  albersUsa.scale = function(_) {
13908    if (!arguments.length) return lower48.scale();
13909    lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
13910    return albersUsa.translate(lower48.translate());
13911  };
13912
13913  albersUsa.translate = function(_) {
13914    if (!arguments.length) return lower48.translate();
13915    var k = lower48.scale(), x = +_[0], y = +_[1];
13916
13917    lower48Point = lower48
13918        .translate(_)
13919        .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
13920        .stream(pointStream);
13921
13922    alaskaPoint = alaska
13923        .translate([x - 0.307 * k, y + 0.201 * k])
13924        .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
13925        .stream(pointStream);
13926
13927    hawaiiPoint = hawaii
13928        .translate([x - 0.205 * k, y + 0.212 * k])
13929        .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
13930        .stream(pointStream);
13931
13932    return reset();
13933  };
13934
13935  albersUsa.fitExtent = function(extent, object) {
13936    return fitExtent(albersUsa, extent, object);
13937  };
13938
13939  albersUsa.fitSize = function(size, object) {
13940    return fitSize(albersUsa, size, object);
13941  };
13942
13943  albersUsa.fitWidth = function(width, object) {
13944    return fitWidth(albersUsa, width, object);
13945  };
13946
13947  albersUsa.fitHeight = function(height, object) {
13948    return fitHeight(albersUsa, height, object);
13949  };
13950
13951  function reset() {
13952    cache = cacheStream = null;
13953    return albersUsa;
13954  }
13955
13956  return albersUsa.scale(1070);
13957}
13958
13959function azimuthalRaw(scale) {
13960  return function(x, y) {
13961    var cx = cos$1(x),
13962        cy = cos$1(y),
13963        k = scale(cx * cy);
13964    return [
13965      k * cy * sin$1(x),
13966      k * sin$1(y)
13967    ];
13968  }
13969}
13970
13971function azimuthalInvert(angle) {
13972  return function(x, y) {
13973    var z = sqrt(x * x + y * y),
13974        c = angle(z),
13975        sc = sin$1(c),
13976        cc = cos$1(c);
13977    return [
13978      atan2(x * sc, z * cc),
13979      asin(z && y * sc / z)
13980    ];
13981  }
13982}
13983
13984var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
13985  return sqrt(2 / (1 + cxcy));
13986});
13987
13988azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
13989  return 2 * asin(z / 2);
13990});
13991
13992function azimuthalEqualArea() {
13993  return projection(azimuthalEqualAreaRaw)
13994      .scale(124.75)
13995      .clipAngle(180 - 1e-3);
13996}
13997
13998var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
13999  return (c = acos(c)) && c / sin$1(c);
14000});
14001
14002azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
14003  return z;
14004});
14005
14006function azimuthalEquidistant() {
14007  return projection(azimuthalEquidistantRaw)
14008      .scale(79.4188)
14009      .clipAngle(180 - 1e-3);
14010}
14011
14012function mercatorRaw(lambda, phi) {
14013  return [lambda, log(tan((halfPi$2 + phi) / 2))];
14014}
14015
14016mercatorRaw.invert = function(x, y) {
14017  return [x, 2 * atan(exp(y)) - halfPi$2];
14018};
14019
14020function mercator() {
14021  return mercatorProjection(mercatorRaw)
14022      .scale(961 / tau$3);
14023}
14024
14025function mercatorProjection(project) {
14026  var m = projection(project),
14027      center = m.center,
14028      scale = m.scale,
14029      translate = m.translate,
14030      clipExtent = m.clipExtent,
14031      x0 = null, y0, x1, y1; // clip extent
14032
14033  m.scale = function(_) {
14034    return arguments.length ? (scale(_), reclip()) : scale();
14035  };
14036
14037  m.translate = function(_) {
14038    return arguments.length ? (translate(_), reclip()) : translate();
14039  };
14040
14041  m.center = function(_) {
14042    return arguments.length ? (center(_), reclip()) : center();
14043  };
14044
14045  m.clipExtent = function(_) {
14046    return arguments.length ? (_ == null ? x0 = y0 = x1 = y1 = null : (x0 
vendor: 32,791 bytes, lines 14046-15327
14046= +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
14047  };
14048
14049  function reclip() {
14050    var k = pi$3 * scale(),
14051        t = m(rotation(m.rotate()).invert([0, 0]));
14052    return clipExtent(x0 == null
14053        ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
14054        ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
14055        : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
14056  }
14057
14058  return reclip();
14059}
14060
14061function tany(y) {
14062  return tan((halfPi$2 + y) / 2);
14063}
14064
14065function conicConformalRaw(y0, y1) {
14066  var cy0 = cos$1(y0),
14067      n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
14068      f = cy0 * pow(tany(y0), n) / n;
14069
14070  if (!n) return mercatorRaw;
14071
14072  function project(x, y) {
14073    if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
14074    else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
14075    var r = f / pow(tany(y), n);
14076    return [r * sin$1(n * x), f - r * cos$1(n * x)];
14077  }
14078
14079  project.invert = function(x, y) {
14080    var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
14081    return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
14082  };
14083
14084  return project;
14085}
14086
14087function conicConformal() {
14088  return conicProjection(conicConformalRaw)
14089      .scale(109.5)
14090      .parallels([30, 30]);
14091}
14092
14093function equirectangularRaw(lambda, phi) {
14094  return [lambda, phi];
14095}
14096
14097equirectangularRaw.invert = equirectangularRaw;
14098
14099function equirectangular() {
14100  return projection(equirectangularRaw)
14101      .scale(152.63);
14102}
14103
14104function conicEquidistantRaw(y0, y1) {
14105  var cy0 = cos$1(y0),
14106      n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
14107      g = cy0 / n + y0;
14108
14109  if (abs(n) < epsilon$2) return equirectangularRaw;
14110
14111  function project(x, y) {
14112    var gy = g - y, nx = n * x;
14113    return [gy * sin$1(nx), g - gy * cos$1(nx)];
14114  }
14115
14116  project.invert = function(x, y) {
14117    var gy = g - y;
14118    return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
14119  };
14120
14121  return project;
14122}
14123
14124function conicEquidistant() {
14125  return conicProjection(conicEquidistantRaw)
14126      .scale(131.154)
14127      .center([0, 13.9389]);
14128}
14129
14130function gnomonicRaw(x, y) {
14131  var cy = cos$1(y), k = cos$1(x) * cy;
14132  return [cy * sin$1(x) / k, sin$1(y) / k];
14133}
14134
14135gnomonicRaw.invert = azimuthalInvert(atan);
14136
14137function gnomonic() {
14138  return projection(gnomonicRaw)
14139      .scale(144.049)
14140      .clipAngle(60);
14141}
14142
14143function scaleTranslate(kx, ky, tx, ty) {
14144  return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
14145    point: function(x, y) {
14146      this.stream.point(x * kx + tx, y * ky + ty);
14147    }
14148  });
14149}
14150
14151function identity$5() {
14152  var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
14153      x0 = null, y0, x1, y1, // clip extent
14154      postclip = identity$4,
14155      cache,
14156      cacheStream,
14157      projection;
14158
14159  function reset() {
14160    cache = cacheStream = null;
14161    return projection;
14162  }
14163
14164  return projection = {
14165    stream: function(stream) {
14166      return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
14167    },
14168    postclip: function(_) {
14169      return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
14170    },
14171    clipExtent: function(_) {
14172      return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
14173    },
14174    scale: function(_) {
14175      return arguments.length ? (transform$$1 = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
14176    },
14177    translate: function(_) {
14178      return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
14179    },
14180    reflectX: function(_) {
14181      return arguments.length ? (transform$$1 = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
14182    },
14183    reflectY: function(_) {
14184      return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
14185    },
14186    fitExtent: function(extent, object) {
14187      return fitExtent(projection, extent, object);
14188    },
14189    fitSize: function(size, object) {
14190      return fitSize(projection, size, object);
14191    },
14192    fitWidth: function(width, object) {
14193      return fitWidth(projection, width, object);
14194    },
14195    fitHeight: function(height, object) {
14196      return fitHeight(projection, height, object);
14197    }
14198  };
14199}
14200
14201function naturalEarth1Raw(lambda, phi) {
14202  var phi2 = phi * phi, phi4 = phi2 * phi2;
14203  return [
14204    lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
14205    phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
14206  ];
14207}
14208
14209naturalEarth1Raw.invert = function(x, y) {
14210  var phi = y, i = 25, delta;
14211  do {
14212    var phi2 = phi * phi, phi4 = phi2 * phi2;
14213    phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
14214        (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
14215  } while (abs(delta) > epsilon$2 && --i > 0);
14216  return [
14217    x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
14218    phi
14219  ];
14220};
14221
14222function naturalEarth1() {
14223  return projection(naturalEarth1Raw)
14224      .scale(175.295);
14225}
14226
14227function orthographicRaw(x, y) {
14228  return [cos$1(y) * sin$1(x), sin$1(y)];
14229}
14230
14231orthographicRaw.invert = azimuthalInvert(asin);
14232
14233function orthographic() {
14234  return projection(orthographicRaw)
14235      .scale(249.5)
14236      .clipAngle(90 + epsilon$2);
14237}
14238
14239function stereographicRaw(x, y) {
14240  var cy = cos$1(y), k = 1 + cos$1(x) * cy;
14241  return [cy * sin$1(x) / k, sin$1(y) / k];
14242}
14243
14244stereographicRaw.invert = azimuthalInvert(function(z) {
14245  return 2 * atan(z);
14246});
14247
14248function stereographic() {
14249  return projection(stereographicRaw)
14250      .scale(250)
14251      .clipAngle(142);
14252}
14253
14254function transverseMercatorRaw(lambda, phi) {
14255  return [log(tan((halfPi$2 + phi) / 2)), -lambda];
14256}
14257
14258transverseMercatorRaw.invert = function(x, y) {
14259  return [-y, 2 * atan(exp(x)) - halfPi$2];
14260};
14261
14262function transverseMercator() {
14263  var m = mercatorProjection(transverseMercatorRaw),
14264      center = m.center,
14265      rotate = m.rotate;
14266
14267  m.center = function(_) {
14268    return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
14269  };
14270
14271  m.rotate = function(_) {
14272    return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
14273  };
14274
14275  return rotate([0, 0, 90])
14276      .scale(159.155);
14277}
14278
14279function defaultSeparation(a, b) {
14280  return a.parent === b.parent ? 1 : 2;
14281}
14282
14283function meanX(children) {
14284  return children.reduce(meanXReduce, 0) / children.length;
14285}
14286
14287function meanXReduce(x, c) {
14288  return x + c.x;
14289}
14290
14291function maxY(children) {
14292  return 1 + children.reduce(maxYReduce, 0);
14293}
14294
14295function maxYReduce(y, c) {
14296  return Math.max(y, c.y);
14297}
14298
14299function leafLeft(node) {
14300  var children;
14301  while (children = node.children) node = children[0];
14302  return node;
14303}
14304
14305function leafRight(node) {
14306  var children;
14307  while (children = node.children) node = children[children.length - 1];
14308  return node;
14309}
14310
14311function cluster() {
14312  var separation = defaultSeparation,
14313      dx = 1,
14314      dy = 1,
14315      nodeSize = false;
14316
14317  function cluster(root) {
14318    var previousNode,
14319        x = 0;
14320
14321    // First walk, computing the initial x & y values.
14322    root.eachAfter(function(node) {
14323      var children = node.children;
14324      if (children) {
14325        node.x = meanX(children);
14326        node.y = maxY(children);
14327      } else {
14328        node.x = previousNode ? x += separation(node, previousNode) : 0;
14329        node.y = 0;
14330        previousNode = node;
14331      }
14332    });
14333
14334    var left = leafLeft(root),
14335        right = leafRight(root),
14336        x0 = left.x - separation(left, right) / 2,
14337        x1 = right.x + separation(right, left) / 2;
14338
14339    // Second walk, normalizing x & y to the desired size.
14340    return root.eachAfter(nodeSize ? function(node) {
14341      node.x = (node.x - root.x) * dx;
14342      node.y = (root.y - node.y) * dy;
14343    } : function(node) {
14344      node.x = (node.x - x0) / (x1 - x0) * dx;
14345      node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
14346    });
14347  }
14348
14349  cluster.separation = function(x) {
14350    return arguments.length ? (separation = x, cluster) : separation;
14351  };
14352
14353  cluster.size = function(x) {
14354    return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
14355  };
14356
14357  cluster.nodeSize = function(x) {
14358    return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
14359  };
14360
14361  return cluster;
14362}
14363
14364function count(node) {
14365  var sum = 0,
14366      children = node.children,
14367      i = children && children.length;
14368  if (!i) sum = 1;
14369  else while (--i >= 0) sum += children[i].value;
14370  node.value = sum;
14371}
14372
14373function node_count() {
14374  return this.eachAfter(count);
14375}
14376
14377function node_each(callback) {
14378  var node = this, current, next = [node], children, i, n;
14379  do {
14380    current = next.reverse(), next = [];
14381    while (node = current.pop()) {
14382      callback(node), children = node.children;
14383      if (children) for (i = 0, n = children.length; i < n; ++i) {
14384        next.push(children[i]);
14385      }
14386    }
14387  } while (next.length);
14388  return this;
14389}
14390
14391function node_eachBefore(callback) {
14392  var node = this, nodes = [node], children, i;
14393  while (node = nodes.pop()) {
14394    callback(node), children = node.children;
14395    if (children) for (i = children.length - 1; i >= 0; --i) {
14396      nodes.push(children[i]);
14397    }
14398  }
14399  return this;
14400}
14401
14402function node_eachAfter(callback) {
14403  var node = this, nodes = [node], next = [], children, i, n;
14404  while (node = nodes.pop()) {
14405    next.push(node), children = node.children;
14406    if (children) for (i = 0, n = children.length; i < n; ++i) {
14407      nodes.push(children[i]);
14408    }
14409  }
14410  while (node = next.pop()) {
14411    callback(node);
14412  }
14413  return this;
14414}
14415
14416function node_sum(value) {
14417  return this.eachAfter(function(node) {
14418    var sum = +value(node.data) || 0,
14419        children = node.children,
14420        i = children && children.length;
14421    while (--i >= 0) sum += children[i].value;
14422    node.value = sum;
14423  });
14424}
14425
14426function node_sort(compare) {
14427  return this.eachBefore(function(node) {
14428    if (node.children) {
14429      node.children.sort(compare);
14430    }
14431  });
14432}
14433
14434function node_path(end) {
14435  var start = this,
14436      ancestor = leastCommonAncestor(start, end),
14437      nodes = [start];
14438  while (start !== ancestor) {
14439    start = start.parent;
14440    nodes.push(start);
14441  }
14442  var k = nodes.length;
14443  while (end !== ancestor) {
14444    nodes.splice(k, 0, end);
14445    end = end.parent;
14446  }
14447  return nodes;
14448}
14449
14450function leastCommonAncestor(a, b) {
14451  if (a === b) return a;
14452  var aNodes = a.ancestors(),
14453      bNodes = b.ancestors(),
14454      c = null;
14455  a = aNodes.pop();
14456  b = bNodes.pop();
14457  while (a === b) {
14458    c = a;
14459    a = aNodes.pop();
14460    b = bNodes.pop();
14461  }
14462  return c;
14463}
14464
14465function node_ancestors() {
14466  var node = this, nodes = [node];
14467  while (node = node.parent) {
14468    nodes.push(node);
14469  }
14470  return nodes;
14471}
14472
14473function node_descendants() {
14474  var nodes = [];
14475  this.each(function(node) {
14476    nodes.push(node);
14477  });
14478  return nodes;
14479}
14480
14481function node_leaves() {
14482  var leaves = [];
14483  this.eachBefore(function(node) {
14484    if (!node.children) {
14485      leaves.push(node);
14486    }
14487  });
14488  return leaves;
14489}
14490
14491function node_links() {
14492  var root = this, links = [];
14493  root.each(function(node) {
14494    if (node !== root) { // Don’t include the root’s parent, if any.
14495      links.push({source: node.parent, target: node});
14496    }
14497  });
14498  return links;
14499}
14500
14501function hierarchy(data, children) {
14502  var root = new Node(data),
14503      valued = +data.value && (root.value = data.value),
14504      node,
14505      nodes = [root],
14506      child,
14507      childs,
14508      i,
14509      n;
14510
14511  if (children == null) children = defaultChildren;
14512
14513  while (node = nodes.pop()) {
14514    if (valued) node.value = +node.data.value;
14515    if ((childs = children(node.data)) && (n = childs.length)) {
14516      node.children = new Array(n);
14517      for (i = n - 1; i >= 0; --i) {
14518        nodes.push(child = node.children[i] = new Node(childs[i]));
14519        child.parent = node;
14520        child.depth = node.depth + 1;
14521      }
14522    }
14523  }
14524
14525  return root.eachBefore(computeHeight);
14526}
14527
14528function node_copy() {
14529  return hierarchy(this).eachBefore(copyData);
14530}
14531
14532function defaultChildren(d) {
14533  return d.children;
14534}
14535
14536function copyData(node) {
14537  node.data = node.data.data;
14538}
14539
14540function computeHeight(node) {
14541  var height = 0;
14542  do node.height = height;
14543  while ((node = node.parent) && (node.height < ++height));
14544}
14545
14546function Node(data) {
14547  this.data = data;
14548  this.depth =
14549  this.height = 0;
14550  this.parent = null;
14551}
14552
14553Node.prototype = hierarchy.prototype = {
14554  constructor: Node,
14555  count: node_count,
14556  each: node_each,
14557  eachAfter: node_eachAfter,
14558  eachBefore: node_eachBefore,
14559  sum: node_sum,
14560  sort: node_sort,
14561  path: node_path,
14562  ancestors: node_ancestors,
14563  descendants: node_descendants,
14564  leaves: node_leaves,
14565  links: node_links,
14566  copy: node_copy
14567};
14568
14569var slice$3 = Array.prototype.slice;
14570
14571function shuffle$1(array) {
14572  var m = array.length,
14573      t,
14574      i;
14575
14576  while (m) {
14577    i = Math.random() * m-- | 0;
14578    t = array[m];
14579    array[m] = array[i];
14580    array[i] = t;
14581  }
14582
14583  return array;
14584}
14585
14586function enclose(circles) {
14587  var i = 0, n = (circles = shuffle$1(slice$3.call(circles))).length, B = [], p, e;
14588
14589  while (i < n) {
14590    p = circles[i];
14591    if (e && enclosesWeak(e, p)) ++i;
14592    else e = encloseBasis(B = extendBasis(B, p)), i = 0;
14593  }
14594
14595  return e;
14596}
14597
14598function extendBasis(B, p) {
14599  var i, j;
14600
14601  if (enclosesWeakAll(p, B)) return [p];
14602
14603  // If we get here then B must have at least one element.
14604  for (i = 0; i < B.length; ++i) {
14605    if (enclosesNot(p, B[i])
14606        && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
14607      return [B[i], p];
14608    }
14609  }
14610
14611  // If we get here then B must have at least two elements.
14612  for (i = 0; i < B.length - 1; ++i) {
14613    for (j = i + 1; j < B.length; ++j) {
14614      if (enclosesNot(encloseBasis2(B[i], B[j]), p)
14615          && enclosesNot(encloseBasis2(B[i], p), B[j])
14616          && enclosesNot(encloseBasis2(B[j], p), B[i])
14617          && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
14618        return [B[i], B[j], p];
14619      }
14620    }
14621  }
14622
14623  // If we get here then something is very wrong.
14624  throw new Error;
14625}
14626
14627function enclosesNot(a, b) {
14628  var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
14629  return dr < 0 || dr * dr < dx * dx + dy * dy;
14630}
14631
14632function enclosesWeak(a, b) {
14633  var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
14634  return dr > 0 && dr * dr > dx * dx + dy * dy;
14635}
14636
14637function enclosesWeakAll(a, B) {
14638  for (var i = 0; i < B.length; ++i) {
14639    if (!enclosesWeak(a, B[i])) {
14640      return false;
14641    }
14642  }
14643  return true;
14644}
14645
14646function encloseBasis(B) {
14647  switch (B.length) {
14648    case 1: return encloseBasis1(B[0]);
14649    case 2: return encloseBasis2(B[0], B[1]);
14650    case 3: return encloseBasis3(B[0], B[1], B[2]);
14651  }
14652}
14653
14654function encloseBasis1(a) {
14655  return {
14656    x: a.x,
14657    y: a.y,
14658    r: a.r
14659  };
14660}
14661
14662function encloseBasis2(a, b) {
14663  var x1 = a.x, y1 = a.y, r1 = a.r,
14664      x2 = b.x, y2 = b.y, r2 = b.r,
14665      x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
14666      l = Math.sqrt(x21 * x21 + y21 * y21);
14667  return {
14668    x: (x1 + x2 + x21 / l * r21) / 2,
14669    y: (y1 + y2 + y21 / l * r21) / 2,
14670    r: (l + r1 + r2) / 2
14671  };
14672}
14673
14674function encloseBasis3(a, b, c) {
14675  var x1 = a.x, y1 = a.y, r1 = a.r,
14676      x2 = b.x, y2 = b.y, r2 = b.r,
14677      x3 = c.x, y3 = c.y, r3 = c.r,
14678      a2 = x1 - x2,
14679      a3 = x1 - x3,
14680      b2 = y1 - y2,
14681      b3 = y1 - y3,
14682      c2 = r2 - r1,
14683      c3 = r3 - r1,
14684      d1 = x1 * x1 + y1 * y1 - r1 * r1,
14685      d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
14686      d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
14687      ab = a3 * b2 - a2 * b3,
14688      xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
14689      xb = (b3 * c2 - b2 * c3) / ab,
14690      ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
14691      yb = (a2 * c3 - a3 * c2) / ab,
14692      A = xb * xb + yb * yb - 1,
14693      B = 2 * (r1 + xa * xb + ya * yb),
14694      C = xa * xa + ya * ya - r1 * r1,
14695      r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
14696  return {
14697    x: x1 + xa + xb * r,
14698    y: y1 + ya + yb * r,
14699    r: r
14700  };
14701}
14702
14703function place(a, b, c) {
14704  var ax = a.x,
14705      ay = a.y,
14706      da = b.r + c.r,
14707      db = a.r + c.r,
14708      dx = b.x - ax,
14709      dy = b.y - ay,
14710      dc = dx * dx + dy * dy;
14711  if (dc) {
14712    var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
14713        y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
14714    c.x = ax + x * dx + y * dy;
14715    c.y = ay + x * dy - y * dx;
14716  } else {
14717    c.x = ax + db;
14718    c.y = ay;
14719  }
14720}
14721
14722function intersects(a, b) {
14723  var dx = b.x - a.x,
14724      dy = b.y - a.y,
14725      dr = a.r + b.r;
14726  return dr * dr - 1e-6 > dx * dx + dy * dy;
14727}
14728
14729function score(node) {
14730  var a = node._,
14731      b = node.next._,
14732      ab = a.r + b.r,
14733      dx = (a.x * b.r + b.x * a.r) / ab,
14734      dy = (a.y * b.r + b.y * a.r) / ab;
14735  return dx * dx + dy * dy;
14736}
14737
14738function Node$1(circle) {
14739  this._ = circle;
14740  this.next = null;
14741  this.previous = null;
14742}
14743
14744function packEnclose(circles) {
14745  if (!(n = circles.length)) return 0;
14746
14747  var a, b, c, n, aa, ca, i, j, k, sj, sk;
14748
14749  // Place the first circle.
14750  a = circles[0], a.x = 0, a.y = 0;
14751  if (!(n > 1)) return a.r;
14752
14753  // Place the second circle.
14754  b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
14755  if (!(n > 2)) return a.r + b.r;
14756
14757  // Place the third circle.
14758  place(b, a, c = circles[2]);
14759
14760  // Initialize the front-chain using the first three circles a, b and c.
14761  a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
14762  a.next = c.previous = b;
14763  b.next = a.previous = c;
14764  c.next = b.previous = a;
14765
14766  // Attempt to place each remaining circle…
14767  pack: for (i = 3; i < n; ++i) {
14768    place(a._, b._, c = circles[i]), c = new Node$1(c);
14769
14770    // Find the closest intersecting circle on the front-chain, if any.
14771    // “Closeness” is determined by linear distance along the front-chain.
14772    // “Ahead” or “behind” is likewise determined by linear distance.
14773    j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
14774    do {
14775      if (sj <= sk) {
14776        if (intersects(j._, c._)) {
14777          b = j, a.next = b, b.previous = a, --i;
14778          continue pack;
14779        }
14780        sj += j._.r, j = j.next;
14781      } else {
14782        if (intersects(k._, c._)) {
14783          a = k, a.next = b, b.previous = a, --i;
14784          continue pack;
14785        }
14786        sk += k._.r, k = k.previous;
14787      }
14788    } while (j !== k.next);
14789
14790    // Success! Insert the new circle c between a and b.
14791    c.previous = a, c.next = b, a.next = b.previous = b = c;
14792
14793    // Compute the new closest circle pair to the centroid.
14794    aa = score(a);
14795    while ((c = c.next) !== b) {
14796      if ((ca = score(c)) < aa) {
14797        a = c, aa = ca;
14798      }
14799    }
14800    b = a.next;
14801  }
14802
14803  // Compute the enclosing circle of the front chain.
14804  a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
14805
14806  // Translate the circles to put the enclosing circle around the origin.
14807  for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
14808
14809  return c.r;
14810}
14811
14812function siblings(circles) {
14813  packEnclose(circles);
14814  return circles;
14815}
14816
14817function optional(f) {
14818  return f == null ? null : required(f);
14819}
14820
14821function required(f) {
14822  if (typeof f !== "function") throw new Error;
14823  return f;
14824}
14825
14826function constantZero() {
14827  return 0;
14828}
14829
14830function constant$8(x) {
14831  return function() {
14832    return x;
14833  };
14834}
14835
14836function defaultRadius$1(d) {
14837  return Math.sqrt(d.value);
14838}
14839
14840function index$2() {
14841  var radius = null,
14842      dx = 1,
14843      dy = 1,
14844      padding = constantZero;
14845
14846  function pack(root) {
14847    root.x = dx / 2, root.y = dy / 2;
14848    if (radius) {
14849      root.eachBefore(radiusLeaf(radius))
14850          .eachAfter(packChildren(padding, 0.5))
14851          .eachBefore(translateChild(1));
14852    } else {
14853      root.eachBefore(radiusLeaf(defaultRadius$1))
14854          .eachAfter(packChildren(constantZero, 1))
14855          .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
14856          .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
14857    }
14858    return root;
14859  }
14860
14861  pack.radius = function(x) {
14862    return arguments.length ? (radius = optional(x), pack) : radius;
14863  };
14864
14865  pack.size = function(x) {
14866    return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
14867  };
14868
14869  pack.padding = function(x) {
14870    return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
14871  };
14872
14873  return pack;
14874}
14875
14876function radiusLeaf(radius) {
14877  return function(node) {
14878    if (!node.children) {
14879      node.r = Math.max(0, +radius(node) || 0);
14880    }
14881  };
14882}
14883
14884function packChildren(padding, k) {
14885  return function(node) {
14886    if (children = node.children) {
14887      var children,
14888          i,
14889          n = children.length,
14890          r = padding(node) * k || 0,
14891          e;
14892
14893      if (r) for (i = 0; i < n; ++i) children[i].r += r;
14894      e = packEnclose(children);
14895      if (r) for (i = 0; i < n; ++i) children[i].r -= r;
14896      node.r = e + r;
14897    }
14898  };
14899}
14900
14901function translateChild(k) {
14902  return function(node) {
14903    var parent = node.parent;
14904    node.r *= k;
14905    if (parent) {
14906      node.x = parent.x + k * node.x;
14907      node.y = parent.y + k * node.y;
14908    }
14909  };
14910}
14911
14912function roundNode(node) {
14913  node.x0 = Math.round(node.x0);
14914  node.y0 = Math.round(node.y0);
14915  node.x1 = Math.round(node.x1);
14916  node.y1 = Math.round(node.y1);
14917}
14918
14919function treemapDice(parent, x0, y0, x1, y1) {
14920  var nodes = parent.children,
14921      node,
14922      i = -1,
14923      n = nodes.length,
14924      k = parent.value && (x1 - x0) / parent.value;
14925
14926  while (++i < n) {
14927    node = nodes[i], node.y0 = y0, node.y1 = y1;
14928    node.x0 = x0, node.x1 = x0 += node.value * k;
14929  }
14930}
14931
14932function partition() {
14933  var dx = 1,
14934      dy = 1,
14935      padding = 0,
14936      round = false;
14937
14938  function partition(root) {
14939    var n = root.height + 1;
14940    root.x0 =
14941    root.y0 = padding;
14942    root.x1 = dx;
14943    root.y1 = dy / n;
14944    root.eachBefore(positionNode(dy, n));
14945    if (round) root.eachBefore(roundNode);
14946    return root;
14947  }
14948
14949  function positionNode(dy, n) {
14950    return function(node) {
14951      if (node.children) {
14952        treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
14953      }
14954      var x0 = node.x0,
14955          y0 = node.y0,
14956          x1 = node.x1 - padding,
14957          y1 = node.y1 - padding;
14958      if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
14959      if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
14960      node.x0 = x0;
14961      node.y0 = y0;
14962      node.x1 = x1;
14963      node.y1 = y1;
14964    };
14965  }
14966
14967  partition.round = function(x) {
14968    return arguments.length ? (round = !!x, partition) : round;
14969  };
14970
14971  partition.size = function(x) {
14972    return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
14973  };
14974
14975  partition.padding = function(x) {
14976    return arguments.length ? (padding = +x, partition) : padding;
14977  };
14978
14979  return partition;
14980}
14981
14982var keyPrefix$1 = "$";
14983var preroot = {depth: -1};
14984var ambiguous = {};
14985
14986function defaultId(d) {
14987  return d.id;
14988}
14989
14990function defaultParentId(d) {
14991  return d.parentId;
14992}
14993
14994function stratify() {
14995  var id = defaultId,
14996      parentId = defaultParentId;
14997
14998  function stratify(data) {
14999    var d,
15000        i,
15001        n = data.length,
15002        root,
15003        parent,
15004        node,
15005        nodes = new Array(n),
15006        nodeId,
15007        nodeKey,
15008        nodeByKey = {};
15009
15010    for (i = 0; i < n; ++i) {
15011      d = data[i], node = nodes[i] = new Node(d);
15012      if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
15013        nodeKey = keyPrefix$1 + (node.id = nodeId);
15014        nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
15015      }
15016    }
15017
15018    for (i = 0; i < n; ++i) {
15019      node = nodes[i], nodeId = parentId(data[i], i, data);
15020      if (nodeId == null || !(nodeId += "")) {
15021        if (root) throw new Error("multiple roots");
15022        root = node;
15023      } else {
15024        parent = nodeByKey[keyPrefix$1 + nodeId];
15025        if (!parent) throw new Error("missing: " + nodeId);
15026        if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
15027        if (parent.children) parent.children.push(node);
15028        else parent.children = [node];
15029        node.parent = parent;
15030      }
15031    }
15032
15033    if (!root) throw new Error("no root");
15034    root.parent = preroot;
15035    root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
15036    root.parent = null;
15037    if (n > 0) throw new Error("cycle");
15038
15039    return root;
15040  }
15041
15042  stratify.id = function(x) {
15043    return arguments.length ? (id = required(x), stratify) : id;
15044  };
15045
15046  stratify.parentId = function(x) {
15047    return arguments.length ? (parentId = required(x), stratify) : parentId;
15048  };
15049
15050  return stratify;
15051}
15052
15053function defaultSeparation$1(a, b) {
15054  return a.parent === b.parent ? 1 : 2;
15055}
15056
15057// function radialSeparation(a, b) {
15058//   return (a.parent === b.parent ? 1 : 2) / a.depth;
15059// }
15060
15061// This function is used to traverse the left contour of a subtree (or
15062// subforest). It returns the successor of v on this contour. This successor is
15063// either given by the leftmost child of v or by the thread of v. The function
15064// returns null if and only if v is on the highest level of its subtree.
15065function nextLeft(v) {
15066  var children = v.children;
15067  return children ? children[0] : v.t;
15068}
15069
15070// This function works analogously to nextLeft.
15071function nextRight(v) {
15072  var children = v.children;
15073  return children ? children[children.length - 1] : v.t;
15074}
15075
15076// Shifts the current subtree rooted at w+. This is done by increasing
15077// prelim(w+) and mod(w+) by shift.
15078function moveSubtree(wm, wp, shift) {
15079  var change = shift / (wp.i - wm.i);
15080  wp.c -= change;
15081  wp.s += shift;
15082  wm.c += change;
15083  wp.z += shift;
15084  wp.m += shift;
15085}
15086
15087// All other shifts, applied to the smaller subtrees between w- and w+, are
15088// performed by this function. To prepare the shifts, we have to adjust
15089// change(w+), shift(w+), and change(w-).
15090function executeShifts(v) {
15091  var shift = 0,
15092      change = 0,
15093      children = v.children,
15094      i = children.length,
15095      w;
15096  while (--i >= 0) {
15097    w = children[i];
15098    w.z += shift;
15099    w.m += shift;
15100    shift += w.s + (change += w.c);
15101  }
15102}
15103
15104// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
15105// returns the specified (default) ancestor.
15106function nextAncestor(vim, v, ancestor) {
15107  return vim.a.parent === v.parent ? vim.a : ancestor;
15108}
15109
15110function TreeNode(node, i) {
15111  this._ = node;
15112  this.parent = null;
15113  this.children = null;
15114  this.A = null; // default ancestor
15115  this.a = this; // ancestor
15116  this.z = 0; // prelim
15117  this.m = 0; // mod
15118  this.c = 0; // change
15119  this.s = 0; // shift
15120  this.t = null; // thread
15121  this.i = i; // number
15122}
15123
15124TreeNode.prototype = Object.create(Node.prototype);
15125
15126function treeRoot(root) {
15127  var tree = new TreeNode(root, 0),
15128      node,
15129      nodes = [tree],
15130      child,
15131      children,
15132      i,
15133      n;
15134
15135  while (node = nodes.pop()) {
15136    if (children = node._.children) {
15137      node.children = new Array(n = children.length);
15138      for (i = n - 1; i >= 0; --i) {
15139        nodes.push(child = node.children[i] = new TreeNode(children[i], i));
15140        child.parent = node;
15141      }
15142    }
15143  }
15144
15145  (tree.parent = new TreeNode(null, 0)).children = [tree];
15146  return tree;
15147}
15148
15149// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
15150function tree() {
15151  var separation = defaultSeparation$1,
15152      dx = 1,
15153      dy = 1,
15154      nodeSize = null;
15155
15156  function tree(root) {
15157    var t = treeRoot(root);
15158
15159    // Compute the layout using Buchheim et al.’s algorithm.
15160    t.eachAfter(firstWalk), t.parent.m = -t.z;
15161    t.eachBefore(secondWalk);
15162
15163    // If a fixed node size is specified, scale x and y.
15164    if (nodeSize) root.eachBefore(sizeNode);
15165
15166    // If a fixed tree size is specified, scale x and y based on the extent.
15167    // Compute the left-most, right-most, and depth-most nodes for extents.
15168    else {
15169      var left = root,
15170          right = root,
15171          bottom = root;
15172      root.eachBefore(function(node) {
15173        if (node.x < left.x) left = node;
15174        if (node.x > right.x) right = node;
15175        if (node.depth > bottom.depth) bottom = node;
15176      });
15177      var s = left === right ? 1 : separation(left, right) / 2,
15178          tx = s - left.x,
15179          kx = dx / (right.x + s + tx),
15180          ky = dy / (bottom.depth || 1);
15181      root.eachBefore(function(node) {
15182        node.x = (node.x + tx) * kx;
15183        node.y = node.depth * ky;
15184      });
15185    }
15186
15187    return root;
15188  }
15189
15190  // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
15191  // applied recursively to the children of v, as well as the function
15192  // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
15193  // node v is placed to the midpoint of its outermost children.
15194  function firstWalk(v) {
15195    var children = v.children,
15196        siblings = v.parent.children,
15197        w = v.i ? siblings[v.i - 1] : null;
15198    if (children) {
15199      executeShifts(v);
15200      var midpoint = (children[0].z + children[children.length - 1].z) / 2;
15201      if (w) {
15202        v.z = w.z + separation(v._, w._);
15203        v.m = v.z - midpoint;
15204      } else {
15205        v.z = midpoint;
15206      }
15207    } else if (w) {
15208      v.z = w.z + separation(v._, w._);
15209    }
15210    v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
15211  }
15212
15213  // Computes all real x-coordinates by summing up the modifiers recursively.
15214  function secondWalk(v) {
15215    v._.x = v.z + v.parent.m;
15216    v.m += v.parent.m;
15217  }
15218
15219  // The core of the algorithm. Here, a new subtree is combined with the
15220  // previous subtrees. Threads are used to traverse the inside and outside
15221  // contours of the left and right subtree up to the highest common level. The
15222  // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
15223  // superscript o means outside and i means inside, the subscript - means left
15224  // subtree and + means right subtree. For summing up the modifiers along the
15225  // contour, we use respective variables si+, si-, so-, and so+. Whenever two
15226  // nodes of the inside contours conflict, we compute the left one of the
15227  // greatest uncommon ancestors using the function ANCESTOR and call MOVE
15228  // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
15229  // Finally, we add a new thread (if necessary).
15230  function apportion(v, w, ancestor) {
15231    if (w) {
15232      var vip = v,
15233          vop = v,
15234          vim = w,
15235          vom = vip.parent.children[0],
15236          sip = vip.m,
15237          sop = vop.m,
15238          sim = vim.m,
15239          som = vom.m,
15240          shift;
15241      while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
15242        vom = nextLeft(vom);
15243        vop = nextRight(vop);
15244        vop.a = v;
15245        shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
15246        if (shift > 0) {
15247          moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
15248          sip += shift;
15249          sop += shift;
15250        }
15251        sim += vim.m;
15252        sip += vip.m;
15253        som += vom.m;
15254        sop += vop.m;
15255      }
15256      if (vim && !nextRight(vop)) {
15257        vop.t = vim;
15258        vop.m += sim - sop;
15259      }
15260      if (vip && !nextLeft(vom)) {
15261        vom.t = vip;
15262        vom.m += sip - som;
15263        ancestor = v;
15264      }
15265    }
15266    return ancestor;
15267  }
15268
15269  function sizeNode(node) {
15270    node.x *= dx;
15271    node.y = node.depth * dy;
15272  }
15273
15274  tree.separation = function(x) {
15275    return arguments.length ? (separation = x, tree) : separation;
15276  };
15277
15278  tree.size = function(x) {
15279    return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
15280  };
15281
15282  tree.nodeSize = function(x) {
15283    return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
15284  };
15285
15286  return tree;
15287}
15288
15289function treemapSlice(parent, x0, y0, x1, y1) {
15290  var nodes = parent.children,
15291      node,
15292      i = -1,
15293      n = nodes.length,
15294      k = parent.value && (y1 - y0) / parent.value;
15295
15296  while (++i < n) {
15297    node = nodes[i], node.x0 = x0, node.x1 = x1;
15298    node.y0 = y0, node.y1 = y0 += node.value * k;
15299  }
15300}
15301
15302var phi = (1 + Math.sqrt(5)) / 2;
15303
15304function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
15305  var rows = [],
15306      nodes = parent.children,
15307      row,
15308      nodeValue,
15309      i0 = 0,
15310      i1 = 0,
15311      n = nodes.length,
15312      dx, dy,
15313      value = parent.value,
15314      sumValue,
15315      minValue,
15316      maxValue,
15317      newRatio,
15318      minRatio,
15319      alpha,
15320      beta;
15321
15322  while (i0 < n) {
15323    dx = x1 - x0, dy = y1 - y0;
15324
15325    // Find the next non-empty node.
15326    do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
15327    minValue = maxValue = sumValue;
vendor: 9,012 bytes, lines 15328-15639
15328    alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
15329    beta = sumValue * sumValue * alpha;
15330    minRatio = Math.max(maxValue / beta, beta / minValue);
15331
15332    // Keep adding nodes while the aspect ratio maintains or improves.
15333    for (; i1 < n; ++i1) {
15334      sumValue += nodeValue = nodes[i1].value;
15335      if (nodeValue < minValue) minValue = nodeValue;
15336      if (nodeValue > maxValue) maxValue = nodeValue;
15337      beta = sumValue * sumValue * alpha;
15338      newRatio = Math.max(maxValue / beta, beta / minValue);
15339      if (newRatio > minRatio) { sumValue -= nodeValue; break; }
15340      minRatio = newRatio;
15341    }
15342
15343    // Position and record the row orientation.
15344    rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
15345    if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
15346    else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
15347    value -= sumValue, i0 = i1;
15348  }
15349
15350  return rows;
15351}
15352
15353var squarify = (function custom(ratio) {
15354
15355  function squarify(parent, x0, y0, x1, y1) {
15356    squarifyRatio(ratio, parent, x0, y0, x1, y1);
15357  }
15358
15359  squarify.ratio = function(x) {
15360    return custom((x = +x) > 1 ? x : 1);
15361  };
15362
15363  return squarify;
15364})(phi);
15365
15366function index$3() {
15367  var tile = squarify,
15368      round = false,
15369      dx = 1,
15370      dy = 1,
15371      paddingStack = [0],
15372      paddingInner = constantZero,
15373      paddingTop = constantZero,
15374      paddingRight = constantZero,
15375      paddingBottom = constantZero,
15376      paddingLeft = constantZero;
15377
15378  function treemap(root) {
15379    root.x0 =
15380    root.y0 = 0;
15381    root.x1 = dx;
15382    root.y1 = dy;
15383    root.eachBefore(positionNode);
15384    paddingStack = [0];
15385    if (round) root.eachBefore(roundNode);
15386    return root;
15387  }
15388
15389  function positionNode(node) {
15390    var p = paddingStack[node.depth],
15391        x0 = node.x0 + p,
15392        y0 = node.y0 + p,
15393        x1 = node.x1 - p,
15394        y1 = node.y1 - p;
15395    if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
15396    if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
15397    node.x0 = x0;
15398    node.y0 = y0;
15399    node.x1 = x1;
15400    node.y1 = y1;
15401    if (node.children) {
15402      p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
15403      x0 += paddingLeft(node) - p;
15404      y0 += paddingTop(node) - p;
15405      x1 -= paddingRight(node) - p;
15406      y1 -= paddingBottom(node) - p;
15407      if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
15408      if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
15409      tile(node, x0, y0, x1, y1);
15410    }
15411  }
15412
15413  treemap.round = function(x) {
15414    return arguments.length ? (round = !!x, treemap) : round;
15415  };
15416
15417  treemap.size = function(x) {
15418    return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
15419  };
15420
15421  treemap.tile = function(x) {
15422    return arguments.length ? (tile = required(x), treemap) : tile;
15423  };
15424
15425  treemap.padding = function(x) {
15426    return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
15427  };
15428
15429  treemap.paddingInner = function(x) {
15430    return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
15431  };
15432
15433  treemap.paddingOuter = function(x) {
15434    return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
15435  };
15436
15437  treemap.paddingTop = function(x) {
15438    return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
15439  };
15440
15441  treemap.paddingRight = function(x) {
15442    return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
15443  };
15444
15445  treemap.paddingBottom = function(x) {
15446    return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
15447  };
15448
15449  treemap.paddingLeft = function(x) {
15450    return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
15451  };
15452
15453  return treemap;
15454}
15455
15456function binary(parent, x0, y0, x1, y1) {
15457  var nodes = parent.children,
15458      i, n = nodes.length,
15459      sum, sums = new Array(n + 1);
15460
15461  for (sums[0] = sum = i = 0; i < n; ++i) {
15462    sums[i + 1] = sum += nodes[i].value;
15463  }
15464
15465  partition(0, n, parent.value, x0, y0, x1, y1);
15466
15467  function partition(i, j, value, x0, y0, x1, y1) {
15468    if (i >= j - 1) {
15469      var node = nodes[i];
15470      node.x0 = x0, node.y0 = y0;
15471      node.x1 = x1, node.y1 = y1;
15472      return;
15473    }
15474
15475    var valueOffset = sums[i],
15476        valueTarget = (value / 2) + valueOffset,
15477        k = i + 1,
15478        hi = j - 1;
15479
15480    while (k < hi) {
15481      var mid = k + hi >>> 1;
15482      if (sums[mid] < valueTarget) k = mid + 1;
15483      else hi = mid;
15484    }
15485
15486    if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
15487
15488    var valueLeft = sums[k] - valueOffset,
15489        valueRight = value - valueLeft;
15490
15491    if ((x1 - x0) > (y1 - y0)) {
15492      var xk = (x0 * valueRight + x1 * valueLeft) / value;
15493      partition(i, k, valueLeft, x0, y0, xk, y1);
15494      partition(k, j, valueRight, xk, y0, x1, y1);
15495    } else {
15496      var yk = (y0 * valueRight + y1 * valueLeft) / value;
15497      partition(i, k, valueLeft, x0, y0, x1, yk);
15498      partition(k, j, valueRight, x0, yk, x1, y1);
15499    }
15500  }
15501}
15502
15503function sliceDice(parent, x0, y0, x1, y1) {
15504  (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
15505}
15506
15507var resquarify = (function custom(ratio) {
15508
15509  function resquarify(parent, x0, y0, x1, y1) {
15510    if ((rows = parent._squarify) && (rows.ratio === ratio)) {
15511      var rows,
15512          row,
15513          nodes,
15514          i,
15515          j = -1,
15516          n,
15517          m = rows.length,
15518          value = parent.value;
15519
15520      while (++j < m) {
15521        row = rows[j], nodes = row.children;
15522        for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
15523        if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
15524        else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
15525        value -= row.value;
15526      }
15527    } else {
15528      parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
15529      rows.ratio = ratio;
15530    }
15531  }
15532
15533  resquarify.ratio = function(x) {
15534    return custom((x = +x) > 1 ? x : 1);
15535  };
15536
15537  return resquarify;
15538})(phi);
15539
15540function area$1(polygon) {
15541  var i = -1,
15542      n = polygon.length,
15543      a,
15544      b = polygon[n - 1],
15545      area = 0;
15546
15547  while (++i < n) {
15548    a = b;
15549    b = polygon[i];
15550    area += a[1] * b[0] - a[0] * b[1];
15551  }
15552
15553  return area / 2;
15554}
15555
15556function centroid$1(polygon) {
15557  var i = -1,
15558      n = polygon.length,
15559      x = 0,
15560      y = 0,
15561      a,
15562      b = polygon[n - 1],
15563      c,
15564      k = 0;
15565
15566  while (++i < n) {
15567    a = b;
15568    b = polygon[i];
15569    k += c = a[0] * b[1] - b[0] * a[1];
15570    x += (a[0] + b[0]) * c;
15571    y += (a[1] + b[1]) * c;
15572  }
15573
15574  return k *= 3, [x / k, y / k];
15575}
15576
15577// Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
15578// the 3D cross product in a quadrant I Cartesian coordinate system (+x is
15579// right, +y is up). Returns a positive value if ABC is counter-clockwise,
15580// negative if clockwise, and zero if the points are collinear.
15581function cross$1(a, b, c) {
15582  return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
15583}
15584
15585function lexicographicOrder(a, b) {
15586  return a[0] - b[0] || a[1] - b[1];
15587}
15588
15589// Computes the upper convex hull per the monotone chain algorithm.
15590// Assumes points.length >= 3, is sorted by x, unique in y.
15591// Returns an array of indices into points in left-to-right order.
15592function computeUpperHullIndexes(points) {
15593  var n = points.length,
15594      indexes = [0, 1],
15595      size = 2;
15596
15597  for (var i = 2; i < n; ++i) {
15598    while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
15599    indexes[size++] = i;
15600  }
15601
15602  return indexes.slice(0, size); // remove popped points
15603}
15604
15605function hull(points) {
15606  if ((n = points.length) < 3) return null;
15607
15608  var i,
15609      n,
15610      sortedPoints = new Array(n),
15611      flippedPoints = new Array(n);
15612
15613  for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
15614  sortedPoints.sort(lexicographicOrder);
15615  for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
15616
15617  var upperIndexes = computeUpperHullIndexes(sortedPoints),
15618      lowerIndexes = computeUpperHullIndexes(flippedPoints);
15619
15620  // Construct the hull polygon, removing possible duplicate endpoints.
15621  var skipLeft = lowerIndexes[0] === upperIndexes[0],
15622      skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
15623      hull = [];
15624
15625  // Add upper hull in right-to-l order.
15626  // Then add lower hull in left-to-right order.
15627  for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
15628  for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
15629
15630  return hull;
15631}
15632
15633function contains$1(polygon, point) {
15634  var n = polygon.length,
15635      p = polygon[n - 1],
15636      x = point[0], y = point[1],
15637      x0 = p[0], y0 = p[1],
15638      x1, y1,
15639      inside = false;
15640
15641  for (var i = 0; i < n; ++i) {
15642    p = polygon[i], x1 = p[0], y1 = p[1];
15643    if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
15644    x0 = x1, y0 = y1;
15645  }
15646
15647  return inside;
15648}
15649
15650function length$2(polygon) {
15651  var i = -1,
15652      n = polygon.length,
15653      b = polygon[n - 1],
15654      xa,
15655      ya,
15656      xb = b[0],
15657      yb = b[1],
15658      perimeter = 0;
15659
15660  while (++i < n) {
15661    xa = xb;
15662    ya = yb;
15663    b = polygon[i];
15664    xb = b[0];
15665    yb = b[1];
15666    xa -= xb;
15667    ya -= yb;
15668    perimeter += Math.sqrt(xa * xa + ya * ya);
15669  }
15670
15671  return perimeter;
15672}
15673
15674var slice$4 = [].slice;
15675
15676var noabort = {};
15677
15678function Queue(size) {
15679  this._size = size;
15680  this._call =
15681  this._error = null;
15682  this._tasks = [];
15683  this._data = [];
15684  this._waiting =
15685  this._active =
15686  this._ended =
15687  this._start = 0; // inside a synchronous task callback?
15688}
15689
15690Queue.prototype = queue.prototype = {
15691  constructor: Queue,
15692  defer: function(callback) {
15693    if (typeof callback !== "function") throw new Error("invalid callback");
15694    if (this._call) throw new Error("defer after await");
15695    if (this._error != null) return this;
15696    var t = slice$4.call(arguments, 1);
15697    t.push(callback);
15698    ++this._waiting, this._tasks.push(t);
15699    poke$1(this);
15700    return this;
15701  },
15702  abort: function() {
15703    if (this._error == null) abort(this, new Error("abort"));
15704    return this;
15705  },
15706  await: function(callback) {
15707    if (typeof callback !== "function") throw new Error("invalid callback");
15708    if (this._call) throw new Error("multiple await");
15709    this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
15710    maybeNotify(this);
15711    return this;
15712  },
15713  awaitAll: function(callback) {
15714    if (typeof callback !== "function") throw new Error("invalid callback");
15715    if (this._call) throw new Error("multiple await");
15716    this._call = callback;
15717    maybeNotify(this);
15718    return this;
15719  }
15720};
15721
15722function poke$1(q) {
15723  if (!q._start) {
15724    try { start$1(q); } // let the current task complete
15725    catch (e) {
15726      if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
15727      else if (!q._data) throw e; // await callback errored synchronously
15728    }
15729  }
15730}
15731
15732function start$1(q) {
15733  while (q._start = q._waiting && q._active < q._size) {
15734    var i = q._ended + q._active,
15735        t = q._tasks[i],
15736        j = t.length - 1,
15737        c = t[j];
15738    t[j] = end(q, i);
15739    --q._waiting, ++q._active;
15740    t = c.apply(null, t);
15741    if (!q._tasks[i]) continue; // task finished synchronously
15742    q._tasks[i] = t || noabort;
15743  }
15744}
15745
15746function end(q, i) {
15747  return function(e, r) {
15748    if (!q._tasks[i]) return; // ignore multiple callbacks
15749    --q._active, ++q._ended;
15750    q._tasks[i] = null;
15751    if (q._error != null) return; // ignore secondary errors
15752    if (e != null) {
15753      abort(q, e);
15754    } else {
15755      q._data[i] = r;
15756      if (q._waiting) poke$1(q);
15757      else maybeNotify(q);
15758    }
15759  };
15760}
15761
15762function abort(q, e) {
15763  var i = q._tasks.length, t;
15764  q._error = e; // ignore active callbacks
15765  q._data = undefined; // allow gc
15766  q._waiting = NaN; // prevent starting
15767
15768  while (--i >= 0) {
15769    if (t = q._tasks[i]) {
15770      q._tasks[i] = null;
15771      if (t.abort) {
15772        try { t.abort(); }
15773        catch (e) { /* ignore */ }
15774      }
15775    }
15776  }
15777
15778  q._active = NaN; // allow notification
15779  maybeNotify(q);
15780}
15781
15782function maybeNotify(q) {
15783  if (!q._active && q._call) {
15784    var d = q._data;
15785    q._data = undefined; // allow gc
15786    q._call(q._error, d);
15787  }
15788}
15789
15790function queue(concurrency) {
15791  if (concurrency == null) concurrency = Infinity;
15792  else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
15793  return new Queue(concurrency);
15794}
15795
15796function defaultSource$1() {
15797  return Math.random();
15798}
15799
15800var uniform = (function sourceRandomUniform(source) {
15801  function randomUniform(min, max) {
15802    min = min == null ? 0 : +min;
15803    max = max == null ? 1 : +max;
15804    if (arguments.length === 1) max = min, min = 0;
15805    else max -= min;
15806    return function() {
15807      return source() * max + min;
15808    };
15809  }
15810
15811  randomUniform.source = sourceRandomUniform;
15812
15813  return randomUniform;
15814})(defaultSource$1);
15815
15816var normal = (function sourceRandomNormal(source) {
15817  function randomNormal(mu, sigma) {
15818    var x, r;
15819    mu = mu == null ? 0 : +mu;
15820    sigma = sigma == null ? 1 : +sigma;
15821    return function() {
15822      var y;
15823
15824      // If available, use the second previously-generated uniform random.
15825      if (x != null) y = x, x = null;
15826
15827      // Otherwise, generate a new x and y.
15828      else do {
15829        x = source() * 2 - 1;
15830        y = source() * 2 - 1;
15831        r = x * x + y * y;
15832      } while (!r || r > 1);
15833
15834      return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
15835    };
15836  }
15837
15838  randomNormal.source = sourceRandomNormal;
15839
15840  return randomNormal;
15841})(defaultSource$1);
15842
15843var logNormal = (function sourceRandomLogNormal(source) {
15844  function randomLogNormal() {
15845    var randomNormal = normal.source(source).apply(this, arguments);
15846    return function() {
15847      return Math.exp(randomNormal());
15848    };
15849  }
15850
15851  randomLogNormal.source = sourceRandomLogNormal;
15852
15853  return randomLogNormal;
15854})(defaultSource$1);
15855
15856var irwinHall = (function sourceRandomIrwinHall(source) {
15857  function randomIrwinHall(n) {
15858    return function() {
15859      for (var sum = 0, i = 0; i < n; ++i) sum += source();
15860      return sum;
15861    };
15862  }
15863
15864  randomIrwinHall.source = sourceRandomIrwinHall;
15865
15866  return randomIrwinHall;
15867})(defaultSource$1);
15868
15869var bates = (function sourceRandomBates(source) {
15870  function randomBates(n) {
15871    var randomIrwinHall = irwinHall.source(source)(n);
15872    return function() {
15873      return randomIrwinHall() / n;
15874    };
15875  }
15876
15877  randomBates.source = sourceRandomBates;
15878
15879  return randomBates;
15880})(defaultSource$1);
15881
15882var exponential$1 = (function sourceRandomExponential(source) {
15883  function randomExponential(lambda) {
15884    return function() {
15885      return -Math.log(1 - source()) / lambda;
15886    };
15887  }
15888
15889  randomExponential.source = sourceRandomExponential;
15890
15891  return randomExponential;
15892})(defaultSource$1);
15893
15894function request(url, callback) {
15895  var request,
15896      event = dispatch("beforesend", "progress", "load", "error"),
15897      mimeType,
15898      headers = map$1(),
15899      xhr = new XMLHttpRequest,
15900      user = null,
15901      password = null,
15902      response,
15903      responseType,
15904      timeout = 0;
15905
15906  // If IE does not support CORS, use XDomainRequest.
15907  if (typeof XDomainRequest !== "undefined"
15908      && !("withCredentials" in xhr)
15909      && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
15910
15911  "onload" in xhr
15912      ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
15913      : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
15914
15915  function respond(o) {
15916    var status = xhr.status, result;
15917    if (!status && hasResponse(xhr)
15918        || status >= 200 && status < 300
15919        || status === 304) {
15920      if (response) {
15921        try {
15922          result = response.call(request, xhr);
15923        } catch (e) {
15924          event.call("error", request, e);
15925          return;
15926        }
15927      } else {
15928        result = xhr;
15929      }
15930      event.call("load", request, result);
15931    } else {
15932      event.call("error", request, o);
15933    }
15934  }
15935
15936  xhr.onprogress = function(e) {
15937    event.call("progress", request, e);
15938  };
15939
15940  request = {
15941    header: function(name, value) {
15942      name = (name + "").toLowerCase();
15943      if (arguments.length < 2) return headers.get(name);
15944      if (value == null) headers.remove(name);
15945      else headers.set(name, value + "");
15946      return request;
15947    },
15948
15949    // If mimeType is non-null and no Accept header is set, a default is used.
15950    mimeType: function(value) {
15951      if (!arguments.length) return mimeType;
15952      mimeType = value == null ? null : value + "";
15953      return request;
15954    },
15955
15956    // Specifies what type the response value should take;
15957    // for instance, arraybuffer, blob, document, or text.
15958    responseType: function(value) {
15959      if (!arguments.length) return responseType;
15960      responseType = value;
15961      return request;
15962    },
15963
15964    timeout: function(value) {
15965      if (!arguments.length) return timeout;
15966      timeout = +value;
15967      return request;
15968    },
15969
15970    user: function(value) {
15971      return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
15972    },
15973
15974    password: function(value) {
15975      return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
15976    },
15977
15978    // Specify how to convert the response content to a specific type;
15979    // changes the callback value on "load" events.
15980    response: function(value) {
15981      response = value;
15982      return request;
15983    },
15984
15985    // Alias for send("GET", …).
15986    get: function(data, callback) {
15987      return request.send("GET", data, callback);
15988    },
15989
15990    // Alias for send("POST", …).
15991    post: function(data, callback) {
15992      return request.send("POST", data, callback);
15993    },
15994
15995    // If callback is non-null, it will be used for error and load events.
15996    send: function(method, data, callback) {
15997      xhr.open(method, url, true, user, password);
15998      if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
15999      if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
16000      if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
16001      if (responseType != null) xhr.responseType = responseType;
16002      if (timeout > 0) xhr.timeout = timeout;
16003      if (callback == null && typeof data === "function") callback = data, data = null;
16004      if (callback != null && callback.length === 1) callback = fixCallback(callback);
16005      if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
16006      event.call("beforesend", request, xhr);
16007      xhr.send(data == null ? null : data);
16008      return request;
16009    },
16010
16011    abort: function() {
16012      xhr.abort();
16013      return request;
16014    },
16015
16016    on: function() {
16017      var value = event.on.apply(event, arguments);
16018      return value === event ? request : value;
16019    }
16020  };
16021
16022  if (callback != null) {
16023    if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
16024    return request.get(callback);
16025  }
16026
16027  return request;
16028}
16029
16030function fixCallback(callback) {
16031  return function(error, xhr) {
16032    callback(error == null ? xhr : null);
16033  };
16034}
16035
16036function hasResponse(xhr) {
16037  var type = xhr.responseType;
16038  return type && type !== "text"
16039      ? xhr.response // null on error
16040      : xhr.responseText; // "" on error
16041}
16042
16043function type$1(defaultMimeType, response) {
16044  return function(url, callback) {
16045    var r = request(url).mimeType(defaultMimeType).response(response);
16046    if (callback != null) {
16047      if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
16048      return r.get(callback);
16049    }
16050    return r;
16051  };
16052}
16053
16054var html = type$1("text/html", function(xhr) {
16055  return document.createRange().createContextualFragment(xhr.responseText);
16056});
16057
16058var json = type$1("application/json", function(xhr) {
16059  return JSON.parse(xhr.responseText);
16060});
16061
16062var text = type$1("text/plain", function(xhr) {
16063  return xhr.responseText;
16064});
16065
16066var xml = type$1("application/xml", function(xhr) {
16067  var xml = xhr.responseXML;
16068  if (!xml) throw new Error("parse error");
16069  return xml;
16070});
16071
16072function dsv$1(defaultMimeType, parse) {
16073  return function(url, row, callback) {
16074    if (arguments.length < 3) callback = row, row = null;
16075    var r = request(url).mimeType(defaultMimeType);
16076    r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
16077    r.row(row);
16078    return callback ? r.get(callback) : r;
16079  };
16080}
16081
16082function responseOf(parse, row) {
16083  return function(request$$1) {
16084    return parse(request$$1.responseText, row);
16085  };
16086}
16087
16088var csv$1 = dsv$1("text/csv", csvParse);
16089
16090var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
16091
16092var array$2 = Array.prototype;
16093
16094var map$3 = array$2.map;
16095var slice$5 = array$2.slice;
16096
16097var implicit = {name: "implicit"};
16098
16099function ordinal(range) {
16100  var index = map$1(),
16101      domain = [],
16102      unknown = implicit;
16103
16104  range = range == null ? [] : slice$5.call(range);
16105
16106  function scale(d) {
16107    var key = d + "", i = index.get(key);
16108    if (!i) {
16109      if (unknown !== implicit) return unknown;
16110      index.set(key, i = domain.push(d));
16111    }
16112    return range[(i - 1) % range.length];
16113  }
16114
16115  scale.domain = function(_) {
16116    if (!arguments.length) return domain.slice();
16117    domain = [], index = map$1();
16118    var i = -1, n = _.length, d, key;
16119    while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
16120    return scale;
16121  };
16122
16123  scale.range = function(_) {
16124    return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
16125  };
16126
16127  scale.unknown = function(_) {
16128    return arguments.length ? (unknown = _, scale) : unknown;
16129  };
16130
16131  scale.copy = function() {
16132    return ordinal()
16133        .domain(domain)
16134        .range(range)
16135        .unknown(unknown);
16136  };
16137
16138  return scale;
16139}
16140
16141function band() {
16142  var scale = ordinal().unknown(undefined),
16143      domain = scale.domain,
16144      ordinalRange = scale.range,
16145      range$$1 = [0, 1],
16146      step,
16147      bandwidth,
16148      round = false,
16149      paddingInner = 0,
16150      paddingOuter = 0,
16151      align = 0.5;
16152
16153  delete scale.unknown;
16154
16155  function rescale() {
16156    var n = domain().length,
16157        reverse = range$$1[1] < range$$1[0],
16158        start = range$$1[reverse - 0],
16159        stop = range$$1[1 - reverse];
16160    step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
16161    if (round) step = Math.floor(step);
16162    start += (stop - start - step * (n - paddingInner)) * align;
16163    bandwidth = step * (1 - paddingInner);
16164    if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
16165    var values = sequence(n).map(function(i) { return start + step * i; });
16166    return ordinalRange(reverse ? values.reverse() : values);
16167  }
16168
16169  scale.domain = function(_) {
16170    return arguments.length ? (domain(_), rescale()) : domain();
16171  };
16172
16173  scale.range = function(_) {
16174    return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
16175  };
16176
16177  scale.rangeRound = function(_) {
16178    return range$$1 = [+_[0], +_[1]], round = true, rescale();
16179  };
16180
16181  scale.bandwidth = function() {
16182    return bandwidth;
16183  };
16184
16185  scale.step = function() {
16186    return step;
16187  };
16188
16189  scale.round = function(_) {
16190    return arguments.length ? (round = !!_, rescale()) : round;
16191  };
16192
16193  scale.padding = function(_) {
16194    return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
16195  };
16196
16197  scale.paddingInner = function(_) {
16198    return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
16199  };
16200
16201  scale.paddingOuter = function(_) {
16202    return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
16203  };
16204
16205  scale.align = function(_) {
16206    return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
16207  };
16208
16209  scale.copy = function() {
16210    return band()
16211        .domain(domain())
16212        .range(range$$1)
16213        .round(round)
16214        .paddingInner(paddingInner)
16215        .paddingOuter(paddingOuter)
16216        .align(align);
16217  };
16218
16219  return rescale();
16220}
16221
16222function pointish(scale) {
16223  var copy = scale.copy;
16224
16225  scale.padding = scale.paddingOuter;
16226  delete scale.paddingInner;
16227  delete scale.paddingOuter;
16228
16229  scale.copy = function() {
16230    return pointish(copy());
16231  };
16232
16233  return scale;
16234}
16235
16236function point$1() {
16237  return pointish(band().paddingInner(1));
16238}
16239
16240function constant$9(x) {
16241  return function() {
16242    return x;
16243  };
16244}
16245
16246function number$2(x) {
16247  return +x;
16248}
16249
16250var unit = [0, 1];
16251
16252function deinterpolateLinear(a, b) {
16253  return (b -= (a = +a))
16254      ? function(x) { return (x - a) / b; }
16255      : constant$9(b);
16256}
16257
16258function deinterpolateClamp(deinterpolate) {
16259  return function(a, b) {
16260    var d = deinterpolate(a = +a, b = +b);
16261    return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
16262  };
16263}
16264
16265function reinterpolateClamp(reinterpolate) {
16266  return function(a, b) {
16267    var r = reinterpolate(a = +a, b = +b);
16268    return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
16269  };
16270}
16271
16272function bimap(domain, range, deinterpolate, reinterpolate) {
16273  var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
16274  i
16274f (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
16275  else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
16276  return function(x) { return r0(d0(x)); };
16277}
16278
16279function polymap(domain, range, deinterpolate, reinterpolate) {
16280  var j = Math.min(domain.length, range.length) - 1,
16281      d = new Array(j),
16282      r = new Array(j),
16283      i = -1;
16284
16285  // Reverse descending domains.
16286  if (domain[j] < domain[0]) {
16287    domain = domain.slice().reverse();
16288    range = range.slice().reverse();
16289  }
16290
16291  while (++i < j) {
16292    d[i] = deinterpolate(domain[i], domain[i + 1]);
16293    r[i] = reinterpolate(range[i], range[i + 1]);
16294  }
16295
16296  return function(x) {
16297    var i = bisectRight(domain, x, 1, j) - 1;
16298    return r[i](d[i](x));
16299  };
16300}
16301
16302function copy(source, target) {
16303  return target
16304      .domain(source.domain())
16305      .range(source.range())
16306      .interpolate(source.interpolate())
16307      .clamp(source.clamp());
16308}
16309
16310// deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
16311// reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
16312function continuous(deinterpolate, reinterpolate) {
16313  var domain = unit,
16314      range = unit,
16315      interpolate$$1 = interpolateValue,
16316      clamp = false,
16317      piecewise,
16318      output,
16319      input;
16320
16321  function rescale() {
16322    piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
16323    output = input = null;
16324    return scale;
16325  }
16326
16327  function scale(x) {
16328    return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
16329  }
16330
16331  scale.invert = function(y) {
16332    return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
16333  };
16334
16335  scale.domain = function(_) {
16336    return arguments.length ? (domain = map$3.call(_, number$2), rescale()) : domain.slice();
16337  };
16338
16339  scale.range = function(_) {
16340    return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
16341  };
16342
16343  scale.rangeRound = function(_) {
16344    return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
16345  };
16346
16347  scale.clamp = function(_) {
16348    return arguments.length ? (clamp = !!_, rescale()) : clamp;
16349  };
16350
16351  scale.interpolate = function(_) {
16352    return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
16353  };
16354
16355  return rescale();
16356}
16357
16358function tickFormat(domain, count, specifier) {
16359  var start = domain[0],
16360      stop = domain[domain.length - 1],
16361      step = tickStep(start, stop, count == null ? 10 : count),
16362      precision;
16363  specifier = formatSpecifier(specifier == null ? ",f" : specifier);
16364  switch (specifier.type) {
16365    case "s": {
16366      var value = Math.max(Math.abs(start), Math.abs(stop));
16367      if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
16368      return exports.formatPrefix(specifier, value);
16369    }
16370    case "":
16371    case "e":
16372    case "g":
16373    case "p":
16374    case "r": {
16375      if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
16376      break;
16377    }
16378    case "f":
16379    case "%": {
16380      if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
16381      break;
16382    }
16383  }
16384  return exports.format(specifier);
16385}
16386
16387function linearish(scale) {
16388  var domain = scale.domain;
16389
16390  scale.ticks = function(count) {
16391    var d = domain();
16392    return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
16393  };
16394
16395  scale.tickFormat = function(count, specifier) {
16396    return tickFormat(domain(), count, specifier);
16397  };
16398
16399  scale.nice = function(count) {
16400    if (count == null) count = 10;
16401
16402    var d = domain(),
16403        i0 = 0,
16404        i1 = d.length - 1,
16405        start = d[i0],
16406        stop = d[i1],
16407        step;
16408
16409    if (stop < start) {
16410      step = start, start = stop, stop = step;
16411      step = i0, i0 = i1, i1 = step;
16412    }
16413
16414    step = tickIncrement(start, stop, count);
16415
16416    if (step > 0) {
16417      start = Math.floor(start / step) * step;
16418      stop = Math.ceil(stop / step) * step;
16419      step = tickIncrement(start, stop, count);
16420    } else if (step < 0) {
vendor: 10,544 bytes, lines 16421-16852
16421      start = Math.ceil(start * step) / step;
16422      stop = Math.floor(stop * step) / step;
16423      step = tickIncrement(start, stop, count);
16424    }
16425
16426    if (step > 0) {
16427      d[i0] = Math.floor(start / step) * step;
16428      d[i1] = Math.ceil(stop / step) * step;
16429      domain(d);
16430    } else if (step < 0) {
16431      d[i0] = Math.ceil(start * step) / step;
16432      d[i1] = Math.floor(stop * step) / step;
16433      domain(d);
16434    }
16435
16436    return scale;
16437  };
16438
16439  return scale;
16440}
16441
16442function linear$2() {
16443  var scale = continuous(deinterpolateLinear, reinterpolate);
16444
16445  scale.copy = function() {
16446    return copy(scale, linear$2());
16447  };
16448
16449  return linearish(scale);
16450}
16451
16452function identity$6() {
16453  var domain = [0, 1];
16454
16455  function scale(x) {
16456    return +x;
16457  }
16458
16459  scale.invert = scale;
16460
16461  scale.domain = scale.range = function(_) {
16462    return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
16463  };
16464
16465  scale.copy = function() {
16466    return identity$6().domain(domain);
16467  };
16468
16469  return linearish(scale);
16470}
16471
16472function nice(domain, interval) {
16473  domain = domain.slice();
16474
16475  var i0 = 0,
16476      i1 = domain.length - 1,
16477      x0 = domain[i0],
16478      x1 = domain[i1],
16479      t;
16480
16481  if (x1 < x0) {
16482    t = i0, i0 = i1, i1 = t;
16483    t = x0, x0 = x1, x1 = t;
16484  }
16485
16486  domain[i0] = interval.floor(x0);
16487  domain[i1] = interval.ceil(x1);
16488  return domain;
16489}
16490
16491function deinterpolate(a, b) {
16492  return (b = Math.log(b / a))
16493      ? function(x) { return Math.log(x / a) / b; }
16494      : constant$9(b);
16495}
16496
16497function reinterpolate$1(a, b) {
16498  return a < 0
16499      ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
16500      : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
16501}
16502
16503function pow10(x) {
16504  return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
16505}
16506
16507function powp(base) {
16508  return base === 10 ? pow10
16509      : base === Math.E ? Math.exp
16510      : function(x) { return Math.pow(base, x); };
16511}
16512
16513function logp(base) {
16514  return base === Math.E ? Math.log
16515      : base === 10 && Math.log10
16516      || base === 2 && Math.log2
16517      || (base = Math.log(base), function(x) { return Math.log(x) / base; });
16518}
16519
16520function reflect(f) {
16521  return function(x) {
16522    return -f(-x);
16523  };
16524}
16525
16526function log$1() {
16527  var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
16528      domain = scale.domain,
16529      base = 10,
16530      logs = logp(10),
16531      pows = powp(10);
16532
16533  function rescale() {
16534    logs = logp(base), pows = powp(base);
16535    if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
16536    return scale;
16537  }
16538
16539  scale.base = function(_) {
16540    return arguments.length ? (base = +_, rescale()) : base;
16541  };
16542
16543  scale.domain = function(_) {
16544    return arguments.length ? (domain(_), rescale()) : domain();
16545  };
16546
16547  scale.ticks = function(count) {
16548    var d = domain(),
16549        u = d[0],
16550        v = d[d.length - 1],
16551        r;
16552
16553    if (r = v < u) i = u, u = v, v = i;
16554
16555    var i = logs(u),
16556        j = logs(v),
16557        p,
16558        k,
16559        t,
16560        n = count == null ? 10 : +count,
16561        z = [];
16562
16563    if (!(base % 1) && j - i < n) {
16564      i = Math.round(i) - 1, j = Math.round(j) + 1;
16565      if (u > 0) for (; i < j; ++i) {
16566        for (k = 1, p = pows(i); k < base; ++k) {
16567          t = p * k;
16568          if (t < u) continue;
16569          if (t > v) break;
16570          z.push(t);
16571        }
16572      } else for (; i < j; ++i) {
16573        for (k = base - 1, p = pows(i); k >= 1; --k) {
16574          t = p * k;
16575          if (t < u) continue;
16576          if (t > v) break;
16577          z.push(t);
16578        }
16579      }
16580    } else {
16581      z = ticks(i, j, Math.min(j - i, n)).map(pows);
16582    }
16583
16584    return r ? z.reverse() : z;
16585  };
16586
16587  scale.tickFormat = function(count, specifier) {
16588    if (specifier == null) specifier = base === 10 ? ".0e" : ",";
16589    if (typeof specifier !== "function") specifier = exports.format(specifier);
16590    if (count === Infinity) return specifier;
16591    if (count == null) count = 10;
16592    var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
16593    return function(d) {
16594      var i = d / pows(Math.round(logs(d)));
16595      if (i * base < base - 0.5) i *= base;
16596      return i <= k ? specifier(d) : "";
16597    };
16598  };
16599
16600  scale.nice = function() {
16601    return domain(nice(domain(), {
16602      floor: function(x) { return pows(Math.floor(logs(x))); },
16603      ceil: function(x) { return pows(Math.ceil(logs(x))); }
16604    }));
16605  };
16606
16607  scale.copy = function() {
16608    return copy(scale, log$1().base(base));
16609  };
16610
16611  return scale;
16612}
16613
16614function raise$1(x, exponent) {
16615  return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
16616}
16617
16618function pow$1() {
16619  var exponent = 1,
16620      scale = continuous(deinterpolate, reinterpolate),
16621      domain = scale.domain;
16622
16623  function deinterpolate(a, b) {
16624    return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
16625        ? function(x) { return (raise$1(x, exponent) - a) / b; }
16626        : constant$9(b);
16627  }
16628
16629  function reinterpolate(a, b) {
16630    b = raise$1(b, exponent) - (a = raise$1(a, exponent));
16631    return function(t) { return raise$1(a + b * t, 1 / exponent); };
16632  }
16633
16634  scale.exponent = function(_) {
16635    return arguments.length ? (exponent = +_, domain(domain())) : exponent;
16636  };
16637
16638  scale.copy = function() {
16639    return copy(scale, pow$1().exponent(exponent));
16640  };
16641
16642  return linearish(scale);
16643}
16644
16645function sqrt$1() {
16646  return pow$1().exponent(0.5);
16647}
16648
16649function quantile$$1() {
16650  var domain = [],
16651      range = [],
16652      thresholds = [];
16653
16654  function rescale() {
16655    var i = 0, n = Math.max(1, range.length);
16656    thresholds = new Array(n - 1);
16657    while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
16658    return scale;
16659  }
16660
16661  function scale(x) {
16662    if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
16663  }
16664
16665  scale.invertExtent = function(y) {
16666    var i = range.indexOf(y);
16667    return i < 0 ? [NaN, NaN] : [
16668      i > 0 ? thresholds[i - 1] : domain[0],
16669      i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
16670    ];
16671  };
16672
16673  scale.domain = function(_) {
16674    if (!arguments.length) return domain.slice();
16675    domain = [];
16676    for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
16677    domain.sort(ascending);
16678    return rescale();
16679  };
16680
16681  scale.range = function(_) {
16682    return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
16683  };
16684
16685  scale.quantiles = function() {
16686    return thresholds.slice();
16687  };
16688
16689  scale.copy = function() {
16690    return quantile$$1()
16691        .domain(domain)
16692        .range(range);
16693  };
16694
16695  return scale;
16696}
16697
16698function quantize$1() {
16699  var x0 = 0,
16700      x1 = 1,
16701      n = 1,
16702      domain = [0.5],
16703      range = [0, 1];
16704
16705  function scale(x) {
16706    if (x <= x) return range[bisectRight(domain, x, 0, n)];
16707  }
16708
16709  function rescale() {
16710    var i = -1;
16711    domain = new Array(n);
16712    while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
16713    return scale;
16714  }
16715
16716  scale.domain = function(_) {
16717    return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
16718  };
16719
16720  scale.range = function(_) {
16721    return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
16722  };
16723
16724  scale.invertExtent = function(y) {
16725    var i = range.indexOf(y);
16726    return i < 0 ? [NaN, NaN]
16727        : i < 1 ? [x0, domain[0]]
16728        : i >= n ? [domain[n - 1], x1]
16729        : [domain[i - 1], domain[i]];
16730  };
16731
16732  scale.copy = function() {
16733    return quantize$1()
16734        .domain([x0, x1])
16735        .range(range);
16736  };
16737
16738  return linearish(scale);
16739}
16740
16741function threshold$1() {
16742  var domain = [0.5],
16743      range = [0, 1],
16744      n = 1;
16745
16746  function scale(x) {
16747    if (x <= x) return range[bisectRight(domain, x, 0, n)];
16748  }
16749
16750  scale.domain = function(_) {
16751    return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
16752  };
16753
16754  scale.range = function(_) {
16755    return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
16756  };
16757
16758  scale.invertExtent = function(y) {
16759    var i = range.indexOf(y);
16760    return [domain[i - 1], domain[i]];
16761  };
16762
16763  scale.copy = function() {
16764    return threshold$1()
16765        .domain(domain)
16766        .range(range);
16767  };
16768
16769  return scale;
16770}
16771
16772var t0$1 = new Date;
16773var t1$1 = new Date;
16774
16775function newInterval(floori, offseti, count, field) {
16776
16777  function interval(date) {
16778    return floori(date = new Date(+date)), date;
16779  }
16780
16781  interval.floor = interval;
16782
16783  interval.ceil = function(date) {
16784    return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
16785  };
16786
16787  interval.round = function(date) {
16788    var d0 = interval(date),
16789        d1 = interval.ceil(date);
16790    return date - d0 < d1 - date ? d0 : d1;
16791  };
16792
16793  interval.offset = function(date, step) {
16794    return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
16795  };
16796
16797  interval.range = function(start, stop, step) {
16798    var range = [], previous;
16799    start = interval.ceil(start);
16800    step = step == null ? 1 : Math.floor(step);
16801    if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
16802    do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
16803    while (previous < start && start < stop);
16804    return range;
16805  };
16806
16807  interval.filter = function(test) {
16808    return newInterval(function(date) {
16809      if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
16810    }, function(date, step) {
16811      if (date >= date) {
16812        if (step < 0) while (++step <= 0) {
16813          while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
16814        } else while (--step >= 0) {
16815          while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
16816        }
16817      }
16818    });
16819  };
16820
16821  if (count) {
16822    interval.count = function(start, end) {
16823      t0$1.setTime(+start), t1$1.setTime(+end);
16824      floori(t0$1), floori(t1$1);
16825      return Math.floor(count(t0$1, t1$1));
16826    };
16827
16828    interval.every = function(step) {
16829      step = Math.floor(step);
16830      return !isFinite(step) || !(step > 0) ? null
16831          : !(step > 1) ? interval
16832          : interval.filter(field
16833              ? function(d) { return field(d) % step === 0; }
16834              : function(d) { return interval.count(0, d) % step === 0; });
16835    };
16836  }
16837
16838  return interval;
16839}
16840
16841var millisecond = newInterval(function() {
16842  // noop
16843}, function(date, step) {
16844  date.setTime(+date + step);
16845}, function(start, end) {
16846  return end - start;
16847});
16848
16849// An optimized implementation for this simple case.
16850millisecond.every = function(k) {
16851  k = Math.floor(k);
16852  if (!isFinite(k) || !(k >
vendor: 8,396 bytes, lines 16852-17142
16852 0)) return null;
16853  if (!(k > 1)) return millisecond;
16854  return newInterval(function(date) {
16855    date.setTime(Math.floor(date / k) * k);
16856  }, function(date, step) {
16857    date.setTime(+date + step * k);
16858  }, function(start, end) {
16859    return (end - start) / k;
16860  });
16861};
16862
16863var milliseconds = millisecond.range;
16864
16865var durationSecond$1 = 1e3;
16866var durationMinute$1 = 6e4;
16867var durationHour$1 = 36e5;
16868var durationDay$1 = 864e5;
16869var durationWeek$1 = 6048e5;
16870
16871var second = newInterval(function(date) {
16872  date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
16873}, function(date, step) {
16874  date.setTime(+date + step * durationSecond$1);
16875}, function(start, end) {
16876  return (end - start) / durationSecond$1;
16877}, function(date) {
16878  return date.getUTCSeconds();
16879});
16880
16881var seconds = second.range;
16882
16883var minute = newInterval(function(date) {
16884  date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
16885}, function(date, step) {
16886  date.setTime(+date + step * durationMinute$1);
16887}, function(start, end) {
16888  return (end - start) / durationMinute$1;
16889}, function(date) {
16890  return date.getMinutes();
16891});
16892
16893var minutes = minute.range;
16894
16895var hour = newInterval(function(date) {
16896  var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
16897  if (offset < 0) offset += durationHour$1;
16898  date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
16899}, function(date, step) {
16900  date.setTime(+date + step * durationHour$1);
16901}, function(start, end) {
16902  return (end - start) / durationHour$1;
16903}, function(date) {
16904  return date.getHours();
16905});
16906
16907var hours = hour.range;
16908
16909var day = newInterval(function(date) {
16910  date.setHours(0, 0, 0, 0);
16911}, function(date, step) {
16912  date.setDate(date.getDate() + step);
16913}, function(start, end) {
16914  return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
16915}, function(date) {
16916  return date.getDate() - 1;
16917});
16918
16919var days = day.range;
16920
16921function weekday(i) {
16922  return newInterval(function(date) {
16923    date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
16924    date.setHours(0, 0, 0, 0);
16925  }, function(date, step) {
16926    date.setDate(date.getDate() + step * 7);
16927  }, function(start, end) {
16928    return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
16929  });
16930}
16931
16932var sunday = weekday(0);
16933var monday = weekday(1);
16934var tuesday = weekday(2);
16935var wednesday = weekday(3);
16936var thursday = weekday(4);
16937var friday = weekday(5);
16938var saturday = weekday(6);
16939
16940var sundays = sunday.range;
16941var mondays = monday.range;
16942var tuesdays = tuesday.range;
16943var wednesdays = wednesday.range;
16944var thursdays = thursday.range;
16945var fridays = friday.range;
16946var saturdays = saturday.range;
16947
16948var month = newInterval(function(date) {
16949  date.setDate(1);
16950  date.setHours(0, 0, 0, 0);
16951}, function(date, step) {
16952  date.setMonth(date.getMonth() + step);
16953}, function(start, end) {
16954  return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
16955}, function(date) {
16956  return date.getMonth();
16957});
16958
16959var months = month.range;
16960
16961var year = newInterval(function(date) {
16962  date.setMonth(0, 1);
16963  date.setHours(0, 0, 0, 0);
16964}, function(date, step) {
16965  date.setFullYear(date.getFullYear() + step);
16966}, function(start, end) {
16967  return end.getFullYear() - start.getFullYear();
16968}, function(date) {
16969  return date.getFullYear();
16970});
16971
16972// An optimized implementation for this simple case.
16973year.every = function(k) {
16974  return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
16975    date.setFullYear(Math.floor(date.getFullYear() / k) * k);
16976    date.setMonth(0, 1);
16977    date.setHours(0, 0, 0, 0);
16978  }, function(date, step) {
16979    date.setFullYear(date.getFullYear() + step * k);
16980  });
16981};
16982
16983var years = year.range;
16984
16985var utcMinute = newInterval(function(date) {
16986  date.setUTCSeconds(0, 0);
16987}, function(date, step) {
16988  date.setTime(+date + step * durationMinute$1);
16989}, function(start, end) {
16990  return (end - start) / durationMinute$1;
16991}, function(date) {
16992  return date.getUTCMinutes();
16993});
16994
16995var utcMinutes = utcMinute.range;
16996
16997var utcHour = newInterval(function(date) {
16998  date.setUTCMinutes(0, 0, 0);
16999}, function(date, step) {
17000  date.setTime(+date + step * durationHour$1);
17001}, function(start, end) {
17002  return (end - start) / durationHour$1;
17003}, function(date) {
17004  return date.getUTCHours();
17005});
17006
17007var utcHours = utcHour.range;
17008
17009var utcDay = newInterval(function(date) {
17010  date.setUTCHours(0, 0, 0, 0);
17011}, function(date, step) {
17012  date.setUTCDate(date.getUTCDate() + step);
17013}, function(start, end) {
17014  return (end - start) / durationDay$1;
17015}, function(date) {
17016  return date.getUTCDate() - 1;
17017});
17018
17019var utcDays = utcDay.range;
17020
17021function utcWeekday(i) {
17022  return newInterval(function(date) {
17023    date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
17024    date.setUTCHours(0, 0, 0, 0);
17025  }, function(date, step) {
17026    date.setUTCDate(date.getUTCDate() + step * 7);
17027  }, function(start, end) {
17028    return (end - start) / durationWeek$1;
17029  });
17030}
17031
17032var utcSunday = utcWeekday(0);
17033var utcMonday = utcWeekday(1);
17034var utcTuesday = utcWeekday(2);
17035var utcWednesday = utcWeekday(3);
17036var utcThursday = utcWeekday(4);
17037var utcFriday = utcWeekday(5);
17038var utcSaturday = utcWeekday(6);
17039
17040var utcSundays = utcSunday.range;
17041var utcMondays = utcMonday.range;
17042var utcTuesdays = utcTuesday.range;
17043var utcWednesdays = utcWednesday.range;
17044var utcThursdays = utcThursday.range;
17045var utcFridays = utcFriday.range;
17046var utcSaturdays = utcSaturday.range;
17047
17048var utcMonth = newInterval(function(date) {
17049  date.setUTCDate(1);
17050  date.setUTCHours(0, 0, 0, 0);
17051}, function(date, step) {
17052  date.setUTCMonth(date.getUTCMonth() + step);
17053}, function(start, end) {
17054  return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
17055}, function(date) {
17056  return date.getUTCMonth();
17057});
17058
17059var utcMonths = utcMonth.range;
17060
17061var utcYear = newInterval(function(date) {
17062  date.setUTCMonth(0, 1);
17063  date.setUTCHours(0, 0, 0, 0);
17064}, function(date, step) {
17065  date.setUTCFullYear(date.getUTCFullYear() + step);
17066}, function(start, end) {
17067  return end.getUTCFullYear() - start.getUTCFullYear();
17068}, function(date) {
17069  return date.getUTCFullYear();
17070});
17071
17072// An optimized implementation for this simple case.
17073utcYear.every = function(k) {
17074  return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
17075    date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
17076    date.setUTCMonth(0, 1);
17077    date.setUTCHours(0, 0, 0, 0);
17078  }, function(date, step) {
17079    date.setUTCFullYear(date.getUTCFullYear() + step * k);
17080  });
17081};
17082
17083var utcYears = utcYear.range;
17084
17085function localDate(d) {
17086  if (0 <= d.y && d.y < 100) {
17087    var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
17088    date.setFullYear(d.y);
17089    return date;
17090  }
17091  return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
17092}
17093
17094function utcDate(d) {
17095  if (0 <= d.y && d.y < 100) {
17096    var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
17097    date.setUTCFullYear(d.y);
17098    return date;
17099  }
17100  return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
17101}
17102
17103function newYear(y) {
17104  return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
17105}
17106
17107function formatLocale$1(locale) {
17108  var locale_dateTime = locale.dateTime,
17109      locale_date = locale.date,
17110      locale_time = locale.time,
17111      locale_periods = locale.periods,
17112      locale_weekdays = locale.days,
17113      locale_shortWeekdays = locale.shortDays,
17114      locale_months = locale.months,
17115      locale_shortMonths = locale.shortMonths;
17116
17117  var periodRe = formatRe(locale_periods),
17118      periodLookup = formatLookup(locale_periods),
17119      weekdayRe = formatRe(locale_weekdays),
17120      weekdayLookup = formatLookup(locale_weekdays),
17121      shortWeekdayRe = formatRe(locale_shortWeekdays),
17122      shortWeekdayLookup = formatLookup(locale_shortWeekdays),
17123      monthRe = formatRe(locale_months),
17124      monthLookup = formatLookup(locale_months),
17125      shortMonthRe = formatRe(locale_shortMonths),
17126      shortMonthLookup = formatLookup(locale_shortMonths);
17127
17128  var formats = {
17129    "a": formatShortWeekday,
17130    "A": formatWeekday,
17131    "b": formatShortMonth,
17132    "B": formatMonth,
17133    "c": null,
17134    "d": formatDayOfMonth,
17135    "e": formatDayOfMonth,
17136    "f": formatMicroseconds,
17137    "H": formatHour24,
17138    "I": formatHour12,
17139    "j": formatDayOfYear,
17140    "L": formatMilliseconds,
17141    "m": formatMonthNumber,
17142    "M": formatMinutes,
vendor: 3,081 bytes, lines 17143-17254
17143    "p": formatPeriod,
17144    "Q": formatUnixTimestamp,
17145    "s": formatUnixTimestampSeconds,
17146    "S": formatSeconds,
17147    "u": formatWeekdayNumberMonday,
17148    "U": formatWeekNumberSunday,
17149    "V": formatWeekNumberISO,
17150    "w": formatWeekdayNumberSunday,
17151    "W": formatWeekNumberMonday,
17152    "x": null,
17153    "X": null,
17154    "y": formatYear,
17155    "Y": formatFullYear,
17156    "Z": formatZone,
17157    "%": formatLiteralPercent
17158  };
17159
17160  var utcFormats = {
17161    "a": formatUTCShortWeekday,
17162    "A": formatUTCWeekday,
17163    "b": formatUTCShortMonth,
17164    "B": formatUTCMonth,
17165    "c": null,
17166    "d": formatUTCDayOfMonth,
17167    "e": formatUTCDayOfMonth,
17168    "f": formatUTCMicroseconds,
17169    "H": formatUTCHour24,
17170    "I": formatUTCHour12,
17171    "j": formatUTCDayOfYear,
17172    "L": formatUTCMilliseconds,
17173    "m": formatUTCMonthNumber,
17174    "M": formatUTCMinutes,
17175    "p": formatUTCPeriod,
17176    "Q": formatUnixTimestamp,
17177    "s": formatUnixTimestampSeconds,
17178    "S": formatUTCSeconds,
17179    "u": formatUTCWeekdayNumberMonday,
17180    "U": formatUTCWeekNumberSunday,
17181    "V": formatUTCWeekNumberISO,
17182    "w": formatUTCWeekdayNumberSunday,
17183    "W": formatUTCWeekNumberMonday,
17184    "x": null,
17185    "X": null,
17186    "y": formatUTCYear,
17187    "Y": formatUTCFullYear,
17188    "Z": formatUTCZone,
17189    "%": formatLiteralPercent
17190  };
17191
17192  var parses = {
17193    "a": parseShortWeekday,
17194    "A": parseWeekday,
17195    "b": parseShortMonth,
17196    "B": parseMonth,
17197    "c": parseLocaleDateTime,
17198    "d": parseDayOfMonth,
17199    "e": parseDayOfMonth,
17200    "f": parseMicroseconds,
17201    "H": parseHour24,
17202    "I": parseHour24,
17203    "j": parseDayOfYear,
17204    "L": parseMilliseconds,
17205    "m": parseMonthNumber,
17206    "M": parseMinutes,
17207    "p": parsePeriod,
17208    "Q": parseUnixTimestamp,
17209    "s": parseUnixTimestampSeconds,
17210    "S": parseSeconds,
17211    "u": parseWeekdayNumberMonday,
17212    "U": parseWeekNumberSunday,
17213    "V": parseWeekNumberISO,
17214    "w": parseWeekdayNumberSunday,
17215    "W": parseWeekNumberMonday,
17216    "x": parseLocaleDate,
17217    "X": parseLocaleTime,
17218    "y": parseYear,
17219    "Y": parseFullYear,
17220    "Z": parseZone,
17221    "%": parseLiteralPercent
17222  };
17223
17224  // These recursive directive definitions must be deferred.
17225  formats.x = newFormat(locale_date, formats);
17226  formats.X = newFormat(locale_time, formats);
17227  formats.c = newFormat(locale_dateTime, formats);
17228  utcFormats.x = newFormat(locale_date, utcFormats);
17229  utcFormats.X = newFormat(locale_time, utcFormats);
17230  utcFormats.c = newFormat(locale_dateTime, utcFormats);
17231
17232  function newFormat(specifier, formats) {
17233    return function(date) {
17234      var string = [],
17235          i = -1,
17236          j = 0,
17237          n = specifier.length,
17238          c,
17239          pad,
17240          format;
17241
17242      if (!(date instanceof Date)) date = new Date(+date);
17243
17244      while (++i < n) {
17245        if (specifier.charCodeAt(i) === 37) {
17246          string.push(specifier.slice(j, i));
17247          if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
17248          else pad = c === "e" ? " " : "0";
17249          if (format = formats[c]) c = format(date, pad);
17250          string.push(c);
17251          j = i + 1;
17252        }
17253      }
17254
vendor: 5,438 bytes, lines 17255-17441
17255      string.push(specifier.slice(j, i));
17256      return string.join("");
17257    };
17258  }
17259
17260  function newParse(specifier, newDate) {
17261    return function(string) {
17262      var d = newYear(1900),
17263          i = parseSpecifier(d, specifier, string += "", 0),
17264          week, day$$1;
17265      if (i != string.length) return null;
17266
17267      // If a UNIX timestamp is specified, return it.
17268      if ("Q" in d) return new Date(d.Q);
17269
17270      // The am-pm flag is 0 for AM, and 1 for PM.
17271      if ("p" in d) d.H = d.H % 12 + d.p * 12;
17272
17273      // Convert day-of-week and week-of-year to day-of-year.
17274      if ("V" in d) {
17275        if (d.V < 1 || d.V > 53) return null;
17276        if (!("w" in d)) d.w = 1;
17277        if ("Z" in d) {
17278          week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
17279          week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
17280          week = utcDay.offset(week, (d.V - 1) * 7);
17281          d.y = week.getUTCFullYear();
17282          d.m = week.getUTCMonth();
17283          d.d = week.getUTCDate() + (d.w + 6) % 7;
17284        } else {
17285          week = newDate(newYear(d.y)), day$$1 = week.getDay();
17286          week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
17287          week = day.offset(week, (d.V - 1) * 7);
17288          d.y = week.getFullYear();
17289          d.m = week.getMonth();
17290          d.d = week.getDate() + (d.w + 6) % 7;
17291        }
17292      } else if ("W" in d || "U" in d) {
17293        if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
17294        day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
17295        d.m = 0;
17296        d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$$1 + 5) % 7 : d.w + d.U * 7 - (day$$1 + 6) % 7;
17297      }
17298
17299      // If a time zone is specified, all fields are interpreted as UTC and then
17300      // offset according to the specified time zone.
17301      if ("Z" in d) {
17302        d.H += d.Z / 100 | 0;
17303        d.M += d.Z % 100;
17304        return utcDate(d);
17305      }
17306
17307      // Otherwise, all fields are in local time.
17308      return newDate(d);
17309    };
17310  }
17311
17312  function parseSpecifier(d, specifier, string, j) {
17313    var i = 0,
17314        n = specifier.length,
17315        m = string.length,
17316        c,
17317        parse;
17318
17319    while (i < n) {
17320      if (j >= m) return -1;
17321      c = specifier.charCodeAt(i++);
17322      if (c === 37) {
17323        c = specifier.charAt(i++);
17324        parse = parses[c in pads ? specifier.charAt(i++) : c];
17325        if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
17326      } else if (c != string.charCodeAt(j++)) {
17327        return -1;
17328      }
17329    }
17330
17331    return j;
17332  }
17333
17334  function parsePeriod(d, string, i) {
17335    var n = periodRe.exec(string.slice(i));
17336    return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
17337  }
17338
17339  function parseShortWeekday(d, string, i) {
17340    var n = shortWeekdayRe.exec(string.slice(i));
17341    return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
17342  }
17343
17344  function parseWeekday(d, string, i) {
17345    var n = weekdayRe.exec(string.slice(i));
17346    return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
17347  }
17348
17349  function parseShortMonth(d, string, i) {
17350    var n = shortMonthRe.exec(string.slice(i));
17351    return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
17352  }
17353
17354  function parseMonth(d, string, i) {
17355    var n = monthRe.exec(string.slice(i));
17356    return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
17357  }
17358
17359  function parseLocaleDateTime(d, string, i) {
17360    return parseSpecifier(d, locale_dateTime, string, i);
17361  }
17362
17363  function parseLocaleDate(d, string, i) {
17364    return parseSpecifier(d, locale_date, string, i);
17365  }
17366
17367  function parseLocaleTime(d, string, i) {
17368    return parseSpecifier(d, locale_time, string, i);
17369  }
17370
17371  function formatShortWeekday(d) {
17372    return locale_shortWeekdays[d.getDay()];
17373  }
17374
17375  function formatWeekday(d) {
17376    return locale_weekdays[d.getDay()];
17377  }
17378
17379  function formatShortMonth(d) {
17380    return locale_shortMonths[d.getMonth()];
17381  }
17382
17383  function formatMonth(d) {
17384    return locale_months[d.getMonth()];
17385  }
17386
17387  function formatPeriod(d) {
17388    return locale_periods[+(d.getHours() >= 12)];
17389  }
17390
17391  function formatUTCShortWeekday(d) {
17392    return locale_shortWeekdays[d.getUTCDay()];
17393  }
17394
17395  function formatUTCWeekday(d) {
17396    return locale_weekdays[d.getUTCDay()];
17397  }
17398
17399  function formatUTCShortMonth(d) {
17400    return locale_shortMonths[d.getUTCMonth()];
17401  }
17402
17403  function formatUTCMonth(d) {
17404    return locale_months[d.getUTCMonth()];
17405  }
17406
17407  function formatUTCPeriod(d) {
17408    return locale_periods[+(d.getUTCHours() >= 12)];
17409  }
17410
17411  return {
17412    format: function(specifier) {
17413      var f = newFormat(specifier += "", formats);
17414      f.toString = function() { return specifier; };
17415      return f;
17416    },
17417    parse: function(specifier) {
17418      var p = newParse(specifier += "", localDate);
17419      p.toString = function() { return specifier; };
17420      return p;
17421    },
17422    utcFormat: function(specifier) {
17423      var f = newFormat(specifier += "", utcFormats);
17424      f.toString = function() { return specifier; };
17425      return f;
17426    },
17427    utcParse: function(specifier) {
17428      var p = newParse(specifier, utcDate);
17429      p.toString = function() { return specifier; };
17430      return p;
17431    }
17432  };
17433}
17434
17435var pads = {"-": "", "_": " ", "0": "0"};
17436var numberRe = /^\s*\d+/;
17437var percentRe = /^%/;
17438var requoteRe = /[\\^$*+?|[\]().{}]/g;
17439
17440function pad(value, fill, width) {
17441  var sign = value < 0 ? "-" : "",
vendor: 1,078 bytes, lines 17442-17480
17442      string = (sign ? -value : value) + "",
17443      length = string.length;
17444  return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
17445}
17446
17447function requote(s) {
17448  return s.replace(requoteRe, "\\$&");
17449}
17450
17451function formatRe(names) {
17452  return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
17453}
17454
17455function formatLookup(names) {
17456  var map = {}, i = -1, n = names.length;
17457  while (++i < n) map[names[i].toLowerCase()] = i;
17458  return map;
17459}
17460
17461function parseWeekdayNumberSunday(d, string, i) {
17462  var n = numberRe.exec(string.slice(i, i + 1));
17463  return n ? (d.w = +n[0], i + n[0].length) : -1;
17464}
17465
17466function parseWeekdayNumberMonday(d, string, i) {
17467  var n = numberRe.exec(string.slice(i, i + 1));
17468  return n ? (d.u = +n[0], i + n[0].length) : -1;
17469}
17470
17471function parseWeekNumberSunday(d, string, i) {
17472  var n = numberRe.exec(string.slice(i, i + 2));
17473  return n ? (d.U = +n[0], i + n[0].length) : -1;
17474}
17475
17476function parseWeekNumberISO(d, string, i) {
17477  var n = numberRe.exec(string.slice(i, i + 2));
17478  return n ? (d.V = +n[0], i + n[0].length) : -1;
17479}
17480
vendor: 5,913 bytes, lines 17481-17726
17481function parseWeekNumberMonday(d, string, i) {
17482  var n = numberRe.exec(string.slice(i, i + 2));
17483  return n ? (d.W = +n[0], i + n[0].length) : -1;
17484}
17485
17486function parseFullYear(d, string, i) {
17487  var n = numberRe.exec(string.slice(i, i + 4));
17488  return n ? (d.y = +n[0], i + n[0].length) : -1;
17489}
17490
17491function parseYear(d, string, i) {
17492  var n = numberRe.exec(string.slice(i, i + 2));
17493  return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
17494}
17495
17496function parseZone(d, string, i) {
17497  var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
17498  return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
17499}
17500
17501function parseMonthNumber(d, string, i) {
17502  var n = numberRe.exec(string.slice(i, i + 2));
17503  return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
17504}
17505
17506function parseDayOfMonth(d, string, i) {
17507  var n = numberRe.exec(string.slice(i, i + 2));
17508  return n ? (d.d = +n[0], i + n[0].length) : -1;
17509}
17510
17511function parseDayOfYear(d, string, i) {
17512  var n = numberRe.exec(string.slice(i, i + 3));
17513  return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
17514}
17515
17516function parseHour24(d, string, i) {
17517  var n = numberRe.exec(string.slice(i, i + 2));
17518  return n ? (d.H = +n[0], i + n[0].length) : -1;
17519}
17520
17521function parseMinutes(d, string, i) {
17522  var n = numberRe.exec(string.slice(i, i + 2));
17523  return n ? (d.M = +n[0], i + n[0].length) : -1;
17524}
17525
17526function parseSeconds(d, string, i) {
17527  var n = numberRe.exec(string.slice(i, i + 2));
17528  return n ? (d.S = +n[0], i + n[0].length) : -1;
17529}
17530
17531function parseMilliseconds(d, string, i) {
17532  var n = numberRe.exec(string.slice(i, i + 3));
17533  return n ? (d.L = +n[0], i + n[0].length) : -1;
17534}
17535
17536function parseMicroseconds(d, string, i) {
17537  var n = numberRe.exec(string.slice(i, i + 6));
17538  return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
17539}
17540
17541function parseLiteralPercent(d, string, i) {
17542  var n = percentRe.exec(string.slice(i, i + 1));
17543  return n ? i + n[0].length : -1;
17544}
17545
17546function parseUnixTimestamp(d, string, i) {
17547  var n = numberRe.exec(string.slice(i));
17548  return n ? (d.Q = +n[0], i + n[0].length) : -1;
17549}
17550
17551function parseUnixTimestampSeconds(d, string, i) {
17552  var n = numberRe.exec(string.slice(i));
17553  return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
17554}
17555
17556function formatDayOfMonth(d, p) {
17557  return pad(d.getDate(), p, 2);
17558}
17559
17560function formatHour24(d, p) {
17561  return pad(d.getHours(), p, 2);
17562}
17563
17564function formatHour12(d, p) {
17565  return pad(d.getHours() % 12 || 12, p, 2);
17566}
17567
17568function formatDayOfYear(d, p) {
17569  return pad(1 + day.count(year(d), d), p, 3);
17570}
17571
17572function formatMilliseconds(d, p) {
17573  return pad(d.getMilliseconds(), p, 3);
17574}
17575
17576function formatMicroseconds(d, p) {
17577  return formatMilliseconds(d, p) + "000";
17578}
17579
17580function formatMonthNumber(d, p) {
17581  return pad(d.getMonth() + 1, p, 2);
17582}
17583
17584function formatMinutes(d, p) {
17585  return pad(d.getMinutes(), p, 2);
17586}
17587
17588function formatSeconds(d, p) {
17589  return pad(d.getSeconds(), p, 2);
17590}
17591
17592function formatWeekdayNumberMonday(d) {
17593  var day$$1 = d.getDay();
17594  return day$$1 === 0 ? 7 : day$$1;
17595}
17596
17597function formatWeekNumberSunday(d, p) {
17598  return pad(sunday.count(year(d), d), p, 2);
17599}
17600
17601function formatWeekNumberISO(d, p) {
17602  var day$$1 = d.getDay();
17603  d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
17604  return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
17605}
17606
17607function formatWeekdayNumberSunday(d) {
17608  return d.getDay();
17609}
17610
17611function formatWeekNumberMonday(d, p) {
17612  return pad(monday.count(year(d), d), p, 2);
17613}
17614
17615function formatYear(d, p) {
17616  return pad(d.getFullYear() % 100, p, 2);
17617}
17618
17619function formatFullYear(d, p) {
17620  return pad(d.getFullYear() % 10000, p, 4);
17621}
17622
17623function formatZone(d) {
17624  var z = d.getTimezoneOffset();
17625  return (z > 0 ? "-" : (z *= -1, "+"))
17626      + pad(z / 60 | 0, "0", 2)
17627      + pad(z % 60, "0", 2);
17628}
17629
17630function formatUTCDayOfMonth(d, p) {
17631  return pad(d.getUTCDate(), p, 2);
17632}
17633
17634function formatUTCHour24(d, p) {
17635  return pad(d.getUTCHours(), p, 2);
17636}
17637
17638function formatUTCHour12(d, p) {
17639  return pad(d.getUTCHours() % 12 || 12, p, 2);
17640}
17641
17642function formatUTCDayOfYear(d, p) {
17643  return pad(1 + utcDay.count(utcYear(d), d), p, 3);
17644}
17645
17646function formatUTCMilliseconds(d, p) {
17647  return pad(d.getUTCMilliseconds(), p, 3);
17648}
17649
17650function formatUTCMicroseconds(d, p) {
17651  return formatUTCMilliseconds(d, p) + "000";
17652}
17653
17654function formatUTCMonthNumber(d, p) {
17655  return pad(d.getUTCMonth() + 1, p, 2);
17656}
17657
17658function formatUTCMinutes(d, p) {
17659  return pad(d.getUTCMinutes(), p, 2);
17660}
17661
17662function formatUTCSeconds(d, p) {
17663  return pad(d.getUTCSeconds(), p, 2);
17664}
17665
17666function formatUTCWeekdayNumberMonday(d) {
17667  var dow = d.getUTCDay();
17668  return dow === 0 ? 7 : dow;
17669}
17670
17671function formatUTCWeekNumberSunday(d, p) {
17672  return pad(utcSunday.count(utcYear(d), d), p, 2);
17673}
17674
17675function formatUTCWeekNumberISO(d, p) {
17676  var day$$1 = d.getUTCDay();
17677  d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
17678  return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
17679}
17680
17681function formatUTCWeekdayNumberSunday(d) {
17682  return d.getUTCDay();
17683}
17684
17685function formatUTCWeekNumberMonday(d, p) {
17686  return pad(utcMonday.count(utcYear(d), d), p, 2);
17687}
17688
17689function formatUTCYear(d, p) {
17690  return pad(d.getUTCFullYear() % 100, p, 2);
17691}
17692
17693function formatUTCFullYear(d, p) {
17694  return pad(d.getUTCFullYear() % 10000, p, 4);
17695}
17696
17697function formatUTCZone() {
17698  return "+0000";
17699}
17700
17701function formatLiteralPercent() {
17702  return "%";
17703}
17704
17705function formatUnixTimestamp(d) {
17706  return +d;
17707}
17708
17709function formatUnixTimestampSeconds(d) {
17710  return Math.floor(+d / 1000);
17711}
17712
17713var locale$1;
17714
17715
17716
17717
17718
17719defaultLocale$1({
17720  dateTime: "%x, %X",
17721  date: "%-m/%-d/%Y",
17722  time: "%-I:%M:%S %p",
17723  periods: ["AM", "PM"],
17724  days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
17725  shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
17726  months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
17726November", "December"],
17727  shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
17728});
17729
17730function defaultLocale$1(definition) {
17731  locale$1 = formatLocale$1(definition);
17732  exports.timeFormat = locale$1.format;
17733  exports.timeParse = locale$1.parse;
17734  exports.utcFormat = locale$1.utcFormat;
17735  exports.utcParse = locale$1.utcParse;
17736  return locale$1;
17737}
17738
17739var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
17740
17741function formatIsoNative(date) {
17742  return date.toISOString();
17743}
17744
17745var formatIso = Date.prototype.toISOString
17746    ? formatIsoNative
17747    : exports.utcFormat(isoSpecifier);
17748
17749function parseIsoNative(string) {
17750  var date = new Date(string);
17751  return isNaN(date) ? null : date;
17752}
17753
17754var parseIso = +new Date("2000-01-01T00:00:00.000Z")
17755    ? parseIsoNative
17756    : exports.utcParse(isoSpecifier);
17757
17758var durationSecond = 1000;
17759var durationMinute = durationSecond * 60;
17760var durationHour = durationMinute * 60;
17761var durationDay = durationHour * 24;
17762var durationWeek = durationDay * 7;
17763var durationMonth = durationDay * 30;
17764var durationYear = durationDay * 365;
17765
17766function date$1(t) {
17767  return new Date(t);
17768}
17769
17770function number$3(t) {
17771  return t instanceof Date ? +t : +new Date(+t);
17772}
17773
17774function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
17775  var scale = continuous(deinterpolateLinear, reinterpolate),
17776      invert = scale.invert,
17777      domain = scale.domain;
17778
17779  var formatMillisecond = format(".%L"),
17780      formatSecond = format(":%S"),
17781      formatMinute = format("%I:%M"),
17782      formatHour = format("%I %p"),
17783      formatDay = format("%a %d"),
17784      formatWeek = format("%b %d"),
17785      formatMonth = format("%B"),
17786      formatYear = format("%Y");
17787
17788  var tickIntervals = [
17789    [second$$1,  1,      durationSecond],
17790    [second$$1,  5,  5 * durationSecond],
17791    [second$$1, 15, 15 * durationSecond],
17792    [second$$1, 30, 30 * durationSecond],
17793    [minute$$1,  1,      durationMinute],
17794    [minute$$1,  5,  5 * durationMinute],
17795    [minute$$1, 15, 15 * durationMinute],
17796    [minute$$1, 30, 30 * durationMinute],
17797    [  hour$$1,  1,      durationHour  ],
17798    [  hour$$1,  3,  3 * durationHour  ],
17799    [  hour$$1,  6,  6 * durationHour  ],
17800    [  hour$$1, 12, 12 * durationHour  ],
17801    [   day$$1,  1,      durationDay   ],
17802    [   day$$1,  2,  2 * durationDay   ],
17803    [  week,  1,      durationWeek  ],
17804    [ month$$1,  1,      durationMonth ],
17805    [ month$$1,  3,  3 * durationMonth ],
17806    [  year$$1,  1,      durationYear  ]
17807  ];
17808
17809  function tickFormat(date) {
17810    return (second$$1(date) < date ? formatMillisecond
17811        : minute$$1(date) < date ? formatSecond
17812        : hour$$1(date) < date ? formatMinute
17813        : day$$1(date) < date ? formatHour
17814        : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
17815        : year$$1(date) < date ? formatMonth
17816        : formatYear)(date);
17817  }
17818
17819  function tickInterval(interval, start, stop, step) {
17820    if (interval == null) interval = 10;
17821
17822    // If a desired tick count is specified, pick a reasonable tick interval
17823    // based on the extent of the domain and a rough estimate of tick size.
17824    // Otherwise, assume interval is already a time interval and use it.
17825    if (typeof interval === "number") {
17826      var target = Math.abs(stop - start) / interval,
17827          i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
17828      if (i === tickIntervals.length) {
17829        step = tickStep(start / durationYear, stop / durationYear, interval);
17830        interval = year$$1;
17831      } else if (i) {
17832        i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
17833        step = i[1];
17834        interval = i[0];
17835      } else {
17836        step = Math.max(tickStep(start, stop, interval), 1);
17837        interval = millisecond$$1;
17838      }
17839    }
17840
17841    return step == null ? interval : interval.every(step);
17842  }
17843
17844  scale.invert = function(y) {
17845    return new Date(invert(y));
17846  };
17847
17848  scale.domain = function(_) {
17849    return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
17850  };
17851
17852  scale.ticks = function(interval, step) {
17853    var d = domain(),
17854        t0 = d[0],
17855        t1 = d[d.length - 1],
17856        r = t1 < t0,
17857        t;
17858    if (r) t = t0, t0 = t1, t1 = t;
17859    t = tickInterval(interval, t0, t1, step);
17860    t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
17861    return r ? t.reverse() : t;
17862  };
17863
17864  scale.tickFormat = function(count, specifier) {
17865    return specifier == null ? tickFormat : format(specifier);
17866  };
17867
17868  scale.nice = function(interval, step) {
17869    var d = domain();
17870    return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
17871        ? domain(nice(d, interval))
17872        : scale;
17873  };
17874
17875  scale.copy = function() {
17876    return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
17877  };
17878
17879  return scale;
17880}
17881
17882function time() {
17883  return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
17884}
17885
17886function utcTime() {
17887  return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
17888}
17889
17890function colors(s) {
17891  return s.match(/.{6}/g).map(function(x) {
17892    return "#" + x;
17893  });
17894}
17895
17896var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
17897
17898var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
17899
17900var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
17901
17902var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
17903
vendor: 11,575 bytes, lines 17904-18118
17904var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
17905
17906var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
17907
17908var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
17909
17910var rainbow = cubehelix();
17911
17912function rainbow$1(t) {
17913  if (t < 0 || t > 1) t -= Math.floor(t);
17914  var ts = Math.abs(t - 0.5);
17915  rainbow.h = 360 * t - 100;
17916  rainbow.s = 1.5 - 1.5 * ts;
17917  rainbow.l = 0.8 - 0.9 * ts;
17918  return rainbow + "";
17919}
17920
17921function ramp(range) {
17922  var n = range.length;
17923  return function(t) {
17924    return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
17925  };
17926}
17927
17928var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
17929
17930var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
17931
17932var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
17933
17934var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
17935
17936function sequential(interpolator) {
17937  var x0 = 0,
17938      x1 = 1,
17939      clamp = false;
17940
17941  function scale(x) {
17942    var t = (x - x0) / (x1 - x0);
17943    return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
17944  }
17945
17946  scale.domain = function(_) {
17947    return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
17948  };
17949
17950  scale.clamp = function(_) {
17951    return arguments.length ? (clamp = !!_, scale) : clamp;
17952  };
17953
17954  scale.interpolator = function(_) {
17955    return arguments.length ? (interpolator = _, scale) : interpolator;
17956  };
17957
17958  scale.copy = function() {
17959    return sequential(interpolator).domain([x0, x1]).clamp(clamp);
17960  };
17961
17962  return linearish(scale);
17963}
17964
17965function constant$10(x) {
17966  return function constant() {
17967    return x;
17968  };
17969}
17970
17971var abs$1 = Math.abs;
17972var atan2$1 = Math.atan2;
17973var cos$2 = Math.cos;
17974var max$2 = Math.max;
17975var min$1 = Math.min;
17976var sin$2 = Math.sin;
17977var sqrt$2 = Math.sqrt;
17978
17979var epsilon$3 = 1e-12;
17980var pi$4 = Math.PI;
17981var halfPi$3 = pi$4 / 2;
17982var tau$4 = 2 * pi$4;
17983
17984function acos$1(x) {
17985  return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
17986}
17987
17988function asin$1(x) {
17989  return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
17990}
17991
17992function arcInnerRadius(d) {
17993  return d.innerRadius;
17994}
17995
17996function arcOuterRadius(d) {
17997  return d.outerRadius;
17998}
17999
18000function arcStartAngle(d) {
18001  return d.startAngle;
18002}
18003
18004function arcEndAngle(d) {
18005  return d.endAngle;
18006}
18007
18008function arcPadAngle(d) {
18009  return d && d.padAngle; // Note: optional!
18010}
18011
18012function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
18013  var x10 = x1 - x0, y10 = y1 - y0,
18014      x32 = x3 - x2, y32 = y3 - y2,
18015      t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
18016  return [x0 + t * x10, y0 + t * y10];
18017}
18018
18019// Compute perpendicular offset line of length rc.
18020// http://mathworld.wolfram.com/Circle-LineIntersection.html
18021function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
18022  var x01 = x0 - x1,
18023      y01 = y0 - y1,
18024      lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
18025      ox = lo * y01,
18026      oy = -lo * x01,
18027      x11 = x0 + ox,
18028      y11 = y0 + oy,
18029      x10 = x1 + ox,
18030      y10 = y1 + oy,
18031      x00 = (x11 + x10) / 2,
18032      y00 = (y11 + y10) / 2,
18033      dx = x10 - x11,
18034      dy = y10 - y11,
18035      d2 = dx * dx + dy * dy,
18036      r = r1 - rc,
18037      D = x11 * y10 - x10 * y11,
18038      d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
18039      cx0 = (D * dy - dx * d) / d2,
18040      cy0 = (-D * dx - dy * d) / d2,
18041      cx1 = (D * dy + dx * d) / d2,
18042      cy1 = (-D * dx + dy * d) / d2,
18043      dx0 = cx0 - x00,
18044      dy0 = cy0 - y00,
18045      dx1 = cx1 - x00,
18046      dy1 = cy1 - y00;
18047
18048  // Pick the closer of the two intersection points.
18049  // TODO Is there a faster way to determine which intersection to use?
18050  if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
18051
18052  return {
18053    cx: cx0,
18054    cy: cy0,
18055    x01: -ox,
18056    y01: -oy,
18057    x11: cx0 * (r1 / r - 1),
18058    y11: cy0 * (r1 / r - 1)
18059  };
18060}
18061
18062function arc() {
18063  var innerRadius = arcInnerRadius,
18064      outerRadius = arcOuterRadius,
18065      cornerRadius = constant$10(0),
18066      padRadius = null,
18067      startAngle = arcStartAngle,
18068      endAngle = arcEndAngle,
18069      padAngle = arcPadAngle,
18070      context = null;
18071
18072  function arc() {
18073    var buffer,
18074        r,
18075        r0 = +innerRadius.apply(this, arguments),
18076        r1 = +outerRadius.apply(this, arguments),
18077        a0 = startAngle.apply(this, arguments) - halfPi$3,
18078        a1 = endAngle.apply(this, arguments) - halfPi$3,
18079        da = abs$1(a1 - a0),
18080        cw = a1 > a0;
18081
18082    if (!context) context = buffer = path();
18083
18084    // Ensure that the outer radius is always larger than the inner radius.
18085    if (r1 < r0) r = r1, r1 = r0, r0 = r;
18086
18087    // Is it a point?
18088    if (!(r1 > epsilon$3)) context.moveTo(0, 0);
18089
18090    // Or is it a circle or annulus?
18091    else if (da > tau$4 - epsilon$3) {
18092      context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
18093      context.arc(0, 0, r1, a0, a1, !cw);
18094      if (r0 > epsilon$3) {
18095        context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
18096        context.arc(0, 0, r0, a1, a0, cw);
18097      }
18098    }
18099
18100    // Or is it a circular or annular sector?
18101    else {
18102      var a01 = a0,
18103          a11 = a1,
18104          a00 = a0,
18105          a10 = a1,
18106          da0 = da,
18107          da1 = da,
18108          ap = padAngle.apply(this, arguments) / 2,
18109          rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
18110          rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
18111          rc0 = rc,
18112          rc1 = rc,
18113          t0,
18114          t1;
18115
18116      // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
18117      if (rp > epsilon$3) {
18118        var p0 = asin$1(rp / r0 * sin$2(ap)),
vendor: 22,134 bytes, lines 18119-18928
18119            p1 = asin$1(rp / r1 * sin$2(ap));
18120        if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
18121        else da0 = 0, a00 = a10 = (a0 + a1) / 2;
18122        if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
18123        else da1 = 0, a01 = a11 = (a0 + a1) / 2;
18124      }
18125
18126      var x01 = r1 * cos$2(a01),
18127          y01 = r1 * sin$2(a01),
18128          x10 = r0 * cos$2(a10),
18129          y10 = r0 * sin$2(a10);
18130
18131      // Apply rounded corners?
18132      if (rc > epsilon$3) {
18133        var x11 = r1 * cos$2(a11),
18134            y11 = r1 * sin$2(a11),
18135            x00 = r0 * cos$2(a00),
18136            y00 = r0 * sin$2(a00);
18137
18138        // Restrict the corner radius according to the sector angle.
18139        if (da < pi$4) {
18140          var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
18141              ax = x01 - oc[0],
18142              ay = y01 - oc[1],
18143              bx = x11 - oc[0],
18144              by = y11 - oc[1],
18145              kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
18146              lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
18147          rc0 = min$1(rc, (r0 - lc) / (kc - 1));
18148          rc1 = min$1(rc, (r1 - lc) / (kc + 1));
18149        }
18150      }
18151
18152      // Is the sector collapsed to a line?
18153      if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
18154
18155      // Does the sector’s outer ring have rounded corners?
18156      else if (rc1 > epsilon$3) {
18157        t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
18158        t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
18159
18160        context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
18161
18162        // Have the corners merged?
18163        if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
18164
18165        // Otherwise, draw the two corners and the ring.
18166        else {
18167          context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
18168          context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
18169          context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
18170        }
18171      }
18172
18173      // Or is the outer ring just a circular arc?
18174      else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
18175
18176      // Is there no inner ring, and it’s a circular sector?
18177      // Or perhaps it’s an annular sector collapsed due to padding?
18178      if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
18179
18180      // Does the sector’s inner ring (or point) have rounded corners?
18181      else if (rc0 > epsilon$3) {
18182        t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
18183        t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
18184
18185        context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
18186
18187        // Have the corners merged?
18188        if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
18189
18190        // Otherwise, draw the two corners and the ring.
18191        else {
18192          context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
18193          context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
18194          context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
18195        }
18196      }
18197
18198      // Or is the inner ring just a circular arc?
18199      else context.arc(0, 0, r0, a10, a00, cw);
18200    }
18201
18202    context.closePath();
18203
18204    if (buffer) return context = null, buffer + "" || null;
18205  }
18206
18207  arc.centroid = function() {
18208    var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
18209        a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
18210    return [cos$2(a) * r, sin$2(a) * r];
18211  };
18212
18213  arc.innerRadius = function(_) {
18214    return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
18215  };
18216
18217  arc.outerRadius = function(_) {
18218    return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
18219  };
18220
18221  arc.cornerRadius = function(_) {
18222    return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
18223  };
18224
18225  arc.padRadius = function(_) {
18226    return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
18227  };
18228
18229  arc.startAngle = function(_) {
18230    return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
18231  };
18232
18233  arc.endAngle = function(_) {
18234    return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
18235  };
18236
18237  arc.padAngle = function(_) {
18238    return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
18239  };
18240
18241  arc.context = function(_) {
18242    return arguments.length ? (context = _ == null ? null : _, arc) : context;
18243  };
18244
18245  return arc;
18246}
18247
18248function Linear(context) {
18249  this._context = context;
18250}
18251
18252Linear.prototype = {
18253  areaStart: function() {
18254    this._line = 0;
18255  },
18256  areaEnd: function() {
18257    this._line = NaN;
18258  },
18259  lineStart: function() {
18260    this._point = 0;
18261  },
18262  lineEnd: function() {
18263    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
18264    this._line = 1 - this._line;
18265  },
18266  point: function(x, y) {
18267    x = +x, y = +y;
18268    switch (this._point) {
18269      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
18270      case 1: this._point = 2; // proceed
18271      default: this._context.lineTo(x, y); break;
18272    }
18273  }
18274};
18275
18276function curveLinear(context) {
18277  return new Linear(context);
18278}
18279
18280function x$3(p) {
18281  return p[0];
18282}
18283
18284function y$3(p) {
18285  return p[1];
18286}
18287
18288function line() {
18289  var x$$1 = x$3,
18290      y$$1 = y$3,
18291      defined = constant$10(true),
18292      context = null,
18293      curve = curveLinear,
18294      output = null;
18295
18296  function line(data) {
18297    var i,
18298        n = data.length,
18299        d,
18300        defined0 = false,
18301        buffer;
18302
18303    if (context == null) output = curve(buffer = path());
18304
18305    for (i = 0; i <= n; ++i) {
18306      if (!(i < n && defined(d = data[i], i, data)) === defined0) {
18307        if (defined0 = !defined0) output.lineStart();
18308        else output.lineEnd();
18309      }
18310      if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
18311    }
18312
18313    if (buffer) return output = null, buffer + "" || null;
18314  }
18315
18316  line.x = function(_) {
18317    return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
18318  };
18319
18320  line.y = function(_) {
18321    return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
18322  };
18323
18324  line.defined = function(_) {
18325    return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
18326  };
18327
18328  line.curve = function(_) {
18329    return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
18330  };
18331
18332  line.context = function(_) {
18333    return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
18334  };
18335
18336  return line;
18337}
18338
18339function area$2() {
18340  var x0 = x$3,
18341      x1 = null,
18342      y0 = constant$10(0),
18343      y1 = y$3,
18344      defined = constant$10(true),
18345      context = null,
18346      curve = curveLinear,
18347      output = null;
18348
18349  function area(data) {
18350    var i,
18351        j,
18352        k,
18353        n = data.length,
18354        d,
18355        defined0 = false,
18356        buffer,
18357        x0z = new Array(n),
18358        y0z = new Array(n);
18359
18360    if (context == null) output = curve(buffer = path());
18361
18362    for (i = 0; i <= n; ++i) {
18363      if (!(i < n && defined(d = data[i], i, data)) === defined0) {
18364        if (defined0 = !defined0) {
18365          j = i;
18366          output.areaStart();
18367          output.lineStart();
18368        } else {
18369          output.lineEnd();
18370          output.lineStart();
18371          for (k = i - 1; k >= j; --k) {
18372            output.point(x0z[k], y0z[k]);
18373          }
18374          output.lineEnd();
18375          output.areaEnd();
18376        }
18377      }
18378      if (defined0) {
18379        x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
18380        output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
18381      }
18382    }
18383
18384    if (buffer) return output = null, buffer + "" || null;
18385  }
18386
18387  function arealine() {
18388    return line().defined(defined).curve(curve).context(context);
18389  }
18390
18391  area.x = function(_) {
18392    return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
18393  };
18394
18395  area.x0 = function(_) {
18396    return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
18397  };
18398
18399  area.x1 = function(_) {
18400    return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
18401  };
18402
18403  area.y = function(_) {
18404    return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
18405  };
18406
18407  area.y0 = function(_) {
18408    return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
18409  };
18410
18411  area.y1 = function(_) {
18412    return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
18413  };
18414
18415  area.lineX0 =
18416  area.lineY0 = function() {
18417    return arealine().x(x0).y(y0);
18418  };
18419
18420  area.lineY1 = function() {
18421    return arealine().x(x0).y(y1);
18422  };
18423
18424  area.lineX1 = function() {
18425    return arealine().x(x1).y(y0);
18426  };
18427
18428  area.defined = function(_) {
18429    return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
18430  };
18431
18432  area.curve = function(_) {
18433    return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
18434  };
18435
18436  area.context = function(_) {
18437    return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
18438  };
18439
18440  return area;
18441}
18442
18443function descending$1(a, b) {
18444  return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
18445}
18446
18447function identity$7(d) {
18448  return d;
18449}
18450
18451function pie() {
18452  var value = identity$7,
18453      sortValues = descending$1,
18454      sort = null,
18455      startAngle = constant$10(0),
18456      endAngle = constant$10(tau$4),
18457      padAngle = constant$10(0);
18458
18459  function pie(data) {
18460    var i,
18461        n = data.length,
18462        j,
18463        k,
18464        sum = 0,
18465        index = new Array(n),
18466        arcs = new Array(n),
18467        a0 = +startAngle.apply(this, arguments),
18468        da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
18469        a1,
18470        p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
18471        pa = p * (da < 0 ? -1 : 1),
18472        v;
18473
18474    for (i = 0; i < n; ++i) {
18475      if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
18476        sum += v;
18477      }
18478    }
18479
18480    // Optionally sort the arcs by previously-computed values or by data.
18481    if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
18482    else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
18483
18484    // Compute the arcs! They are stored in the original data's order.
18485    for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
18486      j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
18487        data: data[j],
18488        index: i,
18489        value: v,
18490        startAngle: a0,
18491        endAngle: a1,
18492        padAngle: p
18493      };
18494    }
18495
18496    return arcs;
18497  }
18498
18499  pie.value = function(_) {
18500    return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
18501  };
18502
18503  pie.sortValues = function(_) {
18504    return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
18505  };
18506
18507  pie.sort = function(_) {
18508    return arguments.length ? (sort = _, sortValues = null, pie) : sort;
18509  };
18510
18511  pie.startAngle = function(_) {
18512    return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
18513  };
18514
18515  pie.endAngle = function(_) {
18516    return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
18517  };
18518
18519  pie.padAngle = function(_) {
18520    return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
18521  };
18522
18523  return pie;
18524}
18525
18526var curveRadialLinear = curveRadial(curveLinear);
18527
18528function Radial(curve) {
18529  this._curve = curve;
18530}
18531
18532Radial.prototype = {
18533  areaStart: function() {
18534    this._curve.areaStart();
18535  },
18536  areaEnd: function() {
18537    this._curve.areaEnd();
18538  },
18539  lineStart: function() {
18540    this._curve.lineStart();
18541  },
18542  lineEnd: function() {
18543    this._curve.lineEnd();
18544  },
18545  point: function(a, r) {
18546    this._curve.point(r * Math.sin(a), r * -Math.cos(a));
18547  }
18548};
18549
18550function curveRadial(curve) {
18551
18552  function radial(context) {
18553    return new Radial(curve(context));
18554  }
18555
18556  radial._curve = curve;
18557
18558  return radial;
18559}
18560
18561function lineRadial(l) {
18562  var c = l.curve;
18563
18564  l.angle = l.x, delete l.x;
18565  l.radius = l.y, delete l.y;
18566
18567  l.curve = function(_) {
18568    return arguments.length ? c(curveRadial(_)) : c()._curve;
18569  };
18570
18571  return l;
18572}
18573
18574function lineRadial$1() {
18575  return lineRadial(line().curve(curveRadialLinear));
18576}
18577
18578function areaRadial() {
18579  var a = area$2().curve(curveRadialLinear),
18580      c = a.curve,
18581      x0 = a.lineX0,
18582      x1 = a.lineX1,
18583      y0 = a.lineY0,
18584      y1 = a.lineY1;
18585
18586  a.angle = a.x, delete a.x;
18587  a.startAngle = a.x0, delete a.x0;
18588  a.endAngle = a.x1, delete a.x1;
18589  a.radius = a.y, delete a.y;
18590  a.innerRadius = a.y0, delete a.y0;
18591  a.outerRadius = a.y1, delete a.y1;
18592  a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
18593  a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
18594  a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
18595  a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
18596
18597  a.curve = function(_) {
18598    return arguments.length ? c(curveRadial(_)) : c()._curve;
18599  };
18600
18601  return a;
18602}
18603
18604function pointRadial(x, y) {
18605  return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
18606}
18607
18608var slice$6 = Array.prototype.slice;
18609
18610function linkSource(d) {
18611  return d.source;
18612}
18613
18614function linkTarget(d) {
18615  return d.target;
18616}
18617
18618function link$2(curve) {
18619  var source = linkSource,
18620      target = linkTarget,
18621      x$$1 = x$3,
18622      y$$1 = y$3,
18623      context = null;
18624
18625  function link() {
18626    var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
18627    if (!context) context = buffer = path();
18628    curve(context, +x$$1.apply(this, (argv[0] = s, argv)), +y$$1.apply(this, argv), +x$$1.apply(this, (argv[0] = t, argv)), +y$$1.apply(this, argv));
18629    if (buffer) return context = null, buffer + "" || null;
18630  }
18631
18632  link.source = function(_) {
18633    return arguments.length ? (source = _, link) : source;
18634  };
18635
18636  link.target = function(_) {
18637    return arguments.length ? (target = _, link) : target;
18638  };
18639
18640  link.x = function(_) {
18641    return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
18642  };
18643
18644  link.y = function(_) {
18645    return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
18646  };
18647
18648  link.context = function(_) {
18649    return arguments.length ? (context = _ == null ? null : _, link) : context;
18650  };
18651
18652  return link;
18653}
18654
18655function curveHorizontal(context, x0, y0, x1, y1) {
18656  context.moveTo(x0, y0);
18657  context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
18658}
18659
18660function curveVertical(context, x0, y0, x1, y1) {
18661  context.moveTo(x0, y0);
18662  context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
18663}
18664
18665function curveRadial$1(context, x0, y0, x1, y1) {
18666  var p0 = pointRadial(x0, y0),
18667      p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
18668      p2 = pointRadial(x1, y0),
18669      p3 = pointRadial(x1, y1);
18670  context.moveTo(p0[0], p0[1]);
18671  context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
18672}
18673
18674function linkHorizontal() {
18675  return link$2(curveHorizontal);
18676}
18677
18678function linkVertical() {
18679  return link$2(curveVertical);
18680}
18681
18682function linkRadial() {
18683  var l = link$2(curveRadial$1);
18684  l.angle = l.x, delete l.x;
18685  l.radius = l.y, delete l.y;
18686  return l;
18687}
18688
18689var circle$2 = {
18690  draw: function(context, size) {
18691    var r = Math.sqrt(size / pi$4);
18692    context.moveTo(r, 0);
18693    context.arc(0, 0, r, 0, tau$4);
18694  }
18695};
18696
18697var cross$2 = {
18698  draw: function(context, size) {
18699    var r = Math.sqrt(size / 5) / 2;
18700    context.moveTo(-3 * r, -r);
18701    context.lineTo(-r, -r);
18702    context.lineTo(-r, -3 * r);
18703    context.lineTo(r, -3 * r);
18704    context.lineTo(r, -r);
18705    context.lineTo(3 * r, -r);
18706    context.lineTo(3 * r, r);
18707    context.lineTo(r, r);
18708    context.lineTo(r, 3 * r);
18709    context.lineTo(-r, 3 * r);
18710    context.lineTo(-r, r);
18711    context.lineTo(-3 * r, r);
18712    context.closePath();
18713  }
18714};
18715
18716var tan30 = Math.sqrt(1 / 3);
18717var tan30_2 = tan30 * 2;
18718
18719var diamond = {
18720  draw: function(context, size) {
18721    var y = Math.sqrt(size / tan30_2),
18722        x = y * tan30;
18723    context.moveTo(0, -y);
18724    context.lineTo(x, 0);
18725    context.lineTo(0, y);
18726    context.lineTo(-x, 0);
18727    context.closePath();
18728  }
18729};
18730
18731var ka = 0.89081309152928522810;
18732var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
18733var kx = Math.sin(tau$4 / 10) * kr;
18734var ky = -Math.cos(tau$4 / 10) * kr;
18735
18736var star = {
18737  draw: function(context, size) {
18738    var r = Math.sqrt(size * ka),
18739        x = kx * r,
18740        y = ky * r;
18741    context.moveTo(0, -r);
18742    context.lineTo(x, y);
18743    for (var i = 1; i < 5; ++i) {
18744      var a = tau$4 * i / 5,
18745          c = Math.cos(a),
18746          s = Math.sin(a);
18747      context.lineTo(s * r, -c * r);
18748      context.lineTo(c * x - s * y, s * x + c * y);
18749    }
18750    context.closePath();
18751  }
18752};
18753
18754var square = {
18755  draw: function(context, size) {
18756    var w = Math.sqrt(size),
18757        x = -w / 2;
18758    context.rect(x, x, w, w);
18759  }
18760};
18761
18762var sqrt3 = Math.sqrt(3);
18763
18764var triangle = {
18765  draw: function(context, size) {
18766    var y = -Math.sqrt(size / (sqrt3 * 3));
18767    context.moveTo(0, y * 2);
18768    context.lineTo(-sqrt3 * y, -y);
18769    context.lineTo(sqrt3 * y, -y);
18770    context.closePath();
18771  }
18772};
18773
18774var c = -0.5;
18775var s = Math.sqrt(3) / 2;
18776var k = 1 / Math.sqrt(12);
18777var a = (k / 2 + 1) * 3;
18778
18779var wye = {
18780  draw: function(context, size) {
18781    var r = Math.sqrt(size / a),
18782        x0 = r / 2,
18783        y0 = r * k,
18784        x1 = x0,
18785        y1 = r * k + r,
18786        x2 = -x1,
18787        y2 = y1;
18788    context.moveTo(x0, y0);
18789    context.lineTo(x1, y1);
18790    context.lineTo(x2, y2);
18791    context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
18792    context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
18793    context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
18794    context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
18795    context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
18796    context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
18797    context.closePath();
18798  }
18799};
18800
18801var symbols = [
18802  circle$2,
18803  cross$2,
18804  diamond,
18805  square,
18806  star,
18807  triangle,
18808  wye
18809];
18810
18811function symbol() {
18812  var type = constant$10(circle$2),
18813      size = constant$10(64),
18814      context = null;
18815
18816  function symbol() {
18817    var buffer;
18818    if (!context) context = buffer = path();
18819    type.apply(this, arguments).draw(context, +size.apply(this, arguments));
18820    if (buffer) return context = null, buffer + "" || null;
18821  }
18822
18823  symbol.type = function(_) {
18824    return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
18825  };
18826
18827  symbol.size = function(_) {
18828    return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
18829  };
18830
18831  symbol.context = function(_) {
18832    return arguments.length ? (context = _ == null ? null : _, symbol) : context;
18833  };
18834
18835  return symbol;
18836}
18837
18838function noop$2() {}
18839
18840function point$2(that, x, y) {
18841  that._context.bezierCurveTo(
18842    (2 * that._x0 + that._x1) / 3,
18843    (2 * that._y0 + that._y1) / 3,
18844    (that._x0 + 2 * that._x1) / 3,
18845    (that._y0 + 2 * that._y1) / 3,
18846    (that._x0 + 4 * that._x1 + x) / 6,
18847    (that._y0 + 4 * that._y1 + y) / 6
18848  );
18849}
18850
18851function Basis(context) {
18852  this._context = context;
18853}
18854
18855Basis.prototype = {
18856  areaStart: function() {
18857    this._line = 0;
18858  },
18859  areaEnd: function() {
18860    this._line = NaN;
18861  },
18862  lineStart: function() {
18863    this._x0 = this._x1 =
18864    this._y0 = this._y1 = NaN;
18865    this._point = 0;
18866  },
18867  lineEnd: function() {
18868    switch (this._point) {
18869      case 3: point$2(this, this._x1, this._y1); // proceed
18870      case 2: this._context.lineTo(this._x1, this._y1); break;
18871    }
18872    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
18873    this._line = 1 - this._line;
18874  },
18875  point: function(x, y) {
18876    x = +x, y = +y;
18877    switch (this._point) {
18878      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
18879      case 1: this._point = 2; break;
18880      case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
18881      default: point$2(this, x, y); break;
18882    }
18883    this._x0 = this._x1, this._x1 = x;
18884    this._y0 = this._y1, this._y1 = y;
18885  }
18886};
18887
18888function basis$2(context) {
18889  return new Basis(context);
18890}
18891
18892function BasisClosed(context) {
18893  this._context = context;
18894}
18895
18896BasisClosed.prototype = {
18897  areaStart: noop$2,
18898  areaEnd: noop$2,
18899  lineStart: function() {
18900    this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
18901    this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
18902    this._point = 0;
18903  },
18904  lineEnd: function() {
18905    switch (this._point) {
18906      case 1: {
18907        this._context.moveTo(this._x2, this._y2);
18908        this._context.closePath();
18909        break;
18910      }
18911      case 2: {
18912        this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
18913        this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
18914        this._context.closePath();
18915        break;
18916      }
18917      case 3: {
18918        this.point(this._x2, this._y2);
18919        this.point(this._x3, this._y3);
18920        this.point(this._x4, this._y4);
18921        break;
18922      }
18923    }
18924  },
18925  point: function(x, y) {
18926    x = +x, y = +y;
18927    switch (this._point) {
18928      case 0: this._point = 1;
vendor: 14,446 bytes, lines 18928-19463
18928 this._x2 = x, this._y2 = y; break;
18929      case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
18930      case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
18931      default: point$2(this, x, y); break;
18932    }
18933    this._x0 = this._x1, this._x1 = x;
18934    this._y0 = this._y1, this._y1 = y;
18935  }
18936};
18937
18938function basisClosed$1(context) {
18939  return new BasisClosed(context);
18940}
18941
18942function BasisOpen(context) {
18943  this._context = context;
18944}
18945
18946BasisOpen.prototype = {
18947  areaStart: function() {
18948    this._line = 0;
18949  },
18950  areaEnd: function() {
18951    this._line = NaN;
18952  },
18953  lineStart: function() {
18954    this._x0 = this._x1 =
18955    this._y0 = this._y1 = NaN;
18956    this._point = 0;
18957  },
18958  lineEnd: function() {
18959    if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
18960    this._line = 1 - this._line;
18961  },
18962  point: function(x, y) {
18963    x = +x, y = +y;
18964    switch (this._point) {
18965      case 0: this._point = 1; break;
18966      case 1: this._point = 2; break;
18967      case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
18968      case 3: this._point = 4; // proceed
18969      default: point$2(this, x, y); break;
18970    }
18971    this._x0 = this._x1, this._x1 = x;
18972    this._y0 = this._y1, this._y1 = y;
18973  }
18974};
18975
18976function basisOpen(context) {
18977  return new BasisOpen(context);
18978}
18979
18980function Bundle(context, beta) {
18981  this._basis = new Basis(context);
18982  this._beta = beta;
18983}
18984
18985Bundle.prototype = {
18986  lineStart: function() {
18987    this._x = [];
18988    this._y = [];
18989    this._basis.lineStart();
18990  },
18991  lineEnd: function() {
18992    var x = this._x,
18993        y = this._y,
18994        j = x.length - 1;
18995
18996    if (j > 0) {
18997      var x0 = x[0],
18998          y0 = y[0],
18999          dx = x[j] - x0,
19000          dy = y[j] - y0,
19001          i = -1,
19002          t;
19003
19004      while (++i <= j) {
19005        t = i / j;
19006        this._basis.point(
19007          this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
19008          this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
19009        );
19010      }
19011    }
19012
19013    this._x = this._y = null;
19014    this._basis.lineEnd();
19015  },
19016  point: function(x, y) {
19017    this._x.push(+x);
19018    this._y.push(+y);
19019  }
19020};
19021
19022var bundle = (function custom(beta) {
19023
19024  function bundle(context) {
19025    return beta === 1 ? new Basis(context) : new Bundle(context, beta);
19026  }
19027
19028  bundle.beta = function(beta) {
19029    return custom(+beta);
19030  };
19031
19032  return bundle;
19033})(0.85);
19034
19035function point$3(that, x, y) {
19036  that._context.bezierCurveTo(
19037    that._x1 + that._k * (that._x2 - that._x0),
19038    that._y1 + that._k * (that._y2 - that._y0),
19039    that._x2 + that._k * (that._x1 - x),
19040    that._y2 + that._k * (that._y1 - y),
19041    that._x2,
19042    that._y2
19043  );
19044}
19045
19046function Cardinal(context, tension) {
19047  this._context = context;
19048  this._k = (1 - tension) / 6;
19049}
19050
19051Cardinal.prototype = {
19052  areaStart: function() {
19053    this._line = 0;
19054  },
19055  areaEnd: function() {
19056    this._line = NaN;
19057  },
19058  lineStart: function() {
19059    this._x0 = this._x1 = this._x2 =
19060    this._y0 = this._y1 = this._y2 = NaN;
19061    this._point = 0;
19062  },
19063  lineEnd: function() {
19064    switch (this._point) {
19065      case 2: this._context.lineTo(this._x2, this._y2); break;
19066      case 3: point$3(this, this._x1, this._y1); break;
19067    }
19068    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
19069    this._line = 1 - this._line;
19070  },
19071  point: function(x, y) {
19072    x = +x, y = +y;
19073    switch (this._point) {
19074      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
19075      case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
19076      case 2: this._point = 3; // proceed
19077      default: point$3(this, x, y); break;
19078    }
19079    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
19080    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
19081  }
19082};
19083
19084var cardinal = (function custom(tension) {
19085
19086  function cardinal(context) {
19087    return new Cardinal(context, tension);
19088  }
19089
19090  cardinal.tension = function(tension) {
19091    return custom(+tension);
19092  };
19093
19094  return cardinal;
19095})(0);
19096
19097function CardinalClosed(context, tension) {
19098  this._context = context;
19099  this._k = (1 - tension) / 6;
19100}
19101
19102CardinalClosed.prototype = {
19103  areaStart: noop$2,
19104  areaEnd: noop$2,
19105  lineStart: function() {
19106    this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
19107    this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
19108    this._point = 0;
19109  },
19110  lineEnd: function() {
19111    switch (this._point) {
19112      case 1: {
19113        this._context.moveTo(this._x3, this._y3);
19114        this._context.closePath();
19115        break;
19116      }
19117      case 2: {
19118        this._context.lineTo(this._x3, this._y3);
19119        this._context.closePath();
19120        break;
19121      }
19122      case 3: {
19123        this.point(this._x3, this._y3);
19124        this.point(this._x4, this._y4);
19125        this.point(this._x5, this._y5);
19126        break;
19127      }
19128    }
19129  },
19130  point: function(x, y) {
19131    x = +x, y = +y;
19132    switch (this._point) {
19133      case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
19134      case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
19135      case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
19136      default: point$3(this, x, y); break;
19137    }
19138    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
19139    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
19140  }
19141};
19142
19143var cardinalClosed = (function custom(tension) {
19144
19145  function cardinal$$1(context) {
19146    return new CardinalClosed(context, tension);
19147  }
19148
19149  cardinal$$1.tension = function(tension) {
19150    return custom(+tension);
19151  };
19152
19153  return cardinal$$1;
19154})(0);
19155
19156function CardinalOpen(context, tension) {
19157  this._context = context;
19158  this._k = (1 - tension) / 6;
19159}
19160
19161CardinalOpen.prototype = {
19162  areaStart: function() {
19163    this._line = 0;
19164  },
19165  areaEnd: function() {
19166    this._line = NaN;
19167  },
19168  lineStart: function() {
19169    this._x0 = this._x1 = this._x2 =
19170    this._y0 = this._y1 = this._y2 = NaN;
19171    this._point = 0;
19172  },
19173  lineEnd: function() {
19174    if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
19175    this._line = 1 - this._line;
19176  },
19177  point: function(x, y) {
19178    x = +x, y = +y;
19179    switch (this._point) {
19180      case 0: this._point = 1; break;
19181      case 1: this._point = 2; break;
19182      case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
19183      case 3: this._point = 4; // proceed
19184      default: point$3(this, x, y); break;
19185    }
19186    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
19187    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
19188  }
19189};
19190
19191var cardinalOpen = (function custom(tension) {
19192
19193  function cardinal$$1(context) {
19194    return new CardinalOpen(context, tension);
19195  }
19196
19197  cardinal$$1.tension = function(tension) {
19198    return custom(+tension);
19199  };
19200
19201  return cardinal$$1;
19202})(0);
19203
19204function point$4(that, x, y) {
19205  var x1 = that._x1,
19206      y1 = that._y1,
19207      x2 = that._x2,
19208      y2 = that._y2;
19209
19210  if (that._l01_a > epsilon$3) {
19211    var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
19212        n = 3 * that._l01_a * (that._l01_a + that._l12_a);
19213    x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
19214    y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
19215  }
19216
19217  if (that._l23_a > epsilon$3) {
19218    var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
19219        m = 3 * that._l23_a * (that._l23_a + that._l12_a);
19220    x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
19221    y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
19222  }
19223
19224  that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
19225}
19226
19227function CatmullRom(context, alpha) {
19228  this._context = context;
19229  this._alpha = alpha;
19230}
19231
19232CatmullRom.prototype = {
19233  areaStart: function() {
19234    this._line = 0;
19235  },
19236  areaEnd: function() {
19237    this._line = NaN;
19238  },
19239  lineStart: function() {
19240    this._x0 = this._x1 = this._x2 =
19241    this._y0 = this._y1 = this._y2 = NaN;
19242    this._l01_a = this._l12_a = this._l23_a =
19243    this._l01_2a = this._l12_2a = this._l23_2a =
19244    this._point = 0;
19245  },
19246  lineEnd: function() {
19247    switch (this._point) {
19248      case 2: this._context.lineTo(this._x2, this._y2); break;
19249      case 3: this.point(this._x2, this._y2); break;
19250    }
19251    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
19252    this._line = 1 - this._line;
19253  },
19254  point: function(x, y) {
19255    x = +x, y = +y;
19256
19257    if (this._point) {
19258      var x23 = this._x2 - x,
19259          y23 = this._y2 - y;
19260      this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
19261    }
19262
19263    switch (this._point) {
19264      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
19265      case 1: this._point = 2; break;
19266      case 2: this._point = 3; // proceed
19267      default: point$4(this, x, y); break;
19268    }
19269
19270    this._l01_a = this._l12_a, this._l12_a = this._l23_a;
19271    this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
19272    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
19273    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
19274  }
19275};
19276
19277var catmullRom = (function custom(alpha) {
19278
19279  function catmullRom(context) {
19280    return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
19281  }
19282
19283  catmullRom.alpha = function(alpha) {
19284    return custom(+alpha);
19285  };
19286
19287  return catmullRom;
19288})(0.5);
19289
19290function CatmullRomClosed(context, alpha) {
19291  this._context = context;
19292  this._alpha = alpha;
19293}
19294
19295CatmullRomClosed.prototype = {
19296  areaStart: noop$2,
19297  areaEnd: noop$2,
19298  lineStart: function() {
19299    this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
19300    this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
19301    this._l01_a = this._l12_a = this._l23_a =
19302    this._l01_2a = this._l12_2a = this._l23_2a =
19303    this._point = 0;
19304  },
19305  lineEnd: function() {
19306    switch (this._point) {
19307      case 1: {
19308        this._context.moveTo(this._x3, this._y3);
19309        this._context.closePath();
19310        break;
19311      }
19312      case 2: {
19313        this._context.lineTo(this._x3, this._y3);
19314        this._context.closePath();
19315        break;
19316      }
19317      case 3: {
19318        this.point(this._x3, this._y3);
19319        this.point(this._x4, this._y4);
19320        this.point(this._x5, this._y5);
19321        break;
19322      }
19323    }
19324  },
19325  point: function(x, y) {
19326    x = +x, y = +y;
19327
19328    if (this._point) {
19329      var x23 = this._x2 - x,
19330          y23 = this._y2 - y;
19331      this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
19332    }
19333
19334    switch (this._point) {
19335      case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
19336      case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
19337      case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
19338      default: point$4(this, x, y); break;
19339    }
19340
19341    this._l01_a = this._l12_a, this._l12_a = this._l23_a;
19342    this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
19343    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
19344    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
19345  }
19346};
19347
19348var catmullRomClosed = (function custom(alpha) {
19349
19350  function catmullRom$$1(context) {
19351    return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
19352  }
19353
19354  catmullRom$$1.alpha = function(alpha) {
19355    return custom(+alpha);
19356  };
19357
19358  return catmullRom$$1;
19359})(0.5);
19360
19361function CatmullRomOpen(context, alpha) {
19362  this._context = context;
19363  this._alpha = alpha;
19364}
19365
19366CatmullRomOpen.prototype = {
19367  areaStart: function() {
19368    this._line = 0;
19369  },
19370  areaEnd: function() {
19371    this._line = NaN;
19372  },
19373  lineStart: function() {
19374    this._x0 = this._x1 = this._x2 =
19375    this._y0 = this._y1 = this._y2 = NaN;
19376    this._l01_a = this._l12_a = this._l23_a =
19377    this._l01_2a = this._l12_2a = this._l23_2a =
19378    this._point = 0;
19379  },
19380  lineEnd: function() {
19381    if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
19382    this._line = 1 - this._line;
19383  },
19384  point: function(x, y) {
19385    x = +x, y = +y;
19386
19387    if (this._point) {
19388      var x23 = this._x2 - x,
19389          y23 = this._y2 - y;
19390      this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
19391    }
19392
19393    switch (this._point) {
19394      case 0: this._point = 1; break;
19395      case 1: this._point = 2; break;
19396      case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
19397      case 3: this._point = 4; // proceed
19398      default: point$4(this, x, y); break;
19399    }
19400
19401    this._l01_a = this._l12_a, this._l12_a = this._l23_a;
19402    this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
19403    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
19404    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
19405  }
19406};
19407
19408var catmullRomOpen = (function custom(alpha) {
19409
19410  function catmullRom$$1(context) {
19411    return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
19412  }
19413
19414  catmullRom$$1.alpha = function(alpha) {
19415    return custom(+alpha);
19416  };
19417
19418  return catmullRom$$1;
19419})(0.5);
19420
19421function LinearClosed(context) {
19422  this._context = context;
19423}
19424
19425LinearClosed.prototype = {
19426  areaStart: noop$2,
19427  areaEnd: noop$2,
19428  lineStart: function() {
19429    this._point = 0;
19430  },
19431  lineEnd: function() {
19432    if (this._point) this._context.closePath();
19433  },
19434  point: function(x, y) {
19435    x = +x, y = +y;
19436    if (this._point) this._context.lineTo(x, y);
19437    else this._point = 1, this._context.moveTo(x, y);
19438  }
19439};
19440
19441function linearClosed(context) {
19442  return new LinearClosed(context);
19443}
19444
19445function sign$1(x) {
19446  return x < 0 ? -1 : 1;
19447}
19448
19449// Calculate the slopes of the tangents (Hermite-type interpolation) based on
19450// the following paper: Steffen, M. 1990. A Simple Method for Monotonic
19451// Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
19452// NOV(II), P. 443, 1990.
19453function slope3(that, x2, y2) {
19454  var h0 = that._x1 - that._x0,
19455      h1 = x2 - that._x1,
19456      s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
19457      s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
19458      p = (s0 * h1 + s1 * h0) / (h0 + h1);
19459  return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
19460}
19461
19462// Calculate a one-sided slope.
19463function slope2(that, t) {
vendor: 11,963 bytes, lines 19464-19931
19464  var h = that._x1 - that._x0;
19465  return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
19466}
19467
19468// According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
19469// "you can express cubic Hermite interpolation in terms of cubic Bézier curves
19470// with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
19471function point$5(that, t0, t1) {
19472  var x0 = that._x0,
19473      y0 = that._y0,
19474      x1 = that._x1,
19475      y1 = that._y1,
19476      dx = (x1 - x0) / 3;
19477  that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
19478}
19479
19480function MonotoneX(context) {
19481  this._context = context;
19482}
19483
19484MonotoneX.prototype = {
19485  areaStart: function() {
19486    this._line = 0;
19487  },
19488  areaEnd: function() {
19489    this._line = NaN;
19490  },
19491  lineStart: function() {
19492    this._x0 = this._x1 =
19493    this._y0 = this._y1 =
19494    this._t0 = NaN;
19495    this._point = 0;
19496  },
19497  lineEnd: function() {
19498    switch (this._point) {
19499      case 2: this._context.lineTo(this._x1, this._y1); break;
19500      case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
19501    }
19502    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
19503    this._line = 1 - this._line;
19504  },
19505  point: function(x, y) {
19506    var t1 = NaN;
19507
19508    x = +x, y = +y;
19509    if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
19510    switch (this._point) {
19511      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
19512      case 1: this._point = 2; break;
19513      case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
19514      default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
19515    }
19516
19517    this._x0 = this._x1, this._x1 = x;
19518    this._y0 = this._y1, this._y1 = y;
19519    this._t0 = t1;
19520  }
19521};
19522
19523function MonotoneY(context) {
19524  this._context = new ReflectContext(context);
19525}
19526
19527(MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
19528  MonotoneX.prototype.point.call(this, y, x);
19529};
19530
19531function ReflectContext(context) {
19532  this._context = context;
19533}
19534
19535ReflectContext.prototype = {
19536  moveTo: function(x, y) { this._context.moveTo(y, x); },
19537  closePath: function() { this._context.closePath(); },
19538  lineTo: function(x, y) { this._context.lineTo(y, x); },
19539  bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
19540};
19541
19542function monotoneX(context) {
19543  return new MonotoneX(context);
19544}
19545
19546function monotoneY(context) {
19547  return new MonotoneY(context);
19548}
19549
19550function Natural(context) {
19551  this._context = context;
19552}
19553
19554Natural.prototype = {
19555  areaStart: function() {
19556    this._line = 0;
19557  },
19558  areaEnd: function() {
19559    this._line = NaN;
19560  },
19561  lineStart: function() {
19562    this._x = [];
19563    this._y = [];
19564  },
19565  lineEnd: function() {
19566    var x = this._x,
19567        y = this._y,
19568        n = x.length;
19569
19570    if (n) {
19571      this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
19572      if (n === 2) {
19573        this._context.lineTo(x[1], y[1]);
19574      } else {
19575        var px = controlPoints(x),
19576            py = controlPoints(y);
19577        for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
19578          this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
19579        }
19580      }
19581    }
19582
19583    if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
19584    this._line = 1 - this._line;
19585    this._x = this._y = null;
19586  },
19587  point: function(x, y) {
19588    this._x.push(+x);
19589    this._y.push(+y);
19590  }
19591};
19592
19593// See https://www.particleincell.com/2012/bezier-splines/ for derivation.
19594function controlPoints(x) {
19595  var i,
19596      n = x.length - 1,
19597      m,
19598      a = new Array(n),
19599      b = new Array(n),
19600      r = new Array(n);
19601  a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
19602  for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
19603  a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
19604  for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
19605  a[n - 1] = r[n - 1] / b[n - 1];
19606  for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
19607  b[n - 1] = (x[n] + a[n - 1]) / 2;
19608  for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
19609  return [a, b];
19610}
19611
19612function natural(context) {
19613  return new Natural(context);
19614}
19615
19616function Step(context, t) {
19617  this._context = context;
19618  this._t = t;
19619}
19620
19621Step.prototype = {
19622  areaStart: function() {
19623    this._line = 0;
19624  },
19625  areaEnd: function() {
19626    this._line = NaN;
19627  },
19628  lineStart: function() {
19629    this._x = this._y = NaN;
19630    this._point = 0;
19631  },
19632  lineEnd: function() {
19633    if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
19634    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
19635    if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
19636  },
19637  point: function(x, y) {
19638    x = +x, y = +y;
19639    switch (this._point) {
19640      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
19641      case 1: this._point = 2; // proceed
19642      default: {
19643        if (this._t <= 0) {
19644          this._context.lineTo(this._x, y);
19645          this._context.lineTo(x, y);
19646        } else {
19647          var x1 = this._x * (1 - this._t) + x * this._t;
19648          this._context.lineTo(x1, this._y);
19649          this._context.lineTo(x1, y);
19650        }
19651        break;
19652      }
19653    }
19654    this._x = x, this._y = y;
19655  }
19656};
19657
19658function step(context) {
19659  return new Step(context, 0.5);
19660}
19661
19662function stepBefore(context) {
19663  return new Step(context, 0);
19664}
19665
19666function stepAfter(context) {
19667  return new Step(context, 1);
19668}
19669
19670function none$1(series, order) {
19671  if (!((n = series.length) > 1)) return;
19672  for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
19673    s0 = s1, s1 = series[order[i]];
19674    for (j = 0; j < m; ++j) {
19675      s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
19676    }
19677  }
19678}
19679
19680function none$2(series) {
19681  var n = series.length, o = new Array(n);
19682  while (--n >= 0) o[n] = n;
19683  return o;
19684}
19685
19686function stackValue(d, key) {
19687  return d[key];
19688}
19689
19690function stack() {
19691  var keys = constant$10([]),
19692      order = none$2,
19693      offset = none$1,
19694      value = stackValue;
19695
19696  function stack(data) {
19697    var kz = keys.apply(this, arguments),
19698        i,
19699        m = data.length,
19700        n = kz.length,
19701        sz = new Array(n),
19702        oz;
19703
19704    for (i = 0; i < n; ++i) {
19705      for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
19706        si[j] = sij = [0, +value(data[j], ki, j, data)];
19707        sij.data = data[j];
19708      }
19709      si.key = ki;
19710    }
19711
19712    for (i = 0, oz = order(sz); i < n; ++i) {
19713      sz[oz[i]].index = i;
19714    }
19715
19716    offset(sz, oz);
19717    return sz;
19718  }
19719
19720  stack.keys = function(_) {
19721    return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : keys;
19722  };
19723
19724  stack.value = function(_) {
19725    return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
19726  };
19727
19728  stack.order = function(_) {
19729    return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : order;
19730  };
19731
19732  stack.offset = function(_) {
19733    return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
19734  };
19735
19736  return stack;
19737}
19738
19739function expand(series, order) {
19740  if (!((n = series.length) > 0)) return;
19741  for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
19742    for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
19743    if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
19744  }
19745  none$1(series, order);
19746}
19747
19748function diverging(series, order) {
19749  if (!((n = series.length) > 1)) return;
19750  for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
19751    for (yp = yn = 0, i = 0; i < n; ++i) {
19752      if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
19753        d[0] = yp, d[1] = yp += dy;
19754      } else if (dy < 0) {
19755        d[1] = yn, d[0] = yn += dy;
19756      } else {
19757        d[0] = yp;
19758      }
19759    }
19760  }
19761}
19762
19763function silhouette(series, order) {
19764  if (!((n = series.length) > 0)) return;
19765  for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
19766    for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
19767    s0[j][1] += s0[j][0] = -y / 2;
19768  }
19769  none$1(series, order);
19770}
19771
19772function wiggle(series, order) {
19773  if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
19774  for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
19775    for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
19776      var si = series[order[i]],
19777          sij0 = si[j][1] || 0,
19778          sij1 = si[j - 1][1] || 0,
19779          s3 = (sij0 - sij1) / 2;
19780      for (var k = 0; k < i; ++k) {
19781        var sk = series[order[k]],
19782            skj0 = sk[j][1] || 0,
19783            skj1 = sk[j - 1][1] || 0;
19784        s3 += skj0 - skj1;
19785      }
19786      s1 += sij0, s2 += s3 * sij0;
19787    }
19788    s0[j - 1][1] += s0[j - 1][0] = y;
19789    if (s1) y -= s2 / s1;
19790  }
19791  s0[j - 1][1] += s0[j - 1][0] = y;
19792  none$1(series, order);
19793}
19794
19795function ascending$2(series) {
19796  var sums = series.map(sum$2);
19797  return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
19798}
19799
19800function sum$2(series) {
19801  var s = 0, i = -1, n = series.length, v;
19802  while (++i < n) if (v = +series[i][1]) s += v;
19803  return s;
19804}
19805
19806function descending$2(series) {
19807  return ascending$2(series).reverse();
19808}
19809
19810function insideOut(series) {
19811  var n = series.length,
19812      i,
19813      j,
19814      sums = series.map(sum$2),
19815      order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
19816      top = 0,
19817      bottom = 0,
19818      tops = [],
19819      bottoms = [];
19820
19821  for (i = 0; i < n; ++i) {
19822    j = order[i];
19823    if (top < bottom) {
19824      top += sums[j];
19825      tops.push(j);
19826    } else {
19827      bottom += sums[j];
19828      bottoms.push(j);
19829    }
19830  }
19831
19832  return bottoms.reverse().concat(tops);
19833}
19834
19835function reverse(series) {
19836  return none$2(series).reverse();
19837}
19838
19839function constant$11(x) {
19840  return function() {
19841    return x;
19842  };
19843}
19844
19845function x$4(d) {
19846  return d[0];
19847}
19848
19849function y$4(d) {
19850  return d[1];
19851}
19852
19853function RedBlackTree() {
19854  this._ = null; // root node
19855}
19856
19857function RedBlackNode(node) {
19858  node.U = // parent node
19859  node.C = // color - true for red, false for black
19860  node.L = // left node
19861  node.R = // right node
19862  node.P = // previous node
19863  node.N = null; // next node
19864}
19865
19866RedBlackTree.prototype = {
19867  constructor: RedBlackTree,
19868
19869  insert: function(after, node) {
19870    var parent, grandpa, uncle;
19871
19872    if (after) {
19873      node.P = after;
19874      node.N = after.N;
19875      if (after.N) after.N.P = node;
19876      after.N = node;
19877      if (after.R) {
19878        after = after.R;
19879        while (after.L) after = after.L;
19880        after.L = node;
19881      } else {
19882        after.R = node;
19883      }
19884      parent = after;
19885    } else if (this._) {
19886      after = RedBlackFirst(this._);
19887      node.P = null;
19888      node.N = after;
19889      after.P = after.L = node;
19890      parent = after;
19891    } else {
19892      node.P = node.N = null;
19893      this._ = node;
19894      parent = null;
19895    }
19896    node.L = node.R = null;
19897    node.U = parent;
19898    node.C = true;
19899
19900    after = node;
19901    while (parent && parent.C) {
19902      grandpa = parent.U;
19903      if (parent === grandpa.L) {
19904        uncle = grandpa.R;
19905        if (uncle && uncle.C) {
19906          parent.C = uncle.C = false;
19907          grandpa.C = true;
19908          after = grandpa;
19909        } else {
19910          if (after === parent.R) {
19911            RedBlackRotateLeft(this, parent);
19912            after = parent;
19913            parent = after.U;
19914          }
19915          parent.C = false;
19916          grandpa.C = true;
19917          RedBlackRotateRight(this, grandpa);
19918        }
19919      } else {
19920        uncle = grandpa.L;
19921        if (uncle && uncle.C) {
19922          parent.C = uncle.C = false;
19923          grandpa.C = true;
19924          after = grandpa;
19925        } else {
19926          if (after === parent.L) {
19927            RedBlackRotateRight(this, parent);
19928            after = parent;
19929            parent = after.U;
19930          }
19931          parent.C = false;
vendor: 16,603 bytes, lines 19932-20645
19932          grandpa.C = true;
19933          RedBlackRotateLeft(this, grandpa);
19934        }
19935      }
19936      parent = after.U;
19937    }
19938    this._.C = false;
19939  },
19940
19941  remove: function(node) {
19942    if (node.N) node.N.P = node.P;
19943    if (node.P) node.P.N = node.N;
19944    node.N = node.P = null;
19945
19946    var parent = node.U,
19947        sibling,
19948        left = node.L,
19949        right = node.R,
19950        next,
19951        red;
19952
19953    if (!left) next = right;
19954    else if (!right) next = left;
19955    else next = RedBlackFirst(right);
19956
19957    if (parent) {
19958      if (parent.L === node) parent.L = next;
19959      else parent.R = next;
19960    } else {
19961      this._ = next;
19962    }
19963
19964    if (left && right) {
19965      red = next.C;
19966      next.C = node.C;
19967      next.L = left;
19968      left.U = next;
19969      if (next !== right) {
19970        parent = next.U;
19971        next.U = node.U;
19972        node = next.R;
19973        parent.L = node;
19974        next.R = right;
19975        right.U = next;
19976      } else {
19977        next.U = parent;
19978        parent = next;
19979        node = next.R;
19980      }
19981    } else {
19982      red = node.C;
19983      node = next;
19984    }
19985
19986    if (node) node.U = parent;
19987    if (red) return;
19988    if (node && node.C) { node.C = false; return; }
19989
19990    do {
19991      if (node === this._) break;
19992      if (node === parent.L) {
19993        sibling = parent.R;
19994        if (sibling.C) {
19995          sibling.C = false;
19996          parent.C = true;
19997          RedBlackRotateLeft(this, parent);
19998          sibling = parent.R;
19999        }
20000        if ((sibling.L && sibling.L.C)
20001            || (sibling.R && sibling.R.C)) {
20002          if (!sibling.R || !sibling.R.C) {
20003            sibling.L.C = false;
20004            sibling.C = true;
20005            RedBlackRotateRight(this, sibling);
20006            sibling = parent.R;
20007          }
20008          sibling.C = parent.C;
20009          parent.C = sibling.R.C = false;
20010          RedBlackRotateLeft(this, parent);
20011          node = this._;
20012          break;
20013        }
20014      } else {
20015        sibling = parent.L;
20016        if (sibling.C) {
20017          sibling.C = false;
20018          parent.C = true;
20019          RedBlackRotateRight(this, parent);
20020          sibling = parent.L;
20021        }
20022        if ((sibling.L && sibling.L.C)
20023          || (sibling.R && sibling.R.C)) {
20024          if (!sibling.L || !sibling.L.C) {
20025            sibling.R.C = false;
20026            sibling.C = true;
20027            RedBlackRotateLeft(this, sibling);
20028            sibling = parent.L;
20029          }
20030          sibling.C = parent.C;
20031          parent.C = sibling.L.C = false;
20032          RedBlackRotateRight(this, parent);
20033          node = this._;
20034          break;
20035        }
20036      }
20037      sibling.C = true;
20038      node = parent;
20039      parent = parent.U;
20040    } while (!node.C);
20041
20042    if (node) node.C = false;
20043  }
20044};
20045
20046function RedBlackRotateLeft(tree, node) {
20047  var p = node,
20048      q = node.R,
20049      parent = p.U;
20050
20051  if (parent) {
20052    if (parent.L === p) parent.L = q;
20053    else parent.R = q;
20054  } else {
20055    tree._ = q;
20056  }
20057
20058  q.U = parent;
20059  p.U = q;
20060  p.R = q.L;
20061  if (p.R) p.R.U = p;
20062  q.L = p;
20063}
20064
20065function RedBlackRotateRight(tree, node) {
20066  var p = node,
20067      q = node.L,
20068      parent = p.U;
20069
20070  if (parent) {
20071    if (parent.L === p) parent.L = q;
20072    else parent.R = q;
20073  } else {
20074    tree._ = q;
20075  }
20076
20077  q.U = parent;
20078  p.U = q;
20079  p.L = q.R;
20080  if (p.L) p.L.U = p;
20081  q.R = p;
20082}
20083
20084function RedBlackFirst(node) {
20085  while (node.L) node = node.L;
20086  return node;
20087}
20088
20089function createEdge(left, right, v0, v1) {
20090  var edge = [null, null],
20091      index = edges.push(edge) - 1;
20092  edge.left = left;
20093  edge.right = right;
20094  if (v0) setEdgeEnd(edge, left, right, v0);
20095  if (v1) setEdgeEnd(edge, right, left, v1);
20096  cells[left.index].halfedges.push(index);
20097  cells[right.index].halfedges.push(index);
20098  return edge;
20099}
20100
20101function createBorderEdge(left, v0, v1) {
20102  var edge = [v0, v1];
20103  edge.left = left;
20104  return edge;
20105}
20106
20107function setEdgeEnd(edge, left, right, vertex) {
20108  if (!edge[0] && !edge[1]) {
20109    edge[0] = vertex;
20110    edge.left = left;
20111    edge.right = right;
20112  } else if (edge.left === right) {
20113    edge[1] = vertex;
20114  } else {
20115    edge[0] = vertex;
20116  }
20117}
20118
20119// Liang–Barsky line clipping.
20120function clipEdge(edge, x0, y0, x1, y1) {
20121  var a = edge[0],
20122      b = edge[1],
20123      ax = a[0],
20124      ay = a[1],
20125      bx = b[0],
20126      by = b[1],
20127      t0 = 0,
20128      t1 = 1,
20129      dx = bx - ax,
20130      dy = by - ay,
20131      r;
20132
20133  r = x0 - ax;
20134  if (!dx && r > 0) return;
20135  r /= dx;
20136  if (dx < 0) {
20137    if (r < t0) return;
20138    if (r < t1) t1 = r;
20139  } else if (dx > 0) {
20140    if (r > t1) return;
20141    if (r > t0) t0 = r;
20142  }
20143
20144  r = x1 - ax;
20145  if (!dx && r < 0) return;
20146  r /= dx;
20147  if (dx < 0) {
20148    if (r > t1) return;
20149    if (r > t0) t0 = r;
20150  } else if (dx > 0) {
20151    if (r < t0) return;
20152    if (r < t1) t1 = r;
20153  }
20154
20155  r = y0 - ay;
20156  if (!dy && r > 0) return;
20157  r /= dy;
20158  if (dy < 0) {
20159    if (r < t0) return;
20160    if (r < t1) t1 = r;
20161  } else if (dy > 0) {
20162    if (r > t1) return;
20163    if (r > t0) t0 = r;
20164  }
20165
20166  r = y1 - ay;
20167  if (!dy && r < 0) return;
20168  r /= dy;
20169  if (dy < 0) {
20170    if (r > t1) return;
20171    if (r > t0) t0 = r;
20172  } else if (dy > 0) {
20173    if (r < t0) return;
20174    if (r < t1) t1 = r;
20175  }
20176
20177  if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
20178
20179  if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
20180  if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
20181  return true;
20182}
20183
20184function connectEdge(edge, x0, y0, x1, y1) {
20185  var v1 = edge[1];
20186  if (v1) return true;
20187
20188  var v0 = edge[0],
20189      left = edge.left,
20190      right = edge.right,
20191      lx = left[0],
20192      ly = left[1],
20193      rx = right[0],
20194      ry = right[1],
20195      fx = (lx + rx) / 2,
20196      fy = (ly + ry) / 2,
20197      fm,
20198      fb;
20199
20200  if (ry === ly) {
20201    if (fx < x0 || fx >= x1) return;
20202    if (lx > rx) {
20203      if (!v0) v0 = [fx, y0];
20204      else if (v0[1] >= y1) return;
20205      v1 = [fx, y1];
20206    } else {
20207      if (!v0) v0 = [fx, y1];
20208      else if (v0[1] < y0) return;
20209      v1 = [fx, y0];
20210    }
20211  } else {
20212    fm = (lx - rx) / (ry - ly);
20213    fb = fy - fm * fx;
20214    if (fm < -1 || fm > 1) {
20215      if (lx > rx) {
20216        if (!v0) v0 = [(y0 - fb) / fm, y0];
20217        else if (v0[1] >= y1) return;
20218        v1 = [(y1 - fb) / fm, y1];
20219      } else {
20220        if (!v0) v0 = [(y1 - fb) / fm, y1];
20221        else if (v0[1] < y0) return;
20222        v1 = [(y0 - fb) / fm, y0];
20223      }
20224    } else {
20225      if (ly < ry) {
20226        if (!v0) v0 = [x0, fm * x0 + fb];
20227        else if (v0[0] >= x1) return;
20228        v1 = [x1, fm * x1 + fb];
20229      } else {
20230        if (!v0) v0 = [x1, fm * x1 + fb];
20231        else if (v0[0] < x0) return;
20232        v1 = [x0, fm * x0 + fb];
20233      }
20234    }
20235  }
20236
20237  edge[0] = v0;
20238  edge[1] = v1;
20239  return true;
20240}
20241
20242function clipEdges(x0, y0, x1, y1) {
20243  var i = edges.length,
20244      edge;
20245
20246  while (i--) {
20247    if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
20248        || !clipEdge(edge, x0, y0, x1, y1)
20249        || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
20250            || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
20251      delete edges[i];
20252    }
20253  }
20254}
20255
20256function createCell(site) {
20257  return cells[site.index] = {
20258    site: site,
20259    halfedges: []
20260  };
20261}
20262
20263function cellHalfedgeAngle(cell, edge) {
20264  var site = cell.site,
20265      va = edge.left,
20266      vb = edge.right;
20267  if (site === vb) vb = va, va = site;
20268  if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
20269  if (site === va) va = edge[1], vb = edge[0];
20270  else va = edge[0], vb = edge[1];
20271  return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
20272}
20273
20274function cellHalfedgeStart(cell, edge) {
20275  return edge[+(edge.left !== cell.site)];
20276}
20277
20278function cellHalfedgeEnd(cell, edge) {
20279  return edge[+(edge.left === cell.site)];
20280}
20281
20282function sortCellHalfedges() {
20283  for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
20284    if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
20285      var index = new Array(m),
20286          array = new Array(m);
20287      for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
20288      index.sort(function(i, j) { return array[j] - array[i]; });
20289      for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
20290      for (j = 0; j < m; ++j) halfedges[j] = array[j];
20291    }
20292  }
20293}
20294
20295function clipCells(x0, y0, x1, y1) {
20296  var nCells = cells.length,
20297      iCell,
20298      cell,
20299      site,
20300      iHalfedge,
20301      halfedges,
20302      nHalfedges,
20303      start,
20304      startX,
20305      startY,
20306      end,
20307      endX,
20308      endY,
20309      cover = true;
20310
20311  for (iCell = 0; iCell < nCells; ++iCell) {
20312    if (cell = cells[iCell]) {
20313      site = cell.site;
20314      halfedges = cell.halfedges;
20315      iHalfedge = halfedges.length;
20316
20317      // Remove any dangling clipped edges.
20318      while (iHalfedge--) {
20319        if (!edges[halfedges[iHalfedge]]) {
20320          halfedges.splice(iHalfedge, 1);
20321        }
20322      }
20323
20324      // Insert any border edges as necessary.
20325      iHalfedge = 0, nHalfedges = halfedges.length;
20326      while (iHalfedge < nHalfedges) {
20327        end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
20328        start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
20329        if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
20330          halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
20331              Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
20332              : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
20333              : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
20334              : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
20335              : null)) - 1);
20336          ++nHalfedges;
20337        }
20338      }
20339
20340      if (nHalfedges) cover = false;
20341    }
20342  }
20343
20344  // If there weren’t any edges, have the closest site cover the extent.
20345  // It doesn’t matter which corner of the extent we measure!
20346  if (cover) {
20347    var dx, dy, d2, dc = Infinity;
20348
20349    for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
20350      if (cell = cells[iCell]) {
20351        site = cell.site;
20352        dx = site[0] - x0;
20353        dy = site[1] - y0;
20354        d2 = dx * dx + dy * dy;
20355        if (d2 < dc) dc = d2, cover = cell;
20356      }
20357    }
20358
20359    if (cover) {
20360      var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
20361      cover.halfedges.push(
20362        edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
20363        edges.push(createBorderEdge(site, v01, v11)) - 1,
20364        edges.push(createBorderEdge(site, v11, v10)) - 1,
20365        edges.push(createBorderEdge(site, v10, v00)) - 1
20366      );
20367    }
20368  }
20369
20370  // Lastly delete any cells with no edges; these were entirely clipped.
20371  for (iCell = 0; iCell < nCells; ++iCell) {
20372    if (cell = cells[iCell]) {
20373      if (!cell.halfedges.length) {
20374        delete cells[iCell];
20375      }
20376    }
20377  }
20378}
20379
20380var circlePool = [];
20381
20382var firstCircle;
20383
20384function Circle() {
20385  RedBlackNode(this);
20386  this.x =
20387  this.y =
20388  this.arc =
20389  this.site =
20390  this.cy = null;
20391}
20392
20393function attachCircle(arc) {
20394  var lArc = arc.P,
20395      rArc = arc.N;
20396
20397  if (!lArc || !rArc) return;
20398
20399  var lSite = lArc.site,
20400      cSite = arc.site,
20401      rSite = rArc.site;
20402
20403  if (lSite === rSite) return;
20404
20405  var bx = cSite[0],
20406      by = cSite[1],
20407      ax = lSite[0] - bx,
20408      ay = lSite[1] - by,
20409      cx = rSite[0] - bx,
20410      cy = rSite[1] - by;
20411
20412  var d = 2 * (ax * cy - ay * cx);
20413  if (d >= -epsilon2$2) return;
20414
20415  var ha = ax * ax + ay * ay,
20416      hc = cx * cx + cy * cy,
20417      x = (cy * ha - ay * hc) / d,
20418      y = (ax * hc - cx * ha) / d;
20419
20420  var circle = circlePool.pop() || new Circle;
20421  circle.arc = arc;
20422  circle.site = cSite;
20423  circle.x = x + bx;
20424  circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
20425
20426  arc.circle = circle;
20427
20428  var before = null,
20429      node = circles._;
20430
20431  while (node) {
20432    if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
20433      if (node.L) node = node.L;
20434      else { before = node.P; break; }
20435    } else {
20436      if (node.R) node = node.R;
20437      else { before = node; break; }
20438    }
20439  }
20440
20441  circles.insert(before, circle);
20442  if (!before) firstCircle = circle;
20443}
20444
20445function detachCircle(arc) {
20446  var circle = arc.circle;
20447  if (circle) {
20448    if (!circle.P) firstCircle = circle.N;
20449    circles.remove(circle);
20450    circlePool.push(circle);
20451    RedBlackNode(circle);
20452    arc.circle = null;
20453  }
20454}
20455
20456var beachPool = [];
20457
20458function Beach() {
20459  RedBlackNode(this);
20460  this.edge =
20461  this.site =
20462  this.circle = null;
20463}
20464
20465function createBeach(site) {
20466  var beach = beachPool.pop() || new Beach;
20467  beach.site = site;
20468  return beach;
20469}
20470
20471function detachBeach(beach) {
20472  detachCircle(beach);
20473  beaches.remove(beach);
20474  beachPool.push(beach);
20475  RedBlackNode(beach);
20476}
20477
20478function removeBeach(beach) {
20479  var circle = beach.circle,
20480      x = circle.x,
20481      y = circle.cy,
20482      vertex = [x, y],
20483      previous = beach.P,
20484      next = beach.N,
20485      disappearing = [beach];
20486
20487  detachBeach(beach);
20488
20489  var lArc = previous;
20490  while (lArc.circle
20491      && Math.abs(x - lArc.circle.x) < epsilon$4
20492      && Math.abs(y - lArc.circle.cy) < epsilon$4) {
20493    previous = lArc.P;
20494    disappearing.unshift(lArc);
20495    detachBeach(lArc);
20496    lArc = previous;
20497  }
20498
20499  disappearing.unshift(lArc);
20500  detachCircle(lArc);
20501
20502  var rArc = next;
20503  while (rArc.circle
20504      && Math.abs(x - rArc.circle.x) < epsilon$4
20505      && Math.abs(y - rArc.circle.cy) < epsilon$4) {
20506    next = rArc.N;
20507    disappearing.push(rArc);
20508    detachBeach(rArc);
20509    rArc = next;
20510  }
20511
20512  disappearing.push(rArc);
20513  detachCircle(rArc);
20514
20515  var nArcs = disappearing.length,
20516      iArc;
20517  for (iArc = 1; iArc < nArcs; ++iArc) {
20518    rArc = disappearing[iArc];
20519    lArc = disappearing[iArc - 1];
20520    setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
20521  }
20522
20523  lArc = disappearing[0];
20524  rArc = disappearing[nArcs - 1];
20525  rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
20526
20527  attachCircle(lArc);
20528  attachCircle(rArc);
20529}
20530
20531function addBeach(site) {
20532  var x = site[0],
20533      directrix = site[1],
20534      lArc,
20535      rArc,
20536      dxl,
20537      dxr,
20538      node = beaches._;
20539
20540  while (node) {
20541    dxl = leftBreakPoint(node, directrix) - x;
20542    if (dxl > epsilon$4) node = node.L; else {
20543      dxr = x - rightBreakPoint(node, directrix);
20544      if (dxr > epsilon$4) {
20545        if (!node.R) {
20546          lArc = node;
20547          break;
20548        }
20549        node = node.R;
20550      } else {
20551        if (dxl > -epsilon$4) {
20552          lArc = node.P;
20553          rArc = node;
20554        } else if (dxr > -epsilon$4) {
20555          lArc = node;
20556          rArc = node.N;
20557        } else {
20558          lArc = rArc = node;
20559        }
20560        break;
20561      }
20562    }
20563  }
20564
20565  createCell(site);
20566  var newArc = createBeach(site);
20567  beaches.insert(lArc, newArc);
20568
20569  if (!lArc && !rArc) return;
20570
20571  if (lArc === rArc) {
20572    detachCircle(lArc);
20573    rArc = createBeach(lArc.site);
20574    beaches.insert(newArc, rArc);
20575    newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
20576    attachCircle(lArc);
20577    attachCircle(rArc);
20578    return;
20579  }
20580
20581  if (!rArc) { // && lArc
20582    newArc.edge = createEdge(lArc.site, newArc.site);
20583    return;
20584  }
20585
20586  // else lArc !== rArc
20587  detachCircle(lArc);
20588  detachCircle(rArc);
20589
20590  var lSite = lArc.site,
20591      ax = lSite[0],
20592      ay = lSite[1],
20593      bx = site[0] - ax,
20594      by = site[1] - ay,
20595      rSite = rArc.site,
20596      cx = rSite[0] - ax,
20597      cy = rSite[1] - ay,
20598      d = 2 * (bx * cy - by * cx),
20599      hb = bx * bx + by * by,
20600      hc = cx * cx + cy * cy,
20601      vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
20602
20603  setEdgeEnd(rArc.edge, lSite, rSite, vertex);
20604  newArc.edge = createEdge(lSite, site, null, vertex);
20605  rArc.edge = createEdge(site, rSite, null, vertex);
20606  attachCircle(lArc);
20607  attachCircle(rArc);
20608}
20609
20610function leftBreakPoint(arc, directrix) {
20611  var site = arc.site,
20612      rfocx = site[0],
20613      rfocy = site[1],
20614      pby2 = rfocy - directrix;
20615
20616  if (!pby2) return rfocx;
20617
20618  var lArc = arc.P;
20619  if (!lArc) return -Infinity;
20620
20621  site = lArc.site;
20622  var lfocx = site[0],
20623      lfocy = site[1],
20624      plby2 = lfocy - directrix;
20625
20626  if (!plby2) return lfocx;
20627
20628  var hl = lfocx - rfocx,
20629      aby2 = 1 / pby2 - 1 / plby2,
20630      b = hl / plby2;
20631
20632  if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
20633
20634  return (rfocx + lfocx) / 2;
20635}
20636
20637function rightBreakPoint(arc, directrix) {
20638  var rArc = arc.N;
20639  if (rArc) return leftBreakPoint(rArc, directrix);
20640  var site = arc.site;
20641  return site[1] === directrix ? site[0] : Infinity;
20642}
20643
20644var epsilon$4 = 1e-6;
20645var epsilon2$
vendor: 3,281 bytes, lines 20645-20782
206452 = 1e-12;
20646var beaches;
20647var cells;
20648var circles;
20649var edges;
20650
20651function triangleArea(a, b, c) {
20652  return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
20653}
20654
20655function lexicographic(a, b) {
20656  return b[1] - a[1]
20657      || b[0] - a[0];
20658}
20659
20660function Diagram(sites, extent) {
20661  var site = sites.sort(lexicographic).pop(),
20662      x,
20663      y,
20664      circle;
20665
20666  edges = [];
20667  cells = new Array(sites.length);
20668  beaches = new RedBlackTree;
20669  circles = new RedBlackTree;
20670
20671  while (true) {
20672    circle = firstCircle;
20673    if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
20674      if (site[0] !== x || site[1] !== y) {
20675        addBeach(site);
20676        x = site[0], y = site[1];
20677      }
20678      site = sites.pop();
20679    } else if (circle) {
20680      removeBeach(circle.arc);
20681    } else {
20682      break;
20683    }
20684  }
20685
20686  sortCellHalfedges();
20687
20688  if (extent) {
20689    var x0 = +extent[0][0],
20690        y0 = +extent[0][1],
20691        x1 = +extent[1][0],
20692        y1 = +extent[1][1];
20693    clipEdges(x0, y0, x1, y1);
20694    clipCells(x0, y0, x1, y1);
20695  }
20696
20697  this.edges = edges;
20698  this.cells = cells;
20699
20700  beaches =
20701  circles =
20702  edges =
20703  cells = null;
20704}
20705
20706Diagram.prototype = {
20707  constructor: Diagram,
20708
20709  polygons: function() {
20710    var edges = this.edges;
20711
20712    return this.cells.map(function(cell) {
20713      var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
20714      polygon.data = cell.site.data;
20715      return polygon;
20716    });
20717  },
20718
20719  triangles: function() {
20720    var triangles = [],
20721        edges = this.edges;
20722
20723    this.cells.forEach(function(cell, i) {
20724      if (!(m = (halfedges = cell.halfedges).length)) return;
20725      var site = cell.site,
20726          halfedges,
20727          j = -1,
20728          m,
20729          s0,
20730          e1 = edges[halfedges[m - 1]],
20731          s1 = e1.left === site ? e1.right : e1.left;
20732
20733      while (++j < m) {
20734        s0 = s1;
20735        e1 = edges[halfedges[j]];
20736        s1 = e1.left === site ? e1.right : e1.left;
20737        if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
20738          triangles.push([site.data, s0.data, s1.data]);
20739        }
20740      }
20741    });
20742
20743    return triangles;
20744  },
20745
20746  links: function() {
20747    return this.edges.filter(function(edge) {
20748      return edge.right;
20749    }).map(function(edge) {
20750      return {
20751        source: edge.left.data,
20752        target: edge.right.data
20753      };
20754    });
20755  },
20756
20757  find: function(x, y, radius) {
20758    var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
20759
20760    // Use the previously-found cell, or start with an arbitrary one.
20761    while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
20762    var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
20763
20764    // Traverse the half-edges to find a closer cell, if any.
20765    do {
20766      cell = that.cells[i0 = i1], i1 = null;
20767      cell.halfedges.forEach(function(e) {
20768        var edge = that.edges[e], v = edge.left;
20769        if ((v === cell.site || !v) && !(v = edge.right)) return;
20770        var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
20771        if (v2 < d2) d2 = v2, i1 = v.index;
20772      });
20773    } while (i1 !== null);
20774
20775    that._found = i0;
20776
20777    return radius == null || d2 <= radius * radius ? cell.site : null;
20778  }
20779};
20780
20781function voronoi() {
20782  var x$$1 = x
20782$4,
20783      y$$1 = y$4,
20784      extent = null;
20785
20786  function voronoi(data) {
20787    return new Diagram(data.map(function(d, i) {
20788      var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
20789      s.index = i;
20790      s.data = d;
20791      return s;
20792    }), extent);
20793  }
20794
20795  voronoi.polygons = function(data) {
20796    return voronoi(data).polygons();
20797  };
20798
20799  voronoi.links = function(data) {
20800    return voronoi(data).links();
20801  };
20802
20803  voronoi.triangles = function(data) {
20804    return voronoi(data).triangles();
20805  };
20806
20807  voronoi.x = function(_) {
20808    return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
20809  };
20810
20811  voronoi.y = function(_) {
20812    return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
20813  };
20814
20815  voronoi.extent = function(_) {
20816    return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
20817  };
20818
20819  voronoi.size = function(_) {
20820    return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
20821  };
20822
20823  return voronoi;
20824}
20825
20826function constant$12(x) {
20827  return function() {
20828    return x;
20829  };
20830}
20831
20832function ZoomEvent(target, type, transform) {
20833  this.target = target;
20834  this.type = type;
20835  this.transform = transform;
20836}
20837
20838function Transform(k, x, y) {
20839  this.k = k;
20840  this.x = x;
20841  this.y = y;
20842}
20843
20844Transform.prototype = {
20845  constructor: Transform,
20846  scale: function(k) {
20847    return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
20848  },
20849  translate: function(x, y) {
20850    return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
20851  },
20852  apply: function(point) {
20853    return [point[0] * this.k + this.x, point[1] * this.k + this.y];
20854  },
20855  applyX: function(x) {
20856    return x * this.k + this.x;
20857  },
20858  applyY: function(y) {
20859    return y * this.k + this.y;
20860  },
20861  invert: function(location) {
20862    return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
20863  },
20864  invertX: function(x) {
20865    return (x - this.x) / this.k;
20866  },
20867  invertY: function(y) {
20868    return (y - this.y) / this.k;
20869  },
20870  rescaleX: function(x) {
20871    return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
20872  },
20873  rescaleY: function(y) {
20874    return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
20875  },
20876  toString: function() {
20877    return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
20878  }
20879};
20880
20881var identity$8 = new Transform(1, 0, 0);
20882
20883transform$1.prototype = Transform.prototype;
20884
20885function transform$1(node) {
20886  return node.__zoom || identity$8;
20887}
20888
20889function nopropagation$2() {
20890  exports.event.stopImmediatePropagation();
20891}
20892
20893function noevent$2() {
20894  exports.event.preventDefault();
20895  exports.event.stopImmediatePropagation();
20896}
20897
20898// Ignore right-click, since that should open the context menu.
20899function defaultFilter$2() {
20900  return !exports.event.button;
20901}
20902
20903function defaultExtent$1() {
20904  var e = this, w, h;
20905  if (e instanceof SVGElement) {
20906    e = e.ownerSVGElement || e;
20907    w = e.width.baseVal.value;
20908    h = e.height.baseVal.value;
20909  } else {
20910    w = e.clientWidth;
20911    h = e.clientHeight;
20912  }
20913  return [[0, 0], [w, h]];
20914}
20915
20916function defaultTransform() {
20917  return this.__zoom || identity$8;
20918}
20919
20920function defaultWheelDelta() {
20921  return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
20922}
20923
20924function defaultTouchable$1() {
20925  return "ontouchstart" in this;
20926}
20927
20928function defaultConstrain(transform$$1, extent, translateExtent) {
20929  var dx0 = transform$$1.invertX(extent[0][0]) - translateExtent[0][0],
20930      dx1 = transform$$1.invertX(extent[1][0]) - translateExtent[1][0],
20931      dy0 = transform$$1.invertY(extent[0][1]) - translateExtent[0][1],
20932      dy1 = transform$$1.invertY(extent[1][1]) - translateExtent[1][1];
20933  return transform$$1.translate(
20934    dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
20935    dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
20936  );
20937}
20938
20939function zoom() {
20940  var filter = defaultFilter$2,
20941      extent = defaultExtent$1,
20942      constrain = defaultConstrain,
20943      wheelDelta = defaultWheelDelta,
20944      touchable = defaultTouchable$1,
20945      scaleExtent = [0, Infinity],
20946      translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
20947      duration = 250,
20948      interpolate = interpolateZoom,
20949      gestures = [],
20950      listeners = dispatch("start", "zoom", "end"),
20951      touchstarting,
20952      touchending,
20953      touchDelay = 500,
20954      wheelDelay = 150,
20955      clickDistance2 = 0;
20956
20957  function zoom(selection) {
20958    selection
20959        .property("__zoom", defaultTransform)
20960        .on("wheel.zoom", wheeled)
20961        .on("mousedown.zoom", mousedowned)
20962        .on("dblclick.zoom", dblclicked)
20963      .filter(touchable)
20964        .on("touchstart.zoom", touchstarted)
20965        .on("touchmove.zoom", touchmoved)
20966        .on("touchend.zoom touchcancel.zoom", touchended)
20967        .style("touch-action", "none")
20968        .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
20969  }
20970
20971  zoom.transform = function(collection, transform$$1) {
20972    var selection = collection.selection ? collection.selection() : collection;
20973    selection.property("__zoom", defaultTransform);
20974    if (collection !== selection) {
20975      schedule(collection, transform$$1);
20976    } else {
20977      selection.interrupt().each(function() {
20978        gesture(this, arguments)
20979            .start()
20980            .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
20981            .end();
20982      });
20983    }
20984  };
20985
20986  zoom.scaleBy = function(selection, k) {
20987    zoom.scaleTo(selection, function() {
20988      var k0 = this.__zoom.k,
20989          k1 = typeof k === "function" ? k.apply(this, arguments) : k;
20990      return k0 * k1;
20991    });
20992  };
20993
20994  zoom.scaleTo = function(selection, k) {
20995    zoom.transform(selection, function() {
20996      var e = extent.apply(this, arguments),
20997          t0 = this.__zoom,
20998          p0 = centroid(e),
20999          p1 = t0.invert(p0),
21000          k1 = typeof k === "function" ? k.apply(this, arguments) : k;
21001      return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
21002    });
21003  };
21004
21005  zoom.translateBy = function(selection, x, y) {
21006    zoom.transform(selection, function() {
21007      return constrain(this.__zoom.translate(
21008        typeof x === "function" ? x.apply(this, arguments) : x,
21009        typeof y === "function" ? y.apply(this, arguments) : y
21010      ), extent.apply(this, arguments), translateExtent);
21011    });
21012  };
21013
21014  zoom.translateTo = function(selection, x, y) {
21015    zoom.transform(selection, function() {
21016      var e = extent.apply(this, arguments),
21017          t = this.__zoom,
21018          p = centroid(e);
21019      return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
21020        typeof x === "function" ? -x.apply(this, arguments) : -x,
21021        typeof y === "function" ? -y.apply(this, arguments) : -y
21022      ), e, translateExtent);
21023    });
21024  };
21025
21026  function scale(transform$$1, k) {
21027    k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
21028    return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
21029  }
21030
21031  function translate(transform$$1, p0, p1) {
21032    var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
21033    return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
21034  }
21035
21036  function centroid(extent) {
21037    return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
21038  }
21039
21040  function schedule(transition, transform$$1, center) {
21041    transition
21042        .on("start.zoom", function() { gesture(this, arguments).start(); })
21043        .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
21044        .tween("zoom", function() {
21045          var that = this,
21046              args = arguments,
21047              g = gesture(that, args),
21048              e = extent.apply(that, args),
21049              p = center || centroid(e),
21050              w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
21051              a = that.__zoom,
21052              b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
21053              i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
21054          return function(t) {
21055            if (t === 1) t = b; // Avoid rounding error on end.
21056            else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
21057            g.zoom(null, t);
21058          };
21059        });
21060  }
21061
21062  function gesture(that, args) {
21063    for (var i = 0, n = gestures.length, g; i < n; ++i) {
21064      if ((g = gestures[i]).that === that) {
21065        return g;
21066      }
21067    }
21068    return new Gesture(that, args);
21069  }
21070
21071  function Gesture(that, args) {
21072    this.that = that;
21073    this.args = args;
21074    this.index = -1;
21075    this.active = 0;
21076    this.extent = extent.apply(that, args);
21077  }
21078
21079  Gesture.prototype = {
21080    start: function() {
21081      if (++this.active === 1) {
21082        this.index = gestures.push(this) - 1;
21083        this.emit("start");
21084      }
21085      return this;
21086    },
21087    zoom: function(key, transform$$1) {
21088      if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
21089      if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
21090      if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
21091      this.that.__zoom = transform$$1;
21092      this.emit("zoom");
21093      return this;
21094    },
21095    end: function() {
21096      if (--this.active === 0) {
21097        gestures.splice(this.index, 1);
21098        this.index = -1;
21099        this.emit("end");
21100      }
21101      return this;
21102    },
21103    emit: function(type) {
21104      customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
21105    }
21106  };
21107
21108  function wheeled() {
21109    if (!filter.apply(this, arguments)) return;
21110    var g = gesture(this, arguments),
21111        t = this.__zoom,
21112        k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
21113        p = mouse(this);
21114
21115    // If the mouse is in the same location as before, reuse it.
21116    // If there were recent wheel events, reset the wheel idle timeout.
21117    if (g.wheel) {
21118      if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
21119        g.mouse[1] = t.invert(g.mouse[0] = p);
21120      }
21121      clearTimeout(g.wheel);
21122    }
21123
21124    // If this wheel event won’t trigger a transform change, ignore it.
21125    else if (t.k === k) return;
21126
21127    // Otherwise, capture the mouse point and location at the start.
21128    else {
21129      g.mouse = [p, t.invert(p)];
21130      interrupt(this);
21131      g.start();
21132    }
21133
21134    noevent$2();
21135    g.wheel = setTimeout(wheelidled, wheelDelay);
21136    g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
21137
21138    function wheelidled() {
21139      g.wheel = null;
21140      g.end();
21141    }
21142  }
21143
21144  function mousedowned() {
21145    if (touchending || !filter.apply(this, arguments)) return;
21146    var g = gesture(this, arguments),
21147        v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
21148        p = mouse(this),
21149        x0 = exports.event.clientX,
21150        y0 = exports.event.clientY;
21151
21152    dragDisable(exports.event.view);
21153    nopropagation$2();
21154    g.mouse = [p, this.__zoom.invert(p)];
21155    interrupt(this);
21156    g.start();
21157
21158    function mousemoved() {
21159      noevent$2();
21160      if (!g.moved) {
21161        var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
21162        g.moved = dx * dx + dy * dy > clickDistance2;
21163      }
21164      g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
21165    }
21166
21167    function mouseupped() {
21168      v.on("mousemove.zoom mouseup.zoom", null);
21169      yesdrag(exports.event.view, g.moved);
21170      noevent$2();
21171      g.end();
21172    }
21173  }
21174
21175  function dblclicked() {
21176    if (!filter.apply(this, arguments)) return;
21177    var t0 = this.__zoom,
21178        p0 = mouse(this),
21179        p1 = t0.invert(p0),
21180        k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
21181        t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
21182
21183    noevent$2();
21184    if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
21185    else select(this).call(zoom.transform, t1);
21186  }
21187
21188  function touchstarted() {
21189    if (!filter.apply(this, arguments)) return;
21190    var g = gesture(this, arguments),
21191        touches = exports.event.changedTouches,
21192        started,
21193        n = touches.length, i, t, p;
21194
21195    nopropagation$2();
21196    for (i = 0; i < n; ++i) {
21197      t = touches[i], p = touch(this, touches, t.identifier);
21198      p = [p, this.__zoom.invert(p), t.identifier];
21199      if (!g.touch0) g.touch0 = p, started = true;
21200      else if (!g.touch1) g.touch1 = p;
21201    }
21202
21203    // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
21204    if (touchstarting) {
21205      touchstarting = clearTimeout(touchstarting);
21206      if (!g.touch1) {
21207        g.end();
21208        p = select(this).on("dblclick.zoom");
21209        if (p) p.apply(this, arguments);
21210        return;
21211      }
21212    }
21213
21214    if (started) {
21215      touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
21216      interrupt(this);
21217      g.start();
21218    }
21219  }
21220
21221  function touchmoved() {
21222    var g = gesture(this, arguments),
21223        touches = exports.event.changedTouches,
21224        n = touches.length, i, t, p, l;
21225
21226    noevent$2();
21227    if (touchstarting) touchstarting = clearTimeout(touchstarting);
21228    for (i = 0; i < n; ++i) {
21229      t = touches[i], p = touch(this, touches, t.identifier);
21230      if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
21231      else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
21232    }
21233    t = g.that.__zoom;
21234    if (g.touch1) {
21235      var p0 = g.touch0[0], l0 = g.touch0[1],
21236          p1 = g.touch1[0], l1 = g.touch1[1],
21237          dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
21238          dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
21239      t = scale(t, Math.sqrt(dp / dl));
21240      p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
21241      l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
21242    }
21243    else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
21244    else return;
21245    g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
21246  }
21247
21248  function touchended() {
21249    var g = gesture(this, arguments),
21250        touches = exports.event.changedTouches,
21251        n = touches.length, i, t;
21252
21253    nopropagation$2();
21254    if (touchending) clearTimeout(touchending);
21255    touchending = setTimeout(function() { touchending = null; }, touchDelay);
21256    for (i = 0; i < n; ++i) {
21257      t = touches[i];
21258      if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
21259      else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
21260    }
21261    if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
21262    if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
21263    else g.end();
21264  }
21265
21266  zoom.wheelDelta = function(_) {
21267    return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$12(+_), zoom) : wheelDelta;
21268  };
21269
21270  zoom.filter = function(_) {
21271    return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
21272  };
21273
21274  zoom.touchable = function(_) {
21275    return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$12(!!_), zoom) : touchable;
21276  };
21277
21278  zoom.extent = function(_) {
21279    return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
21280  };
21281
21282  zoom.scaleExtent = function(_) {
21283    return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
21284  };
21285
21286  zoom.translateExtent = function(_) {
21287    return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
21288  };
21289
21290  zoom.constrain = function(_) {
21291    return arguments.length ? (constrain = _, zoom) : constrain;
21292  };
21293
21294  zoom.duration = function(_) {
21295    return arguments.length ? (duration = +_, zoom) : duration;
21296  };
21297
21298  zoom.interpolate = function(_) {
21299    return arguments.length ? (interpolate = _, zoom) : interpolate;
21300  };
21301
21302  zoom.on = function() {
21303    var value = listeners.on.apply(listeners, arguments);
21304    return value === listeners ? zoom : value;
21305  };
21306
21307  zoom.clickDistance = function(_) {
21308    return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
21309  };
21310
21311  return zoom;
21312}
21313
21314exports.version = version;
21315exports.bisect = bisectRight;
21316exports.bisectRight = bisectRight;
21317exports.bisectLeft = bisectLeft;
21318exports.ascending = ascending;
21319exports.bisector = bisector;
21320exports.cross = cross;
21321exports.descending = descending;
21322exports.deviation = deviation;
21323exports.extent = extent;
21324exports.histogram = histogram;
21325exports.thresholdFreedmanDiaconis = freedmanDiaconis;
21326exports.thresholdScott = scott;
21327exports.thresholdSturges = sturges;
21328exports.max = max;
21329exports.mean = mean;
21330exports.median = median;
21331exports.merge = merge;
21332exports.min = min;
21333exports.pairs = pairs;
21334exports.permute = permute;
21335exports.quantile = threshold;
21336exports.range = sequence;
21337exports.scan = scan;
21338exports.shuffle = shuffle;
21339exports.sum = sum;
21340exports.ticks = ticks;
21341exports.tickIncrement = tickIncrement;
21342exports.tickStep = tickStep;
21343exports.transpose = transpose;
21344exports.variance = variance;
21345exports.zip = zip;
21346exports.axisTop = axisTop;
21347exports.axisRight = axisRight;
21348exports.axisBottom = axisBottom;
21349exports.axisLeft = axisLeft;
21350exports.brush = brush;
21351exports.brushX = brushX;
21352exports.brushY = brushY;
21353exports.brushSelection = brushSelection;
21354exports.chord = chord;
21355exports.ribbon = ribbon;
21356exports.nest = nest;
21357exports.set = set$2;
21358exports.map = map$1;
21359exports.keys = keys;
21360exports.values = values;
21361exports.entries = entries;
21362exports.color = color;
21363exports.rgb = rgb;
21364exports.hsl = hsl;
21365exports.lab = lab;
21366exports.hcl = hcl;
21367exports.cubehelix = cubehelix;
21368exports.dispatch = dispatch;
21369exports.drag = drag;
21370exports.dragDisable = dragDisable;
21371exports.dragEnable = yesdrag;
21372exports.dsvFormat = dsv;
21373exports.csvParse = csvParse;
21374exports.csvParseRows = csvParseRows;
21375exports.csvFormat = csvFormat;
21376exports.csvFormatRows = csvFormatRows;
21377exports.tsvParse = tsvParse;
21378exports.tsvParseRows = tsvParseRows;
21379exports.tsvFormat = tsvFormat;
21380exports.tsvFormatRows = tsvFormatRows;
21381exports.easeLinear = linear$1;
21382exports.easeQuad = quadInOut;
21383exports.easeQuadIn = quadIn;
21384exports.easeQuadOut = quadOut;
21385exports.easeQuadInOut = quadInOut;
21386exports.easeCubic = cubicInOut;
21387exports.easeCubicIn = cubicIn;
21388exports.easeCubicOut = cubicOut;
21389exports.easeCubicInOut = cubicInOut;
21390exports.easePoly = polyInOut;
21391exports.easePolyIn = polyIn;
21392exports.easePolyOut = polyOut;
21393exports.easePolyInOut = polyInOut;
21394exports.easeSin = sinInOut;
21395exports.easeSinIn = sinIn;
21396exports.easeSinOut = sinOut;
21397exports.easeSinInOut = sinInOut;
21398exports.easeExp = expInOut;
21399exports.easeExpIn = expIn;
21400exports.easeExpOut = expOut;
21401exports.easeExpInOut = expInOut;
21402exports.easeCircle = circleInOut;
21403exports.easeCircleIn = circleIn;
21404exports.easeCircleOut = circleOut;
21405exports.easeCircleInOut = circleInOut;
21406exports.easeBounce = bounceOut;
21407exports.easeBounceIn = bounceIn;
21408exports.easeBounceOut = bounceOut;
21409exports.easeBounceInOut = bounceInOut;
21410exports.easeBack = backInOut;
21411exports.easeBackIn = backIn;
21412exports.easeBackOut = backOut;
21413exports.easeBackInOut = backInOut;
21414exports.easeElastic = elasticOut;
21415exports.easeElasticIn = elasticIn;
21416exports.easeElasticOut = elasticOut;
21417exports.easeElasticInOut = elasticInOut;
21418exports.forceCenter = center$1;
21419exports.forceCollide = collide;
21420exports.forceLink = link;
21421exports.forceManyBody = manyBody;
21422exports.forceRadial = radial;
21423exports.forceSimulation = simulation;
21424exports.forceX = x$2;
21425exports.forceY = y$2;
21426exports.formatDefaultLocale = defaultLocale;
21427exports.formatLocale = formatLocale;
21428exports.formatSpecifier = formatSpecifier;
21429exports.precisionFixed = precisionFixed;
21430exports.precisionPrefix = precisionPrefix;
21431exports.precisionRound = precisionRound;
21432exports.geoArea = area;
21433exports.geoBounds = bounds;
21434exports.geoCentroid = centroid;
21435exports.geoCircle = circle;
21436exports.geoClipAntimeridian = clipAntimeridian;
21437exports.geoClipCircle = clipCircle;
21438exports.geoClipExtent = extent$1;
21439exports.geoClipRectangle = clipRectangle;
21440exports.geoContains = contains;
21441exports.geoDistance = distance;
21442exports.geoGraticule = graticule;
21443exports.geoGraticule10 = graticule10;
21444exports.geoInterpolate = interpolate$1;
21445exports.geoLength = length$1;
21446exports.geoPath = index$1;
21447exports.geoAlbers = albers;
21448exports.geoAlbersUsa = albersUsa;
21449exports.geoAzimuthalEqualArea = azimuthalEqualArea;
21450exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
21451exports.geoAzimuthalEquidistant = azimuthalEquidistant;
21452exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
21453exports.geoConicConformal = conicConformal;
21454exports.geoConicConformalRaw = conicConformalRaw;
21455exports.geoConicEqualArea = conicEqualArea;
21456exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
21457exports.geoConicEquidistant = conicEquidistant;
21458exports.geoConicEquidistantRaw = conicEquidistantRaw;
21459exports.geoEquirectangular = equirectangular;
21460exports.geoEquirectangularRaw = equirectangularRaw;
21461exports.geoGnomonic = gnomonic;
21462exports.geoGnomonicRaw = gnomonicRaw;
21463exports.geoIdentity = identity$5;
21464exports.geoProjection = projection;
21465exports.geoProjectionMutator = projectionMutator;
21466exports.geoMercator = mercator;
21467exports.geoMercatorRaw = mercatorRaw;
21468exports.geoNaturalEarth1 = naturalEarth1;
21469exports.geoNaturalEarth1Raw = naturalEarth1Raw;
21470exports.geoOrthographic = orthographic;
21471exports.geoOrthographicRaw = orthographicRaw;
21472exports.geoStereographic = stereographic;
21473exports.geoStereographicRaw = stereographicRaw;
21474exports.geoTransverseMercator = transverseMercator;
21475exports.geoTransverseMercatorRaw = transverseMercatorRaw;
21476exports.geoRotation = rotation;
21477exports.geoStream = geoStream;
21478exports.geoTransform = transform;
21479exports.cluster = cluster;
21480exports.hierarchy = hierarchy;
21481exports.pack = index$2;
21482exports.packSiblings = siblings;
21483exports.packEnclose = enclose;
21484exports.partition = partition;
21485exports.stratify = stratify;
21486exports.tree = tree;
21487exports.treemap = index$3;
21488exports.treemapBinary = binary;
21489exports.treemapDice = treemapDice;
21490exports.treemapSlice = treemapSlice;
21491exports.treemapSliceDice = sliceDice;
21492exports.treemapSquarify = squarify;
21493exports.treemapResquarify = resquarify;
21494exports.interpolate = interpolateValue;
21495exports.interpolateArray = array$1;
21496exports.interpolateBasis = basis$1;
21497exports.interpolateBasisClosed = basisClosed;
21498exports.interpolateDate = date;
21499exports.interpolateNumber = reinterpolate;
21500exports.interpolateObject = object;
21501exports.interpolateRound = interpolateRound;
21502exports.interpolateString = interpolateString;
21503exports.interpolateTransformCss = interpolateTransformCss;
21504exports.interpolateTransformSvg = interpolateTransformSvg;
21505exports.interpolateZoom = interpolateZoom;
21506exports.interpolateRgb = interpolateRgb;
21507exports.interpolateRgbBasis = rgbBasis;
21508exports.interpolateRgbBasisClosed = rgbBasisClosed;
21509exports.interpolateHsl = hsl$2;
21510exports.interpolateHslLong = hslLong;
21511exports.interpolateLab = lab$1;
21512exports.interpolateHcl = hcl$2;
21513exports.interpolateHclLong = hclLong;
21514exports.interpolateCubehelix = cubehelix$2;
21515exports.interpolateCubehelixLong = cubehelixLong;
21516exports.quantize = quantize;
21517exports.path = path;
21518exports.polygonArea = area$1;
21519exports.polygonCentroid = centroid$1;
21520exports.polygonHull = hull;
21521exports.polygonContains = contains$1;
21522exports.polygonLength = length$2;
21523exports.quadtree = quadtree;
21524exports.queue = queue;
21525exports.randomUniform = uniform;
21526exports.randomNormal = normal;
21527exports.randomLogNormal = logNormal;
21528exports.randomBates = bates;
21529exports.randomIrwinHall = irwinHall;
21530exports.randomExponential = exponential$1;
21531exports.request = request;
21532exports.html = html;
21533exports.json = json;
21534exports.text = text;
21535exports.xml = xml;
21536exports.csv = csv$1;
21537exports.tsv = tsv$1;
21538exports.scaleBand = band;
21539exports.scalePoint = point$1;
21540exports.scaleIdentity = identity$6;
21541exports.scaleLinear = linear$2;
21542exports.scaleLog = log$1;
21543exports.scaleOrdinal = ordinal;
21544exports.scaleImplicit = implicit;
21545exports.scalePow = pow$1;
21546exports.scaleSqrt = sqrt$1;
21547exports.scaleQuantile = quantile$$1;
21548exports.scaleQuantize = quantize$1;
21549exports.scaleThreshold = threshold$1;
21550exports.scaleTime = time;
21551exports.scaleUtc = utcTime;
21552exports.schemeCategory10 = category10;
21553exports.schemeCategory20b = category20b;
21554exports.schemeCategory20c = category20c;
21555exports.schemeCategory20 = category20;
21556exports.interpolateCubehelixDefault = cubehelix$3;
21557exports.interpolateRainbow = rainbow$1;
21558exports.interpolateWarm = warm;
21559exports.interpolateCool = cool;
21560exports.interpolateViridis = viridis;
21561exports.interpolateMagma = magma;
21562exports.interpolateInferno = inferno;
21563exports.interpolatePlasma = plasma;
21564exports.scaleSequential = sequential;
21565exports.create = create;
21566exports.creator = creator;
21567exports.local = local$1;
21568exports.matcher = matcher$1;
21569exports.mouse = mouse;
21570exports.namespace = namespace;
21571exports.namespaces = namespaces;
21572exports.clientPoint = point;
21573exports.select = select;
21574exports.selectAll = selectAll;
21575exports.selection = selection;
21576exports.selector = selector;
21577exports.selectorAll = selectorAll;
21578exports.style = styleValue;
21579exports.touch = touch;
21580exports.touches = touches;
21581exports.window = defaultView;
21582exports.customEvent = customEvent;
21583exports.arc = arc;
21584exports.area = area$2;
21585exports.line = line;
21586exports.pie = pie;
21587exports.areaRadial = areaRadial;
21588exports.radialArea = areaRadial;
21589exports.lineRadial = lineRadial$1;
21590exports.radialLine = lineRadial$1;
21591exports.pointRadial = pointRadial;
21592exports.linkHorizontal = linkHorizontal;
21593exports.linkVertical = linkVertical;
21594exports.linkRadial = linkRadial;
21595exports.symbol = symbol;
21596exports.symbols = symbols;
21597exports.symbolCircle = circle$2;
21598exports.symbolCross = cross$2;
21599exports.symbolDiamond = diamond;
21600exports.symbolSquare = square;
21601exports.symbolStar = star;
21602exports.symbolTriangle = triangle;
21603exports.symbolWye = wye;
21604exports.curveBasisClosed = basisClosed$1;
21605exports.curveBasisOpen = basisOpen;
21606exports.curveBasis = basis$2;
21607exports.curveBundle = bundle;
21608exports.curveCardinalClosed = cardinalClosed;
21609exports.curveCardinalOpen = cardinalOpen;
21610exports.curveCardinal = cardinal;
21611exports.curveCatmullRomClosed = catmullRomClosed;
21612exports.curveCatmullRomOpen = catmullRomOpen;
21613exports.curveCatmullRom = catmullRom;
21614exports.curveLinearClosed = linearClosed;
21615exports.curveLinear = curveLinear;
21616exports.curveMonotoneX = monotoneX;
21617exports.curveMonotoneY = monotoneY;
21618exports.curveNatural = natural;
21619exports.curveStep = step;
21620exports.curveStepAfter = stepAfter;
21621exports.curveStepBefore = stepBefore;
21622exports.stack = stack;
21623exports.stackOffsetExpand = expand;
21624exports.stackOffsetDiverging = diverging;
21625exports.stackOffsetNone = none$1;
21626exports.stackOffsetSilhouette = silhouette;
21627exports.stackOffsetWiggle = wiggle;
21628exports.stackOrderAscending = ascending$2;
21629exports.stackOrderDescending = descending$2;
21630exports.stackOrderInsideOut = insideOut;
21631exports.stackOrderNone = none$2;
21632exports.stackOrderReverse = reverse;
21633exports.timeInterval = newInterval;
21634exports.timeMillisecond = millisecond;
21635exports.timeMilliseconds = milliseconds;
21636exports.utcMillisecond = millisecond;
21637exports.utcMilliseconds = milliseconds;
21638exports.timeSecond = second;
21639exports.timeSeconds = seconds;
21640exports.utcSecond = second;
21641exports.utcSeconds = seconds;
21642exports.timeMinute = minute;
21643exports.timeMinutes = minutes;
21644exports.timeHour = hour;
21645exports.timeHours = hours;
21646exports.timeDay = day;
21647exports.timeDays = days;
21648exports.timeWeek = sunday;
21649exports.timeWeeks = sundays;
21650exports.timeSunday = sunday;
21651exports.timeSundays = sundays;
21652exports.timeMonday = monday;
21653exports.timeMondays = mondays;
21654exports.timeTuesday = tuesday;
21655exports.timeTuesdays = tuesdays;
21656exports.timeWednesday = wednesday;
21657exports.timeWednesdays = wednesdays;
21658exports.timeThursday = thursday;
21659exports.timeThursdays = thursdays;
21660exports.timeFriday = friday;
21661exports.timeFridays = fridays;
21662exports.timeSaturday = saturday;
21663exports.timeSaturdays = saturdays;
21664exports.timeMonth = month;
21665exports.timeMonths = months;
21666exports.timeYear = year;
21667exports.timeYears = years;
21668exports.utcMinute = utcMinute;
21669exports.utcMinutes = utcMinutes;
21670exports.utcHour = utcHour;
21671exports.utcHours = utcHours;
21672exports.utcDay = utcDay;
21673exports.utcDays = utcDays;
21674exports.utcWeek = utcSunday;
21675exports.utcWeeks = utcSundays;
21676exports.utcSunday = utcSunday;
21677exports.utcSundays = utcSundays;
21678exports.utcMonday = utcMonday;
21679exports.utcMondays = utcMondays;
21680exports.utcTuesday = utcTuesday;
21681exports.utcTuesdays = utcTuesdays;
21682exports.utcWednesday = utcWednesday;
21683exports.utcWednesdays = utcWednesdays;
21684exports.utcThursday = utcThursday;
21685exports.utcThursdays = utcThursdays;
21686exports.utcFriday = utcFriday;
21687exports.utcFridays = utcFridays;
21688exports.utcSaturday = utcSaturday;
21689exports.utcSaturdays = utcSaturdays;
21690exports.utcMonth = utcMonth;
21691exports.utcMonths = utcMonths;
21692exports.utcYear = utcYear;
21693exports.utcYears = utcYears;
21694exports.timeFormatDefaultLocale = defaultLocale$1;
21695exports.timeFormatLocale = formatLocale$1;
21696exports.isoFormat = formatIso;
21697exports.isoParse = parseIso;
21698exports.now = now;
21699exports.timer = timer;
21700exports.timerFlush = timerFlush;
21701exports.timeout = timeout$1;
21702exports.interval = interval$1;
21703exports.transition = transition;
21704exports.active = active;
21705exports.interrupt = interrupt;
21706exports.voronoi = voronoi;
21707exports.zoom = zoom;
21708exports.zoomTransform = transform$1;
21709exports.zoomIdentity = identity$8;
21710
21711Object.defineProperty(exports, '__esModule', { value: true });
21712
21713})));
21714// https://d3js.org/d3-scale-chromatic/ v1.5.0 Copyright 2019 Mike Bostock
21715!function(f,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-interpolate"),require("d3-color")):"function"==typeof define&&define.amd?define(["exports","d3-interpolate","d3-color"],e):e((f=f||self).d3=f.d3||{},f.d3,f.d3)}(this,function(f,e,d){"use strict";function a(f){for(var e=f.length/6|0,d=new Array(e),a=0;a<e;)d[a]="#"+f.slice(6*a,6*++a);return d}var c=a("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),b=a("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666"),t=a("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666"),n=a("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"),r=a("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2"),o=a("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc"),i=a("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999"),l=a("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3"),m=a("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"),h=a("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");function p(f){return e.interpolateRgbBasis(f[f.length-1])}var u=new Array(3).concat("d8b365f5f5f55ab4ac","a6611adfc27d80cdc1018571","a6611adfc27df5f5f580cdc1018571","8c510ad8b365f6e8c3c7eae55ab4ac01665e","8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e","8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e","8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e","5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30","5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30").map(a),s=p(u),y=new Array(3).concat("af8dc3f7f7f77fbf7b","7b3294c2a5cfa6dba0008837","7b3294c2a5cff7f7f7a6dba0008837","762a83af8dc3e7d4e8d9f0d37fbf7b1b7837","762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837","762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837","762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837","40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b","40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b").map(a),M=p(y),w=new Array(3).concat("e9a3c9f7f7f7a1d76a","d01c8bf1b6dab8e1864dac26","d01c8bf1b6daf7f7f7b8e1864dac26","c51b7de9a3c9fde0efe6f5d0a1d76a4d9221","c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221","c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221","c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221","8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419","8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419").map(a),A=p(w),P=new Array(3).concat("998ec3f7f7f7f1a340","5e3c99b2abd2fdb863e66101","5e3c99b2abd2f7f7f7fdb863e66101","542788998ec3d8daebfee0b6f1a340b35806","542788998ec3d8daebf7f7f7fee0b6f1a340b35806","5427888073acb2abd2d8daebfee0b6fdb863e08214b35806","5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806","2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08","2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08").map(a),B=p(P),G=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(a),x=p(G),R=new Array(3).concat("ef8a62ffffff999999","ca0020f4a582bababa404040","ca0020f4a582ffffffbababa404040","b2182bef8a62fddbc7e0e0e09999994d4d4d","b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d","b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d","b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d","67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a","67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a").map(a),g=p(R),Y=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(a),v=p(Y),O=new Array(3).concat("fc8d59ffffbf91cf60","d7191cfdae61a6d96a1a9641","d
217157191cfdae61ffffbfa6d96a1a9641","d73027fc8d59fee08bd9ef8b91cf601a9850","d73027fc8d59fee08bffffbfd9ef8b91cf601a9850","d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850","d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850","a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837","a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837").map(a),C=p(O),S=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(a),I=p(S),L=new Array(3).concat("e5f5f999d8c92ca25f","edf8fbb2e2e266c2a4238b45","edf8fbb2e2e266c2a42ca25f006d2c","edf8fbccece699d8c966c2a42ca25f006d2c","edf8fbccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b").map(a),j=p(L),q=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(a),D=p(q),T=new Array(3).concat("e0f3dba8ddb543a2ca","f0f9e8bae4bc7bccc42b8cbe","f0f9e8bae4bc7bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081").map(a),_=p(T),k=new Array(3).concat("fee8c8fdbb84e34a33","fef0d9fdcc8afc8d59d7301f","fef0d9fdcc8afc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000").map(a),V=p(k),W=new Array(3).concat("ece2f0a6bddb1c9099","f6eff7bdc9e167a9cf02818a","f6eff7bdc9e167a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636").map(a),z=p(W),E=new Array(3).concat("ece7f2a6bddb2b8cbe","f1eef6bdc9e174a9cf0570b0","f1eef6bdc9e174a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858").map(a),F=p(E),H=new Array(3).concat("e7e1efc994c7dd1c77","f1eef6d7b5d8df65b0ce1256","f1eef6d7b5d8df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f").map(a),J=p(H),K=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(a),N=p(K),Q=new Array(3).concat("edf8b17fcdbb2c7fb8","ffffcca1dab441b6c4225ea8","ffffcca1dab441b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58").map(a),U=p(Q),X=new Array(3).concat("f7fcb9addd8e31a354","ffffccc2e69978c679238443","ffffccc2e69978c67931a354006837","ffffccd9f0a3addd8e78c67931a354006837","ffffccd9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529").map(a),Z=p(X),$=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(a),ff=p($),ef=new Array(3).concat("ffeda0feb24cf03b20","ffffb2fecc5cfd8d3ce31a1c","ffffb2fecc5cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026").map(a),df=p(ef),af=new Array(3).concat("deebf79ecae13182bd","eff3ffbdd7e76baed62171b5","eff3ffbdd7e76baed63182bd08519c","eff3ffc6dbef9ec
21715ae16baed63182bd08519c","eff3ffc6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b").map(a),cf=p(af),bf=new Array(3).concat("e5f5e0a1d99b31a354","edf8e9bae4b374c476238b45","edf8e9bae4b374c47631a354006d2c","edf8e9c7e9c0a1d99b74c47631a354006d2c","edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b").map(a),tf=p(bf),nf=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(a),rf=p(nf),of=new Array(3).concat("efedf5bcbddc756bb1","f2f0f7cbc9e29e9ac86a51a3","f2f0f7cbc9e29e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d").map(a),lf=p(of),mf=new Array(3).concat("fee0d2fc9272de2d26","fee5d9fcae91fb6a4acb181d","fee5d9fcae91fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d").map(a),hf=p(mf),pf=new Array(3).concat("fee6cefdae6be6550d","feeddefdbe85fd8d3cd94701","feeddefdbe85fd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704").map(a),uf=p(pf);var sf=e.interpolateCubehelixLong(d.cubehelix(300,.5,0),d.cubehelix(-240,.5,1)),yf=e.interpolateCubehelixLong(d.cubehelix(-100,.75,.35),d.cubehelix(80,1.5,.8)),Mf=e.interpolateCubehelixLong(d.cubehelix(260,.75,.35),d.cubehelix(80,1.5,.8)),wf=d.cubehelix();var Af=d.rgb(),Pf=Math.PI/3,Bf=2*Math.PI/3;function Gf(f){var e=f.length;return function(d){return f[Math.max(0,Math.min(e-1,Math.floor(d*e)))]}}var xf=Gf(a("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725")),Rf=Gf(a("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb8
217151febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),gf=Gf(a("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),Yf=Gf(a("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));f.interpolateBlues=cf,f.interpolateBrBG=s,f.interpolateBuGn=j,f.interpolateBuPu=D,f.interpolateCividis=function(f){return f=Math.max(0,Math.min(1,f)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-f*(35.34-f*(2381.73-f*(6402.7-f*(7024.72-2710.57*f)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+f*(170.73+f*(52.82-f*(131.46-f*(176.58-67.37*f)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+f*(442.36-f*(2482.43-f*(6167.24-f*(6614.94-2475.67*f)))))))+")"},f.interpolateCool=Mf,f.interpolateCubehelixDefault=sf,f.interpolateGnBu=_,f.interpolateGreens=tf,f.interpolateGreys=rf,f.interpolateInferno=gf,f.interpolateMagma=Rf,f.interpolateOrRd=V,f.interpolateOranges=uf,f.interpolatePRGn=M,f.interpolatePiYG=A,f.interpolatePlasma=Yf,f.interpolatePuBu=F,f.interpolatePuBuGn=z,f.interpolatePuOr=B,f.interpolatePuRd=J,f.interpolatePurples=lf,f.interpolateRainbow=function(f){(f<0||f>1)&&(f-=Math.floor(f));var e=Math.abs(f-.5);return wf.h=360*f-100,wf.s=1.5-1.5*e,wf.l=.8-.9*e,wf+""},f.interpolateRdBu=x,f.interpolateRdGy=g,f.interpolateRdPu=N,f.interpolateRdYlBu=v,f.interpolateRdYlGn=C,f.interpolateReds=hf,f.interpolateSinebow=function(f){var e;return f=(.5-f)*Math.PI,Af.r=255*(e=Math.sin(f))*e,Af.g=255*(e=Math.sin(f+Pf))*e,Af.b=255*(e=Math.sin(f+Bf))*e,Af+""},f.interpolateSpectral=I,f.interpolateTurbo=function(f){return f=Math.max(0,Math.min(1,f)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+f*(1172.33-f*(10793.56-f*(33300.12-f*(38394.49-14825.05*f)))))))+", "+
21715Math.max(0,Math.min(255,Math.round(23.31+f*(557.33+f*(1225.33-f*(3574.96-f*(1073.77+707.56*f)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+f*(3211.1-f*(15327.97-f*(27814-f*(22569.18-6838.66*f)))))))+")"},f.interpolateViridis=xf,f.interpolateWarm=yf,f.interpolateYlGn=Z,f.interpolateYlGnBu=U,f.interpolateYlOrBr=ff,f.interpolateYlOrRd=df,f.schemeAccent=b,f.schemeBlues=af,f.schemeBrBG=u,f.schemeBuGn=L,f.schemeBuPu=q,f.schemeCategory10=c,f.schemeDark2=t,f.schemeGnBu=T,f.schemeGreens=bf,f.schemeGreys=nf,f.schemeOrRd=k,f.schemeOranges=pf,f.schemePRGn=y,f.schemePaired=n,f.schemePastel1=r,f.schemePastel2=o,f.schemePiYG=w,f.schemePuBu=E,f.schemePuBuGn=W,f.schemePuOr=P,f.schemePuRd=H,f.schemePurples=of,f.schemeRdBu=G,f.schemeRdGy=R,f.schemeRdPu=K,f.schemeRdYlBu=Y,f.schemeRdYlGn=O,f.schemeReds=mf,f.schemeSet1=i,f.schemeSet2=l,f.schemeSet3=m,f.schemeSpectral=S,f.schemeTableau10=h,f.schemeYlGn=X,f.schemeYlGnBu=Q,f.schemeYlOrBr=$,f.schemeYlOrRd=ef,Object.defineProperty(f,"__esModule",{value:!0})});
21716const generateDonut = (type, data, elem) => {
21717
21718// set the dimensions and margins of the graph
21719var width = 450
21720    height = 450
21721    margin = 40
21722
21723// The radius of the pieplot is half the width or half the height (smallest one). I subtract a bit of margin.
21724var radius = Math.min(width, height) / 2 - margin
21725
21726
21727const chartColors = data.charts.map(chart => chart.color);
21728const dataDomain = data.charts.map(chart => chart.content);
21729const newData = data.charts.reduce(
21730  (obj, item) => Object.assign(obj, { [item.content]: item.val }), {});
21731
21732var data = newData;
21733
21734// append the svg object to the div called 'my_dataviz'
21735var svg = d3.select(elem)
21736  .append("svg")
21737    .attr("width", width)
21738    .attr("height", height)
21739  .append("g")
21740    .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
21741
21742
21743// set the color scale
21744var color = d3.scaleOrdinal()
21745  .domain(dataDomain)
21746  .range(chartColors);
21747
21748 var colourArray = d3.range(dataDomain.length).map(function(d) { return color(d) });
21749
21750// Compute the position of each group on the pie:
21751var pie = d3.pie()
21752  .sort(null) // Do not sort group by size
21753  .value(function(d) {return d.value; })
21754var data_ready = pie(d3.entries(data))
21755
21756// The arc generator
21757var arc = d3.arc()
21758  .innerRadius(radius * 0.5)         // This is the size of the donut hole
21759  .outerRadius(radius * 0.8)
21760
21761// Another arc that won't be drawn. Just for labels positioning
21762var outerArc = d3.arc()
21763  .innerRadius(radius * 0.9)
21764  .outerRadius(radius * 0.9)
21765
21766// Build the pie chart: Basically, each part of the pie is a path that we build using the arc function.
21767svg
21768  .selectAll('allSlices')
21769  .data(data_ready)
21770  .enter()
21771  .append('path')
21772  .attr('d', arc)
21773  .attr('fill', function(d, i){ return(colourArray[i]) })
21774  .attr("stroke", "white")
21775  .style("stroke-width", "2px")
21776  .style("opacity", 0.7)
21777
21778if(type == 'donut-poly'){
21779// Add the polylines between chart and labels:
21780svg
21781  .selectAll('allPolylines')
21782  .data(data_ready)
21783  .enter()
21784  .append('polyline')
21785    .attr("stroke", "black")
21786    .style("fill", "none")
21787    .attr("stroke-width", 1)
21788    .attr('points', function(d) {
21789      var posA = arc.centroid(d) // line insertion in the slice
21790      var posB = outerArc.centroid(d) // line break: we use the other arc generator that has been built only for that
21791      var posC = outerArc.centroid(d); // Label position = almost the same as posB
21792      var midangle = d.startAngle + (d.endAngle - d.startAngle) / 2 // we need the angle to see if the X position will be at the extreme right or extreme left
21793      posC[0] = radius * 0.95 * (midangle < Math.PI ? 1 : -1); // multiply by 1 or -1 to put it on the right or on the left
21794      return [posA, posB, posC]
21795    })
21796
21797// Add the polylines between chart and labels:
21798svg
21799  .selectAll('allLabels')
21800  .data(data_ready)
21801  .enter()
21802  .append('text')
21803    .text( function(d) { return d.data.key } )
21804    .attr('transform', function(d) {
21805        var pos = outerArc.centroid(d);
21806        var midangle = d.startAngle + (d.endAngle - d.startAngle) / 2
21807        pos[0] = radius * 0.99 * (midangle < Math.PI ? 1 : -1);
21808        return 'translate(' + pos + ')';
21809    })
21810    .style('text-anchor', function(d) {
21811        var midangle = d.startAngle + (d.endAngle - d.startAngle) / 2
21812        return (midangle < Math.PI ? 'start' : 'end')
21813    })
21814
21815}
21816}
21817if (document.querySelector('.cmp-chart') && document.querySelectorAll('.cmp-chart__wrapper') !== null) {
21818    const generateCharts = () => {
21819        const allCharts = [].slice.call(document.querySelectorAll('.cmp-chart__wrapper'));
21820        allCharts.forEach(chartElem => {
21821                const dataPath = chartElem.getAttribute('data-chart-path');
21822                const chartType = chartElem.getAttribute('data-chart-type');
21823                fetchChartData(dataPath).then(data => generateDonut(chartType, data, chartElem ));
21824            }
21825        );
21826    }
21827
21828    //Function to fetch JSON from a given path
21829    const fetchChartData = async (path) => {
21830        try {
21831            const response = await fetch(path);
21832            if (!response.ok) {
21833                throw new Error(errMessage(response.status))
21834            }
21835            const chartInfo = await response.json();
21836            return chartInfo;
21837        } catch (err) {
21838            throw new Error(errMessage(err))
21839        }
21840    }
21841
21842    //Error Message
21843    const errMessage = (message) => `An error has occurred ${message}`;
21844
21845    generateCharts();
21846}
21847$(document).ready(function () {
21848	var $twitterCmpElement = $(".cmp-twitter__wrapper");
21849	$twitterCmpElement.each(function () {
21850		_renderTwitterComponents($(this))
21851	});
21852});
21853
21854/**
21855 * Rendering individual twitter component(s)
21856 * @param {*} $currentTwitterComponent 
21857 */
21858function _renderTwitterComponents($currentTwitterComponent) {
21859	var twitterUserName = $currentTwitterComponent.data("twitter-username");
21860	var twitterLimit = $currentTwitterComponent.data("twitter-limit");
21861	var twitterEndpoint = $currentTwitterComponent.data("twitter-endpoint");
21862	var options = {
21863		"username": twitterUserName,
21864		"limit": twitterLimit
21865	};
21866	$.ajax({
21867		method: "GET",
21868		url: twitterEndpoint,
21869		contentType: "application/json;charset=utf-8",
21870		dataType: "json",
21871		data: options
21872	}).done(function (jsonResponse) {
21873		if (jsonResponse !== "" && jsonResponse !== "error") {
21874			_renderIndividualTweets(jsonResponse, $currentTwitterComponent);
21875		} else {
21876			console.log("error in the twitter feed!");
21877		}
21878		_addTwitterWidgetJs();
21879	}).fail(function () {
21880		console.log("error while fetching the tweets!")
21881	});
21882}
21883
21884/**
21885 * Iterate through individual tweet urls and form appropriate HTML
21886 * @param {*} tweetUrlList 
21887 * @param {*} $currentTwitterComponent 
21888 */
21889function _renderIndividualTweets(tweetUrlList, $currentTwitterComponent) {
21890	$.each(tweetUrlList, function (index) {
21891		var tweetUrl = tweetUrlList[index];
21892		var prefix = "<blockquote class=\"twitter-tweet\">";
21893		var suffix = "</blockquote>";
21894		var tweetAnchorTag = "<a href=" + tweetUrl + ">" + "</a>";
21895		var tweetBlockQuote = prefix + tweetAnchorTag + suffix;
21896		$currentTwitterComponent.append(tweetBlockQuote);
21897		index++;
21898	});
21899}
21900
21901/**
21902 * Adding the Twitter Widget JS file to the head tag.
21903 */
21904function _addTwitterWidgetJs() {
21905	var script = document.createElement('script');
21906	script.async = true;
21907	script.src = 'https://platform.twitter.com/widgets.js';
21908	document.getElementsByTagName('head')[0].appendChild(script);
21909}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.