Skip to content
Snippets Groups Projects
d3.js 106 KiB
Newer Older
  • Learn to ignore specific revisions
  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    (function(){if (!Date.now) Date.now = function() {
      return +new Date;
    };
    try {
      document.createElement("div").style.setProperty("opacity", 0, "");
    } catch (error) {
      var d3_style_prototype = CSSStyleDeclaration.prototype,
          d3_style_setProperty = d3_style_prototype.setProperty;
      d3_style_prototype.setProperty = function(name, value, priority) {
        d3_style_setProperty.call(this, name, value + "", priority);
      };
    }
    d3 = {version: "2.1.3"}; // semver
    var d3_arraySubclass = [].__proto__?
    
    // Until ECMAScript supports array subclassing, prototype injection works well.
    function(array, prototype) {
      array.__proto__ = prototype;
    }:
    
    // And if your browser doesn't support __proto__, we'll use direct extension.
    function(array, prototype) {
      for (var property in prototype) array[property] = prototype[property];
    };
    function d3_this() {
      return this;
    }
    d3.functor = function(v) {
      return typeof v === "function" ? v : function() { return v; };
    };
    // A getter-setter method that preserves the appropriate `this` context.
    d3.rebind = function(object, method) {
      return function() {
        var x = method.apply(object, arguments);
        return arguments.length ? object : x;
      };
    };
    d3.ascending = function(a, b) {
      return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
    };
    d3.descending = function(a, b) {
      return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
    };
    d3.min = function(array, f) {
      var i = -1,
          n = array.length,
          a,
          b;
      if (arguments.length === 1) {
        while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
        while (++i < n) if ((b = array[i]) != null && a > b) a = b;
      } else {
        while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
        while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
      }
      return a;
    };
    d3.max = function(array, f) {
      var i = -1,
          n = array.length,
          a,
          b;
      if (arguments.length === 1) {
        while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
        while (++i < n) if ((b = array[i]) != null && b > a) a = b;
      } else {
        while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
        while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
      }
      return a;
    };
    d3.sum = function(array, f) {
      var s = 0,
          n = array.length,
          a,
          i = -1;
    
      if (arguments.length === 1) {
        while (++i < n) if (!isNaN(a = +array[i])) s += a;
      } else {
        while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
      }
    
      return s;
    };
    // R-7 per <http://en.wikipedia.org/wiki/Quantile>
    d3.quantile = function(values, p) {
      var H = (values.length - 1) * p + 1,
          h = Math.floor(H),
          v = values[h - 1],
          e = H - h;
      return e ? v + e * (values[h] - v) : v;
    };
    d3.zip = function() {
      if (!(n = arguments.length)) return [];
      for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m;) {
        for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n;) {
          zip[j] = arguments[j][i];
        }
      }
      return zips;
    };
    
    function d3_zipLength(d) {
      return d.length;
    }
    // Locate the insertion point for x in a to maintain sorted order. The
    // arguments lo and hi may be used to specify a subset of the array which should
    // be considered; by default the entire array is used. If x is already present
    // in a, the insertion point will be before (to the left of) any existing
    // entries. The return value is suitable for use as the first argument to
    // `array.splice` assuming that a is already sorted.
    //
    // The returned insertion point i partitions the array a into two halves so that
    // all v < x for v in a[lo:i] for the left side and all v >= x for v in a[i:hi]
    // for the right side.
    d3.bisectLeft = function(a, x, lo, hi) {
      if (arguments.length < 3) lo = 0;
      if (arguments.length < 4) hi = a.length;
      while (lo < hi) {
        var mid = (lo + hi) >> 1;
        if (a[mid] < x) lo = mid + 1;
        else hi = mid;
      }
      return lo;
    };
    
    // Similar to bisectLeft, but returns an insertion point which comes after (to
    // the right of) any existing entries of x in a.
    //
    // The returned insertion point i partitions the array into two halves so that
    // all v <= x for v in a[lo:i] for the left side and all v > x for v in a[i:hi]
    // for the right side.
    d3.bisect =
    d3.bisectRight = function(a, x, lo, hi) {
      if (arguments.length < 3) lo = 0;
      if (arguments.length < 4) hi = a.length;
      while (lo < hi) {
        var mid = (lo + hi) >> 1;
        if (x < a[mid]) hi = mid;
        else lo = mid + 1;
      }
      return lo;
    };
    d3.first = function(array, f) {
      var i = 0,
          n = array.length,
          a = array[0],
          b;
      if (arguments.length === 1) f = d3.ascending;
      while (++i < n) {
        if (f.call(array, a, b = array[i]) > 0) {
          a = b;
        }
      }
      return a;
    };
    d3.last = function(array, f) {
      var i = 0,
          n = array.length,
          a = array[0],
          b;
      if (arguments.length === 1) f = d3.ascending;
      while (++i < n) {
        if (f.call(array, a, b = array[i]) <= 0) {
          a = b;
        }
      }
      return a;
    };
    d3.nest = function() {
      var nest = {},
          keys = [],
          sortKeys = [],
          sortValues,
          rollup;
    
      function map(array, depth) {
        if (depth >= keys.length) return rollup
            ? rollup.call(nest, array) : (sortValues
            ? array.sort(sortValues)
            : array);
    
        var i = -1,
            n = array.length,
            key = keys[depth++],
            keyValue,
            object,
            o = {};
    
        while (++i < n) {
          if ((keyValue = key(object = array[i])) in o) {
            o[keyValue].push(object);
          } else {
            o[keyValue] = [object];
          }
        }
    
        for (keyValue in o) {
          o[keyValue] = map(o[keyValue], depth);
        }
    
        return o;
      }
    
      function entries(map, depth) {
        if (depth >= keys.length) return map;
    
        var a = [],
            sortKey = sortKeys[depth++],
            key;
    
        for (key in map) {
          a.push({key: key, values: entries(map[key], depth)});
        }
    
        if (sortKey) a.sort(function(a, b) {
          return sortKey(a.key, b.key);
        });
    
        return a;
      }
    
      nest.map = function(array) {
        return map(array, 0);
      };
    
      nest.entries = function(array) {
        return entries(map(array, 0), 0);
      };
    
      nest.key = function(d) {
        keys.push(d);
        return nest;
      };
    
      // Specifies the order for the most-recently specified key.
      // Note: only applies to entries. Map keys are unordered!
      nest.sortKeys = function(order) {
        sortKeys[keys.length - 1] = order;
        return nest;
      };
    
      // Specifies the order for leaf values.
      // Applies to both maps and entries array.
      nest.sortValues = function(order) {
        sortValues = order;
        return nest;
      };
    
      nest.rollup = function(f) {
        rollup = f;
        return nest;
      };
    
      return nest;
    };
    d3.keys = function(map) {
      var keys = [];
      for (var key in map) keys.push(key);
      return keys;
    };
    d3.values = function(map) {
      var values = [];
      for (var key in map) values.push(map[key]);
      return values;
    };
    d3.entries = function(map) {
      var entries = [];
      for (var key in map) entries.push({key: key, value: map[key]});
      return entries;
    };
    d3.permute = function(array, indexes) {
      var permutes = [],
          i = -1,
          n = indexes.length;
      while (++i < n) permutes[i] = array[indexes[i]];
      return permutes;
    };
    d3.merge = function(arrays) {
      return Array.prototype.concat.apply([], arrays);
    };
    d3.split = function(array, f) {
      var arrays = [],
          values = [],
          value,
          i = -1,
          n = array.length;
      if (arguments.length < 2) f = d3_splitter;
      while (++i < n) {
        if (f.call(values, value = array[i], i)) {
          values = [];
        } else {
          if (!values.length) arrays.push(values);
          values.push(value);
        }
      }
      return arrays;
    };
    
    function d3_splitter(d) {
      return d == null;
    }
    function d3_collapse(s) {
      return s.replace(/(^\s+)|(\s+$)/g, "").replace(/\s+/g, " ");
    }
    /**
     * @param {number} start
     * @param {number=} stop
     * @param {number=} step
     */
    d3.range = function(start, stop, step) {
      if (arguments.length < 3) {
        step = 1;
        if (arguments.length < 2) {
          stop = start;
          start = 0;
        }
      }
      if ((stop - start) / step == Infinity) throw new Error("infinite range");
      var range = [],
           i = -1,
           j;
      if (step < 0) while ((j = start + step * ++i) > stop) range.push(j);
      else while ((j = start + step * ++i) < stop) range.push(j);
      return range;
    };
    d3.requote = function(s) {
      return s.replace(d3_requote_re, "\\$&");
    };
    
    var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
    d3.round = function(x, n) {
      return n
          ? Math.round(x * Math.pow(10, n)) * Math.pow(10, -n)
          : Math.round(x);
    };
    d3.xhr = function(url, mime, callback) {
      var req = new XMLHttpRequest;
      if (arguments.length < 3) callback = mime;
      else if (mime && req.overrideMimeType) req.overrideMimeType(mime);
      req.open("GET", url, true);
      req.onreadystatechange = function() {
        if (req.readyState === 4) callback(req.status < 300 ? req : null);
      };
      req.send(null);
    };
    d3.text = function(url, mime, callback) {
      function ready(req) {
        callback(req && req.responseText);
      }
      if (arguments.length < 3) {
        callback = mime;
        mime = null;
      }
      d3.xhr(url, mime, ready);
    };
    d3.json = function(url, callback) {
      d3.text(url, "application/json", function(text) {
        callback(text ? JSON.parse(text) : null);
      });
    };
    d3.html = function(url, callback) {
      d3.text(url, "text/html", function(text) {
        if (text != null) { // Treat empty string as valid HTML.
          var range = document.createRange();
          range.selectNode(document.body);
          text = range.createContextualFragment(text);
        }
        callback(text);
      });
    };
    d3.xml = function(url, mime, callback) {
      function ready(req) {
        callback(req && req.responseXML);
      }
      if (arguments.length < 3) {
        callback = mime;
        mime = null;
      }
      d3.xhr(url, mime, ready);
    };
    d3.ns = {
    
      prefix: {
        svg: "http://www.w3.org/2000/svg",
        xhtml: "http://www.w3.org/1999/xhtml",
        xlink: "http://www.w3.org/1999/xlink",
        xml: "http://www.w3.org/XML/1998/namespace",
        xmlns: "http://www.w3.org/2000/xmlns/"
      },
    
      qualify: function(name) {
        var i = name.indexOf(":");
        return i < 0 ? name : {
          space: d3.ns.prefix[name.substring(0, i)],
          local: name.substring(i + 1)
        };
      }
    
    };
    /** @param {...string} types */
    d3.dispatch = function(types) {
      var dispatch = {},
          type;
      for (var i = 0, n = arguments.length; i < n; i++) {
        type = arguments[i];
        dispatch[type] = d3_dispatch(type);
      }
      return dispatch;
    };
    
    function d3_dispatch(type) {
      var dispatch = {},
          listeners = [];
    
      dispatch.add = function(listener) {
        for (var i = 0; i < listeners.length; i++) {
          if (listeners[i].listener == listener) return dispatch; // already registered
        }
        listeners.push({listener: listener, on: true});
        return dispatch;
      };
    
      dispatch.remove = function(listener) {
        for (var i = 0; i < listeners.length; i++) {
          var l = listeners[i];
          if (l.listener == listener) {
            l.on = false;
            listeners = listeners.slice(0, i).concat(listeners.slice(i + 1));
            break;
          }
        }
        return dispatch;
      };
    
      dispatch.dispatch = function() {
        var ls = listeners; // defensive reference
        for (var i = 0, n = ls.length; i < n; i++) {
          var l = ls[i];
          if (l.on) l.listener.apply(this, arguments);
        }
      };
    
      return dispatch;
    };
    // TODO align
    d3.format = function(specifier) {
      var match = d3_format_re.exec(specifier),
          fill = match[1] || " ",
          sign = match[3] || "",
          zfill = match[5],
          width = +match[6],
          comma = match[7],
          precision = match[8],
          type = match[9],
          percentage = false,
          integer = false;
    
      if (precision) precision = precision.substring(1);
    
      if (zfill) {
        fill = "0"; // TODO align = "=";
        if (comma) width -= Math.floor((width - 1) / 4);
      }
    
      switch (type) {
        case "n": comma = true; type = "g"; break;
        case "%": percentage = true; type = "f"; break;
        case "p": percentage = true; type = "r"; break;
        case "d": integer = true; precision = "0"; break;
      }
    
      type = d3_format_types[type] || d3_format_typeDefault;
    
      return function(value) {
        var number = percentage ? value * 100 : +value,
            negative = (number < 0) && (number = -number) ? "\u2212" : sign;
    
        // Return the empty string for floats formatted as ints.
        if (integer && (number % 1)) return "";
    
        // Convert the input value to the desired precision.
        value = type(number, precision);
    
        // If the fill character is 0, the sign and group is applied after the fill.
        if (zfill) {
          var length = value.length + negative.length;
          if (length < width) value = new Array(width - length + 1).join(fill) + value;
          if (comma) value = d3_format_group(value);
          value = negative + value;
        }
    
        // Otherwise (e.g., space-filling), the sign and group is applied before.
        else {
          if (comma) value = d3_format_group(value);
          value = negative + value;
          var length = value.length;
          if (length < width) value = new Array(width - length + 1).join(fill) + value;
        }
        if (percentage) value += "%";
    
        return value;
      };
    };
    
    // [[fill]align][sign][#][0][width][,][.precision][type]
    var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
    
    var d3_format_types = {
      g: function(x, p) { return x.toPrecision(p); },
      e: function(x, p) { return x.toExponential(p); },
      f: function(x, p) { return x.toFixed(p); },
      r: function(x, p) {
        var n = 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10);
        return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
      }
    };
    
    function d3_format_typeDefault(x) {
      return x + "";
    }
    
    // Apply comma grouping for thousands.
    function d3_format_group(value) {
      var i = value.lastIndexOf("."),
          f = i >= 0 ? value.substring(i) : (i = value.length, ""),
          t = [];
      while (i > 0) t.push(value.substring(i -= 3, i + 3));
      return t.reverse().join(",") + f;
    }
    /*
     * TERMS OF USE - EASING EQUATIONS
     *
     * Open source under the BSD License.
     *
     * Copyright 2001 Robert Penner
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions are met:
     *
     * - Redistributions of source code must retain the above copyright notice, this
     *   list of conditions and the following disclaimer.
     *
     * - Redistributions in binary form must reproduce the above copyright notice,
     *   this list of conditions and the following disclaimer in the documentation
     *   and/or other materials provided with the distribution.
     *
     * - Neither the name of the author nor the names of contributors may be used to
     *   endorse or promote products derived from this software without specific
     *   prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     * POSSIBILITY OF SUCH DAMAGE.
     */
    
    var d3_ease_quad = d3_ease_poly(2),
        d3_ease_cubic = d3_ease_poly(3);
    
    var d3_ease = {
      linear: function() { return d3_ease_linear; },
      poly: d3_ease_poly,
      quad: function() { return d3_ease_quad; },
      cubic: function() { return d3_ease_cubic; },
      sin: function() { return d3_ease_sin; },
      exp: function() { return d3_ease_exp; },
      circle: function() { return d3_ease_circle; },
      elastic: d3_ease_elastic,
      back: d3_ease_back,
      bounce: function() { return d3_ease_bounce; }
    };
    
    var d3_ease_mode = {
      "in": function(f) { return f; },
      "out": d3_ease_reverse,
      "in-out": d3_ease_reflect,
      "out-in": function(f) { return d3_ease_reflect(d3_ease_reverse(f)); }
    };
    
    d3.ease = function(name) {
      var i = name.indexOf("-"),
          t = i >= 0 ? name.substring(0, i) : name,
          m = i >= 0 ? name.substring(i + 1) : "in";
      return d3_ease_clamp(d3_ease_mode[m](d3_ease[t].apply(null, Array.prototype.slice.call(arguments, 1))));
    };
    
    function d3_ease_clamp(f) {
      return function(t) {
        return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
      };
    }
    
    function d3_ease_reverse(f) {
      return function(t) {
        return 1 - f(1 - t);
      };
    }
    
    function d3_ease_reflect(f) {
      return function(t) {
        return .5 * (t < .5 ? f(2 * t) : (2 - f(2 - 2 * t)));
      };
    }
    
    function d3_ease_linear(t) {
      return t;
    }
    
    function d3_ease_poly(e) {
      return function(t) {
        return Math.pow(t, e);
      }
    }
    
    function d3_ease_sin(t) {
      return 1 - Math.cos(t * Math.PI / 2);
    }
    
    function d3_ease_exp(t) {
      return Math.pow(2, 10 * (t - 1));
    }
    
    function d3_ease_circle(t) {
      return 1 - Math.sqrt(1 - t * t);
    }
    
    function d3_ease_elastic(a, p) {
      var s;
      if (arguments.length < 2) p = 0.45;
      if (arguments.length < 1) { a = 1; s = p / 4; }
      else s = p / (2 * Math.PI) * Math.asin(1 / a);
      return function(t) {
        return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * Math.PI / p);
      };
    }
    
    function d3_ease_back(s) {
      if (!s) s = 1.70158;
      return function(t) {
        return t * t * ((s + 1) * t - s);
      };
    }
    
    function d3_ease_bounce(t) {
      return t < 1 / 2.75 ? 7.5625 * t * t
          : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75
          : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375
          : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
    }
    d3.event = null;
    d3.interpolate = function(a, b) {
      var i = d3.interpolators.length, f;
      while (--i >= 0 && !(f = d3.interpolators[i](a, b)));
      return f;
    };
    
    d3.interpolateNumber = function(a, b) {
      b -= a;
      return function(t) { return a + b * t; };
    };
    
    d3.interpolateRound = function(a, b) {
      b -= a;
      return function(t) { return Math.round(a + b * t); };
    };
    
    d3.interpolateString = function(a, b) {
      var m, // current match
          i, // current index
          j, // current index (for coallescing)
          s0 = 0, // start index of current string prefix
          s1 = 0, // end index of current string prefix
          s = [], // string constants and placeholders
          q = [], // number interpolators
          n, // q.length
          o;
    
      // Reset our regular expression!
      d3_interpolate_number.lastIndex = 0;
    
      // Find all numbers in b.
      for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
        if (m.index) s.push(b.substring(s0, s1 = m.index));
        q.push({i: s.length, x: m[0]});
        s.push(null);
        s0 = d3_interpolate_number.lastIndex;
      }
      if (s0 < b.length) s.push(b.substring(s0));
    
      // Find all numbers in a.
      for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
        o = q[i];
        if (o.x == m[0]) { // The numbers match, so coallesce.
          if (o.i) {
            if (s[o.i + 1] == null) { // This match is followed by another number.
              s[o.i - 1] += o.x;
              s.splice(o.i, 1);
              for (j = i + 1; j < n; ++j) q[j].i--;
            } else { // This match is followed by a string, so coallesce twice.
              s[o.i - 1] += o.x + s[o.i + 1];
              s.splice(o.i, 2);
              for (j = i + 1; j < n; ++j) q[j].i -= 2;
            }
          } else {
              if (s[o.i + 1] == null) { // This match is followed by another number.
              s[o.i] = o.x;
            } else { // This match is followed by a string, so coallesce twice.
              s[o.i] = o.x + s[o.i + 1];
              s.splice(o.i + 1, 1);
              for (j = i + 1; j < n; ++j) q[j].i--;
            }
          }
          q.splice(i, 1);
          n--;
          i--;
        } else {
          o.x = d3.interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
        }
      }
    
      // Remove any numbers in b not found in a.
      while (i < n) {
        o = q.pop();
        if (s[o.i + 1] == null) { // This match is followed by another number.
          s[o.i] = o.x;
        } else { // This match is followed by a string, so coallesce twice.
          s[o.i] = o.x + s[o.i + 1];
          s.splice(o.i + 1, 1);
        }
        n--;
      }
    
      // Special optimization for only a single match.
      if (s.length === 1) {
        return s[0] == null ? q[0].x : function() { return b; };
      }
    
      // Otherwise, interpolate each of the numbers and rejoin the string.
      return function(t) {
        for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
        return s.join("");
      };
    };
    
    d3.interpolateRgb = function(a, b) {
      a = d3.rgb(a);
      b = d3.rgb(b);
      var ar = a.r,
          ag = a.g,
          ab = a.b,
          br = b.r - ar,
          bg = b.g - ag,
          bb = b.b - ab;
      return function(t) {
        return "rgb(" + Math.round(ar + br * t)
            + "," + Math.round(ag + bg * t)
            + "," + Math.round(ab + bb * t)
            + ")";
      };
    };
    
    // interpolates HSL space, but outputs RGB string (for compatibility)
    d3.interpolateHsl = function(a, b) {
      a = d3.hsl(a);
      b = d3.hsl(b);
      var h0 = a.h,
          s0 = a.s,
          l0 = a.l,
          h1 = b.h - h0,
          s1 = b.s - s0,
          l1 = b.l - l0;
      return function(t) {
        return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t).toString();
      };
    };
    
    d3.interpolateArray = function(a, b) {
      var x = [],
          c = [],
          na = a.length,
          nb = b.length,
          n0 = Math.min(a.length, b.length),
          i;
      for (i = 0; i < n0; ++i) x.push(d3.interpolate(a[i], b[i]));
      for (; i < na; ++i) c[i] = a[i];
      for (; i < nb; ++i) c[i] = b[i];
      return function(t) {
        for (i = 0; i < n0; ++i) c[i] = x[i](t);
        return c;
      };
    };
    
    d3.interpolateObject = function(a, b) {
      var i = {},
          c = {},
          k;
      for (k in a) {
        if (k in b) {
          i[k] = d3_interpolateByName(k)(a[k], b[k]);
        } else {
          c[k] = a[k];
        }
      }
      for (k in b) {
        if (!(k in a)) {
          c[k] = b[k];
        }
      }
      return function(t) {
        for (k in i) c[k] = i[k](t);
        return c;
      };
    }
    
    var d3_interpolate_number = /[-+]?(?:\d+\.\d+|\d+\.|\.\d+|\d+)(?:[eE][-]?\d+)?/g,
        d3_interpolate_rgb = {background: 1, fill: 1, stroke: 1};
    
    function d3_interpolateByName(n) {
      return n in d3_interpolate_rgb || /\bcolor\b/.test(n)
          ? d3.interpolateRgb
          : d3.interpolate;
    }
    
    d3.interpolators = [
      d3.interpolateObject,
      function(a, b) { return (b instanceof Array) && d3.interpolateArray(a, b); },
      function(a, b) { return (typeof b === "string") && d3.interpolateString(String(a), b); },
      function(a, b) { return (typeof b === "string" ? b in d3_rgb_names || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(String(a), b); },
      function(a, b) { return (typeof b === "number") && d3.interpolateNumber(+a, b); }
    ];
    function d3_uninterpolateNumber(a, b) {
      b = b - (a = +a) ? 1 / (b - a) : 0;
      return function(x) { return (x - a) * b; };
    }
    
    function d3_uninterpolateClamp(a, b) {
      b = b - (a = +a) ? 1 / (b - a) : 0;
      return function(x) { return Math.max(0, Math.min(1, (x - a) * b)); };
    }
    d3.rgb = function(r, g, b) {
      return arguments.length === 1
          ? d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb)
          : d3_rgb(~~r, ~~g, ~~b);
    };
    
    function d3_rgb(r, g, b) {
      return new d3_Rgb(r, g, b);
    }
    
    function d3_Rgb(r, g, b) {
      this.r = r;
      this.g = g;
      this.b = b;
    }
    
    d3_Rgb.prototype.brighter = function(k) {
      k = Math.pow(0.7, arguments.length ? k : 1);
      var r = this.r,
          g = this.g,
          b = this.b,
          i = 30;
      if (!r && !g && !b) return d3_rgb(i, i, i);
      if (r && r < i) r = i;
      if (g && g < i) g = i;
      if (b && b < i) b = i;
      return d3_rgb(
        Math.min(255, Math.floor(r / k)),
        Math.min(255, Math.floor(g / k)),
        Math.min(255, Math.floor(b / k)));
    };
    
    d3_Rgb.prototype.darker = function(k) {
      k = Math.pow(0.7, arguments.length ? k : 1);
      return d3_rgb(
        Math.max(0, Math.floor(k * this.r)),
        Math.max(0, Math.floor(k * this.g)),
        Math.max(0, Math.floor(k * this.b)));
    };
    
    d3_Rgb.prototype.hsl = function() {
      return d3_rgb_hsl(this.r, this.g, this.b);
    };
    
    d3_Rgb.prototype.toString = function() {
      return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
    };
    
    function d3_rgb_hex(v) {
      return v < 0x10 ? "0" + v.toString(16) : v.toString(16);
    }
    
    function d3_rgb_parse(format, rgb, hsl) {
      var r = 0, // red channel; int in [0, 255]
          g = 0, // green channel; int in [0, 255]
          b = 0, // blue channel; int in [0, 255]
          m1, // CSS color specification match
          m2, // CSS color specification type (e.g., rgb)
          name;
    
      /* Handle hsl, rgb. */
      m1 = /([a-z]+)\((.*)\)/i.exec(format);
      if (m1) {
        m2 = m1[2].split(",");
        switch (m1[1]) {
          case "hsl": {
            return hsl(
              parseFloat(m2[0]), // degrees
              parseFloat(m2[1]) / 100, // percentage
              parseFloat(m2[2]) / 100 // percentage
            );
          }
          case "rgb": {
            return rgb(
              d3_rgb_parseNumber(m2[0]),
              d3_rgb_parseNumber(m2[1]),
              d3_rgb_parseNumber(m2[2])
            );
          }
        }
      }
    
      /* Named colors. */
      if (name = d3_rgb_names[format]) return rgb(name.r, name.g, name.b);
    
      /* Hexadecimal colors: #rgb and #rrggbb. */
      if (format != null && format.charAt(0) === "#") {
        if (format.length === 4) {
          r = format.charAt(1); r += r;
          g = format.charAt(2); g += g;
          b = format.charAt(3); b += b;
        } else if (format.length === 7) {
          r = format.substring(1, 3);
          g = format.substring(3, 5);
          b = format.substring(5, 7);
        }
        r = parseInt(r, 16);
        g = parseInt(g, 16);
        b = parseInt(b, 16);
      }
    
      return rgb(r, g, b);
    }
    
    function d3_rgb_hsl(r, g, b) {
      var min = Math.min(r /= 255, g /= 255, b /= 255),
          max = Math.max(r, g, b),
          d = max - min,
          h,
          s,
          l = (max + min) / 2;
      if (d) {
        s = l < .5 ? d / (max + min) : d / (2 - max - min);
        if (r == max) h = (g - b) / d + (g < b ? 6 : 0);
        else if (g == max) h = (b - r) / d + 2;
        else h = (r - g) / d + 4;
        h *= 60;
      } else {
        s = h = 0;
      }
      return d3_hsl(h, s, l);
    }
    
    function d3_rgb_parseNumber(c) { // either integer or percentage
      var f = parseFloat(c);
      return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
    }
    
    var d3_rgb_names = {
      aliceblue: "#f0f8ff",
      antiquewhite: "#faebd7",
      aqua: "#00ffff",
      aquamarine: "#7fffd4",
      azure: "#f0ffff",
      beige: "#f5f5dc",
      bisque: "#ffe4c4",
      black: "#000000",
      blanchedalmond: "#ffebcd",
      blue: "#0000ff",
      blueviolet: "#8a2be2",
      brown: "#a52a2a",
      burlywood: "#deb887",
      cadetblue: "#5f9ea0",
      chartreuse: "#7fff00",
      chocolate: "#d2691e",
      coral: "#ff7f50",
      cornflowerblue: "#6495ed",
      cornsilk: "#fff8dc",
      crimson: "#dc143c",
      cyan: "#00ffff",
      darkblue: "#00008b",