2 function d3_class(ctor, properties) {
4 for (var key in properties) {
5 Object.defineProperty(ctor.prototype, key, {
6 value: properties[key],
11 ctor.prototype = properties;
14 function d3_arrayCopy(pseudoarray) {
15 var i = -1, n = pseudoarray.length, array = [];
16 while (++i < n) array.push(pseudoarray[i]);
19 function d3_arraySlice(pseudoarray) {
20 return Array.prototype.slice.call(pseudoarray);
23 function d3_identity(d) {
32 function d3_functor(v) {
33 return typeof v === "function" ? v : function() {
37 function d3_rebind(target, source, method) {
39 var value = method.apply(source, arguments);
40 return arguments.length ? target : value;
43 function d3_number(x) {
44 return x != null && !isNaN(x);
46 function d3_zipLength(d) {
49 function d3_splitter(d) {
52 function d3_collapse(s) {
53 return s.trim().replace(/\s+/g, " ");
55 function d3_range_integerScale(x) {
57 while (x * k % 1) k *= 10;
60 function d3_dispatch() {}
61 function d3_dispatch_event(dispatch) {
63 var z = listeners, i = -1, n = z.length, l;
64 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
67 var listeners = [], listenerByName = new d3_Map;
68 event.on = function(name, listener) {
69 var l = listenerByName.get(name), i;
70 if (arguments.length < 2) return l && l.on;
73 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
74 listenerByName.remove(name);
76 if (listener) listeners.push(listenerByName.set(name, {
83 function d3_format_precision(x, p) {
84 return p - (x ? 1 + Math.floor(Math.log(x + Math.pow(10, 1 + Math.floor(Math.log(x) / Math.LN10) - p)) / Math.LN10) : 1);
86 function d3_format_typeDefault(x) {
89 function d3_format_group(value) {
90 var i = value.lastIndexOf("."), f = i >= 0 ? value.substring(i) : (i = value.length, ""), t = [];
91 while (i > 0) t.push(value.substring(i -= 3, i + 3));
92 return t.reverse().join(",") + f;
94 function d3_formatPrefix(d, i) {
95 var k = Math.pow(10, Math.abs(8 - i) * 3);
97 scale: i > 8 ? function(d) {
105 function d3_ease_clamp(f) {
107 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
110 function d3_ease_reverse(f) {
115 function d3_ease_reflect(f) {
117 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
120 function d3_ease_identity(t) {
123 function d3_ease_poly(e) {
125 return Math.pow(t, e);
128 function d3_ease_sin(t) {
129 return 1 - Math.cos(t * Math.PI / 2);
131 function d3_ease_exp(t) {
132 return Math.pow(2, 10 * (t - 1));
134 function d3_ease_circle(t) {
135 return 1 - Math.sqrt(1 - t * t);
137 function d3_ease_elastic(a, p) {
139 if (arguments.length < 2) p = .45;
140 if (arguments.length < 1) {
143 } else s = p / (2 * Math.PI) * Math.asin(1 / a);
145 return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * Math.PI / p);
148 function d3_ease_back(s) {
151 return t * t * ((s + 1) * t - s);
154 function d3_ease_bounce(t) {
155 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;
157 function d3_eventCancel() {
158 d3.event.stopPropagation();
159 d3.event.preventDefault();
161 function d3_eventSource() {
163 while (s = e.sourceEvent) e = s;
166 function d3_eventDispatch(target) {
167 var dispatch = new d3_dispatch, i = 0, n = arguments.length;
168 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
169 dispatch.of = function(thiz, argumentz) {
170 return function(e1) {
172 var e0 = e1.sourceEvent = d3.event;
175 dispatch[e1.type].apply(thiz, argumentz);
183 function d3_transform(m) {
184 var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
185 if (r0[0] * r1[1] < r1[0] * r0[1]) {
191 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_transformDegrees;
192 this.translate = [ m.e, m.f ];
193 this.scale = [ kx, ky ];
194 this.skew = ky ? Math.atan2(kz, ky) * d3_transformDegrees : 0;
196 function d3_transformDot(a, b) {
197 return a[0] * b[0] + a[1] * b[1];
199 function d3_transformNormalize(a) {
200 var k = Math.sqrt(d3_transformDot(a, a));
207 function d3_transformCombine(a, b, k) {
212 function d3_interpolateByName(name) {
213 return name == "transform" ? d3.interpolateTransform : d3.interpolate;
215 function d3_uninterpolateNumber(a, b) {
216 b = b - (a = +a) ? 1 / (b - a) : 0;
221 function d3_uninterpolateClamp(a, b) {
222 b = b - (a = +a) ? 1 / (b - a) : 0;
224 return Math.max(0, Math.min(1, (x - a) * b));
227 function d3_rgb(r, g, b) {
228 return new d3_Rgb(r, g, b);
230 function d3_Rgb(r, g, b) {
235 function d3_rgb_hex(v) {
236 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
238 function d3_rgb_parse(format, rgb, hsl) {
239 var r = 0, g = 0, b = 0, m1, m2, name;
240 m1 = /([a-z]+)\((.*)\)/i.exec(format);
242 m2 = m1[2].split(",");
246 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
250 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
254 if (name = d3_rgb_names.get(format)) return rgb(name.r, name.g, name.b);
255 if (format != null && format.charAt(0) === "#") {
256 if (format.length === 4) {
257 r = format.charAt(1);
259 g = format.charAt(2);
261 b = format.charAt(3);
263 } else if (format.length === 7) {
264 r = format.substring(1, 3);
265 g = format.substring(3, 5);
266 b = format.substring(5, 7);
274 function d3_rgb_hsl(r, g, b) {
275 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;
277 s = l < .5 ? d / (max + min) : d / (2 - max - min);
278 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;
283 return d3_hsl(h, s, l);
285 function d3_rgb_lab(r, g, b) {
289 var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
290 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
292 function d3_rgb_xyz(r) {
293 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
295 function d3_rgb_parseNumber(c) {
296 var f = parseFloat(c);
297 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
299 function d3_hsl(h, s, l) {
300 return new d3_Hsl(h, s, l);
302 function d3_Hsl(h, s, l) {
307 function d3_hsl_rgb(h, s, l) {
309 if (h > 360) h -= 360; else if (h < 0) h += 360;
310 if (h < 60) return m1 + (m2 - m1) * h / 60;
311 if (h < 180) return m2;
312 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
316 return Math.round(v(h) * 255);
321 s = s < 0 ? 0 : s > 1 ? 1 : s;
322 l = l < 0 ? 0 : l > 1 ? 1 : l;
323 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
325 return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
327 function d3_hcl(h, c, l) {
328 return new d3_Hcl(h, c, l);
330 function d3_Hcl(h, c, l) {
335 function d3_hcl_lab(h, c, l) {
336 return d3_lab(l, Math.cos(h *= Math.PI / 180) * c, Math.sin(h) * c);
338 function d3_lab(l, a, b) {
339 return new d3_Lab(l, a, b);
341 function d3_Lab(l, a, b) {
346 function d3_lab_rgb(l, a, b) {
347 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
348 x = d3_lab_xyz(x) * d3_lab_X;
349 y = d3_lab_xyz(y) * d3_lab_Y;
350 z = d3_lab_xyz(z) * d3_lab_Z;
351 return d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
353 function d3_lab_hcl(l, a, b) {
354 return d3_hcl(Math.atan2(b, a) / Math.PI * 180, Math.sqrt(a * a + b * b), l);
356 function d3_lab_xyz(x) {
357 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
359 function d3_xyz_lab(x) {
360 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
362 function d3_xyz_rgb(r) {
363 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
365 function d3_selection(groups) {
366 d3_arraySubclass(groups, d3_selectionPrototype);
369 function d3_selection_selector(selector) {
371 return d3_select(selector, this);
374 function d3_selection_selectorAll(selector) {
376 return d3_selectAll(selector, this);
379 function d3_selection_attr(name, value) {
380 function attrNull() {
381 this.removeAttribute(name);
383 function attrNullNS() {
384 this.removeAttributeNS(name.space, name.local);
386 function attrConstant() {
387 this.setAttribute(name, value);
389 function attrConstantNS() {
390 this.setAttributeNS(name.space, name.local, value);
392 function attrFunction() {
393 var x = value.apply(this, arguments);
394 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
396 function attrFunctionNS() {
397 var x = value.apply(this, arguments);
398 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
400 name = d3.ns.qualify(name);
401 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
403 function d3_selection_classedRe(name) {
404 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
406 function d3_selection_classed(name, value) {
407 function classedConstant() {
409 while (++i < n) name[i](this, value);
411 function classedFunction() {
412 var i = -1, x = value.apply(this, arguments);
413 while (++i < n) name[i](this, x);
415 name = name.trim().split(/\s+/).map(d3_selection_classedName);
417 return typeof value === "function" ? classedFunction : classedConstant;
419 function d3_selection_classedName(name) {
420 var re = d3_selection_classedRe(name);
421 return function(node, value) {
422 if (c = node.classList) return value ? c.add(name) : c.remove(name);
423 var c = node.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
427 cv = d3_collapse(cv + " " + name);
428 if (cb) c.baseVal = cv; else node.className = cv;
431 cv = d3_collapse(cv.replace(re, " "));
432 if (cb) c.baseVal = cv; else node.className = cv;
436 function d3_selection_style(name, value, priority) {
437 function styleNull() {
438 this.style.removeProperty(name);
440 function styleConstant() {
441 this.style.setProperty(name, value, priority);
443 function styleFunction() {
444 var x = value.apply(this, arguments);
445 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
447 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
449 function d3_selection_property(name, value) {
450 function propertyNull() {
453 function propertyConstant() {
456 function propertyFunction() {
457 var x = value.apply(this, arguments);
458 if (x == null) delete this[name]; else this[name] = x;
460 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
462 function d3_selection_dataNode(data) {
467 function d3_selection_filter(selector) {
469 return d3_selectMatches(this, selector);
472 function d3_selection_sortComparator(comparator) {
473 if (!arguments.length) comparator = d3.ascending;
474 return function(a, b) {
475 return comparator(a && a.__data__, b && b.__data__);
478 function d3_selection_on(type, listener, capture) {
479 function onRemove() {
480 var wrapper = this[name];
482 this.removeEventListener(type, wrapper, wrapper.$);
487 function wrapper(e) {
490 args[0] = node.__data__;
492 listener.apply(node, args);
497 var node = this, args = arguments;
499 this.addEventListener(type, this[name] = wrapper, wrapper.$ = capture);
500 wrapper._ = listener;
502 var name = "__on" + type, i = type.indexOf(".");
503 if (i > 0) type = type.substring(0, i);
504 return listener ? onAdd : onRemove;
506 function d3_selection_each(groups, callback) {
507 for (var j = 0, m = groups.length; j < m; j++) {
508 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
509 if (node = group[i]) callback(node, i, j);
514 function d3_selection_enter(selection) {
515 d3_arraySubclass(selection, d3_selection_enterPrototype);
518 function d3_transition(groups, id, time) {
519 d3_arraySubclass(groups, d3_transitionPrototype);
520 var tweens = new d3_Map, event = d3.dispatch("start", "end"), ease = d3_transitionEase;
523 groups.tween = function(name, tween) {
524 if (arguments.length < 2) return tweens.get(name);
525 if (tween == null) tweens.remove(name); else tweens.set(name, tween);
528 groups.ease = function(value) {
529 if (!arguments.length) return ease;
530 ease = typeof value === "function" ? value : d3.ease.apply(d3, arguments);
533 groups.each = function(type, listener) {
534 if (arguments.length < 2) return d3_transition_each.call(groups, type);
535 event.on(type, listener);
538 d3.timer(function(elapsed) {
539 return d3_selection_each(groups, function(node, i, j) {
540 function start(elapsed) {
541 if (lock.active > id) return stop();
543 tweens.forEach(function(key, value) {
544 if (value = value.call(node, d, i)) {
548 event.start.call(node, d, i);
549 if (!tick(elapsed)) d3.timer(tick, 0, time);
552 function tick(elapsed) {
553 if (lock.active !== id) return stop();
554 var t = (elapsed - delay) / duration, e = ease(t), n = tweened.length;
556 tweened[--n].call(node, e);
560 d3_transitionId = id;
561 event.end.call(node, d, i);
567 if (!--lock.count) delete node.__transition__;
570 var tweened = [], delay = node.delay, duration = node.duration, lock = (node = node.node).__transition__ || (node.__transition__ = {
573 }), d = node.__data__;
575 delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time);
580 function d3_transition_each(callback) {
581 var id = d3_transitionId, ease = d3_transitionEase, delay = d3_transitionDelay, duration = d3_transitionDuration;
582 d3_transitionId = this.id;
583 d3_transitionEase = this.ease();
584 d3_selection_each(this, function(node, i, j) {
585 d3_transitionDelay = node.delay;
586 d3_transitionDuration = node.duration;
587 callback.call(node = node.node, node.__data__, i, j);
589 d3_transitionId = id;
590 d3_transitionEase = ease;
591 d3_transitionDelay = delay;
592 d3_transitionDuration = duration;
595 function d3_tweenNull(d, i, a) {
596 return a != "" && d3_tweenRemove;
598 function d3_tweenByName(b, name) {
599 return d3.tween(b, d3_interpolateByName(name));
601 function d3_timer_step() {
602 var elapsed, now = Date.now(), t1 = d3_timer_queue;
604 elapsed = now - t1.then;
605 if (elapsed >= t1.delay) t1.flush = t1.callback(elapsed);
608 var delay = d3_timer_flush() - now;
610 if (isFinite(delay)) {
611 clearTimeout(d3_timer_timeout);
612 d3_timer_timeout = setTimeout(d3_timer_step, delay);
614 d3_timer_interval = 0;
616 d3_timer_interval = 1;
617 d3_timer_frame(d3_timer_step);
620 function d3_timer_flush() {
621 var t0 = null, t1 = d3_timer_queue, then = Infinity;
624 t1 = t0 ? t0.next = t1.next : d3_timer_queue = t1.next;
626 then = Math.min(then, t1.then + t1.delay);
632 function d3_mousePoint(container, e) {
633 var svg = container.ownerSVGElement || container;
634 if (svg.createSVGPoint) {
635 var point = svg.createSVGPoint();
636 if (d3_mouse_bug44083 < 0 && (window.scrollX || window.scrollY)) {
637 svg = d3.select(document.body).append("svg").style("position", "absolute").style("top", 0).style("left", 0);
638 var ctm = svg[0][0].getScreenCTM();
639 d3_mouse_bug44083 = !(ctm.f || ctm.e);
642 if (d3_mouse_bug44083) {
649 point = point.matrixTransform(container.getScreenCTM().inverse());
650 return [ point.x, point.y ];
652 var rect = container.getBoundingClientRect();
653 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
655 function d3_noop() {}
656 function d3_scaleExtent(domain) {
657 var start = domain[0], stop = domain[domain.length - 1];
658 return start < stop ? [ start, stop ] : [ stop, start ];
660 function d3_scaleRange(scale) {
661 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
663 function d3_scale_nice(domain, nice) {
664 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
666 dx = i0, i0 = i1, i1 = dx;
667 dx = x0, x0 = x1, x1 = dx;
669 if (nice = nice(x1 - x0)) {
670 domain[i0] = nice.floor(x0);
671 domain[i1] = nice.ceil(x1);
675 function d3_scale_niceDefault() {
678 function d3_scale_linear(domain, range, interpolate, clamp) {
680 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
681 output = linear(domain, range, uninterpolate, interpolate);
682 input = linear(range, domain, uninterpolate, d3.interpolate);
689 scale.invert = function(y) {
692 scale.domain = function(x) {
693 if (!arguments.length) return domain;
694 domain = x.map(Number);
697 scale.range = function(x) {
698 if (!arguments.length) return range;
702 scale.rangeRound = function(x) {
703 return scale.range(x).interpolate(d3.interpolateRound);
705 scale.clamp = function(x) {
706 if (!arguments.length) return clamp;
710 scale.interpolate = function(x) {
711 if (!arguments.length) return interpolate;
715 scale.ticks = function(m) {
716 return d3_scale_linearTicks(domain, m);
718 scale.tickFormat = function(m) {
719 return d3_scale_linearTickFormat(domain, m);
721 scale.nice = function() {
722 d3_scale_nice(domain, d3_scale_linearNice);
725 scale.copy = function() {
726 return d3_scale_linear(domain, range, interpolate, clamp);
730 function d3_scale_linearRebind(scale, linear) {
731 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
733 function d3_scale_linearNice(dx) {
734 dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
737 return Math.floor(x / dx) * dx;
740 return Math.ceil(x / dx) * dx;
744 function d3_scale_linearTickRange(domain, m) {
745 var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;
746 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
747 extent[0] = Math.ceil(extent[0] / step) * step;
748 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
752 function d3_scale_linearTicks(domain, m) {
753 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
755 function d3_scale_linearTickFormat(domain, m) {
756 return d3.format(",." + Math.max(0, -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01)) + "f");
758 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
759 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
764 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
765 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
766 if (domain[k] < domain[0]) {
767 domain = domain.slice().reverse();
768 range = range.slice().reverse();
771 u.push(uninterpolate(domain[j - 1], domain[j]));
772 i.push(interpolate(range[j - 1], range[j]));
775 var j = d3.bisect(domain, x, 1, k) - 1;
776 return i[j](u[j](x));
779 function d3_scale_log(linear, log) {
781 return linear(log(x));
784 scale.invert = function(x) {
785 return pow(linear.invert(x));
787 scale.domain = function(x) {
788 if (!arguments.length) return linear.domain().map(pow);
789 log = x[0] < 0 ? d3_scale_logn : d3_scale_logp;
791 linear.domain(x.map(log));
794 scale.nice = function() {
795 linear.domain(d3_scale_nice(linear.domain(), d3_scale_niceDefault));
798 scale.ticks = function() {
799 var extent = d3_scaleExtent(linear.domain()), ticks = [];
800 if (extent.every(isFinite)) {
801 var i = Math.floor(extent[0]), j = Math.ceil(extent[1]), u = pow(extent[0]), v = pow(extent[1]);
802 if (log === d3_scale_logn) {
804 for (; i++ < j; ) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
806 for (; i < j; i++) for (var k = 1; k < 10; k++) ticks.push(pow(i) * k);
809 for (i = 0; ticks[i] < u; i++) {}
810 for (j = ticks.length; ticks[j - 1] > v; j--) {}
811 ticks = ticks.slice(i, j);
815 scale.tickFormat = function(n, format) {
816 if (arguments.length < 2) format = d3_scale_logFormat;
817 if (arguments.length < 1) return format;
818 var k = Math.max(.1, n / scale.ticks().length), f = log === d3_scale_logn ? (e = -1e-12, Math.floor) : (e = 1e-12, Math.ceil), e;
820 return d / pow(f(log(d) + e)) <= k ? format(d) : "";
823 scale.copy = function() {
824 return d3_scale_log(linear.copy(), log);
826 return d3_scale_linearRebind(scale, linear);
828 function d3_scale_logp(x) {
829 return Math.log(x < 0 ? 0 : x) / Math.LN10;
831 function d3_scale_logn(x) {
832 return -Math.log(x > 0 ? 0 : -x) / Math.LN10;
834 function d3_scale_pow(linear, exponent) {
836 return linear(powp(x));
838 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
839 scale.invert = function(x) {
840 return powb(linear.invert(x));
842 scale.domain = function(x) {
843 if (!arguments.length) return linear.domain().map(powb);
844 linear.domain(x.map(powp));
847 scale.ticks = function(m) {
848 return d3_scale_linearTicks(scale.domain(), m);
850 scale.tickFormat = function(m) {
851 return d3_scale_linearTickFormat(scale.domain(), m);
853 scale.nice = function() {
854 return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice));
856 scale.exponent = function(x) {
857 if (!arguments.length) return exponent;
858 var domain = scale.domain();
859 powp = d3_scale_powPow(exponent = x);
860 powb = d3_scale_powPow(1 / exponent);
861 return scale.domain(domain);
863 scale.copy = function() {
864 return d3_scale_pow(linear.copy(), exponent);
866 return d3_scale_linearRebind(scale, linear);
868 function d3_scale_powPow(e) {
870 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
873 function d3_scale_ordinal(domain, ranger) {
875 return range[((index.get(x) || index.set(x, domain.push(x))) - 1) % range.length];
877 function steps(start, step) {
878 return d3.range(domain.length).map(function(i) {
879 return start + step * i;
882 var index, range, rangeBand;
883 scale.domain = function(x) {
884 if (!arguments.length) return domain;
887 var i = -1, n = x.length, xi;
888 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
889 return scale[ranger.t].apply(scale, ranger.a);
891 scale.range = function(x) {
892 if (!arguments.length) return range;
901 scale.rangePoints = function(x, padding) {
902 if (arguments.length < 2) padding = 0;
903 var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
904 range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
912 scale.rangeBands = function(x, padding, outerPadding) {
913 if (arguments.length < 2) padding = 0;
914 if (arguments.length < 3) outerPadding = padding;
915 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
916 range = steps(start + step * outerPadding, step);
917 if (reverse) range.reverse();
918 rangeBand = step * (1 - padding);
925 scale.rangeRoundBands = function(x, padding, outerPadding) {
926 if (arguments.length < 2) padding = 0;
927 if (arguments.length < 3) outerPadding = padding;
928 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), error = stop - start - (domain.length - padding) * step;
929 range = steps(start + Math.round(error / 2), step);
930 if (reverse) range.reverse();
931 rangeBand = Math.round(step * (1 - padding));
933 t: "rangeRoundBands",
938 scale.rangeBand = function() {
941 scale.rangeExtent = function() {
942 return d3_scaleExtent(ranger.a[0]);
944 scale.copy = function() {
945 return d3_scale_ordinal(domain, ranger);
947 return scale.domain(domain);
949 function d3_scale_quantile(domain, range) {
951 var k = 0, n = domain.length, q = range.length;
953 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
957 if (isNaN(x = +x)) return NaN;
958 return range[d3.bisect(thresholds, x)];
961 scale.domain = function(x) {
962 if (!arguments.length) return domain;
963 domain = x.filter(function(d) {
965 }).sort(d3.ascending);
968 scale.range = function(x) {
969 if (!arguments.length) return range;
973 scale.quantiles = function() {
976 scale.copy = function() {
977 return d3_scale_quantile(domain, range);
981 function d3_scale_quantize(x0, x1, range) {
983 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
986 kx = range.length / (x1 - x0);
987 i = range.length - 1;
991 scale.domain = function(x) {
992 if (!arguments.length) return [ x0, x1 ];
994 x1 = +x[x.length - 1];
997 scale.range = function(x) {
998 if (!arguments.length) return range;
1002 scale.copy = function() {
1003 return d3_scale_quantize(x0, x1, range);
1007 function d3_scale_threshold(domain, range) {
1009 return range[d3.bisect(domain, x)];
1011 scale.domain = function(_) {
1012 if (!arguments.length) return domain;
1016 scale.range = function(_) {
1017 if (!arguments.length) return range;
1021 scale.copy = function() {
1022 return d3_scale_threshold(domain, range);
1026 function d3_scale_identity(domain) {
1027 function identity(x) {
1030 identity.invert = identity;
1031 identity.domain = identity.range = function(x) {
1032 if (!arguments.length) return domain;
1033 domain = x.map(identity);
1036 identity.ticks = function(m) {
1037 return d3_scale_linearTicks(domain, m);
1039 identity.tickFormat = function(m) {
1040 return d3_scale_linearTickFormat(domain, m);
1042 identity.copy = function() {
1043 return d3_scale_identity(domain);
1047 function d3_svg_arcInnerRadius(d) {
1048 return d.innerRadius;
1050 function d3_svg_arcOuterRadius(d) {
1051 return d.outerRadius;
1053 function d3_svg_arcStartAngle(d) {
1054 return d.startAngle;
1056 function d3_svg_arcEndAngle(d) {
1059 function d3_svg_line(projection) {
1060 function line(data) {
1061 function segment() {
1062 segments.push("M", interpolate(projection(points), tension));
1064 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
1066 if (defined.call(this, d = data[i], i)) {
1067 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
1068 } else if (points.length) {
1073 if (points.length) segment();
1074 return segments.length ? segments.join("") : null;
1076 var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
1077 line.x = function(_) {
1078 if (!arguments.length) return x;
1082 line.y = function(_) {
1083 if (!arguments.length) return y;
1087 line.defined = function(_) {
1088 if (!arguments.length) return defined;
1092 line.interpolate = function(_) {
1093 if (!arguments.length) return interpolateKey;
1094 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
1097 line.tension = function(_) {
1098 if (!arguments.length) return tension;
1104 function d3_svg_lineX(d) {
1107 function d3_svg_lineY(d) {
1110 function d3_svg_lineLinear(points) {
1111 return points.join("L");
1113 function d3_svg_lineLinearClosed(points) {
1114 return d3_svg_lineLinear(points) + "Z";
1116 function d3_svg_lineStepBefore(points) {
1117 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
1118 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
1119 return path.join("");
1121 function d3_svg_lineStepAfter(points) {
1122 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
1123 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
1124 return path.join("");
1126 function d3_svg_lineCardinalOpen(points, tension) {
1127 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
1129 function d3_svg_lineCardinalClosed(points, tension) {
1130 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]), points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
1132 function d3_svg_lineCardinal(points, tension, closed) {
1133 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
1135 function d3_svg_lineHermite(points, tangents) {
1136 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
1137 return d3_svg_lineLinear(points);
1139 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
1141 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
1145 if (tangents.length > 1) {
1149 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
1150 for (var i = 2; i < tangents.length; i++, pi++) {
1153 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
1157 var lp = points[pi];
1158 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
1162 function d3_svg_lineCardinalTangents(points, tension) {
1163 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
1168 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
1172 function d3_svg_lineBasis(points) {
1173 if (points.length < 3) return d3_svg_lineLinear(points);
1174 var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0 ];
1175 d3_svg_lineBasisBezier(path, px, py);
1182 d3_svg_lineBasisBezier(path, px, py);
1190 d3_svg_lineBasisBezier(path, px, py);
1192 return path.join("");
1194 function d3_svg_lineBasisOpen(points) {
1195 if (points.length < 4) return d3_svg_lineLinear(points);
1196 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
1202 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
1210 d3_svg_lineBasisBezier(path, px, py);
1212 return path.join("");
1214 function d3_svg_lineBasisClosed(points) {
1215 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
1221 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
1229 d3_svg_lineBasisBezier(path, px, py);
1231 return path.join("");
1233 function d3_svg_lineBundle(points, tension) {
1234 var n = points.length - 1;
1236 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
1240 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
1241 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
1244 return d3_svg_lineBasis(points);
1246 function d3_svg_lineDot4(a, b) {
1247 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
1249 function d3_svg_lineBasisBezier(path, x, y) {
1250 path.push("C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
1252 function d3_svg_lineSlope(p0, p1) {
1253 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
1255 function d3_svg_lineFiniteDifferences(points) {
1256 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
1258 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
1263 function d3_svg_lineMonotoneTangents(points) {
1264 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
1266 d = d3_svg_lineSlope(points[i], points[i + 1]);
1267 if (Math.abs(d) < 1e-6) {
1268 m[i] = m[i + 1] = 0;
1274 s = d * 3 / Math.sqrt(s);
1282 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
1283 tangents.push([ s || 0, m[i] * s || 0 ]);
1287 function d3_svg_lineMonotone(points) {
1288 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
1290 function d3_svg_lineRadial(points) {
1291 var point, i = -1, n = points.length, r, a;
1295 a = point[1] + d3_svg_arcOffset;
1296 point[0] = r * Math.cos(a);
1297 point[1] = r * Math.sin(a);
1301 function d3_svg_area(projection) {
1302 function area(data) {
1303 function segment() {
1304 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
1306 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
1308 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
1310 } : d3_functor(y1), x, y;
1312 if (defined.call(this, d = data[i], i)) {
1313 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
1314 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
1315 } else if (points0.length) {
1321 if (points0.length) segment();
1322 return segments.length ? segments.join("") : null;
1324 var x0 = d3_svg_lineX, x1 = d3_svg_lineX, y0 = 0, y1 = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
1325 area.x = function(_) {
1326 if (!arguments.length) return x1;
1330 area.x0 = function(_) {
1331 if (!arguments.length) return x0;
1335 area.x1 = function(_) {
1336 if (!arguments.length) return x1;
1340 area.y = function(_) {
1341 if (!arguments.length) return y1;
1345 area.y0 = function(_) {
1346 if (!arguments.length) return y0;
1350 area.y1 = function(_) {
1351 if (!arguments.length) return y1;
1355 area.defined = function(_) {
1356 if (!arguments.length) return defined;
1360 area.interpolate = function(_) {
1361 if (!arguments.length) return interpolateKey;
1362 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
1363 interpolateReverse = interpolate.reverse || interpolate;
1364 L = interpolate.closed ? "M" : "L";
1367 area.tension = function(_) {
1368 if (!arguments.length) return tension;
1374 function d3_svg_chordSource(d) {
1377 function d3_svg_chordTarget(d) {
1380 function d3_svg_chordRadius(d) {
1383 function d3_svg_chordStartAngle(d) {
1384 return d.startAngle;
1386 function d3_svg_chordEndAngle(d) {
1389 function d3_svg_diagonalProjection(d) {
1390 return [ d.x, d.y ];
1392 function d3_svg_diagonalRadialProjection(projection) {
1394 var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
1395 return [ r * Math.cos(a), r * Math.sin(a) ];
1398 function d3_svg_symbolSize() {
1401 function d3_svg_symbolType() {
1404 function d3_svg_symbolCircle(size) {
1405 var r = Math.sqrt(size / Math.PI);
1406 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
1408 function d3_svg_axisX(selection, x) {
1409 selection.attr("transform", function(d) {
1410 return "translate(" + x(d) + ",0)";
1413 function d3_svg_axisY(selection, y) {
1414 selection.attr("transform", function(d) {
1415 return "translate(0," + y(d) + ")";
1418 function d3_svg_axisSubdivide(scale, ticks, m) {
1420 if (m && ticks.length > 1) {
1421 var extent = d3_scaleExtent(scale.domain()), subticks, i = -1, n = ticks.length, d = (ticks[1] - ticks[0]) / ++m, j, v;
1423 for (j = m; --j > 0; ) {
1424 if ((v = +ticks[i] - j * d) >= extent[0]) {
1429 for (--i, j = 0; ++j < m && (v = +ticks[i] + j * d) < extent[1]; ) {
1435 function d3_behavior_zoomDelta() {
1436 if (!d3_behavior_zoomDiv) {
1437 d3_behavior_zoomDiv = d3.select("body").append("div").style("visibility", "hidden").style("top", 0).style("height", 0).style("width", 0).style("overflow-y", "scroll").append("div").style("height", "2000px").node().parentNode;
1439 var e = d3.event, delta;
1441 d3_behavior_zoomDiv.scrollTop = 1e3;
1442 d3_behavior_zoomDiv.dispatchEvent(e);
1443 delta = 1e3 - d3_behavior_zoomDiv.scrollTop;
1445 delta = e.wheelDelta || -e.detail * 5;
1449 function d3_layout_bundlePath(link) {
1450 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
1451 while (start !== lca) {
1452 start = start.parent;
1455 var k = points.length;
1456 while (end !== lca) {
1457 points.splice(k, 0, end);
1462 function d3_layout_bundleAncestors(node) {
1463 var ancestors = [], parent = node.parent;
1464 while (parent != null) {
1465 ancestors.push(node);
1467 parent = parent.parent;
1469 ancestors.push(node);
1472 function d3_layout_bundleLeastCommonAncestor(a, b) {
1473 if (a === b) return a;
1474 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
1475 while (aNode === bNode) {
1477 aNode = aNodes.pop();
1478 bNode = bNodes.pop();
1482 function d3_layout_forceDragstart(d) {
1485 function d3_layout_forceDragend(d) {
1488 function d3_layout_forceMouseover(d) {
1491 function d3_layout_forceMouseout(d) {
1494 function d3_layout_forceAccumulate(quad, alpha, charges) {
1498 var nodes = quad.nodes, n = nodes.length, i = -1, c;
1501 if (c == null) continue;
1502 d3_layout_forceAccumulate(c, alpha, charges);
1503 quad.charge += c.charge;
1504 cx += c.charge * c.cx;
1505 cy += c.charge * c.cy;
1510 quad.point.x += Math.random() - .5;
1511 quad.point.y += Math.random() - .5;
1513 var k = alpha * charges[quad.point.index];
1514 quad.charge += quad.pointCharge = k;
1515 cx += k * quad.point.x;
1516 cy += k * quad.point.y;
1518 quad.cx = cx / quad.charge;
1519 quad.cy = cy / quad.charge;
1521 function d3_layout_forceLinkDistance(link) {
1524 function d3_layout_forceLinkStrength(link) {
1527 function d3_layout_stackX(d) {
1530 function d3_layout_stackY(d) {
1533 function d3_layout_stackOut(d, y0, y) {
1537 function d3_layout_stackOrderDefault(data) {
1538 return d3.range(data.length);
1540 function d3_layout_stackOffsetZero(data) {
1541 var j = -1, m = data[0].length, y0 = [];
1542 while (++j < m) y0[j] = 0;
1545 function d3_layout_stackMaxIndex(array) {
1546 var i = 1, j = 0, v = array[0][1], k, n = array.length;
1547 for (; i < n; ++i) {
1548 if ((k = array[i][1]) > v) {
1555 function d3_layout_stackReduceSum(d) {
1556 return d.reduce(d3_layout_stackSum, 0);
1558 function d3_layout_stackSum(p, d) {
1561 function d3_layout_histogramBinSturges(range, values) {
1562 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
1564 function d3_layout_histogramBinFixed(range, n) {
1565 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
1566 while (++x <= n) f[x] = m * x + b;
1569 function d3_layout_histogramRange(values) {
1570 return [ d3.min(values), d3.max(values) ];
1572 function d3_layout_hierarchyRebind(object, hierarchy) {
1573 d3.rebind(object, hierarchy, "sort", "children", "value");
1574 object.links = d3_layout_hierarchyLinks;
1575 object.nodes = function(d) {
1576 d3_layout_hierarchyInline = true;
1577 return (object.nodes = object)(d);
1581 function d3_layout_hierarchyChildren(d) {
1584 function d3_layout_hierarchyValue(d) {
1587 function d3_layout_hierarchySort(a, b) {
1588 return b.value - a.value;
1590 function d3_layout_hierarchyLinks(nodes) {
1591 return d3.merge(nodes.map(function(parent) {
1592 return (parent.children || []).map(function(child) {
1600 function d3_layout_packSort(a, b) {
1601 return a.value - b.value;
1603 function d3_layout_packInsert(a, b) {
1604 var c = a._pack_next;
1610 function d3_layout_packSplice(a, b) {
1614 function d3_layout_packIntersects(a, b) {
1615 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
1616 return dr * dr - dx * dx - dy * dy > .001;
1618 function d3_layout_packSiblings(node) {
1619 function bound(node) {
1620 xMin = Math.min(node.x - node.r, xMin);
1621 xMax = Math.max(node.x + node.r, xMax);
1622 yMin = Math.min(node.y - node.r, yMin);
1623 yMax = Math.max(node.y + node.r, yMax);
1625 if (!(nodes = node.children) || !(n = nodes.length)) return;
1626 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
1627 nodes.forEach(d3_layout_packLink);
1639 d3_layout_packPlace(a, b, c);
1641 d3_layout_packInsert(a, c);
1643 d3_layout_packInsert(c, b);
1645 for (i = 3; i < n; i++) {
1646 d3_layout_packPlace(a, b, c = nodes[i]);
1647 var isect = 0, s1 = 1, s2 = 1;
1648 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
1649 if (d3_layout_packIntersects(j, c)) {
1655 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
1656 if (d3_layout_packIntersects(k, c)) {
1662 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
1665 d3_layout_packInsert(a, c);
1672 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
1673 for (i = 0; i < n; i++) {
1677 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
1680 nodes.forEach(d3_layout_packUnlink);
1682 function d3_layout_packLink(node) {
1683 node._pack_next = node._pack_prev = node;
1685 function d3_layout_packUnlink(node) {
1686 delete node._pack_next;
1687 delete node._pack_prev;
1689 function d3_layout_packTransform(node, x, y, k) {
1690 var children = node.children;
1691 node.x = x += k * node.x;
1692 node.y = y += k * node.y;
1695 var i = -1, n = children.length;
1696 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
1699 function d3_layout_packPlace(a, b, c) {
1700 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
1701 if (db && (dx || dy)) {
1702 var da = b.r + c.r, dc = dx * dx + dy * dy;
1705 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
1706 c.x = a.x + x * dx + y * dy;
1707 c.y = a.y + x * dy - y * dx;
1713 function d3_layout_clusterY(children) {
1714 return 1 + d3.max(children, function(child) {
1718 function d3_layout_clusterX(children) {
1719 return children.reduce(function(x, child) {
1721 }, 0) / children.length;
1723 function d3_layout_clusterLeft(node) {
1724 var children = node.children;
1725 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
1727 function d3_layout_clusterRight(node) {
1728 var children = node.children, n;
1729 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
1731 function d3_layout_treeSeparation(a, b) {
1732 return a.parent == b.parent ? 1 : 2;
1734 function d3_layout_treeLeft(node) {
1735 var children = node.children;
1736 return children && children.length ? children[0] : node._tree.thread;
1738 function d3_layout_treeRight(node) {
1739 var children = node.children, n;
1740 return children && (n = children.length) ? children[n - 1] : node._tree.thread;
1742 function d3_layout_treeSearch(node, compare) {
1743 var children = node.children;
1744 if (children && (n = children.length)) {
1745 var child, n, i = -1;
1747 if (compare(child = d3_layout_treeSearch(children[i], compare), node) > 0) {
1754 function d3_layout_treeRightmost(a, b) {
1757 function d3_layout_treeLeftmost(a, b) {
1760 function d3_layout_treeDeepest(a, b) {
1761 return a.depth - b.depth;
1763 function d3_layout_treeVisitAfter(node, callback) {
1764 function visit(node, previousSibling) {
1765 var children = node.children;
1766 if (children && (n = children.length)) {
1767 var child, previousChild = null, i = -1, n;
1769 child = children[i];
1770 visit(child, previousChild);
1771 previousChild = child;
1774 callback(node, previousSibling);
1778 function d3_layout_treeShift(node) {
1779 var shift = 0, change = 0, children = node.children, i = children.length, child;
1781 child = children[i]._tree;
1782 child.prelim += shift;
1784 shift += child.shift + (change += child.change);
1787 function d3_layout_treeMove(ancestor, node, shift) {
1788 ancestor = ancestor._tree;
1790 var change = shift / (node.number - ancestor.number);
1791 ancestor.change += change;
1792 node.change -= change;
1793 node.shift += shift;
1794 node.prelim += shift;
1797 function d3_layout_treeAncestor(vim, node, ancestor) {
1798 return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
1800 function d3_layout_treemapPadNull(node) {
1808 function d3_layout_treemapPad(node, padding) {
1809 var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];
1825 function d3_dsv(delimiter, mimeType) {
1826 function dsv(url, callback) {
1827 d3.text(url, mimeType, function(text) {
1828 callback(text && dsv.parse(text));
1831 function formatRow(row) {
1832 return row.map(formatValue).join(delimiter);
1834 function formatValue(text) {
1835 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
1837 var reParse = new RegExp("\r\n|[" + delimiter + "\r\n]", "g"), reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
1838 dsv.parse = function(text) {
1840 return dsv.parseRows(text, function(row, i) {
1842 var o = {}, j = -1, m = header.length;
1843 while (++j < m) o[header[j]] = row[j];
1851 dsv.parseRows = function(text, f) {
1853 if (reParse.lastIndex >= text.length) return EOF;
1858 var j = reParse.lastIndex;
1859 if (text.charCodeAt(j) === 34) {
1861 while (i++ < text.length) {
1862 if (text.charCodeAt(i) === 34) {
1863 if (text.charCodeAt(i + 1) !== 34) break;
1867 reParse.lastIndex = i + 2;
1868 var c = text.charCodeAt(i + 1);
1871 if (text.charCodeAt(i + 2) === 10) reParse.lastIndex++;
1872 } else if (c === 10) {
1875 return text.substring(j + 1, i).replace(/""/g, '"');
1877 var m = reParse.exec(text);
1879 eol = m[0].charCodeAt(0) !== delimiterCode;
1880 return text.substring(j, m.index);
1882 reParse.lastIndex = text.length;
1883 return text.substring(j);
1885 var EOL = {}, EOF = {}, rows = [], n = 0, t, eol;
1886 reParse.lastIndex = 0;
1887 while ((t = token()) !== EOF) {
1889 while (t !== EOL && t !== EOF) {
1893 if (f && !(a = f(a, n++))) continue;
1898 dsv.format = function(rows) {
1899 return rows.map(formatRow).join("\n");
1903 function d3_geo_type(types, defaultValue) {
1904 return function(object) {
1905 return object && types.hasOwnProperty(object.type) ? types[object.type](object) : defaultValue;
1908 function d3_path_circle(radius) {
1909 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
1911 function d3_geo_bounds(o, f) {
1912 if (d3_geo_boundsTypes.hasOwnProperty(o.type)) d3_geo_boundsTypes[o.type](o, f);
1914 function d3_geo_boundsFeature(o, f) {
1915 d3_geo_bounds(o.geometry, f);
1917 function d3_geo_boundsFeatureCollection(o, f) {
1918 for (var a = o.features, i = 0, n = a.length; i < n; i++) {
1919 d3_geo_bounds(a[i].geometry, f);
1922 function d3_geo_boundsGeometryCollection(o, f) {
1923 for (var a = o.geometries, i = 0, n = a.length; i < n; i++) {
1924 d3_geo_bounds(a[i], f);
1927 function d3_geo_boundsLineString(o, f) {
1928 for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
1929 f.apply(null, a[i]);
1932 function d3_geo_boundsMultiLineString(o, f) {
1933 for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
1934 for (var b = a[i], j = 0, m = b.length; j < m; j++) {
1935 f.apply(null, b[j]);
1939 function d3_geo_boundsMultiPolygon(o, f) {
1940 for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
1941 for (var b = a[i][0], j = 0, m = b.length; j < m; j++) {
1942 f.apply(null, b[j]);
1946 function d3_geo_boundsPoint(o, f) {
1947 f.apply(null, o.coordinates);
1949 function d3_geo_boundsPolygon(o, f) {
1950 for (var a = o.coordinates[0], i = 0, n = a.length; i < n; i++) {
1951 f.apply(null, a[i]);
1954 function d3_geo_greatArcSource(d) {
1957 function d3_geo_greatArcTarget(d) {
1960 function d3_geo_greatArcInterpolator() {
1961 function interpolate(t) {
1962 var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;
1963 return [ Math.atan2(y, x) / d3_geo_radians, Math.atan2(z, Math.sqrt(x * x + y * y)) / d3_geo_radians ];
1965 var x0, y0, cy0, sy0, kx0, ky0, x1, y1, cy1, sy1, kx1, ky1, d, k;
1966 interpolate.distance = function() {
1967 if (d == null) k = 1 / Math.sin(d = Math.acos(Math.max(-1, Math.min(1, sy0 * sy1 + cy0 * cy1 * Math.cos(x1 - x0)))));
1970 interpolate.source = function(_) {
1971 var cx0 = Math.cos(x0 = _[0] * d3_geo_radians), sx0 = Math.sin(x0);
1972 cy0 = Math.cos(y0 = _[1] * d3_geo_radians);
1979 interpolate.target = function(_) {
1980 var cx1 = Math.cos(x1 = _[0] * d3_geo_radians), sx1 = Math.sin(x1);
1981 cy1 = Math.cos(y1 = _[1] * d3_geo_radians);
1990 function d3_geo_greatArcInterpolate(a, b) {
1991 var i = d3_geo_greatArcInterpolator().source(a).target(b);
1995 function d3_geom_contourStart(grid) {
2010 function d3_geom_hullCCW(i1, i2, i3, v) {
2011 var t, a, b, c, d, e, f;
2021 return (f - b) * (c - a) - (d - b) * (e - a) > 0;
2023 function d3_geom_polygonInside(p, a, b) {
2024 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
2026 function d3_geom_polygonIntersect(c, d, a, b) {
2027 var x1 = c[0], x2 = d[0], x3 = a[0], x4 = b[0], y1 = c[1], y2 = d[1], y3 = a[1], y4 = b[1], x13 = x1 - x3, x21 = x2 - x1, x43 = x4 - x3, y13 = y1 - y3, y21 = y2 - y1, y43 = y4 - y3, ua = (x43 * y13 - y43 * x13) / (y43 * x21 - x43 * y21);
2028 return [ x1 + ua * x21, y1 + ua * y21 ];
2030 function d3_voronoi_tessellate(vertices, callback) {
2032 list: vertices.map(function(v, i) {
2038 }).sort(function(a, b) {
2039 return a.y < b.y ? -1 : a.y > b.y ? 1 : a.x < b.x ? -1 : a.x > b.x ? 1 : 0;
2048 EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
2049 EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
2050 EdgeList.leftEnd.r = EdgeList.rightEnd;
2051 EdgeList.rightEnd.l = EdgeList.leftEnd;
2052 EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
2054 createHalfEdge: function(edge, side) {
2063 insert: function(lb, he) {
2069 leftBound: function(p) {
2070 var he = EdgeList.leftEnd;
2073 } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
2082 right: function(he) {
2085 left: function(he) {
2088 leftRegion: function(he) {
2089 return he.edge == null ? Sites.bottomSite : he.edge.region[he.side];
2091 rightRegion: function(he) {
2092 return he.edge == null ? Sites.bottomSite : he.edge.region[d3_voronoi_opposite[he.side]];
2096 bisect: function(s1, s2) {
2107 var dx = s2.x - s1.x, dy = s2.y - s1.y, adx = dx > 0 ? dx : -dx, ady = dy > 0 ? dy : -dy;
2108 newEdge.c = s1.x * dx + s1.y * dy + (dx * dx + dy * dy) * .5;
2111 newEdge.b = dy / dx;
2115 newEdge.a = dx / dy;
2120 intersect: function(el1, el2) {
2121 var e1 = el1.edge, e2 = el2.edge;
2122 if (!e1 || !e2 || e1.region.r == e2.region.r) {
2125 var d = e1.a * e2.b - e1.b * e2.a;
2126 if (Math.abs(d) < 1e-10) {
2129 var xint = (e1.c * e2.b - e2.c * e1.b) / d, yint = (e2.c * e1.a - e1.c * e2.a) / d, e1r = e1.region.r, e2r = e2.region.r, el, e;
2130 if (e1r.y < e2r.y || e1r.y == e2r.y && e1r.x < e2r.x) {
2137 var rightOfSite = xint >= e.region.r.x;
2138 if (rightOfSite && el.side === "l" || !rightOfSite && el.side === "r") {
2146 rightOf: function(he, p) {
2147 var e = he.edge, topsite = e.region.r, rightOfSite = p.x > topsite.x;
2148 if (rightOfSite && he.side === "l") {
2151 if (!rightOfSite && he.side === "r") {
2155 var dyp = p.y - topsite.y, dxp = p.x - topsite.x, fast = 0, above = 0;
2156 if (!rightOfSite && e.b < 0 || rightOfSite && e.b >= 0) {
2157 above = fast = dyp >= e.b * dxp;
2159 above = p.x + p.y * e.b > e.c;
2168 var dxs = topsite.x - e.region.l.x;
2169 above = e.b * (dxp * dxp - dyp * dyp) < dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b);
2175 var yl = e.c - e.a * p.x, t1 = p.y - yl, t2 = p.x - topsite.x, t3 = yl - topsite.y;
2176 above = t1 * t1 > t2 * t2 + t3 * t3;
2178 return he.side === "l" ? above : !above;
2180 endPoint: function(edge, side, site) {
2181 edge.ep[side] = site;
2182 if (!edge.ep[d3_voronoi_opposite[side]]) return;
2185 distance: function(s, t) {
2186 var dx = s.x - t.x, dy = s.y - t.y;
2187 return Math.sqrt(dx * dx + dy * dy);
2192 insert: function(he, site, offset) {
2194 he.ystar = site.y + offset;
2195 for (var i = 0, list = EventQueue.list, l = list.length; i < l; i++) {
2197 if (he.ystar > next.ystar || he.ystar == next.ystar && site.x > next.vertex.x) {
2203 list.splice(i, 0, he);
2206 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l && ls[i] != he; ++i) {}
2210 return EventQueue.list.length === 0;
2212 nextEvent: function(he) {
2213 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l; ++i) {
2214 if (ls[i] == he) return ls[i + 1];
2219 var elem = EventQueue.list[0];
2225 extractMin: function() {
2226 return EventQueue.list.shift();
2230 Sites.bottomSite = Sites.list.shift();
2231 var newSite = Sites.list.shift(), newIntStar;
2232 var lbnd, rbnd, llbnd, rrbnd, bisector;
2233 var bot, top, temp, p, v;
2236 if (!EventQueue.empty()) {
2237 newIntStar = EventQueue.min();
2239 if (newSite && (EventQueue.empty() || newSite.y < newIntStar.y || newSite.y == newIntStar.y && newSite.x < newIntStar.x)) {
2240 lbnd = EdgeList.leftBound(newSite);
2241 rbnd = EdgeList.right(lbnd);
2242 bot = EdgeList.rightRegion(lbnd);
2243 e = Geom.bisect(bot, newSite);
2244 bisector = EdgeList.createHalfEdge(e, "l");
2245 EdgeList.insert(lbnd, bisector);
2246 p = Geom.intersect(lbnd, bisector);
2248 EventQueue.del(lbnd);
2249 EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
2252 bisector = EdgeList.createHalfEdge(e, "r");
2253 EdgeList.insert(lbnd, bisector);
2254 p = Geom.intersect(bisector, rbnd);
2256 EventQueue.insert(bisector, p, Geom.distance(p, newSite));
2258 newSite = Sites.list.shift();
2259 } else if (!EventQueue.empty()) {
2260 lbnd = EventQueue.extractMin();
2261 llbnd = EdgeList.left(lbnd);
2262 rbnd = EdgeList.right(lbnd);
2263 rrbnd = EdgeList.right(rbnd);
2264 bot = EdgeList.leftRegion(lbnd);
2265 top = EdgeList.rightRegion(rbnd);
2267 Geom.endPoint(lbnd.edge, lbnd.side, v);
2268 Geom.endPoint(rbnd.edge, rbnd.side, v);
2270 EventQueue.del(rbnd);
2273 if (bot.y > top.y) {
2279 e = Geom.bisect(bot, top);
2280 bisector = EdgeList.createHalfEdge(e, pm);
2281 EdgeList.insert(llbnd, bisector);
2282 Geom.endPoint(e, d3_voronoi_opposite[pm], v);
2283 p = Geom.intersect(llbnd, bisector);
2285 EventQueue.del(llbnd);
2286 EventQueue.insert(llbnd, p, Geom.distance(p, bot));
2288 p = Geom.intersect(bisector, rrbnd);
2290 EventQueue.insert(bisector, p, Geom.distance(p, bot));
2296 for (lbnd = EdgeList.right(EdgeList.leftEnd); lbnd != EdgeList.rightEnd; lbnd = EdgeList.right(lbnd)) {
2297 callback(lbnd.edge);
2300 function d3_geom_quadtreeNode() {
2307 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
2308 if (!f(node, x1, y1, x2, y2)) {
2309 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
2310 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
2311 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
2312 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
2313 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
2316 function d3_geom_quadtreePoint(p) {
2322 function d3_time_utc() {
2323 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2325 function d3_time_formatAbbreviate(name) {
2326 return name.substring(0, 3);
2328 function d3_time_parse(date, template, string, j) {
2329 var c, p, i = 0, n = template.length, m = string.length;
2331 if (j >= m) return -1;
2332 c = template.charCodeAt(i++);
2334 p = d3_time_parsers[template.charAt(i++)];
2335 if (!p || (j = p(date, string, j)) < 0) return -1;
2336 } else if (c != string.charCodeAt(j++)) {
2342 function d3_time_formatRe(names) {
2343 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2345 function d3_time_formatLookup(names) {
2346 var map = new d3_Map, i = -1, n = names.length;
2347 while (++i < n) map.set(names[i].toLowerCase(), i);
2350 function d3_time_parseWeekdayAbbrev(date, string, i) {
2351 d3_time_dayAbbrevRe.lastIndex = 0;
2352 var n = d3_time_dayAbbrevRe.exec(string.substring(i));
2353 return n ? i += n[0].length : -1;
2355 function d3_time_parseWeekday(date, string, i) {
2356 d3_time_dayRe.lastIndex = 0;
2357 var n = d3_time_dayRe.exec(string.substring(i));
2358 return n ? i += n[0].length : -1;
2360 function d3_time_parseMonthAbbrev(date, string, i) {
2361 d3_time_monthAbbrevRe.lastIndex = 0;
2362 var n = d3_time_monthAbbrevRe.exec(string.substring(i));
2363 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
2365 function d3_time_parseMonth(date, string, i) {
2366 d3_time_monthRe.lastIndex = 0;
2367 var n = d3_time_monthRe.exec(string.substring(i));
2368 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
2370 function d3_time_parseLocaleFull(date, string, i) {
2371 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2373 function d3_time_parseLocaleDate(date, string, i) {
2374 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2376 function d3_time_parseLocaleTime(date, string, i) {
2377 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2379 function d3_time_parseFullYear(date, string, i) {
2380 d3_time_numberRe.lastIndex = 0;
2381 var n = d3_time_numberRe.exec(string.substring(i, i + 4));
2382 return n ? (date.y = +n[0], i += n[0].length) : -1;
2384 function d3_time_parseYear(date, string, i) {
2385 d3_time_numberRe.lastIndex = 0;
2386 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2387 return n ? (date.y = d3_time_expandYear(+n[0]), i += n[0].length) : -1;
2389 function d3_time_expandYear(d) {
2390 return d + (d > 68 ? 1900 : 2e3);
2392 function d3_time_parseMonthNumber(date, string, i) {
2393 d3_time_numberRe.lastIndex = 0;
2394 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2395 return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
2397 function d3_time_parseDay(date, string, i) {
2398 d3_time_numberRe.lastIndex = 0;
2399 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2400 return n ? (date.d = +n[0], i += n[0].length) : -1;
2402 function d3_time_parseHour24(date, string, i) {
2403 d3_time_numberRe.lastIndex = 0;
2404 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2405 return n ? (date.H = +n[0], i += n[0].length) : -1;
2407 function d3_time_parseMinutes(date, string, i) {
2408 d3_time_numberRe.lastIndex = 0;
2409 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2410 return n ? (date.M = +n[0], i += n[0].length) : -1;
2412 function d3_time_parseSeconds(date, string, i) {
2413 d3_time_numberRe.lastIndex = 0;
2414 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2415 return n ? (date.S = +n[0], i += n[0].length) : -1;
2417 function d3_time_parseMilliseconds(date, string, i) {
2418 d3_time_numberRe.lastIndex = 0;
2419 var n = d3_time_numberRe.exec(string.substring(i, i + 3));
2420 return n ? (date.L = +n[0], i += n[0].length) : -1;
2422 function d3_time_parseAmPm(date, string, i) {
2423 var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
2424 return n == null ? -1 : (date.p = n, i);
2426 function d3_time_zone(d) {
2427 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
2428 return zs + d3_time_zfill2(zh) + d3_time_zfill2(zm);
2430 function d3_time_formatIsoNative(date) {
2431 return date.toISOString();
2433 function d3_time_interval(local, step, number) {
2434 function round(date) {
2435 var d0 = local(date), d1 = offset(d0, 1);
2436 return date - d0 < d1 - date ? d0 : d1;
2438 function ceil(date) {
2439 step(date = local(new d3_time(date - 1)), 1);
2442 function offset(date, k) {
2443 step(date = new d3_time(+date), k);
2446 function range(t0, t1, dt) {
2447 var time = ceil(t0), times = [];
2450 if (!(number(time) % dt)) times.push(new Date(+time));
2454 while (time < t1) times.push(new Date(+time)), step(time, 1);
2458 function range_utc(t0, t1, dt) {
2460 d3_time = d3_time_utc;
2461 var utc = new d3_time_utc;
2463 return range(utc, t1, dt);
2468 local.floor = local;
2469 local.round = round;
2471 local.offset = offset;
2472 local.range = range;
2473 var utc = local.utc = d3_time_interval_utc(local);
2475 utc.round = d3_time_interval_utc(round);
2476 utc.ceil = d3_time_interval_utc(ceil);
2477 utc.offset = d3_time_interval_utc(offset);
2478 utc.range = range_utc;
2481 function d3_time_interval_utc(method) {
2482 return function(date, k) {
2484 d3_time = d3_time_utc;
2485 var utc = new d3_time_utc;
2487 return method(utc, k)._;
2493 function d3_time_scale(linear, methods, format) {
2497 scale.invert = function(x) {
2498 return d3_time_scaleDate(linear.invert(x));
2500 scale.domain = function(x) {
2501 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
2505 scale.nice = function(m) {
2506 return scale.domain(d3_scale_nice(scale.domain(), function() {
2510 scale.ticks = function(m, k) {
2511 var extent = d3_time_scaleExtent(scale.domain());
2512 if (typeof m !== "function") {
2513 var span = extent[1] - extent[0], target = span / m, i = d3.bisect(d3_time_scaleSteps, target);
2514 if (i == d3_time_scaleSteps.length) return methods.year(extent, m);
2515 if (!i) return linear.ticks(m).map(d3_time_scaleDate);
2516 if (Math.log(target / d3_time_scaleSteps[i - 1]) < Math.log(d3_time_scaleSteps[i] / target)) --i;
2521 return m(extent[0], new Date(+extent[1] + 1), k);
2523 scale.tickFormat = function() {
2526 scale.copy = function() {
2527 return d3_time_scale(linear.copy(), methods, format);
2529 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
2531 function d3_time_scaleExtent(domain) {
2532 var start = domain[0], stop = domain[domain.length - 1];
2533 return start < stop ? [ start, stop ] : [ stop, start ];
2535 function d3_time_scaleDate(t) {
2538 function d3_time_scaleFormat(formats) {
2539 return function(date) {
2540 var i = formats.length - 1, f = formats[i];
2541 while (!f[1](date)) f = formats[--i];
2545 function d3_time_scaleSetYear(y) {
2546 var d = new Date(y, 0, 1);
2550 function d3_time_scaleGetYear(d) {
2551 var y = d.getFullYear(), d0 = d3_time_scaleSetYear(y), d1 = d3_time_scaleSetYear(y + 1);
2552 return y + (d - d0) / (d1 - d0);
2554 function d3_time_scaleUTCSetYear(y) {
2555 var d = new Date(Date.UTC(y, 0, 1));
2556 d.setUTCFullYear(y);
2559 function d3_time_scaleUTCGetYear(d) {
2560 var y = d.getUTCFullYear(), d0 = d3_time_scaleUTCSetYear(y), d1 = d3_time_scaleUTCSetYear(y + 1);
2561 return y + (d - d0) / (d1 - d0);
2563 if (!Date.now) Date.now = function() {
2567 document.createElement("div").style.setProperty("opacity", 0, "");
2569 var d3_style_prototype = CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
2570 d3_style_prototype.setProperty = function(name, value, priority) {
2571 d3_style_setProperty.call(this, name, value + "", priority);
2577 var d3_array = d3_arraySlice;
2579 d3_array(document.documentElement.childNodes)[0].nodeType;
2581 d3_array = d3_arrayCopy;
2583 var d3_arraySubclass = [].__proto__ ? function(array, prototype) {
2584 array.__proto__ = prototype;
2585 } : function(array, prototype) {
2586 for (var property in prototype) array[property] = prototype[property];
2588 d3.map = function(object) {
2589 var map = new d3_Map;
2590 for (var key in object) map.set(key, object[key]);
2594 has: function(key) {
2595 return d3_map_prefix + key in this;
2597 get: function(key) {
2598 return this[d3_map_prefix + key];
2600 set: function(key, value) {
2601 return this[d3_map_prefix + key] = value;
2603 remove: function(key) {
2604 key = d3_map_prefix + key;
2605 return key in this && delete this[key];
2609 this.forEach(function(key) {
2614 values: function() {
2616 this.forEach(function(key, value) {
2621 entries: function() {
2623 this.forEach(function(key, value) {
2631 forEach: function(f) {
2632 for (var key in this) {
2633 if (key.charCodeAt(0) === d3_map_prefixCode) {
2634 f.call(this, key.substring(1), this[key]);
2639 var d3_map_prefix = "\0", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
2640 d3.functor = d3_functor;
2641 d3.rebind = function(target, source) {
2642 var i = 1, n = arguments.length, method;
2643 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
2646 d3.ascending = function(a, b) {
2647 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
2649 d3.descending = function(a, b) {
2650 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
2652 d3.mean = function(array, f) {
2653 var n = array.length, a, m = 0, i = -1, j = 0;
2654 if (arguments.length === 1) {
2655 while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
2657 while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
2659 return j ? m : undefined;
2661 d3.median = function(array, f) {
2662 if (arguments.length > 1) array = array.map(f);
2663 array = array.filter(d3_number);
2664 return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
2666 d3.min = function(array, f) {
2667 var i = -1, n = array.length, a, b;
2668 if (arguments.length === 1) {
2669 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
2670 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
2672 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
2673 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
2677 d3.max = function(array, f) {
2678 var i = -1, n = array.length, a, b;
2679 if (arguments.length === 1) {
2680 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
2681 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
2683 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
2684 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
2688 d3.extent = function(array, f) {
2689 var i = -1, n = array.length, a, b, c;
2690 if (arguments.length === 1) {
2691 while (++i < n && ((a = c = array[i]) == null || a != a)) a = c = undefined;
2692 while (++i < n) if ((b = array[i]) != null) {
2697 while (++i < n && ((a = c = f.call(array, array[i], i)) == null || a != a)) a = undefined;
2698 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
2706 normal: function(µ, σ) {
2707 var n = arguments.length;
2713 x = Math.random() * 2 - 1;
2714 y = Math.random() * 2 - 1;
2716 } while (!r || r > 1);
2717 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
2720 logNormal: function(µ, σ) {
2721 var n = arguments.length;
2724 var random = d3.random.normal();
2726 return Math.exp(µ + σ * random());
2729 irwinHall: function(m) {
2731 for (var s = 0, j = 0; j < m; j++) s += Math.random();
2736 d3.sum = function(array, f) {
2737 var s = 0, n = array.length, a, i = -1;
2738 if (arguments.length === 1) {
2739 while (++i < n) if (!isNaN(a = +array[i])) s += a;
2741 while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
2745 d3.quantile = function(values, p) {
2746 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = values[h - 1], e = H - h;
2747 return e ? v + e * (values[h] - v) : v;
2749 d3.transpose = function(matrix) {
2750 return d3.zip.apply(d3, matrix);
2752 d3.zip = function() {
2753 if (!(n = arguments.length)) return [];
2754 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
2755 for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
2756 zip[j] = arguments[j][i];
2761 d3.bisector = function(f) {
2763 left: function(a, x, lo, hi) {
2764 if (arguments.length < 3) lo = 0;
2765 if (arguments.length < 4) hi = a.length;
2767 var mid = lo + hi >>> 1;
2768 if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid;
2772 right: function(a, x, lo, hi) {
2773 if (arguments.length < 3) lo = 0;
2774 if (arguments.length < 4) hi = a.length;
2776 var mid = lo + hi >>> 1;
2777 if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1;
2783 var d3_bisector = d3.bisector(function(d) {
2786 d3.bisectLeft = d3_bisector.left;
2787 d3.bisect = d3.bisectRight = d3_bisector.right;
2788 d3.first = function(array, f) {
2789 var i = 0, n = array.length, a = array[0], b;
2790 if (arguments.length === 1) f = d3.ascending;
2792 if (f.call(array, a, b = array[i]) > 0) {
2798 d3.last = function(array, f) {
2799 var i = 0, n = array.length, a = array[0], b;
2800 if (arguments.length === 1) f = d3.ascending;
2802 if (f.call(array, a, b = array[i]) <= 0) {
2808 d3.nest = function() {
2809 function map(array, depth) {
2810 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
2811 var i = -1, n = array.length, key = keys[depth++], keyValue, object, valuesByKey = new d3_Map, values, o = {};
2813 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
2814 values.push(object);
2816 valuesByKey.set(keyValue, [ object ]);
2819 valuesByKey.forEach(function(keyValue, values) {
2820 o[keyValue] = map(values, depth);
2824 function entries(map, depth) {
2825 if (depth >= keys.length) return map;
2826 var a = [], sortKey = sortKeys[depth++], key;
2830 values: entries(map[key], depth)
2833 if (sortKey) a.sort(function(a, b) {
2834 return sortKey(a.key, b.key);
2838 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
2839 nest.map = function(array) {
2840 return map(array, 0);
2842 nest.entries = function(array) {
2843 return entries(map(array, 0), 0);
2845 nest.key = function(d) {
2849 nest.sortKeys = function(order) {
2850 sortKeys[keys.length - 1] = order;
2853 nest.sortValues = function(order) {
2857 nest.rollup = function(f) {
2863 d3.keys = function(map) {
2865 for (var key in map) keys.push(key);
2868 d3.values = function(map) {
2870 for (var key in map) values.push(map[key]);
2873 d3.entries = function(map) {
2875 for (var key in map) entries.push({
2881 d3.permute = function(array, indexes) {
2882 var permutes = [], i = -1, n = indexes.length;
2883 while (++i < n) permutes[i] = array[indexes[i]];
2886 d3.merge = function(arrays) {
2887 return Array.prototype.concat.apply([], arrays);
2889 d3.split = function(array, f) {
2890 var arrays = [], values = [], value, i = -1, n = array.length;
2891 if (arguments.length < 2) f = d3_splitter;
2893 if (f.call(values, value = array[i], i)) {
2896 if (!values.length) arrays.push(values);
2902 d3.range = function(start, stop, step) {
2903 if (arguments.length < 3) {
2905 if (arguments.length < 2) {
2910 if ((stop - start) / step === Infinity) throw new Error("infinite range");
2911 var range = [], k = d3_range_integerScale(Math.abs(step)), i = -1, j;
2912 start *= k, stop *= k, step *= k;
2913 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
2916 d3.requote = function(s) {
2917 return s.replace(d3_requote_re, "\\$&");
2919 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
2920 d3.round = function(x, n) {
2921 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2923 d3.xhr = function(url, mime, callback) {
2924 var req = new XMLHttpRequest;
2925 if (arguments.length < 3) callback = mime, mime = null; else if (mime && req.overrideMimeType) req.overrideMimeType(mime);
2926 req.open("GET", url, true);
2927 if (mime) req.setRequestHeader("Accept", mime);
2928 req.onreadystatechange = function() {
2929 if (req.readyState === 4) {
2931 callback(!s && req.response || s >= 200 && s < 300 || s === 304 ? req : null);
2936 d3.text = function(url, mime, callback) {
2937 function ready(req) {
2938 callback(req && req.responseText);
2940 if (arguments.length < 3) {
2944 d3.xhr(url, mime, ready);
2946 d3.json = function(url, callback) {
2947 d3.text(url, "application/json", function(text) {
2948 callback(text ? JSON.parse(text) : null);
2951 d3.html = function(url, callback) {
2952 d3.text(url, "text/html", function(text) {
2954 var range = document.createRange();
2955 range.selectNode(document.body);
2956 text = range.createContextualFragment(text);
2961 d3.xml = function(url, mime, callback) {
2962 function ready(req) {
2963 callback(req && req.responseXML);
2965 if (arguments.length < 3) {
2969 d3.xhr(url, mime, ready);
2972 svg: "http://www.w3.org/2000/svg",
2973 xhtml: "http://www.w3.org/1999/xhtml",
2974 xlink: "http://www.w3.org/1999/xlink",
2975 xml: "http://www.w3.org/XML/1998/namespace",
2976 xmlns: "http://www.w3.org/2000/xmlns/"
2979 prefix: d3_nsPrefix,
2980 qualify: function(name) {
2981 var i = name.indexOf(":"), prefix = name;
2983 prefix = name.substring(0, i);
2984 name = name.substring(i + 1);
2986 return d3_nsPrefix.hasOwnProperty(prefix) ? {
2987 space: d3_nsPrefix[prefix],
2992 d3.dispatch = function() {
2993 var dispatch = new d3_dispatch, i = -1, n = arguments.length;
2994 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
2997 d3_dispatch.prototype.on = function(type, listener) {
2998 var i = type.indexOf("."), name = "";
3000 name = type.substring(i + 1);
3001 type = type.substring(0, i);
3003 return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
3005 d3.format = function(specifier) {
3006 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], scale = 1, suffix = "", integer = false;
3007 if (precision) precision = +precision.substring(1);
3010 if (comma) width -= Math.floor((width - 1) / 4);
3036 if (type == "r" && !precision) type = "g";
3037 type = d3_format_types.get(type) || d3_format_typeDefault;
3038 return function(value) {
3039 if (integer && value % 1) return "";
3040 var negative = value < 0 && (value = -value) ? "-" : sign;
3042 var prefix = d3.formatPrefix(value, precision);
3043 value = prefix.scale(value);
3044 suffix = prefix.symbol;
3048 value = type(value, precision);
3050 var length = value.length + negative.length;
3051 if (length < width) value = (new Array(width - length + 1)).join(fill) + value;
3052 if (comma) value = d3_format_group(value);
3053 value = negative + value;
3055 if (comma) value = d3_format_group(value);
3056 value = negative + value;
3057 var length = value.length;
3058 if (length < width) value = (new Array(width - length + 1)).join(fill) + value;
3060 return value + suffix;
3063 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
3064 var d3_format_types = d3.map({
3066 return x.toPrecision(p);
3069 return x.toExponential(p);
3072 return x.toFixed(p);
3075 return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p)));
3078 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "μ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
3079 d3.formatPrefix = function(value, precision) {
3082 if (value < 0) value *= -1;
3083 if (precision) value = d3.round(value, d3_format_precision(value, precision));
3084 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
3085 i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
3087 return d3_formatPrefixes[8 + i / 3];
3089 var d3_ease_quad = d3_ease_poly(2), d3_ease_cubic = d3_ease_poly(3), d3_ease_default = function() {
3090 return d3_ease_identity;
3092 var d3_ease = d3.map({
3093 linear: d3_ease_default,
3096 return d3_ease_quad;
3099 return d3_ease_cubic;
3107 circle: function() {
3108 return d3_ease_circle;
3110 elastic: d3_ease_elastic,
3112 bounce: function() {
3113 return d3_ease_bounce;
3116 var d3_ease_mode = d3.map({
3117 "in": d3_ease_identity,
3118 out: d3_ease_reverse,
3119 "in-out": d3_ease_reflect,
3120 "out-in": function(f) {
3121 return d3_ease_reflect(d3_ease_reverse(f));
3124 d3.ease = function(name) {
3125 var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
3126 t = d3_ease.get(t) || d3_ease_default;
3127 m = d3_ease_mode.get(m) || d3_ease_identity;
3128 return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1))));
3131 d3.transform = function(string) {
3132 var g = document.createElementNS(d3.ns.prefix.svg, "g");
3133 return (d3.transform = function(string) {
3134 g.setAttribute("transform", string);
3135 var t = g.transform.baseVal.consolidate();
3136 return new d3_transform(t ? t.matrix : d3_transformIdentity);
3139 d3_transform.prototype.toString = function() {
3140 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
3142 var d3_transformDegrees = 180 / Math.PI, d3_transformIdentity = {
3150 d3.interpolate = function(a, b) {
3151 var i = d3.interpolators.length, f;
3152 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
3155 d3.interpolateNumber = function(a, b) {
3157 return function(t) {
3161 d3.interpolateRound = function(a, b) {
3163 return function(t) {
3164 return Math.round(a + b * t);
3167 d3.interpolateString = function(a, b) {
3168 var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
3169 d3_interpolate_number.lastIndex = 0;
3170 for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
3171 if (m.index) s.push(b.substring(s0, s1 = m.index));
3177 s0 = d3_interpolate_number.lastIndex;
3179 if (s0 < b.length) s.push(b.substring(s0));
3180 for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
3184 if (s[o.i + 1] == null) {
3187 for (j = i + 1; j < n; ++j) q[j].i--;
3189 s[o.i - 1] += o.x + s[o.i + 1];
3191 for (j = i + 1; j < n; ++j) q[j].i -= 2;
3194 if (s[o.i + 1] == null) {
3197 s[o.i] = o.x + s[o.i + 1];
3198 s.splice(o.i + 1, 1);
3199 for (j = i + 1; j < n; ++j) q[j].i--;
3206 o.x = d3.interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
3211 if (s[o.i + 1] == null) {
3214 s[o.i] = o.x + s[o.i + 1];
3215 s.splice(o.i + 1, 1);
3219 if (s.length === 1) {
3220 return s[0] == null ? q[0].x : function() {
3224 return function(t) {
3225 for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
3229 d3.interpolateTransform = function(a, b) {
3230 var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
3231 if (ta[0] != tb[0] || ta[1] != tb[1]) {
3232 s.push("translate(", null, ",", null, ")");
3235 x: d3.interpolateNumber(ta[0], tb[0])
3238 x: d3.interpolateNumber(ta[1], tb[1])
3240 } else if (tb[0] || tb[1]) {
3241 s.push("translate(" + tb + ")");
3246 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
3248 i: s.push(s.pop() + "rotate(", null, ")") - 2,
3249 x: d3.interpolateNumber(ra, rb)
3252 s.push(s.pop() + "rotate(" + rb + ")");
3256 i: s.push(s.pop() + "skewX(", null, ")") - 2,
3257 x: d3.interpolateNumber(wa, wb)
3260 s.push(s.pop() + "skewX(" + wb + ")");
3262 if (ka[0] != kb[0] || ka[1] != kb[1]) {
3263 n = s.push(s.pop() + "scale(", null, ",", null, ")");
3266 x: d3.interpolateNumber(ka[0], kb[0])
3269 x: d3.interpolateNumber(ka[1], kb[1])
3271 } else if (kb[0] != 1 || kb[1] != 1) {
3272 s.push(s.pop() + "scale(" + kb + ")");
3275 return function(t) {
3277 while (++i < n) s[(o = q[i]).i] = o.x(t);
3281 d3.interpolateRgb = function(a, b) {
3284 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
3285 return function(t) {
3286 return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));
3289 d3.interpolateHsl = function(a, b) {
3292 var h0 = a.h, s0 = a.s, l0 = a.l, h1 = b.h - h0, s1 = b.s - s0, l1 = b.l - l0;
3293 if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360;
3294 return function(t) {
3295 return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t) + "";
3298 d3.interpolateLab = function(a, b) {
3301 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
3302 return function(t) {
3303 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
3306 d3.interpolateHcl = function(a, b) {
3309 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
3310 if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
3311 return function(t) {
3312 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
3315 d3.interpolateArray = function(a, b) {
3316 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
3317 for (i = 0; i < n0; ++i) x.push(d3.interpolate(a[i], b[i]));
3318 for (; i < na; ++i) c[i] = a[i];
3319 for (; i < nb; ++i) c[i] = b[i];
3320 return function(t) {
3321 for (i = 0; i < n0; ++i) c[i] = x[i](t);
3325 d3.interpolateObject = function(a, b) {
3326 var i = {}, c = {}, k;
3329 i[k] = d3_interpolateByName(k)(a[k], b[k]);
3339 return function(t) {
3340 for (k in i) c[k] = i[k](t);
3344 var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
3345 d3.interpolators = [ d3.interpolateObject, function(a, b) {
3346 return b instanceof Array && d3.interpolateArray(a, b);
3348 return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + "");
3350 return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a, b);
3352 return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b);
3354 d3.rgb = function(r, g, b) {
3355 return arguments.length === 1 ? r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : d3_rgb(~~r, ~~g, ~~b);
3357 d3_Rgb.prototype.brighter = function(k) {
3358 k = Math.pow(.7, arguments.length ? k : 1);
3359 var r = this.r, g = this.g, b = this.b, i = 30;
3360 if (!r && !g && !b) return d3_rgb(i, i, i);
3361 if (r && r < i) r = i;
3362 if (g && g < i) g = i;
3363 if (b && b < i) b = i;
3364 return d3_rgb(Math.min(255, Math.floor(r / k)), Math.min(255, Math.floor(g / k)), Math.min(255, Math.floor(b / k)));
3366 d3_Rgb.prototype.darker = function(k) {
3367 k = Math.pow(.7, arguments.length ? k : 1);
3368 return d3_rgb(Math.floor(k * this.r), Math.floor(k * this.g), Math.floor(k * this.b));
3370 d3_Rgb.prototype.hsl = function() {
3371 return d3_rgb_hsl(this.r, this.g, this.b);
3373 d3_Rgb.prototype.toString = function() {
3374 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
3376 var d3_rgb_names = d3.map({
3377 aliceblue: "#f0f8ff",
3378 antiquewhite: "#faebd7",
3380 aquamarine: "#7fffd4",
3385 blanchedalmond: "#ffebcd",
3387 blueviolet: "#8a2be2",
3389 burlywood: "#deb887",
3390 cadetblue: "#5f9ea0",
3391 chartreuse: "#7fff00",
3392 chocolate: "#d2691e",
3394 cornflowerblue: "#6495ed",
3395 cornsilk: "#fff8dc",
3398 darkblue: "#00008b",
3399 darkcyan: "#008b8b",
3400 darkgoldenrod: "#b8860b",
3401 darkgray: "#a9a9a9",
3402 darkgreen: "#006400",
3403 darkgrey: "#a9a9a9",
3404 darkkhaki: "#bdb76b",
3405 darkmagenta: "#8b008b",
3406 darkolivegreen: "#556b2f",
3407 darkorange: "#ff8c00",
3408 darkorchid: "#9932cc",
3410 darksalmon: "#e9967a",
3411 darkseagreen: "#8fbc8f",
3412 darkslateblue: "#483d8b",
3413 darkslategray: "#2f4f4f",
3414 darkslategrey: "#2f4f4f",
3415 darkturquoise: "#00ced1",
3416 darkviolet: "#9400d3",
3417 deeppink: "#ff1493",
3418 deepskyblue: "#00bfff",
3421 dodgerblue: "#1e90ff",
3422 firebrick: "#b22222",
3423 floralwhite: "#fffaf0",
3424 forestgreen: "#228b22",
3426 gainsboro: "#dcdcdc",
3427 ghostwhite: "#f8f8ff",
3429 goldenrod: "#daa520",
3432 greenyellow: "#adff2f",
3434 honeydew: "#f0fff0",
3436 indianred: "#cd5c5c",
3440 lavender: "#e6e6fa",
3441 lavenderblush: "#fff0f5",
3442 lawngreen: "#7cfc00",
3443 lemonchiffon: "#fffacd",
3444 lightblue: "#add8e6",
3445 lightcoral: "#f08080",
3446 lightcyan: "#e0ffff",
3447 lightgoldenrodyellow: "#fafad2",
3448 lightgray: "#d3d3d3",
3449 lightgreen: "#90ee90",
3450 lightgrey: "#d3d3d3",
3451 lightpink: "#ffb6c1",
3452 lightsalmon: "#ffa07a",
3453 lightseagreen: "#20b2aa",
3454 lightskyblue: "#87cefa",
3455 lightslategray: "#778899",
3456 lightslategrey: "#778899",
3457 lightsteelblue: "#b0c4de",
3458 lightyellow: "#ffffe0",
3460 limegreen: "#32cd32",
3464 mediumaquamarine: "#66cdaa",
3465 mediumblue: "#0000cd",
3466 mediumorchid: "#ba55d3",
3467 mediumpurple: "#9370db",
3468 mediumseagreen: "#3cb371",
3469 mediumslateblue: "#7b68ee",
3470 mediumspringgreen: "#00fa9a",
3471 mediumturquoise: "#48d1cc",
3472 mediumvioletred: "#c71585",
3473 midnightblue: "#191970",
3474 mintcream: "#f5fffa",
3475 mistyrose: "#ffe4e1",
3476 moccasin: "#ffe4b5",
3477 navajowhite: "#ffdead",
3481 olivedrab: "#6b8e23",
3483 orangered: "#ff4500",
3485 palegoldenrod: "#eee8aa",
3486 palegreen: "#98fb98",
3487 paleturquoise: "#afeeee",
3488 palevioletred: "#db7093",
3489 papayawhip: "#ffefd5",
3490 peachpuff: "#ffdab9",
3494 powderblue: "#b0e0e6",
3497 rosybrown: "#bc8f8f",
3498 royalblue: "#4169e1",
3499 saddlebrown: "#8b4513",
3501 sandybrown: "#f4a460",
3502 seagreen: "#2e8b57",
3503 seashell: "#fff5ee",
3507 slateblue: "#6a5acd",
3508 slategray: "#708090",
3509 slategrey: "#708090",
3511 springgreen: "#00ff7f",
3512 steelblue: "#4682b4",
3517 turquoise: "#40e0d0",
3521 whitesmoke: "#f5f5f5",
3523 yellowgreen: "#9acd32"
3525 d3_rgb_names.forEach(function(key, value) {
3526 d3_rgb_names.set(key, d3_rgb_parse(value, d3_rgb, d3_hsl_rgb));
3528 d3.hsl = function(h, s, l) {
3529 return arguments.length === 1 ? h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : d3_hsl(+h, +s, +l);
3531 d3_Hsl.prototype.brighter = function(k) {
3532 k = Math.pow(.7, arguments.length ? k : 1);
3533 return d3_hsl(this.h, this.s, this.l / k);
3535 d3_Hsl.prototype.darker = function(k) {
3536 k = Math.pow(.7, arguments.length ? k : 1);
3537 return d3_hsl(this.h, this.s, k * this.l);
3539 d3_Hsl.prototype.rgb = function() {
3540 return d3_hsl_rgb(this.h, this.s, this.l);
3542 d3_Hsl.prototype.toString = function() {
3543 return this.rgb().toString();
3545 d3.hcl = function(h, c, l) {
3546 return arguments.length === 1 ? h instanceof d3_Hcl ? d3_hcl(h.h, h.c, h.l) : h instanceof d3_Lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : d3_hcl(+h, +c, +l);
3548 d3_Hcl.prototype.brighter = function(k) {
3549 return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
3551 d3_Hcl.prototype.darker = function(k) {
3552 return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
3554 d3_Hcl.prototype.rgb = function() {
3555 return d3_hcl_lab(this.h, this.c, this.l).rgb();
3557 d3_Hcl.prototype.toString = function() {
3558 return this.rgb() + "";
3560 d3.lab = function(l, a, b) {
3561 return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
3564 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
3565 d3_Lab.prototype.brighter = function(k) {
3566 return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
3568 d3_Lab.prototype.darker = function(k) {
3569 return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
3571 d3_Lab.prototype.rgb = function() {
3572 return d3_lab_rgb(this.l, this.a, this.b);
3574 d3_Lab.prototype.toString = function() {
3575 return this.rgb() + "";
3577 var d3_select = function(s, n) {
3578 return n.querySelector(s);
3579 }, d3_selectAll = function(s, n) {
3580 return n.querySelectorAll(s);
3581 }, d3_selectRoot = document.documentElement, d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) {
3582 return d3_selectMatcher.call(n, s);
3584 if (typeof Sizzle === "function") {
3585 d3_select = function(s, n) {
3586 return Sizzle(s, n)[0] || null;
3588 d3_selectAll = function(s, n) {
3589 return Sizzle.uniqueSort(Sizzle(s, n));
3591 d3_selectMatches = Sizzle.matchesSelector;
3593 var d3_selectionPrototype = [];
3594 d3.selection = function() {
3595 return d3_selectionRoot;
3597 d3.selection.prototype = d3_selectionPrototype;
3598 d3_selectionPrototype.select = function(selector) {
3599 var subgroups = [], subgroup, subnode, group, node;
3600 if (typeof selector !== "function") selector = d3_selection_selector(selector);
3601 for (var j = -1, m = this.length; ++j < m; ) {
3602 subgroups.push(subgroup = []);
3603 subgroup.parentNode = (group = this[j]).parentNode;
3604 for (var i = -1, n = group.length; ++i < n; ) {
3605 if (node = group[i]) {
3606 subgroup.push(subnode = selector.call(node, node.__data__, i));
3607 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
3609 subgroup.push(null);
3613 return d3_selection(subgroups);
3615 d3_selectionPrototype.selectAll = function(selector) {
3616 var subgroups = [], subgroup, node;
3617 if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
3618 for (var j = -1, m = this.length; ++j < m; ) {
3619 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
3620 if (node = group[i]) {
3621 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
3622 subgroup.parentNode = node;
3626 return d3_selection(subgroups);
3628 d3_selectionPrototype.attr = function(name, value) {
3629 if (arguments.length < 2) {
3630 if (typeof name === "string") {
3631 var node = this.node();
3632 name = d3.ns.qualify(name);
3633 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
3635 for (value in name) this.each(d3_selection_attr(value, name[value]));
3638 return this.each(d3_selection_attr(name, value));
3640 d3_selectionPrototype.classed = function(name, value) {
3641 if (arguments.length < 2) {
3642 if (typeof name === "string") {
3643 var node = this.node(), n = (name = name.trim().split(/^|\s+/g)).length, i = -1;
3644 if (value = node.classList) {
3645 while (++i < n) if (!value.contains(name[i])) return false;
3647 value = node.className;
3648 if (value.baseVal != null) value = value.baseVal;
3649 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
3653 for (value in name) this.each(d3_selection_classed(value, name[value]));
3656 return this.each(d3_selection_classed(name, value));
3658 d3_selectionPrototype.style = function(name, value, priority) {
3659 var n = arguments.length;
3661 if (typeof name !== "string") {
3662 if (n < 2) value = "";
3663 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
3666 if (n < 2) return window.getComputedStyle(this.node(), null).getPropertyValue(name);
3669 return this.each(d3_selection_style(name, value, priority));
3671 d3_selectionPrototype.property = function(name, value) {
3672 if (arguments.length < 2) {
3673 if (typeof name === "string") return this.node()[name];
3674 for (value in name) this.each(d3_selection_property(value, name[value]));
3677 return this.each(d3_selection_property(name, value));
3679 d3_selectionPrototype.text = function(value) {
3680 return arguments.length < 1 ? this.node().textContent : this.each(typeof value === "function" ? function() {
3681 var v = value.apply(this, arguments);
3682 this.textContent = v == null ? "" : v;
3683 } : value == null ? function() {
3684 this.textContent = "";
3686 this.textContent = value;
3689 d3_selectionPrototype.html = function(value) {
3690 return arguments.length < 1 ? this.node().innerHTML : this.each(typeof value === "function" ? function() {
3691 var v = value.apply(this, arguments);
3692 this.innerHTML = v == null ? "" : v;
3693 } : value == null ? function() {
3694 this.innerHTML = "";
3696 this.innerHTML = value;
3699 d3_selectionPrototype.append = function(name) {
3701 return this.appendChild(document.createElementNS(this.namespaceURI, name));
3703 function appendNS() {
3704 return this.appendChild(document.createElementNS(name.space, name.local));
3706 name = d3.ns.qualify(name);
3707 return this.select(name.local ? appendNS : append);
3709 d3_selectionPrototype.insert = function(name, before) {
3711 return this.insertBefore(document.createElementNS(this.namespaceURI, name), d3_select(before, this));
3713 function insertNS() {
3714 return this.insertBefore(document.createElementNS(name.space, name.local), d3_select(before, this));
3716 name = d3.ns.qualify(name);
3717 return this.select(name.local ? insertNS : insert);
3719 d3_selectionPrototype.remove = function() {
3720 return this.each(function() {
3721 var parent = this.parentNode;
3722 if (parent) parent.removeChild(this);
3725 d3_selectionPrototype.data = function(value, key) {
3726 function bind(group, groupData) {
3727 var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), n1 = Math.max(n, m), updateNodes = [], enterNodes = [], exitNodes = [], node, nodeData;
3729 var nodeByKeyValue = new d3_Map, keyValues = [], keyValue, j = groupData.length;
3730 for (i = -1; ++i < n; ) {
3731 keyValue = key.call(node = group[i], node.__data__, i);
3732 if (nodeByKeyValue.has(keyValue)) {
3733 exitNodes[j++] = node;
3735 nodeByKeyValue.set(keyValue, node);
3737 keyValues.push(keyValue);
3739 for (i = -1; ++i < m; ) {
3740 keyValue = key.call(groupData, nodeData = groupData[i], i);
3741 if (nodeByKeyValue.has(keyValue)) {
3742 updateNodes[i] = node = nodeByKeyValue.get(keyValue);
3743 node.__data__ = nodeData;
3744 enterNodes[i] = exitNodes[i] = null;
3746 enterNodes[i] = d3_selection_dataNode(nodeData);
3747 updateNodes[i] = exitNodes[i] = null;
3749 nodeByKeyValue.remove(keyValue);
3751 for (i = -1; ++i < n; ) {
3752 if (nodeByKeyValue.has(keyValues[i])) {
3753 exitNodes[i] = group[i];
3757 for (i = -1; ++i < n0; ) {
3759 nodeData = groupData[i];
3761 node.__data__ = nodeData;
3762 updateNodes[i] = node;
3763 enterNodes[i] = exitNodes[i] = null;
3765 enterNodes[i] = d3_selection_dataNode(nodeData);
3766 updateNodes[i] = exitNodes[i] = null;
3769 for (; i < m; ++i) {
3770 enterNodes[i] = d3_selection_dataNode(groupData[i]);
3771 updateNodes[i] = exitNodes[i] = null;
3773 for (; i < n1; ++i) {
3774 exitNodes[i] = group[i];
3775 enterNodes[i] = updateNodes[i] = null;
3778 enterNodes.update = updateNodes;
3779 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
3780 enter.push(enterNodes);
3781 update.push(updateNodes);
3782 exit.push(exitNodes);
3784 var i = -1, n = this.length, group, node;
3785 if (!arguments.length) {
3786 value = new Array(n = (group = this[0]).length);
3788 if (node = group[i]) {
3789 value[i] = node.__data__;
3794 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
3795 if (typeof value === "function") {
3797 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
3801 bind(group = this[i], value);
3804 update.enter = function() {
3807 update.exit = function() {
3812 d3_selectionPrototype.datum = d3_selectionPrototype.map = function(value) {
3813 return arguments.length < 1 ? this.property("__data__") : this.property("__data__", value);
3815 d3_selectionPrototype.filter = function(filter) {
3816 var subgroups = [], subgroup, group, node;
3817 if (typeof filter !== "function") filter = d3_selection_filter(filter);
3818 for (var j = 0, m = this.length; j < m; j++) {
3819 subgroups.push(subgroup = []);
3820 subgroup.parentNode = (group = this[j]).parentNode;
3821 for (var i = 0, n = group.length; i < n; i++) {
3822 if ((node = group[i]) && filter.call(node, node.__data__, i)) {
3823 subgroup.push(node);
3827 return d3_selection(subgroups);
3829 d3_selectionPrototype.order = function() {
3830 for (var j = -1, m = this.length; ++j < m; ) {
3831 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
3832 if (node = group[i]) {
3833 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
3840 d3_selectionPrototype.sort = function(comparator) {
3841 comparator = d3_selection_sortComparator.apply(this, arguments);
3842 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
3843 return this.order();
3845 d3_selectionPrototype.on = function(type, listener, capture) {
3846 var n = arguments.length;
3848 if (typeof type !== "string") {
3849 if (n < 2) listener = false;
3850 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
3853 if (n < 2) return (n = this.node()["__on" + type]) && n._;
3856 return this.each(d3_selection_on(type, listener, capture));
3858 d3_selectionPrototype.each = function(callback) {
3859 return d3_selection_each(this, function(node, i, j) {
3860 callback.call(node, node.__data__, i, j);
3863 d3_selectionPrototype.call = function(callback) {
3864 callback.apply(this, (arguments[0] = this, arguments));
3867 d3_selectionPrototype.empty = function() {
3868 return !this.node();
3870 d3_selectionPrototype.node = function(callback) {
3871 for (var j = 0, m = this.length; j < m; j++) {
3872 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
3873 var node = group[i];
3874 if (node) return node;
3879 d3_selectionPrototype.transition = function() {
3880 var subgroups = [], subgroup, node;
3881 for (var j = -1, m = this.length; ++j < m; ) {
3882 subgroups.push(subgroup = []);
3883 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
3884 subgroup.push((node = group[i]) ? {
3886 delay: d3_transitionDelay,
3887 duration: d3_transitionDuration
3891 return d3_transition(subgroups, d3_transitionId || ++d3_transitionNextId, Date.now());
3893 var d3_selectionRoot = d3_selection([ [ document ] ]);
3894 d3_selectionRoot[0].parentNode = d3_selectRoot;
3895 d3.select = function(selector) {
3896 return typeof selector === "string" ? d3_selectionRoot.select(selector) : d3_selection([ [ selector ] ]);
3898 d3.selectAll = function(selector) {
3899 return typeof selector === "string" ? d3_selectionRoot.selectAll(selector) : d3_selection([ d3_array(selector) ]);
3901 var d3_selection_enterPrototype = [];
3902 d3.selection.enter = d3_selection_enter;
3903 d3.selection.enter.prototype = d3_selection_enterPrototype;
3904 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
3905 d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
3906 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
3907 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
3908 d3_selection_enterPrototype.select = function(selector) {
3909 var subgroups = [], subgroup, subnode, upgroup, group, node;
3910 for (var j = -1, m = this.length; ++j < m; ) {
3911 upgroup = (group = this[j]).update;
3912 subgroups.push(subgroup = []);
3913 subgroup.parentNode = group.parentNode;
3914 for (var i = -1, n = group.length; ++i < n; ) {
3915 if (node = group[i]) {
3916 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i));
3917 subnode.__data__ = node.__data__;
3919 subgroup.push(null);
3923 return d3_selection(subgroups);
3925 var d3_transitionPrototype = [], d3_transitionNextId = 0, d3_transitionId = 0, d3_transitionDefaultDelay = 0, d3_transitionDefaultDuration = 250, d3_transitionDefaultEase = d3.ease("cubic-in-out"), d3_transitionDelay = d3_transitionDefaultDelay, d3_transitionDuration = d3_transitionDefaultDuration, d3_transitionEase = d3_transitionDefaultEase;
3926 d3_transitionPrototype.call = d3_selectionPrototype.call;
3927 d3.transition = function(selection) {
3928 return arguments.length ? d3_transitionId ? selection.transition() : selection : d3_selectionRoot.transition();
3930 d3.transition.prototype = d3_transitionPrototype;
3931 d3_transitionPrototype.select = function(selector) {
3932 var subgroups = [], subgroup, subnode, node;
3933 if (typeof selector !== "function") selector = d3_selection_selector(selector);
3934 for (var j = -1, m = this.length; ++j < m; ) {
3935 subgroups.push(subgroup = []);
3936 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
3937 if ((node = group[i]) && (subnode = selector.call(node.node, node.node.__data__, i))) {
3938 if ("__data__" in node.node) subnode.__data__ = node.node.__data__;
3942 duration: node.duration
3945 subgroup.push(null);
3949 return d3_transition(subgroups, this.id, this.time).ease(this.ease());
3951 d3_transitionPrototype.selectAll = function(selector) {
3952 var subgroups = [], subgroup, subnodes, node;
3953 if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
3954 for (var j = -1, m = this.length; ++j < m; ) {
3955 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
3956 if (node = group[i]) {
3957 subnodes = selector.call(node.node, node.node.__data__, i);
3958 subgroups.push(subgroup = []);
3959 for (var k = -1, o = subnodes.length; ++k < o; ) {
3963 duration: node.duration
3969 return d3_transition(subgroups, this.id, this.time).ease(this.ease());
3971 d3_transitionPrototype.filter = function(filter) {
3972 var subgroups = [], subgroup, group, node;
3973 if (typeof filter !== "function") filter = d3_selection_filter(filter);
3974 for (var j = 0, m = this.length; j < m; j++) {
3975 subgroups.push(subgroup = []);
3976 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
3977 if ((node = group[i]) && filter.call(node.node, node.node.__data__, i)) {
3978 subgroup.push(node);
3982 return d3_transition(subgroups, this.id, this.time).ease(this.ease());
3984 d3_transitionPrototype.attr = function(name, value) {
3985 if (arguments.length < 2) {
3986 for (value in name) this.attrTween(value, d3_tweenByName(name[value], value));
3989 return this.attrTween(name, d3_tweenByName(value, name));
3991 d3_transitionPrototype.attrTween = function(nameNS, tween) {
3992 function attrTween(d, i) {
3993 var f = tween.call(this, d, i, this.getAttribute(name));
3994 return f === d3_tweenRemove ? (this.removeAttribute(name), null) : f && function(t) {
3995 this.setAttribute(name, f(t));
3998 function attrTweenNS(d, i) {
3999 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
4000 return f === d3_tweenRemove ? (this.removeAttributeNS(name.space, name.local), null) : f && function(t) {
4001 this.setAttributeNS(name.space, name.local, f(t));
4004 var name = d3.ns.qualify(nameNS);
4005 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
4007 d3_transitionPrototype.style = function(name, value, priority) {
4008 var n = arguments.length;
4010 if (typeof name !== "string") {
4011 if (n < 2) value = "";
4012 for (priority in name) this.styleTween(priority, d3_tweenByName(name[priority], priority), value);
4017 return this.styleTween(name, d3_tweenByName(value, name), priority);
4019 d3_transitionPrototype.styleTween = function(name, tween, priority) {
4020 if (arguments.length < 3) priority = "";
4021 return this.tween("style." + name, function(d, i) {
4022 var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
4023 return f === d3_tweenRemove ? (this.style.removeProperty(name), null) : f && function(t) {
4024 this.style.setProperty(name, f(t), priority);
4028 d3_transitionPrototype.text = function(value) {
4029 return this.tween("text", function(d, i) {
4030 this.textContent = typeof value === "function" ? value.call(this, d, i) : value;
4033 d3_transitionPrototype.remove = function() {
4034 return this.each("end.transition", function() {
4036 if (!this.__transition__ && (p = this.parentNode)) p.removeChild(this);
4039 d3_transitionPrototype.delay = function(value) {
4040 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
4041 node.delay = value.call(node = node.node, node.__data__, i, j) | 0;
4042 } : (value = value | 0, function(node) {
4046 d3_transitionPrototype.duration = function(value) {
4047 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
4048 node.duration = Math.max(1, value.call(node = node.node, node.__data__, i, j) | 0);
4049 } : (value = Math.max(1, value | 0), function(node) {
4050 node.duration = value;
4053 d3_transitionPrototype.transition = function() {
4054 return this.select(d3_this);
4056 d3.tween = function(b, interpolate) {
4057 function tweenFunction(d, i, a) {
4058 var v = b.call(this, d, i);
4059 return v == null ? a != "" && d3_tweenRemove : a != v && interpolate(a, v);
4061 function tweenString(d, i, a) {
4062 return a != b && interpolate(a, b);
4064 return typeof b === "function" ? tweenFunction : b == null ? d3_tweenNull : (b += "", tweenString);
4066 var d3_tweenRemove = {};
4067 var d3_timer_queue = null, d3_timer_interval, d3_timer_timeout;
4068 d3.timer = function(callback, delay, then) {
4069 var found = false, t0, t1 = d3_timer_queue;
4070 if (arguments.length < 3) {
4071 if (arguments.length < 2) delay = 0; else if (!isFinite(delay)) return;
4075 if (t1.callback === callback) {
4084 if (!found) d3_timer_queue = {
4088 next: d3_timer_queue
4090 if (!d3_timer_interval) {
4091 d3_timer_timeout = clearTimeout(d3_timer_timeout);
4092 d3_timer_interval = 1;
4093 d3_timer_frame(d3_timer_step);
4096 d3.timer.flush = function() {
4097 var elapsed, now = Date.now(), t1 = d3_timer_queue;
4099 elapsed = now - t1.then;
4100 if (!t1.delay) t1.flush = t1.callback(elapsed);
4105 var d3_timer_frame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
4106 setTimeout(callback, 17);
4108 d3.mouse = function(container) {
4109 return d3_mousePoint(container, d3_eventSource());
4111 var d3_mouse_bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
4112 d3.touches = function(container, touches) {
4113 if (arguments.length < 2) touches = d3_eventSource().touches;
4114 return touches ? d3_array(touches).map(function(touch) {
4115 var point = d3_mousePoint(container, touch);
4116 point.identifier = touch.identifier;
4121 d3.scale.linear = function() {
4122 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3.interpolate, false);
4124 d3.scale.log = function() {
4125 return d3_scale_log(d3.scale.linear(), d3_scale_logp);
4127 var d3_scale_logFormat = d3.format(".0e");
4128 d3_scale_logp.pow = function(x) {
4129 return Math.pow(10, x);
4131 d3_scale_logn.pow = function(x) {
4132 return -Math.pow(10, -x);
4134 d3.scale.pow = function() {
4135 return d3_scale_pow(d3.scale.linear(), 1);
4137 d3.scale.sqrt = function() {
4138 return d3.scale.pow().exponent(.5);
4140 d3.scale.ordinal = function() {
4141 return d3_scale_ordinal([], {
4146 d3.scale.category10 = function() {
4147 return d3.scale.ordinal().range(d3_category10);
4149 d3.scale.category20 = function() {
4150 return d3.scale.ordinal().range(d3_category20);
4152 d3.scale.category20b = function() {
4153 return d3.scale.ordinal().range(d3_category20b);
4155 d3.scale.category20c = function() {
4156 return d3.scale.ordinal().range(d3_category20c);
4158 var d3_category10 = [ "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf" ];
4159 var d3_category20 = [ "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5" ];
4160 var d3_category20b = [ "#393b79", "#5254a3", "#6b6ecf", "#9c9ede", "#637939", "#8ca252", "#b5cf6b", "#cedb9c", "#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94", "#843c39", "#ad494a", "#d6616b", "#e7969c", "#7b4173", "#a55194", "#ce6dbd", "#de9ed6" ];
4161 var d3_category20c = [ "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" ];
4162 d3.scale.quantile = function() {
4163 return d3_scale_quantile([], []);
4165 d3.scale.quantize = function() {
4166 return d3_scale_quantize(0, 1, [ 0, 1 ]);
4168 d3.scale.threshold = function() {
4169 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
4171 d3.scale.identity = function() {
4172 return d3_scale_identity([ 0, 1 ]);
4175 d3.svg.arc = function() {
4177 var r0 = innerRadius.apply(this, arguments), r1 = outerRadius.apply(this, arguments), a0 = startAngle.apply(this, arguments) + d3_svg_arcOffset, a1 = endAngle.apply(this, arguments) + d3_svg_arcOffset, da = (a1 < a0 && (da = a0, a0 = a1, a1 = da), a1 - a0), df = da < Math.PI ? "0" : "1", c0 = Math.cos(a0), s0 = Math.sin(a0), c1 = Math.cos(a1), s1 = Math.sin(a1);
4178 return da >= d3_svg_arcMax ? r0 ? "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "M0," + r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + -r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + r0 + "Z" : "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "Z" : r0 ? "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L" + r0 * c1 + "," + r0 * s1 + "A" + r0 + "," + r0 + " 0 " + df + ",0 " + r0 * c0 + "," + r0 * s0 + "Z" : "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L0,0" + "Z";
4180 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
4181 arc.innerRadius = function(v) {
4182 if (!arguments.length) return innerRadius;
4183 innerRadius = d3_functor(v);
4186 arc.outerRadius = function(v) {
4187 if (!arguments.length) return outerRadius;
4188 outerRadius = d3_functor(v);
4191 arc.startAngle = function(v) {
4192 if (!arguments.length) return startAngle;
4193 startAngle = d3_functor(v);
4196 arc.endAngle = function(v) {
4197 if (!arguments.length) return endAngle;
4198 endAngle = d3_functor(v);
4201 arc.centroid = function() {
4202 var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
4203 return [ Math.cos(a) * r, Math.sin(a) * r ];
4207 var d3_svg_arcOffset = -Math.PI / 2, d3_svg_arcMax = 2 * Math.PI - 1e-6;
4208 d3.svg.line = function() {
4209 return d3_svg_line(d3_identity);
4211 var d3_svg_lineInterpolators = d3.map({
4212 linear: d3_svg_lineLinear,
4213 "linear-closed": d3_svg_lineLinearClosed,
4214 "step-before": d3_svg_lineStepBefore,
4215 "step-after": d3_svg_lineStepAfter,
4216 basis: d3_svg_lineBasis,
4217 "basis-open": d3_svg_lineBasisOpen,
4218 "basis-closed": d3_svg_lineBasisClosed,
4219 bundle: d3_svg_lineBundle,
4220 cardinal: d3_svg_lineCardinal,
4221 "cardinal-open": d3_svg_lineCardinalOpen,
4222 "cardinal-closed": d3_svg_lineCardinalClosed,
4223 monotone: d3_svg_lineMonotone
4225 d3_svg_lineInterpolators.forEach(function(key, value) {
4227 value.closed = /-closed$/.test(key);
4229 var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];
4230 d3.svg.line.radial = function() {
4231 var line = d3_svg_line(d3_svg_lineRadial);
4232 line.radius = line.x, delete line.x;
4233 line.angle = line.y, delete line.y;
4236 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
4237 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
4238 d3.svg.area = function() {
4239 return d3_svg_area(d3_identity);
4241 d3.svg.area.radial = function() {
4242 var area = d3_svg_area(d3_svg_lineRadial);
4243 area.radius = area.x, delete area.x;
4244 area.innerRadius = area.x0, delete area.x0;
4245 area.outerRadius = area.x1, delete area.x1;
4246 area.angle = area.y, delete area.y;
4247 area.startAngle = area.y0, delete area.y0;
4248 area.endAngle = area.y1, delete area.y1;
4251 d3.svg.chord = function() {
4252 function chord(d, i) {
4253 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
4254 return "M" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + "Z";
4256 function subgroup(self, f, d, i) {
4257 var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) + d3_svg_arcOffset, a1 = endAngle.call(self, subgroup, i) + d3_svg_arcOffset;
4262 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
4263 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
4266 function equals(a, b) {
4267 return a.a0 == b.a0 && a.a1 == b.a1;
4269 function arc(r, p, a) {
4270 return "A" + r + "," + r + " 0 " + +(a > Math.PI) + ",1 " + p;
4272 function curve(r0, p0, r1, p1) {
4273 return "Q 0,0 " + p1;
4275 var source = d3_svg_chordSource, target = d3_svg_chordTarget, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
4276 chord.radius = function(v) {
4277 if (!arguments.length) return radius;
4278 radius = d3_functor(v);
4281 chord.source = function(v) {
4282 if (!arguments.length) return source;
4283 source = d3_functor(v);
4286 chord.target = function(v) {
4287 if (!arguments.length) return target;
4288 target = d3_functor(v);
4291 chord.startAngle = function(v) {
4292 if (!arguments.length) return startAngle;
4293 startAngle = d3_functor(v);
4296 chord.endAngle = function(v) {
4297 if (!arguments.length) return endAngle;
4298 endAngle = d3_functor(v);
4303 d3.svg.diagonal = function() {
4304 function diagonal(d, i) {
4305 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
4312 p = p.map(projection);
4313 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
4315 var source = d3_svg_chordSource, target = d3_svg_chordTarget, projection = d3_svg_diagonalProjection;
4316 diagonal.source = function(x) {
4317 if (!arguments.length) return source;
4318 source = d3_functor(x);
4321 diagonal.target = function(x) {
4322 if (!arguments.length) return target;
4323 target = d3_functor(x);
4326 diagonal.projection = function(x) {
4327 if (!arguments.length) return projection;
4333 d3.svg.diagonal.radial = function() {
4334 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
4335 diagonal.projection = function(x) {
4336 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
4340 d3.svg.mouse = d3.mouse;
4341 d3.svg.touches = d3.touches;
4342 d3.svg.symbol = function() {
4343 function symbol(d, i) {
4344 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
4346 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
4347 symbol.type = function(x) {
4348 if (!arguments.length) return type;
4349 type = d3_functor(x);
4352 symbol.size = function(x) {
4353 if (!arguments.length) return size;
4354 size = d3_functor(x);
4359 var d3_svg_symbols = d3.map({
4360 circle: d3_svg_symbolCircle,
4361 cross: function(size) {
4362 var r = Math.sqrt(size / 5) / 2;
4363 return "M" + -3 * r + "," + -r + "H" + -r + "V" + -3 * r + "H" + r + "V" + -r + "H" + 3 * r + "V" + r + "H" + r + "V" + 3 * r + "H" + -r + "V" + r + "H" + -3 * r + "Z";
4365 diamond: function(size) {
4366 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
4367 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
4369 square: function(size) {
4370 var r = Math.sqrt(size) / 2;
4371 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
4373 "triangle-down": function(size) {
4374 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
4375 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
4377 "triangle-up": function(size) {
4378 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
4379 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
4382 d3.svg.symbolTypes = d3_svg_symbols.keys();
4383 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * Math.PI / 180);
4384 d3.svg.axis = function() {
4387 var g = d3.select(this);
4388 var ticks = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain() : tickValues, tickFormat = tickFormat_ == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : String : tickFormat_;
4389 var subticks = d3_svg_axisSubdivide(scale, ticks, tickSubdivide), subtick = g.selectAll(".minor").data(subticks, String), subtickEnter = subtick.enter().insert("line", "g").attr("class", "tick minor").style("opacity", 1e-6), subtickExit = d3.transition(subtick.exit()).style("opacity", 1e-6).remove(), subtickUpdate = d3.transition(subtick).style("opacity", 1);
4390 var tick = g.selectAll("g").data(ticks, String), tickEnter = tick.enter().insert("g", "path").style("opacity", 1e-6), tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
4391 var range = d3_scaleRange(scale), path = g.selectAll(".domain").data([ 0 ]), pathEnter = path.enter().append("path").attr("class", "domain"), pathUpdate = d3.transition(path);
4392 var scale1 = scale.copy(), scale0 = this.__chart__ || scale1;
4393 this.__chart__ = scale1;
4394 tickEnter.append("line").attr("class", "tick");
4395 tickEnter.append("text");
4396 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
4400 tickTransform = d3_svg_axisX;
4401 subtickEnter.attr("y2", tickMinorSize);
4402 subtickUpdate.attr("x2", 0).attr("y2", tickMinorSize);
4403 lineEnter.attr("y2", tickMajorSize);
4404 textEnter.attr("y", Math.max(tickMajorSize, 0) + tickPadding);
4405 lineUpdate.attr("x2", 0).attr("y2", tickMajorSize);
4406 textUpdate.attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding);
4407 text.attr("dy", ".71em").attr("text-anchor", "middle");
4408 pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize);
4413 tickTransform = d3_svg_axisX;
4414 subtickEnter.attr("y2", -tickMinorSize);
4415 subtickUpdate.attr("x2", 0).attr("y2", -tickMinorSize);
4416 lineEnter.attr("y2", -tickMajorSize);
4417 textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
4418 lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize);
4419 textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
4420 text.attr("dy", "0em").attr("text-anchor", "middle");
4421 pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize);
4426 tickTransform = d3_svg_axisY;
4427 subtickEnter.attr("x2", -tickMinorSize);
4428 subtickUpdate.attr("x2", -tickMinorSize).attr("y2", 0);
4429 lineEnter.attr("x2", -tickMajorSize);
4430 textEnter.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding));
4431 lineUpdate.attr("x2", -tickMajorSize).attr("y2", 0);
4432 textUpdate.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0);
4433 text.attr("dy", ".32em").attr("text-anchor", "end");
4434 pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize);
4439 tickTransform = d3_svg_axisY;
4440 subtickEnter.attr("x2", tickMinorSize);
4441 subtickUpdate.attr("x2", tickMinorSize).attr("y2", 0);
4442 lineEnter.attr("x2", tickMajorSize);
4443 textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding);
4444 lineUpdate.attr("x2", tickMajorSize).attr("y2", 0);
4445 textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0);
4446 text.attr("dy", ".32em").attr("text-anchor", "start");
4447 pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize);
4452 tickEnter.call(tickTransform, scale0);
4453 tickUpdate.call(tickTransform, scale1);
4454 tickExit.call(tickTransform, scale1);
4455 subtickEnter.call(tickTransform, scale0);
4456 subtickUpdate.call(tickTransform, scale1);
4457 subtickExit.call(tickTransform, scale1);
4459 var dx = scale1.rangeBand() / 2, x = function(d) {
4460 return scale1(d) + dx;
4462 tickEnter.call(tickTransform, x);
4463 tickUpdate.call(tickTransform, x);
4467 var scale = d3.scale.linear(), orient = "bottom", tickMajorSize = 6, tickMinorSize = 6, tickEndSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_, tickSubdivide = 0;
4468 axis.scale = function(x) {
4469 if (!arguments.length) return scale;
4473 axis.orient = function(x) {
4474 if (!arguments.length) return orient;
4478 axis.ticks = function() {
4479 if (!arguments.length) return tickArguments_;
4480 tickArguments_ = arguments;
4483 axis.tickValues = function(x) {
4484 if (!arguments.length) return tickValues;
4488 axis.tickFormat = function(x) {
4489 if (!arguments.length) return tickFormat_;
4493 axis.tickSize = function(x, y, z) {
4494 if (!arguments.length) return tickMajorSize;
4495 var n = arguments.length - 1;
4497 tickMinorSize = n > 1 ? +y : tickMajorSize;
4498 tickEndSize = n > 0 ? +arguments[n] : tickMajorSize;
4501 axis.tickPadding = function(x) {
4502 if (!arguments.length) return tickPadding;
4506 axis.tickSubdivide = function(x) {
4507 if (!arguments.length) return tickSubdivide;
4513 d3.svg.brush = function() {
4516 var g = d3.select(this), bg = g.selectAll(".background").data([ 0 ]), fg = g.selectAll(".extent").data([ 0 ]), tz = g.selectAll(".resize").data(resizes, String), e;
4517 g.style("pointer-events", "all").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
4518 bg.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
4519 fg.enter().append("rect").attr("class", "extent").style("cursor", "move");
4520 tz.enter().append("g").attr("class", function(d) {
4521 return "resize " + d;
4522 }).style("cursor", function(d) {
4523 return d3_svg_brushCursor[d];
4524 }).append("rect").attr("x", function(d) {
4525 return /[ew]$/.test(d) ? -3 : null;
4526 }).attr("y", function(d) {
4527 return /^[ns]/.test(d) ? -3 : null;
4528 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
4529 tz.style("display", brush.empty() ? "none" : null);
4532 e = d3_scaleRange(x);
4533 bg.attr("x", e[0]).attr("width", e[1] - e[0]);
4537 e = d3_scaleRange(y);
4538 bg.attr("y", e[0]).attr("height", e[1] - e[0]);
4544 function redraw(g) {
4545 g.selectAll(".resize").attr("transform", function(d) {
4546 return "translate(" + extent[+/e$/.test(d)][0] + "," + extent[+/^s/.test(d)][1] + ")";
4549 function redrawX(g) {
4550 g.select(".extent").attr("x", extent[0][0]);
4551 g.selectAll(".extent,.n>rect,.s>rect").attr("width", extent[1][0] - extent[0][0]);
4553 function redrawY(g) {
4554 g.select(".extent").attr("y", extent[0][1]);
4555 g.selectAll(".extent,.e>rect,.w>rect").attr("height", extent[1][1] - extent[0][1]);
4557 function brushstart() {
4559 var touches = d3.event.changedTouches;
4560 return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
4562 function keydown() {
4563 if (d3.event.keyCode == 32) {
4566 origin[0] -= extent[1][0];
4567 origin[1] -= extent[1][1];
4574 if (d3.event.keyCode == 32 && dragging == 2) {
4575 origin[0] += extent[1][0];
4576 origin[1] += extent[1][1];
4581 function brushmove() {
4582 var point = mouse(), moved = false;
4584 point[0] += offset[0];
4585 point[1] += offset[1];
4588 if (d3.event.altKey) {
4589 if (!center) center = [ (extent[0][0] + extent[1][0]) / 2, (extent[0][1] + extent[1][1]) / 2 ];
4590 origin[0] = extent[+(point[0] < center[0])][0];
4591 origin[1] = extent[+(point[1] < center[1])][1];
4592 } else center = null;
4594 if (resizingX && move1(point, x, 0)) {
4598 if (resizingY && move1(point, y, 1)) {
4606 mode: dragging ? "move" : "resize"
4610 function move1(point, scale, i) {
4611 var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], size = extent[1][i] - extent[0][i], min, max;
4614 r1 -= size + position;
4616 min = Math.max(r0, Math.min(r1, point[i]));
4618 max = (min += position) + size;
4620 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
4621 if (position < min) {
4628 if (extent[0][i] !== min || extent[1][i] !== max) {
4629 extentDomain = null;
4635 function brushend() {
4637 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
4638 d3.select("body").style("cursor", null);
4639 w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null);
4645 var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), center, origin = mouse(), offset;
4646 var w = d3.select(window).on("mousemove.brush", brushmove).on("mouseup.brush", brushend).on("touchmove.brush", brushmove).on("touchend.brush", brushend).on("keydown.brush", keydown).on("keyup.brush", keyup);
4648 origin[0] = extent[0][0] - origin[0];
4649 origin[1] = extent[0][1] - origin[1];
4650 } else if (resizing) {
4651 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
4652 offset = [ extent[1 - ex][0] - origin[0], extent[1 - ey][1] - origin[1] ];
4653 origin[0] = extent[ex][0];
4654 origin[1] = extent[ey][1];
4655 } else if (d3.event.altKey) center = origin.slice();
4656 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
4657 d3.select("body").style("cursor", eventTarget.style("cursor"));
4664 var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, resizes = d3_svg_brushResizes[0], extent = [ [ 0, 0 ], [ 0, 0 ] ], extentDomain;
4665 brush.x = function(z) {
4666 if (!arguments.length) return x;
4668 resizes = d3_svg_brushResizes[!x << 1 | !y];
4671 brush.y = function(z) {
4672 if (!arguments.length) return y;
4674 resizes = d3_svg_brushResizes[!x << 1 | !y];
4677 brush.extent = function(z) {
4678 var x0, x1, y0, y1, t;
4679 if (!arguments.length) {
4680 z = extentDomain || extent;
4682 x0 = z[0][0], x1 = z[1][0];
4683 if (!extentDomain) {
4684 x0 = extent[0][0], x1 = extent[1][0];
4685 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
4686 if (x1 < x0) t = x0, x0 = x1, x1 = t;
4690 y0 = z[0][1], y1 = z[1][1];
4691 if (!extentDomain) {
4692 y0 = extent[0][1], y1 = extent[1][1];
4693 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
4694 if (y1 < y0) t = y0, y0 = y1, y1 = t;
4697 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
4699 extentDomain = [ [ 0, 0 ], [ 0, 0 ] ];
4701 x0 = z[0], x1 = z[1];
4702 if (y) x0 = x0[0], x1 = x1[0];
4703 extentDomain[0][0] = x0, extentDomain[1][0] = x1;
4704 if (x.invert) x0 = x(x0), x1 = x(x1);
4705 if (x1 < x0) t = x0, x0 = x1, x1 = t;
4706 extent[0][0] = x0 | 0, extent[1][0] = x1 | 0;
4709 y0 = z[0], y1 = z[1];
4710 if (x) y0 = y0[1], y1 = y1[1];
4711 extentDomain[0][1] = y0, extentDomain[1][1] = y1;
4712 if (y.invert) y0 = y(y0), y1 = y(y1);
4713 if (y1 < y0) t = y0, y0 = y1, y1 = t;
4714 extent[0][1] = y0 | 0, extent[1][1] = y1 | 0;
4718 brush.clear = function() {
4719 extentDomain = null;
4720 extent[0][0] = extent[0][1] = extent[1][0] = extent[1][1] = 0;
4723 brush.empty = function() {
4724 return x && extent[0][0] === extent[1][0] || y && extent[0][1] === extent[1][1];
4726 return d3.rebind(brush, event, "on");
4728 var d3_svg_brushCursor = {
4738 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
4740 d3.behavior.drag = function() {
4742 this.on("mousedown.drag", mousedown).on("touchstart.drag", mousedown);
4744 function mousedown() {
4746 var p = target.parentNode;
4747 return touchId ? d3.touches(p).filter(function(p) {
4748 return p.identifier === touchId;
4749 })[0] : d3.mouse(p);
4751 function dragmove() {
4752 if (!target.parentNode) return dragend();
4753 var p = point(), dx = p[0] - origin_[0], dy = p[1] - origin_[1];
4759 x: p[0] + offset[0],
4760 y: p[1] + offset[1],
4765 function dragend() {
4771 if (d3.event.target === eventTarget) w.on("click.drag", click, true);
4773 w.on(touchId ? "touchmove.drag-" + touchId : "mousemove.drag", null).on(touchId ? "touchend.drag-" + touchId : "mouseup.drag", null);
4777 w.on("click.drag", null);
4779 var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, touchId = d3.event.touches && d3.event.changedTouches[0].identifier, offset, origin_ = point(), moved = 0;
4780 var w = d3.select(window).on(touchId ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
4782 offset = origin.apply(target, arguments);
4783 offset = [ offset.x - origin_[0], offset.y - origin_[1] ];
4787 if (!touchId) d3_eventCancel();
4792 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null;
4793 drag.origin = function(x) {
4794 if (!arguments.length) return origin;
4798 return d3.rebind(drag, event, "on");
4800 d3.behavior.zoom = function() {
4802 this.on("mousedown.zoom", mousedown).on("mousewheel.zoom", mousewheel).on("mousemove.zoom", mousemove).on("DOMMouseScroll.zoom", mousewheel).on("dblclick.zoom", dblclick).on("touchstart.zoom", touchstart).on("touchmove.zoom", touchmove).on("touchend.zoom", touchstart);
4804 function location(p) {
4805 return [ (p[0] - translate[0]) / scale, (p[1] - translate[1]) / scale ];
4808 return [ l[0] * scale + translate[0], l[1] * scale + translate[1] ];
4810 function scaleTo(s) {
4811 scale = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
4813 function translateTo(p, l) {
4815 translate[0] += p[0] - l[0];
4816 translate[1] += p[1] - l[1];
4818 function dispatch(event) {
4819 if (x1) x1.domain(x0.range().map(function(x) {
4820 return (x - translate[0]) / scale;
4822 if (y1) y1.domain(y0.range().map(function(y) {
4823 return (y - translate[1]) / scale;
4825 d3.event.preventDefault();
4829 translate: translate
4832 function mousedown() {
4833 function mousemove() {
4835 translateTo(d3.mouse(target), l);
4838 function mouseup() {
4839 if (moved) d3_eventCancel();
4840 w.on("mousemove.zoom", null).on("mouseup.zoom", null);
4841 if (moved && d3.event.target === eventTarget) w.on("click.zoom", click, true);
4845 w.on("click.zoom", null);
4847 var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target));
4851 function mousewheel() {
4852 if (!translate0) translate0 = location(d3.mouse(this));
4853 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * scale);
4854 translateTo(d3.mouse(this), translate0);
4855 dispatch(event.of(this, arguments));
4857 function mousemove() {
4860 function dblclick() {
4861 var p = d3.mouse(this), l = location(p);
4862 scaleTo(d3.event.shiftKey ? scale / 2 : scale * 2);
4864 dispatch(event.of(this, arguments));
4866 function touchstart() {
4867 var touches = d3.touches(this), now = Date.now();
4870 touches.forEach(function(t) {
4871 translate0[t.identifier] = location(t);
4874 if (touches.length === 1) {
4875 if (now - touchtime < 500) {
4876 var p = touches[0], l = location(touches[0]);
4879 dispatch(event.of(this, arguments));
4884 function touchmove() {
4885 var touches = d3.touches(this), p0 = touches[0], l0 = translate0[p0.identifier];
4886 if (p1 = touches[1]) {
4887 var p1, l1 = translate0[p1.identifier];
4888 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
4889 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
4890 scaleTo(d3.event.scale * scale0);
4892 translateTo(p0, l0);
4894 dispatch(event.of(this, arguments));
4896 var translate = [ 0, 0 ], translate0, scale = 1, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
4897 zoom.translate = function(x) {
4898 if (!arguments.length) return translate;
4899 translate = x.map(Number);
4902 zoom.scale = function(x) {
4903 if (!arguments.length) return scale;
4907 zoom.scaleExtent = function(x) {
4908 if (!arguments.length) return scaleExtent;
4909 scaleExtent = x == null ? d3_behavior_zoomInfinity : x.map(Number);
4912 zoom.x = function(z) {
4913 if (!arguments.length) return x1;
4918 zoom.y = function(z) {
4919 if (!arguments.length) return y1;
4924 return d3.rebind(zoom, event, "on");
4926 var d3_behavior_zoomDiv, d3_behavior_zoomInfinity = [ 0, Infinity ];
4928 d3.layout.bundle = function() {
4929 return function(links) {
4930 var paths = [], i = -1, n = links.length;
4931 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
4935 d3.layout.chord = function() {
4936 function relayout() {
4937 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
4947 subgroupIndex.push(d3.range(n));
4951 groupIndex.sort(function(a, b) {
4952 return sortGroups(groupSums[a], groupSums[b]);
4955 if (sortSubgroups) {
4956 subgroupIndex.forEach(function(d, i) {
4957 d.sort(function(a, b) {
4958 return sortSubgroups(matrix[i][a], matrix[i][b]);
4962 k = (2 * Math.PI - padding * n) / k;
4967 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
4968 subgroups[di + "-" + dj] = {
4988 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
4989 if (source.value || target.value) {
4990 chords.push(source.value < target.value ? {
5000 if (sortChords) resort();
5003 chords.sort(function(a, b) {
5004 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
5007 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
5008 chord.matrix = function(x) {
5009 if (!arguments.length) return matrix;
5010 n = (matrix = x) && matrix.length;
5011 chords = groups = null;
5014 chord.padding = function(x) {
5015 if (!arguments.length) return padding;
5017 chords = groups = null;
5020 chord.sortGroups = function(x) {
5021 if (!arguments.length) return sortGroups;
5023 chords = groups = null;
5026 chord.sortSubgroups = function(x) {
5027 if (!arguments.length) return sortSubgroups;
5032 chord.sortChords = function(x) {
5033 if (!arguments.length) return sortChords;
5035 if (chords) resort();
5038 chord.chords = function() {
5039 if (!chords) relayout();
5042 chord.groups = function() {
5043 if (!groups) relayout();
5048 d3.layout.force = function() {
5049 function repulse(node) {
5050 return function(quad, x1, y1, x2, y2) {
5051 if (quad.point !== node) {
5052 var dx = quad.cx - node.x, dy = quad.cy - node.y, dn = 1 / Math.sqrt(dx * dx + dy * dy);
5053 if ((x2 - x1) * dn < theta) {
5054 var k = quad.charge * dn * dn;
5059 if (quad.point && isFinite(dn)) {
5060 var k = quad.pointCharge * dn * dn;
5065 return !quad.charge;
5068 function dragmove(d) {
5073 var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, gravity = .1, theta = .8, interval, nodes = [], links = [], distances, strengths, charges;
5074 force.tick = function() {
5075 if ((alpha *= .99) < .005) {
5082 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
5083 for (i = 0; i < m; ++i) {
5089 if (l = x * x + y * y) {
5090 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
5093 t.x -= x * (k = s.weight / (t.weight + s.weight));
5095 s.x += x * (k = 1 - k);
5099 if (k = alpha * gravity) {
5103 if (k) while (++i < n) {
5105 o.x += (x - o.x) * k;
5106 o.y += (y - o.y) * k;
5110 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
5113 if (!(o = nodes[i]).fixed) {
5114 q.visit(repulse(o));
5125 o.x -= (o.px - (o.px = o.x)) * friction;
5126 o.y -= (o.py - (o.py = o.y)) * friction;
5134 force.nodes = function(x) {
5135 if (!arguments.length) return nodes;
5139 force.links = function(x) {
5140 if (!arguments.length) return links;
5144 force.size = function(x) {
5145 if (!arguments.length) return size;
5149 force.linkDistance = function(x) {
5150 if (!arguments.length) return linkDistance;
5151 linkDistance = d3_functor(x);
5154 force.distance = force.linkDistance;
5155 force.linkStrength = function(x) {
5156 if (!arguments.length) return linkStrength;
5157 linkStrength = d3_functor(x);
5160 force.friction = function(x) {
5161 if (!arguments.length) return friction;
5165 force.charge = function(x) {
5166 if (!arguments.length) return charge;
5167 charge = typeof x === "function" ? x : +x;
5170 force.gravity = function(x) {
5171 if (!arguments.length) return gravity;
5175 force.theta = function(x) {
5176 if (!arguments.length) return theta;
5180 force.alpha = function(x) {
5181 if (!arguments.length) return alpha;
5183 if (x > 0) alpha = x; else alpha = 0;
5189 d3.timer(force.tick);
5193 force.start = function() {
5194 function position(dimension, size) {
5195 var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
5196 while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
5197 return Math.random() * size;
5199 function neighbor() {
5202 for (j = 0; j < n; ++j) {
5205 for (j = 0; j < m; ++j) {
5207 neighbors[o.source.index].push(o.target);
5208 neighbors[o.target.index].push(o.source);
5211 return neighbors[i];
5213 var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
5214 for (i = 0; i < n; ++i) {
5215 (o = nodes[i]).index = i;
5220 for (i = 0; i < m; ++i) {
5222 if (typeof o.source == "number") o.source = nodes[o.source];
5223 if (typeof o.target == "number") o.target = nodes[o.target];
5224 distances[i] = linkDistance.call(this, o, i);
5225 strengths[i] = linkStrength.call(this, o, i);
5229 for (i = 0; i < n; ++i) {
5231 if (isNaN(o.x)) o.x = position("x", w);
5232 if (isNaN(o.y)) o.y = position("y", h);
5233 if (isNaN(o.px)) o.px = o.x;
5234 if (isNaN(o.py)) o.py = o.y;
5237 if (typeof charge === "function") {
5238 for (i = 0; i < n; ++i) {
5239 charges[i] = +charge.call(this, nodes[i], i);
5242 for (i = 0; i < n; ++i) {
5243 charges[i] = charge;
5246 return force.resume();
5248 force.resume = function() {
5249 return force.alpha(.1);
5251 force.stop = function() {
5252 return force.alpha(0);
5254 force.drag = function() {
5255 if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart", d3_layout_forceDragstart).on("drag", dragmove).on("dragend", d3_layout_forceDragend);
5256 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
5258 return d3.rebind(force, event, "on");
5260 d3.layout.partition = function() {
5261 function position(node, x, dx, dy) {
5262 var children = node.children;
5264 node.y = node.depth * dy;
5267 if (children && (n = children.length)) {
5268 var i = -1, n, c, d;
5269 dx = node.value ? dx / node.value : 0;
5271 position(c = children[i], x, d = c.value * dx, dy);
5276 function depth(node) {
5277 var children = node.children, d = 0;
5278 if (children && (n = children.length)) {
5280 while (++i < n) d = Math.max(d, depth(children[i]));
5284 function partition(d, i) {
5285 var nodes = hierarchy.call(this, d, i);
5286 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
5289 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
5290 partition.size = function(x) {
5291 if (!arguments.length) return size;
5295 return d3_layout_hierarchyRebind(partition, hierarchy);
5297 d3.layout.pie = function() {
5298 function pie(data, i) {
5299 var values = data.map(function(d, i) {
5300 return +value.call(pie, d, i);
5302 var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
5303 var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - startAngle) / d3.sum(values);
5304 var index = d3.range(data.length);
5305 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
5306 return values[j] - values[i];
5307 } : function(i, j) {
5308 return sort(data[i], data[j]);
5311 index.forEach(function(i) {
5315 value: d = values[i],
5317 endAngle: a += d * k
5322 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = 2 * Math.PI;
5323 pie.value = function(x) {
5324 if (!arguments.length) return value;
5328 pie.sort = function(x) {
5329 if (!arguments.length) return sort;
5333 pie.startAngle = function(x) {
5334 if (!arguments.length) return startAngle;
5338 pie.endAngle = function(x) {
5339 if (!arguments.length) return endAngle;
5345 var d3_layout_pieSortByValue = {};
5346 d3.layout.stack = function() {
5347 function stack(data, index) {
5348 var series = data.map(function(d, i) {
5349 return values.call(stack, d, i);
5351 var points = series.map(function(d, i) {
5352 return d.map(function(v, i) {
5353 return [ x.call(stack, v, i), y.call(stack, v, i) ];
5356 var orders = order.call(stack, points, index);
5357 series = d3.permute(series, orders);
5358 points = d3.permute(points, orders);
5359 var offsets = offset.call(stack, points, index);
5360 var n = series.length, m = series[0].length, i, j, o;
5361 for (j = 0; j < m; ++j) {
5362 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
5363 for (i = 1; i < n; ++i) {
5364 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
5369 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
5370 stack.values = function(x) {
5371 if (!arguments.length) return values;
5375 stack.order = function(x) {
5376 if (!arguments.length) return order;
5377 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
5380 stack.offset = function(x) {
5381 if (!arguments.length) return offset;
5382 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
5385 stack.x = function(z) {
5386 if (!arguments.length) return x;
5390 stack.y = function(z) {
5391 if (!arguments.length) return y;
5395 stack.out = function(z) {
5396 if (!arguments.length) return out;
5402 var d3_layout_stackOrders = d3.map({
5403 "inside-out": function(data) {
5404 var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
5405 return max[a] - max[b];
5406 }), top = 0, bottom = 0, tops = [], bottoms = [];
5407 for (i = 0; i < n; ++i) {
5417 return bottoms.reverse().concat(tops);
5419 reverse: function(data) {
5420 return d3.range(data.length).reverse();
5422 "default": d3_layout_stackOrderDefault
5424 var d3_layout_stackOffsets = d3.map({
5425 silhouette: function(data) {
5426 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
5427 for (j = 0; j < m; ++j) {
5428 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
5429 if (o > max) max = o;
5432 for (j = 0; j < m; ++j) {
5433 y0[j] = (max - sums[j]) / 2;
5437 wiggle: function(data) {
5438 var n = data.length, x = data[0], m = x.length, max = 0, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
5440 for (j = 1; j < m; ++j) {
5441 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
5442 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
5443 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
5444 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
5446 s2 += s3 * data[i][j][1];
5448 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
5451 for (j = 0; j < m; ++j) y0[j] -= o0;
5454 expand: function(data) {
5455 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
5456 for (j = 0; j < m; ++j) {
5457 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
5458 if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
5460 for (j = 0; j < m; ++j) y0[j] = 0;
5463 zero: d3_layout_stackOffsetZero
5465 d3.layout.histogram = function() {
5466 function histogram(data, i) {
5467 var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
5470 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
5477 if (x >= range[0] && x <= range[1]) {
5478 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
5486 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
5487 histogram.value = function(x) {
5488 if (!arguments.length) return valuer;
5492 histogram.range = function(x) {
5493 if (!arguments.length) return ranger;
5494 ranger = d3_functor(x);
5497 histogram.bins = function(x) {
5498 if (!arguments.length) return binner;
5499 binner = typeof x === "number" ? function(range) {
5500 return d3_layout_histogramBinFixed(range, x);
5504 histogram.frequency = function(x) {
5505 if (!arguments.length) return frequency;
5511 d3.layout.hierarchy = function() {
5512 function recurse(data, depth, nodes) {
5513 var childs = children.call(hierarchy, data, depth), node = d3_layout_hierarchyInline ? data : {
5518 if (childs && (n = childs.length)) {
5519 var i = -1, n, c = node.children = [], v = 0, j = depth + 1, d;
5521 d = recurse(childs[i], j, nodes);
5526 if (sort) c.sort(sort);
5527 if (value) node.value = v;
5529 node.value = +value.call(hierarchy, data, depth) || 0;
5533 function revalue(node, depth) {
5534 var children = node.children, v = 0;
5535 if (children && (n = children.length)) {
5536 var i = -1, n, j = depth + 1;
5537 while (++i < n) v += revalue(children[i], j);
5539 v = +value.call(hierarchy, d3_layout_hierarchyInline ? node : node.data, depth) || 0;
5541 if (value) node.value = v;
5544 function hierarchy(d) {
5546 recurse(d, 0, nodes);
5549 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
5550 hierarchy.sort = function(x) {
5551 if (!arguments.length) return sort;
5555 hierarchy.children = function(x) {
5556 if (!arguments.length) return children;
5560 hierarchy.value = function(x) {
5561 if (!arguments.length) return value;
5565 hierarchy.revalue = function(root) {
5571 var d3_layout_hierarchyInline = false;
5572 d3.layout.pack = function() {
5573 function pack(d, i) {
5574 var nodes = hierarchy.call(this, d, i), root = nodes[0];
5577 d3_layout_treeVisitAfter(root, function(d) {
5578 d.r = Math.sqrt(d.value);
5580 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
5581 var w = size[0], h = size[1], k = Math.max(2 * root.r / w, 2 * root.r / h);
5583 var dr = padding * k / 2;
5584 d3_layout_treeVisitAfter(root, function(d) {
5587 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
5588 d3_layout_treeVisitAfter(root, function(d) {
5591 k = Math.max(2 * root.r / w, 2 * root.r / h);
5593 d3_layout_packTransform(root, w / 2, h / 2, 1 / k);
5596 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ];
5597 pack.size = function(x) {
5598 if (!arguments.length) return size;
5602 pack.padding = function(_) {
5603 if (!arguments.length) return padding;
5607 return d3_layout_hierarchyRebind(pack, hierarchy);
5609 d3.layout.cluster = function() {
5610 function cluster(d, i) {
5611 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0, kx, ky;
5612 d3_layout_treeVisitAfter(root, function(node) {
5613 var children = node.children;
5614 if (children && children.length) {
5615 node.x = d3_layout_clusterX(children);
5616 node.y = d3_layout_clusterY(children);
5618 node.x = previousNode ? x += separation(node, previousNode) : 0;
5620 previousNode = node;
5623 var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
5624 d3_layout_treeVisitAfter(root, function(node) {
5625 node.x = (node.x - x0) / (x1 - x0) * size[0];
5626 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
5630 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
5631 cluster.separation = function(x) {
5632 if (!arguments.length) return separation;
5636 cluster.size = function(x) {
5637 if (!arguments.length) return size;
5641 return d3_layout_hierarchyRebind(cluster, hierarchy);
5643 d3.layout.tree = function() {
5644 function tree(d, i) {
5645 function firstWalk(node, previousSibling) {
5646 var children = node.children, layout = node._tree;
5647 if (children && (n = children.length)) {
5648 var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
5650 child = children[i];
5651 firstWalk(child, previousChild);
5652 ancestor = apportion(child, previousChild, ancestor);
5653 previousChild = child;
5655 d3_layout_treeShift(node);
5656 var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
5657 if (previousSibling) {
5658 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5659 layout.mod = layout.prelim - midpoint;
5661 layout.prelim = midpoint;
5664 if (previousSibling) {
5665 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5669 function secondWalk(node, x) {
5670 node.x = node._tree.prelim + x;
5671 var children = node.children;
5672 if (children && (n = children.length)) {
5674 x += node._tree.mod;
5676 secondWalk(children[i], x);
5680 function apportion(node, previousSibling, ancestor) {
5681 if (previousSibling) {
5682 var vip = node, vop = node, vim = previousSibling, vom = node.parent.children[0], sip = vip._tree.mod, sop = vop._tree.mod, sim = vim._tree.mod, som = vom._tree.mod, shift;
5683 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
5684 vom = d3_layout_treeLeft(vom);
5685 vop = d3_layout_treeRight(vop);
5686 vop._tree.ancestor = node;
5687 shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
5689 d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
5693 sim += vim._tree.mod;
5694 sip += vip._tree.mod;
5695 som += vom._tree.mod;
5696 sop += vop._tree.mod;
5698 if (vim && !d3_layout_treeRight(vop)) {
5699 vop._tree.thread = vim;
5700 vop._tree.mod += sim - sop;
5702 if (vip && !d3_layout_treeLeft(vom)) {
5703 vom._tree.thread = vip;
5704 vom._tree.mod += sip - som;
5710 var nodes = hierarchy.call(this, d, i), root = nodes[0];
5711 d3_layout_treeVisitAfter(root, function(node, previousSibling) {
5718 number: previousSibling ? previousSibling._tree.number + 1 : 0
5722 secondWalk(root, -root._tree.prelim);
5723 var left = d3_layout_treeSearch(root, d3_layout_treeLeftmost), right = d3_layout_treeSearch(root, d3_layout_treeRightmost), deep = d3_layout_treeSearch(root, d3_layout_treeDeepest), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2, y1 = deep.depth || 1;
5724 d3_layout_treeVisitAfter(root, function(node) {
5725 node.x = (node.x - x0) / (x1 - x0) * size[0];
5726 node.y = node.depth / y1 * size[1];
5731 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
5732 tree.separation = function(x) {
5733 if (!arguments.length) return separation;
5737 tree.size = function(x) {
5738 if (!arguments.length) return size;
5742 return d3_layout_hierarchyRebind(tree, hierarchy);
5744 d3.layout.treemap = function() {
5745 function scale(children, k) {
5746 var i = -1, n = children.length, child, area;
5748 area = (child = children[i]).value * (k < 0 ? 0 : k);
5749 child.area = isNaN(area) || area <= 0 ? 0 : area;
5752 function squarify(node) {
5753 var children = node.children;
5754 if (children && children.length) {
5755 var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = Math.min(rect.dx, rect.dy), n;
5756 scale(remaining, rect.dx * rect.dy / node.value);
5758 while ((n = remaining.length) > 0) {
5759 row.push(child = remaining[n - 1]);
5760 row.area += child.area;
5761 if ((score = worst(row, u)) <= best) {
5765 row.area -= row.pop().area;
5766 position(row, u, rect, false);
5767 u = Math.min(rect.dx, rect.dy);
5768 row.length = row.area = 0;
5773 position(row, u, rect, true);
5774 row.length = row.area = 0;
5776 children.forEach(squarify);
5779 function stickify(node) {
5780 var children = node.children;
5781 if (children && children.length) {
5782 var rect = pad(node), remaining = children.slice(), child, row = [];
5783 scale(remaining, rect.dx * rect.dy / node.value);
5785 while (child = remaining.pop()) {
5787 row.area += child.area;
5788 if (child.z != null) {
5789 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
5790 row.length = row.area = 0;
5793 children.forEach(stickify);
5796 function worst(row, u) {
5797 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
5799 if (!(r = row[i].area)) continue;
5800 if (r < rmin) rmin = r;
5801 if (r > rmax) rmax = r;
5805 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
5807 function position(row, u, rect, flush) {
5808 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
5810 if (flush || v > rect.dy) v = rect.dy;
5816 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
5819 o.dx += rect.x + rect.dx - x;
5823 if (flush || v > rect.dx) v = rect.dx;
5829 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
5832 o.dy += rect.y + rect.dy - y;
5837 function treemap(d) {
5838 var nodes = stickies || hierarchy(d), root = nodes[0];
5843 if (stickies) hierarchy.revalue(root);
5844 scale([ root ], root.dx * root.dy / root.value);
5845 (stickies ? stickify : squarify)(root);
5846 if (sticky) stickies = nodes;
5849 var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, ratio = .5 * (1 + Math.sqrt(5));
5850 treemap.size = function(x) {
5851 if (!arguments.length) return size;
5855 treemap.padding = function(x) {
5856 function padFunction(node) {
5857 var p = x.call(treemap, node, node.depth);
5858 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
5860 function padConstant(node) {
5861 return d3_layout_treemapPad(node, x);
5863 if (!arguments.length) return padding;
5865 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ], padConstant) : padConstant;
5868 treemap.round = function(x) {
5869 if (!arguments.length) return round != Number;
5870 round = x ? Math.round : Number;
5873 treemap.sticky = function(x) {
5874 if (!arguments.length) return sticky;
5879 treemap.ratio = function(x) {
5880 if (!arguments.length) return ratio;
5884 return d3_layout_hierarchyRebind(treemap, hierarchy);
5886 d3.csv = d3_dsv(",", "text/csv");
5887 d3.tsv = d3_dsv(" ", "text/tab-separated-values");
5889 var d3_geo_radians = Math.PI / 180;
5890 d3.geo.azimuthal = function() {
5891 function azimuthal(coordinates) {
5892 var x1 = coordinates[0] * d3_geo_radians - x0, y1 = coordinates[1] * d3_geo_radians, cx1 = Math.cos(x1), sx1 = Math.sin(x1), cy1 = Math.cos(y1), sy1 = Math.sin(y1), cc = mode !== "orthographic" ? sy0 * sy1 + cy0 * cy1 * cx1 : null, c, k = mode === "stereographic" ? 1 / (1 + cc) : mode === "gnomonic" ? 1 / cc : mode === "equidistant" ? (c = Math.acos(cc), c ? c / Math.sin(c) : 0) : mode === "equalarea" ? Math.sqrt(2 / (1 + cc)) : 1, x = k * cy1 * sx1, y = k * (sy0 * cy1 * cx1 - cy0 * sy1);
5893 return [ scale * x + translate[0], scale * y + translate[1] ];
5895 var mode = "orthographic", origin, scale = 200, translate = [ 480, 250 ], x0, y0, cy0, sy0;
5896 azimuthal.invert = function(coordinates) {
5897 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale, p = Math.sqrt(x * x + y * y), c = mode === "stereographic" ? 2 * Math.atan(p) : mode === "gnomonic" ? Math.atan(p) : mode === "equidistant" ? p : mode === "equalarea" ? 2 * Math.asin(.5 * p) : Math.asin(p), sc = Math.sin(c), cc = Math.cos(c);
5898 return [ (x0 + Math.atan2(x * sc, p * cy0 * cc + y * sy0 * sc)) / d3_geo_radians, Math.asin(cc * sy0 - (p ? y * sc * cy0 / p : 0)) / d3_geo_radians ];
5900 azimuthal.mode = function(x) {
5901 if (!arguments.length) return mode;
5905 azimuthal.origin = function(x) {
5906 if (!arguments.length) return origin;
5908 x0 = origin[0] * d3_geo_radians;
5909 y0 = origin[1] * d3_geo_radians;
5914 azimuthal.scale = function(x) {
5915 if (!arguments.length) return scale;
5919 azimuthal.translate = function(x) {
5920 if (!arguments.length) return translate;
5921 translate = [ +x[0], +x[1] ];
5924 return azimuthal.origin([ 0, 0 ]);
5926 d3.geo.albers = function() {
5927 function albers(coordinates) {
5928 var t = n * (d3_geo_radians * coordinates[0] - lng0), p = Math.sqrt(C - 2 * n * Math.sin(d3_geo_radians * coordinates[1])) / n;
5929 return [ scale * p * Math.sin(t) + translate[0], scale * (p * Math.cos(t) - p0) + translate[1] ];
5932 var phi1 = d3_geo_radians * parallels[0], phi2 = d3_geo_radians * parallels[1], lat0 = d3_geo_radians * origin[1], s = Math.sin(phi1), c = Math.cos(phi1);
5933 lng0 = d3_geo_radians * origin[0];
5934 n = .5 * (s + Math.sin(phi2));
5935 C = c * c + 2 * n * s;
5936 p0 = Math.sqrt(C - 2 * n * Math.sin(lat0)) / n;
5939 var origin = [ -98, 38 ], parallels = [ 29.5, 45.5 ], scale = 1e3, translate = [ 480, 250 ], lng0, n, C, p0;
5940 albers.invert = function(coordinates) {
5941 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale, p0y = p0 + y, t = Math.atan2(x, p0y), p = Math.sqrt(x * x + p0y * p0y);
5942 return [ (lng0 + t / n) / d3_geo_radians, Math.asin((C - p * p * n * n) / (2 * n)) / d3_geo_radians ];
5944 albers.origin = function(x) {
5945 if (!arguments.length) return origin;
5946 origin = [ +x[0], +x[1] ];
5949 albers.parallels = function(x) {
5950 if (!arguments.length) return parallels;
5951 parallels = [ +x[0], +x[1] ];
5954 albers.scale = function(x) {
5955 if (!arguments.length) return scale;
5959 albers.translate = function(x) {
5960 if (!arguments.length) return translate;
5961 translate = [ +x[0], +x[1] ];
5966 d3.geo.albersUsa = function() {
5967 function albersUsa(coordinates) {
5968 var lon = coordinates[0], lat = coordinates[1];
5969 return (lat > 50 ? alaska : lon < -140 ? hawaii : lat < 21 ? puertoRico : lower48)(coordinates);
5971 var lower48 = d3.geo.albers();
5972 var alaska = d3.geo.albers().origin([ -160, 60 ]).parallels([ 55, 65 ]);
5973 var hawaii = d3.geo.albers().origin([ -160, 20 ]).parallels([ 8, 18 ]);
5974 var puertoRico = d3.geo.albers().origin([ -60, 10 ]).parallels([ 8, 18 ]);
5975 albersUsa.scale = function(x) {
5976 if (!arguments.length) return lower48.scale();
5978 alaska.scale(x * .6);
5980 puertoRico.scale(x * 1.5);
5981 return albersUsa.translate(lower48.translate());
5983 albersUsa.translate = function(x) {
5984 if (!arguments.length) return lower48.translate();
5985 var dz = lower48.scale() / 1e3, dx = x[0], dy = x[1];
5986 lower48.translate(x);
5987 alaska.translate([ dx - 400 * dz, dy + 170 * dz ]);
5988 hawaii.translate([ dx - 190 * dz, dy + 200 * dz ]);
5989 puertoRico.translate([ dx + 580 * dz, dy + 430 * dz ]);
5992 return albersUsa.scale(lower48.scale());
5994 d3.geo.bonne = function() {
5995 function bonne(coordinates) {
5996 var x = coordinates[0] * d3_geo_radians - x0, y = coordinates[1] * d3_geo_radians - y0;
5998 var p = c1 + y1 - y, E = x * Math.cos(y) / p;
5999 x = p * Math.sin(E);
6000 y = p * Math.cos(E) - c1;
6005 return [ scale * x + translate[0], scale * y + translate[1] ];
6007 var scale = 200, translate = [ 480, 250 ], x0, y0, y1, c1;
6008 bonne.invert = function(coordinates) {
6009 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale;
6011 var c = c1 + y, p = Math.sqrt(x * x + c * c);
6013 x = x0 + p * Math.atan2(x, c) / Math.cos(y);
6018 return [ x / d3_geo_radians, y / d3_geo_radians ];
6020 bonne.parallel = function(x) {
6021 if (!arguments.length) return y1 / d3_geo_radians;
6022 c1 = 1 / Math.tan(y1 = x * d3_geo_radians);
6025 bonne.origin = function(x) {
6026 if (!arguments.length) return [ x0 / d3_geo_radians, y0 / d3_geo_radians ];
6027 x0 = x[0] * d3_geo_radians;
6028 y0 = x[1] * d3_geo_radians;
6031 bonne.scale = function(x) {
6032 if (!arguments.length) return scale;
6036 bonne.translate = function(x) {
6037 if (!arguments.length) return translate;
6038 translate = [ +x[0], +x[1] ];
6041 return bonne.origin([ 0, 0 ]).parallel(45);
6043 d3.geo.equirectangular = function() {
6044 function equirectangular(coordinates) {
6045 var x = coordinates[0] / 360, y = -coordinates[1] / 360;
6046 return [ scale * x + translate[0], scale * y + translate[1] ];
6048 var scale = 500, translate = [ 480, 250 ];
6049 equirectangular.invert = function(coordinates) {
6050 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale;
6051 return [ 360 * x, -360 * y ];
6053 equirectangular.scale = function(x) {
6054 if (!arguments.length) return scale;
6056 return equirectangular;
6058 equirectangular.translate = function(x) {
6059 if (!arguments.length) return translate;
6060 translate = [ +x[0], +x[1] ];
6061 return equirectangular;
6063 return equirectangular;
6065 d3.geo.mercator = function() {
6066 function mercator(coordinates) {
6067 var x = coordinates[0] / 360, y = -(Math.log(Math.tan(Math.PI / 4 + coordinates[1] * d3_geo_radians / 2)) / d3_geo_radians) / 360;
6068 return [ scale * x + translate[0], scale * Math.max(-.5, Math.min(.5, y)) + translate[1] ];
6070 var scale = 500, translate = [ 480, 250 ];
6071 mercator.invert = function(coordinates) {
6072 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale;
6073 return [ 360 * x, 2 * Math.atan(Math.exp(-360 * y * d3_geo_radians)) / d3_geo_radians - 90 ];
6075 mercator.scale = function(x) {
6076 if (!arguments.length) return scale;
6080 mercator.translate = function(x) {
6081 if (!arguments.length) return translate;
6082 translate = [ +x[0], +x[1] ];
6087 d3.geo.path = function() {
6088 function path(d, i) {
6089 if (typeof pointRadius === "function") pointCircle = d3_path_circle(pointRadius.apply(this, arguments));
6091 var result = buffer.length ? buffer.join("") : null;
6095 function project(coordinates) {
6096 return projection(coordinates).join(",");
6098 function polygonArea(coordinates) {
6099 var sum = area(coordinates[0]), i = 0, n = coordinates.length;
6100 while (++i < n) sum -= area(coordinates[i]);
6103 function polygonCentroid(coordinates) {
6104 var polygon = d3.geom.polygon(coordinates[0].map(projection)), area = polygon.area(), centroid = polygon.centroid(area < 0 ? (area *= -1, 1) : -1), x = centroid[0], y = centroid[1], z = area, i = 0, n = coordinates.length;
6106 polygon = d3.geom.polygon(coordinates[i].map(projection));
6107 area = polygon.area();
6108 centroid = polygon.centroid(area < 0 ? (area *= -1, 1) : -1);
6113 return [ x, y, 6 * z ];
6115 function area(coordinates) {
6116 return Math.abs(d3.geom.polygon(coordinates.map(projection)).area());
6118 var pointRadius = 4.5, pointCircle = d3_path_circle(pointRadius), projection = d3.geo.albersUsa(), buffer = [];
6119 var pathType = d3_geo_type({
6120 FeatureCollection: function(o) {
6121 var features = o.features, i = -1, n = features.length;
6122 while (++i < n) buffer.push(pathType(features[i].geometry));
6124 Feature: function(o) {
6125 pathType(o.geometry);
6127 Point: function(o) {
6128 buffer.push("M", project(o.coordinates), pointCircle);
6130 MultiPoint: function(o) {
6131 var coordinates = o.coordinates, i = -1, n = coordinates.length;
6132 while (++i < n) buffer.push("M", project(coordinates[i]), pointCircle);
6134 LineString: function(o) {
6135 var coordinates = o.coordinates, i = -1, n = coordinates.length;
6137 while (++i < n) buffer.push(project(coordinates[i]), "L");
6140 MultiLineString: function(o) {
6141 var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m;
6143 subcoordinates = coordinates[i];
6145 m = subcoordinates.length;
6147 while (++j < m) buffer.push(project(subcoordinates[j]), "L");
6151 Polygon: function(o) {
6152 var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m;
6154 subcoordinates = coordinates[i];
6156 if ((m = subcoordinates.length - 1) > 0) {
6158 while (++j < m) buffer.push(project(subcoordinates[j]), "L");
6159 buffer[buffer.length - 1] = "Z";
6163 MultiPolygon: function(o) {
6164 var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m, subsubcoordinates, k, p;
6166 subcoordinates = coordinates[i];
6168 m = subcoordinates.length;
6170 subsubcoordinates = subcoordinates[j];
6172 if ((p = subsubcoordinates.length - 1) > 0) {
6174 while (++k < p) buffer.push(project(subsubcoordinates[k]), "L");
6175 buffer[buffer.length - 1] = "Z";
6180 GeometryCollection: function(o) {
6181 var geometries = o.geometries, i = -1, n = geometries.length;
6182 while (++i < n) buffer.push(pathType(geometries[i]));
6185 var areaType = path.area = d3_geo_type({
6186 FeatureCollection: function(o) {
6187 var area = 0, features = o.features, i = -1, n = features.length;
6188 while (++i < n) area += areaType(features[i]);
6191 Feature: function(o) {
6192 return areaType(o.geometry);
6194 Polygon: function(o) {
6195 return polygonArea(o.coordinates);
6197 MultiPolygon: function(o) {
6198 var sum = 0, coordinates = o.coordinates, i = -1, n = coordinates.length;
6199 while (++i < n) sum += polygonArea(coordinates[i]);
6202 GeometryCollection: function(o) {
6203 var sum = 0, geometries = o.geometries, i = -1, n = geometries.length;
6204 while (++i < n) sum += areaType(geometries[i]);
6208 var centroidType = path.centroid = d3_geo_type({
6209 Feature: function(o) {
6210 return centroidType(o.geometry);
6212 Polygon: function(o) {
6213 var centroid = polygonCentroid(o.coordinates);
6214 return [ centroid[0] / centroid[2], centroid[1] / centroid[2] ];
6216 MultiPolygon: function(o) {
6217 var area = 0, coordinates = o.coordinates, centroid, x = 0, y = 0, z = 0, i = -1, n = coordinates.length;
6219 centroid = polygonCentroid(coordinates[i]);
6224 return [ x / z, y / z ];
6227 path.projection = function(x) {
6231 path.pointRadius = function(x) {
6232 if (typeof x === "function") pointRadius = x; else {
6234 pointCircle = d3_path_circle(pointRadius);
6240 d3.geo.bounds = function(feature) {
6241 var left = Infinity, bottom = Infinity, right = -Infinity, top = -Infinity;
6242 d3_geo_bounds(feature, function(x, y) {
6243 if (x < left) left = x;
6244 if (x > right) right = x;
6245 if (y < bottom) bottom = y;
6246 if (y > top) top = y;
6248 return [ [ left, bottom ], [ right, top ] ];
6250 var d3_geo_boundsTypes = {
6251 Feature: d3_geo_boundsFeature,
6252 FeatureCollection: d3_geo_boundsFeatureCollection,
6253 GeometryCollection: d3_geo_boundsGeometryCollection,
6254 LineString: d3_geo_boundsLineString,
6255 MultiLineString: d3_geo_boundsMultiLineString,
6256 MultiPoint: d3_geo_boundsLineString,
6257 MultiPolygon: d3_geo_boundsMultiPolygon,
6258 Point: d3_geo_boundsPoint,
6259 Polygon: d3_geo_boundsPolygon
6261 d3.geo.circle = function() {
6262 function circle() {}
6263 function visible(point) {
6264 return arc.distance(point) < radians;
6266 function clip(coordinates) {
6267 var i = -1, n = coordinates.length, clipped = [], p0, p1, p2, d0, d1;
6269 d1 = arc.distance(p2 = coordinates[i]);
6271 if (p1) clipped.push(d3_geo_greatArcInterpolate(p1, p2)((d0 - radians) / (d0 - d1)));
6276 if (!p0 && clipped.length) {
6277 clipped.push(d3_geo_greatArcInterpolate(clipped[clipped.length - 1], p1)((radians - d0) / (d1 - d0)));
6283 p0 = coordinates[0];
6285 if (p1 && p2[0] === p0[0] && p2[1] === p0[1] && !(p2[0] === p1[0] && p2[1] === p1[1])) {
6288 return resample(clipped);
6290 function resample(coordinates) {
6291 var i = 0, n = coordinates.length, j, m, resampled = n ? [ coordinates[0] ] : coordinates, resamples, origin = arc.source();
6293 resamples = arc.source(coordinates[i - 1])(coordinates[i]).coordinates;
6294 for (j = 0, m = resamples.length; ++j < m; ) resampled.push(resamples[j]);
6299 var origin = [ 0, 0 ], degrees = 90 - .01, radians = degrees * d3_geo_radians, arc = d3.geo.greatArc().source(origin).target(d3_identity);
6300 circle.clip = function(d) {
6301 if (typeof origin === "function") arc.source(origin.apply(this, arguments));
6302 return clipType(d) || null;
6304 var clipType = d3_geo_type({
6305 FeatureCollection: function(o) {
6306 var features = o.features.map(clipType).filter(d3_identity);
6307 return features && (o = Object.create(o), o.features = features, o);
6309 Feature: function(o) {
6310 var geometry = clipType(o.geometry);
6311 return geometry && (o = Object.create(o), o.geometry = geometry, o);
6313 Point: function(o) {
6314 return visible(o.coordinates) && o;
6316 MultiPoint: function(o) {
6317 var coordinates = o.coordinates.filter(visible);
6318 return coordinates.length && {
6320 coordinates: coordinates
6323 LineString: function(o) {
6324 var coordinates = clip(o.coordinates);
6325 return coordinates.length && (o = Object.create(o), o.coordinates = coordinates, o);
6327 MultiLineString: function(o) {
6328 var coordinates = o.coordinates.map(clip).filter(function(d) {
6331 return coordinates.length && (o = Object.create(o), o.coordinates = coordinates, o);
6333 Polygon: function(o) {
6334 var coordinates = o.coordinates.map(clip);
6335 return coordinates[0].length && (o = Object.create(o), o.coordinates = coordinates, o);
6337 MultiPolygon: function(o) {
6338 var coordinates = o.coordinates.map(function(d) {
6340 }).filter(function(d) {
6343 return coordinates.length && (o = Object.create(o), o.coordinates = coordinates, o);
6345 GeometryCollection: function(o) {
6346 var geometries = o.geometries.map(clipType).filter(d3_identity);
6347 return geometries.length && (o = Object.create(o), o.geometries = geometries, o);
6350 circle.origin = function(x) {
6351 if (!arguments.length) return origin;
6353 if (typeof origin !== "function") arc.source(origin);
6356 circle.angle = function(x) {
6357 if (!arguments.length) return degrees;
6358 radians = (degrees = +x) * d3_geo_radians;
6361 return d3.rebind(circle, arc, "precision");
6363 d3.geo.greatArc = function() {
6364 function greatArc() {
6365 var d = greatArc.distance.apply(this, arguments), t = 0, dt = precision / d, coordinates = [ p0 ];
6366 while ((t += dt) < 1) coordinates.push(interpolate(t));
6367 coordinates.push(p1);
6370 coordinates: coordinates
6373 var source = d3_geo_greatArcSource, p0, target = d3_geo_greatArcTarget, p1, precision = 6 * d3_geo_radians, interpolate = d3_geo_greatArcInterpolator();
6374 greatArc.distance = function() {
6375 if (typeof source === "function") interpolate.source(p0 = source.apply(this, arguments));
6376 if (typeof target === "function") interpolate.target(p1 = target.apply(this, arguments));
6377 return interpolate.distance();
6379 greatArc.source = function(_) {
6380 if (!arguments.length) return source;
6382 if (typeof source !== "function") interpolate.source(p0 = source);
6385 greatArc.target = function(_) {
6386 if (!arguments.length) return target;
6388 if (typeof target !== "function") interpolate.target(p1 = target);
6391 greatArc.precision = function(_) {
6392 if (!arguments.length) return precision / d3_geo_radians;
6393 precision = _ * d3_geo_radians;
6398 d3.geo.greatCircle = d3.geo.circle;
6400 d3.geom.contour = function(grid, start) {
6401 var s = start || d3_geom_contourStart(grid), c = [], x = s[0], y = s[1], dx = 0, dy = 0, pdx = NaN, pdy = NaN, i = 0;
6404 if (grid(x - 1, y - 1)) i += 1;
6405 if (grid(x, y - 1)) i += 2;
6406 if (grid(x - 1, y)) i += 4;
6407 if (grid(x, y)) i += 8;
6409 dx = pdy === -1 ? -1 : 1;
6411 } else if (i === 9) {
6413 dy = pdx === 1 ? -1 : 1;
6415 dx = d3_geom_contourDx[i];
6416 dy = d3_geom_contourDy[i];
6418 if (dx != pdx && dy != pdy) {
6425 } while (s[0] != x || s[1] != y);
6428 var d3_geom_contourDx = [ 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 0, 0, -1, 0, -1, NaN ], d3_geom_contourDy = [ 0, -1, 0, 0, 0, -1, 0, 0, 1, -1, 1, 1, 0, -1, 0, NaN ];
6429 d3.geom.hull = function(vertices) {
6430 if (vertices.length < 3) return [];
6431 var len = vertices.length, plen = len - 1, points = [], stack = [], i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
6432 for (i = 1; i < len; ++i) {
6433 if (vertices[i][1] < vertices[h][1]) {
6435 } else if (vertices[i][1] == vertices[h][1]) {
6436 h = vertices[i][0] < vertices[h][0] ? i : h;
6439 for (i = 0; i < len; ++i) {
6440 if (i === h) continue;
6441 y1 = vertices[i][1] - vertices[h][1];
6442 x1 = vertices[i][0] - vertices[h][0];
6444 angle: Math.atan2(y1, x1),
6448 points.sort(function(a, b) {
6449 return a.angle - b.angle;
6451 a = points[0].angle;
6452 v = points[0].index;
6454 for (i = 1; i < plen; ++i) {
6455 j = points[i].index;
6456 if (a == points[i].angle) {
6457 x1 = vertices[v][0] - vertices[h][0];
6458 y1 = vertices[v][1] - vertices[h][1];
6459 x2 = vertices[j][0] - vertices[h][0];
6460 y2 = vertices[j][1] - vertices[h][1];
6461 if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
6462 points[i].index = -1;
6464 points[u].index = -1;
6465 a = points[i].angle;
6470 a = points[i].angle;
6476 for (i = 0, j = 0; i < 2; ++j) {
6477 if (points[j].index !== -1) {
6478 stack.push(points[j].index);
6483 for (; j < plen; ++j) {
6484 if (points[j].index === -1) continue;
6485 while (!d3_geom_hullCCW(stack[sp - 2], stack[sp - 1], points[j].index, vertices)) {
6488 stack[sp++] = points[j].index;
6491 for (i = 0; i < sp; ++i) {
6492 poly.push(vertices[stack[i]]);
6496 d3.geom.polygon = function(coordinates) {
6497 coordinates.area = function() {
6498 var i = 0, n = coordinates.length, a = coordinates[n - 1][0] * coordinates[0][1], b = coordinates[n - 1][1] * coordinates[0][0];
6500 a += coordinates[i - 1][0] * coordinates[i][1];
6501 b += coordinates[i - 1][1] * coordinates[i][0];
6503 return (b - a) * .5;
6505 coordinates.centroid = function(k) {
6506 var i = -1, n = coordinates.length, x = 0, y = 0, a, b = coordinates[n - 1], c;
6507 if (!arguments.length) k = -1 / (6 * coordinates.area());
6511 c = a[0] * b[1] - b[0] * a[1];
6512 x += (a[0] + b[0]) * c;
6513 y += (a[1] + b[1]) * c;
6515 return [ x * k, y * k ];
6517 coordinates.clip = function(subject) {
6518 var input, i = -1, n = coordinates.length, j, m, a = coordinates[n - 1], b, c, d;
6520 input = subject.slice();
6523 c = input[(m = input.length) - 1];
6527 if (d3_geom_polygonInside(d, a, b)) {
6528 if (!d3_geom_polygonInside(c, a, b)) {
6529 subject.push(d3_geom_polygonIntersect(c, d, a, b));
6532 } else if (d3_geom_polygonInside(c, a, b)) {
6533 subject.push(d3_geom_polygonIntersect(c, d, a, b));
6543 d3.geom.voronoi = function(vertices) {
6544 var polygons = vertices.map(function() {
6547 d3_voronoi_tessellate(vertices, function(e) {
6548 var s1, s2, x1, x2, y1, y2;
6549 if (e.a === 1 && e.b >= 0) {
6557 y1 = s1 ? s1.y : -1e6;
6558 x1 = e.c - e.b * y1;
6559 y2 = s2 ? s2.y : 1e6;
6560 x2 = e.c - e.b * y2;
6562 x1 = s1 ? s1.x : -1e6;
6563 y1 = e.c - e.a * x1;
6564 x2 = s2 ? s2.x : 1e6;
6565 y2 = e.c - e.a * x2;
6567 var v1 = [ x1, y1 ], v2 = [ x2, y2 ];
6568 polygons[e.region.l.index].push(v1, v2);
6569 polygons[e.region.r.index].push(v1, v2);
6571 return polygons.map(function(polygon, i) {
6572 var cx = vertices[i][0], cy = vertices[i][1];
6573 polygon.forEach(function(v) {
6574 v.angle = Math.atan2(v[0] - cx, v[1] - cy);
6576 return polygon.sort(function(a, b) {
6577 return a.angle - b.angle;
6578 }).filter(function(d, i) {
6579 return !i || d.angle - polygon[i - 1].angle > 1e-10;
6583 var d3_voronoi_opposite = {
6587 d3.geom.delaunay = function(vertices) {
6588 var edges = vertices.map(function() {
6591 d3_voronoi_tessellate(vertices, function(e) {
6592 edges[e.region.l.index].push(vertices[e.region.r.index]);
6594 edges.forEach(function(edge, i) {
6595 var v = vertices[i], cx = v[0], cy = v[1];
6596 edge.forEach(function(v) {
6597 v.angle = Math.atan2(v[0] - cx, v[1] - cy);
6599 edge.sort(function(a, b) {
6600 return a.angle - b.angle;
6602 for (var j = 0, m = edge.length - 1; j < m; j++) {
6603 triangles.push([ v, edge[j], edge[j + 1] ]);
6608 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
6609 function insert(n, p, x1, y1, x2, y2) {
6610 if (isNaN(p.x) || isNaN(p.y)) return;
6614 if (Math.abs(v.x - p.x) + Math.abs(v.y - p.y) < .01) {
6615 insertChild(n, p, x1, y1, x2, y2);
6618 insertChild(n, v, x1, y1, x2, y2);
6619 insertChild(n, p, x1, y1, x2, y2);
6625 insertChild(n, p, x1, y1, x2, y2);
6628 function insertChild(n, p, x1, y1, x2, y2) {
6629 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = p.x >= sx, bottom = p.y >= sy, i = (bottom << 1) + right;
6631 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
6632 if (right) x1 = sx; else x2 = sx;
6633 if (bottom) y1 = sy; else y2 = sy;
6634 insert(n, p, x1, y1, x2, y2);
6636 var p, i = -1, n = points.length;
6637 if (n && isNaN(points[0].x)) points = points.map(d3_geom_quadtreePoint);
6638 if (arguments.length < 5) {
6639 if (arguments.length === 3) {
6644 x2 = y2 = -Infinity;
6647 if (p.x < x1) x1 = p.x;
6648 if (p.y < y1) y1 = p.y;
6649 if (p.x > x2) x2 = p.x;
6650 if (p.y > y2) y2 = p.y;
6652 var dx = x2 - x1, dy = y2 - y1;
6653 if (dx > dy) y2 = y1 + dx; else x2 = x1 + dy;
6656 var root = d3_geom_quadtreeNode();
6657 root.add = function(p) {
6658 insert(root, p, x1, y1, x2, y2);
6660 root.visit = function(f) {
6661 d3_geom_quadtreeVisit(f, root, x1, y1, x2, y2);
6663 points.forEach(root.add);
6667 var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
6668 d3_time_utc.prototype = {
6669 getDate: function() {
6670 return this._.getUTCDate();
6672 getDay: function() {
6673 return this._.getUTCDay();
6675 getFullYear: function() {
6676 return this._.getUTCFullYear();
6678 getHours: function() {
6679 return this._.getUTCHours();
6681 getMilliseconds: function() {
6682 return this._.getUTCMilliseconds();
6684 getMinutes: function() {
6685 return this._.getUTCMinutes();
6687 getMonth: function() {
6688 return this._.getUTCMonth();
6690 getSeconds: function() {
6691 return this._.getUTCSeconds();
6693 getTime: function() {
6694 return this._.getTime();
6696 getTimezoneOffset: function() {
6699 valueOf: function() {
6700 return this._.valueOf();
6702 setDate: function() {
6703 d3_time_prototype.setUTCDate.apply(this._, arguments);
6705 setDay: function() {
6706 d3_time_prototype.setUTCDay.apply(this._, arguments);
6708 setFullYear: function() {
6709 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
6711 setHours: function() {
6712 d3_time_prototype.setUTCHours.apply(this._, arguments);
6714 setMilliseconds: function() {
6715 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
6717 setMinutes: function() {
6718 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
6720 setMonth: function() {
6721 d3_time_prototype.setUTCMonth.apply(this._, arguments);
6723 setSeconds: function() {
6724 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
6726 setTime: function() {
6727 d3_time_prototype.setTime.apply(this._, arguments);
6730 var d3_time_prototype = Date.prototype;
6731 var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y", d3_time_formatDate = "%m/%d/%y", d3_time_formatTime = "%H:%M:%S";
6732 var d3_time_days = d3_time_daySymbols, d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate), d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
6733 d3.time.format = function(template) {
6734 function format(date) {
6735 var string = [], i = -1, j = 0, c, f;
6737 if (template.charCodeAt(i) == 37) {
6738 string.push(template.substring(j, i), (f = d3_time_formats[c = template.charAt(++i)]) ? f(date) : c);
6742 string.push(template.substring(j, i));
6743 return string.join("");
6745 var n = template.length;
6746 format.parse = function(string) {
6755 }, i = d3_time_parse(d, template, string, 0);
6756 if (i != string.length) return null;
6757 if ("p" in d) d.H = d.H % 12 + d.p * 12;
6758 var date = new d3_time;
6759 date.setFullYear(d.y, d.m, d.d);
6760 date.setHours(d.H, d.M, d.S, d.L);
6763 format.toString = function() {
6768 var d3_time_zfill2 = d3.format("02d"), d3_time_zfill3 = d3.format("03d"), d3_time_zfill4 = d3.format("04d"), d3_time_sfill2 = d3.format("2d");
6769 var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations);
6770 var d3_time_formats = {
6772 return d3_time_dayAbbreviations[d.getDay()];
6775 return d3_time_days[d.getDay()];
6778 return d3_time_monthAbbreviations[d.getMonth()];
6781 return d3_time_months[d.getMonth()];
6783 c: d3.time.format(d3_time_formatDateTime),
6785 return d3_time_zfill2(d.getDate());
6788 return d3_time_sfill2(d.getDate());
6791 return d3_time_zfill2(d.getHours());
6794 return d3_time_zfill2(d.getHours() % 12 || 12);
6797 return d3_time_zfill3(1 + d3.time.dayOfYear(d));
6800 return d3_time_zfill3(d.getMilliseconds());
6803 return d3_time_zfill2(d.getMonth() + 1);
6806 return d3_time_zfill2(d.getMinutes());
6809 return d.getHours() >= 12 ? "PM" : "AM";
6812 return d3_time_zfill2(d.getSeconds());
6815 return d3_time_zfill2(d3.time.sundayOfYear(d));
6821 return d3_time_zfill2(d3.time.mondayOfYear(d));
6823 x: d3.time.format(d3_time_formatDate),
6824 X: d3.time.format(d3_time_formatTime),
6826 return d3_time_zfill2(d.getFullYear() % 100);
6829 return d3_time_zfill4(d.getFullYear() % 1e4);
6836 var d3_time_parsers = {
6837 a: d3_time_parseWeekdayAbbrev,
6838 A: d3_time_parseWeekday,
6839 b: d3_time_parseMonthAbbrev,
6840 B: d3_time_parseMonth,
6841 c: d3_time_parseLocaleFull,
6842 d: d3_time_parseDay,
6843 e: d3_time_parseDay,
6844 H: d3_time_parseHour24,
6845 I: d3_time_parseHour24,
6846 L: d3_time_parseMilliseconds,
6847 m: d3_time_parseMonthNumber,
6848 M: d3_time_parseMinutes,
6849 p: d3_time_parseAmPm,
6850 S: d3_time_parseSeconds,
6851 x: d3_time_parseLocaleDate,
6852 X: d3_time_parseLocaleTime,
6853 y: d3_time_parseYear,
6854 Y: d3_time_parseFullYear
6856 var d3_time_numberRe = /^\s*\d+/;
6857 var d3_time_amPmLookup = d3.map({
6861 d3.time.format.utc = function(template) {
6862 function format(date) {
6864 d3_time = d3_time_utc;
6865 var utc = new d3_time;
6872 var local = d3.time.format(template);
6873 format.parse = function(string) {
6875 d3_time = d3_time_utc;
6876 var date = local.parse(string);
6877 return date && date._;
6882 format.toString = local.toString;
6885 var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
6886 d3.time.format.iso = Date.prototype.toISOString ? d3_time_formatIsoNative : d3_time_formatIso;
6887 d3_time_formatIsoNative.parse = function(string) {
6888 var date = new Date(string);
6889 return isNaN(date) ? null : date;
6891 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
6892 d3.time.second = d3_time_interval(function(date) {
6893 return new d3_time(Math.floor(date / 1e3) * 1e3);
6894 }, function(date, offset) {
6895 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
6897 return date.getSeconds();
6899 d3.time.seconds = d3.time.second.range;
6900 d3.time.seconds.utc = d3.time.second.utc.range;
6901 d3.time.minute = d3_time_interval(function(date) {
6902 return new d3_time(Math.floor(date / 6e4) * 6e4);
6903 }, function(date, offset) {
6904 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
6906 return date.getMinutes();
6908 d3.time.minutes = d3.time.minute.range;
6909 d3.time.minutes.utc = d3.time.minute.utc.range;
6910 d3.time.hour = d3_time_interval(function(date) {
6911 var timezone = date.getTimezoneOffset() / 60;
6912 return new d3_time((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
6913 }, function(date, offset) {
6914 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
6916 return date.getHours();
6918 d3.time.hours = d3.time.hour.range;
6919 d3.time.hours.utc = d3.time.hour.utc.range;
6920 d3.time.day = d3_time_interval(function(date) {
6921 var day = new d3_time(1970, 0);
6922 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
6924 }, function(date, offset) {
6925 date.setDate(date.getDate() + offset);
6927 return date.getDate() - 1;
6929 d3.time.days = d3.time.day.range;
6930 d3.time.days.utc = d3.time.day.utc.range;
6931 d3.time.dayOfYear = function(date) {
6932 var year = d3.time.year(date);
6933 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
6935 d3_time_daySymbols.forEach(function(day, i) {
6936 day = day.toLowerCase();
6938 var interval = d3.time[day] = d3_time_interval(function(date) {
6939 (date = d3.time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
6941 }, function(date, offset) {
6942 date.setDate(date.getDate() + Math.floor(offset) * 7);
6944 var day = d3.time.year(date).getDay();
6945 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
6947 d3.time[day + "s"] = interval.range;
6948 d3.time[day + "s"].utc = interval.utc.range;
6949 d3.time[day + "OfYear"] = function(date) {
6950 var day = d3.time.year(date).getDay();
6951 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7);
6954 d3.time.week = d3.time.sunday;
6955 d3.time.weeks = d3.time.sunday.range;
6956 d3.time.weeks.utc = d3.time.sunday.utc.range;
6957 d3.time.weekOfYear = d3.time.sundayOfYear;
6958 d3.time.month = d3_time_interval(function(date) {
6959 date = d3.time.day(date);
6962 }, function(date, offset) {
6963 date.setMonth(date.getMonth() + offset);
6965 return date.getMonth();
6967 d3.time.months = d3.time.month.range;
6968 d3.time.months.utc = d3.time.month.utc.range;
6969 d3.time.year = d3_time_interval(function(date) {
6970 date = d3.time.day(date);
6971 date.setMonth(0, 1);
6973 }, function(date, offset) {
6974 date.setFullYear(date.getFullYear() + offset);
6976 return date.getFullYear();
6978 d3.time.years = d3.time.year.range;
6979 d3.time.years.utc = d3.time.year.utc.range;
6980 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
6981 var d3_time_scaleLocalMethods = [ [ d3.time.second, 1 ], [ d3.time.second, 5 ], [ d3.time.second, 15 ], [ d3.time.second, 30 ], [ d3.time.minute, 1 ], [ d3.time.minute, 5 ], [ d3.time.minute, 15 ], [ d3.time.minute, 30 ], [ d3.time.hour, 1 ], [ d3.time.hour, 3 ], [ d3.time.hour, 6 ], [ d3.time.hour, 12 ], [ d3.time.day, 1 ], [ d3.time.day, 2 ], [ d3.time.week, 1 ], [ d3.time.month, 1 ], [ d3.time.month, 3 ], [ d3.time.year, 1 ] ];
6982 var d3_time_scaleLocalFormats = [ [ d3.time.format("%Y"), function(d) {
6984 } ], [ d3.time.format("%B"), function(d) {
6985 return d.getMonth();
6986 } ], [ d3.time.format("%b %d"), function(d) {
6987 return d.getDate() != 1;
6988 } ], [ d3.time.format("%a %d"), function(d) {
6989 return d.getDay() && d.getDate() != 1;
6990 } ], [ d3.time.format("%I %p"), function(d) {
6991 return d.getHours();
6992 } ], [ d3.time.format("%I:%M"), function(d) {
6993 return d.getMinutes();
6994 } ], [ d3.time.format(":%S"), function(d) {
6995 return d.getSeconds();
6996 } ], [ d3.time.format(".%L"), function(d) {
6997 return d.getMilliseconds();
6999 var d3_time_scaleLinear = d3.scale.linear(), d3_time_scaleLocalFormat = d3_time_scaleFormat(d3_time_scaleLocalFormats);
7000 d3_time_scaleLocalMethods.year = function(extent, m) {
7001 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleGetYear)).ticks(m).map(d3_time_scaleSetYear);
7003 d3.time.scale = function() {
7004 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
7006 var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
7007 return [ m[0].utc, m[1] ];
7009 var d3_time_scaleUTCFormats = [ [ d3.time.format.utc("%Y"), function(d) {
7011 } ], [ d3.time.format.utc("%B"), function(d) {
7012 return d.getUTCMonth();
7013 } ], [ d3.time.format.utc("%b %d"), function(d) {
7014 return d.getUTCDate() != 1;
7015 } ], [ d3.time.format.utc("%a %d"), function(d) {
7016 return d.getUTCDay() && d.getUTCDate() != 1;
7017 } ], [ d3.time.format.utc("%I %p"), function(d) {
7018 return d.getUTCHours();
7019 } ], [ d3.time.format.utc("%I:%M"), function(d) {
7020 return d.getUTCMinutes();
7021 } ], [ d3.time.format.utc(":%S"), function(d) {
7022 return d.getUTCSeconds();
7023 } ], [ d3.time.format.utc(".%L"), function(d) {
7024 return d.getUTCMilliseconds();
7026 var d3_time_scaleUTCFormat = d3_time_scaleFormat(d3_time_scaleUTCFormats);
7027 d3_time_scaleUTCMethods.year = function(extent, m) {
7028 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleUTCGetYear)).ticks(m).map(d3_time_scaleUTCSetYear);
7030 d3.time.scale.utc = function() {
7031 return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);