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_Color() {}
228 function d3_rgb(r, g, b) {
229 return new d3_Rgb(r, g, b);
231 function d3_Rgb(r, g, b) {
236 function d3_rgb_hex(v) {
237 return v < 16 ?
"0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
239 function d3_rgb_parse(format, rgb, hsl) {
240 var r = 0, g = 0, b = 0, m1, m2, name;
241 m1 = /([a-z]+)\((.*)\)/i.exec(format);
243 m2 = m1[2].split(
",");
247 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
251 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
255 if (name = d3_rgb_names.get(format))
return rgb(name.r, name.g, name.b);
256 if (format != null && format.charAt(0) ===
"#") {
257 if (format.length === 4) {
258 r = format.charAt(1);
260 g = format.charAt(2);
262 b = format.charAt(3);
264 }
else if (format.length === 7) {
265 r = format.substring(1, 3);
266 g = format.substring(3, 5);
267 b = format.substring(5, 7);
275 function d3_rgb_hsl(r, g, b) {
276 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;
278 s = l < .5 ? d / (max + min) : d / (2 - max - min);
279 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;
284 return d3_hsl(h, s, l);
286 function d3_rgb_lab(r, g, b) {
290 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);
291 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
293 function d3_rgb_xyz(r) {
294 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
296 function d3_rgb_parseNumber(c) {
297 var f = parseFloat(c);
298 return c.charAt(c.length - 1) ===
"%" ? Math.round(f * 2.55) : f;
300 function d3_hsl(h, s, l) {
301 return new d3_Hsl(h, s, l);
303 function d3_Hsl(h, s, l) {
308 function d3_hsl_rgb(h, s, l) {
310 if (h > 360) h -= 360;
else if (h < 0) h += 360;
311 if (h < 60)
return m1 + (m2 - m1) * h / 60;
312 if (h < 180)
return m2;
313 if (h < 240)
return m1 + (m2 - m1) * (240 - h) / 60;
317 return Math.round(v(h) * 255);
322 s = s < 0 ? 0 : s > 1 ? 1 : s;
323 l = l < 0 ? 0 : l > 1 ? 1 : l;
324 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
326 return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
328 function d3_hcl(h, c, l) {
329 return new d3_Hcl(h, c, l);
331 function d3_Hcl(h, c, l) {
336 function d3_hcl_lab(h, c, l) {
337 return d3_lab(l, Math.cos(h *= Math.PI / 180) * c, Math.sin(h) * c);
339 function d3_lab(l, a, b) {
340 return new d3_Lab(l, a, b);
342 function d3_Lab(l, a, b) {
347 function d3_lab_rgb(l, a, b) {
348 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
349 x = d3_lab_xyz(x) * d3_lab_X;
350 y = d3_lab_xyz(y) * d3_lab_Y;
351 z = d3_lab_xyz(z) * d3_lab_Z;
352 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));
354 function d3_lab_hcl(l, a, b) {
355 return d3_hcl(Math.atan2(b, a) / Math.PI * 180, Math.sqrt(a * a + b * b), l);
357 function d3_lab_xyz(x) {
358 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
360 function d3_xyz_lab(x) {
361 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
363 function d3_xyz_rgb(r) {
364 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
366 function d3_selection(groups) {
367 d3_arraySubclass(groups, d3_selectionPrototype);
370 function d3_selection_selector(selector) {
372 return d3_select(selector,
this);
375 function d3_selection_selectorAll(selector) {
377 return d3_selectAll(selector,
this);
380 function d3_selection_attr(name, value) {
381 function attrNull() {
382 this.removeAttribute(name);
384 function attrNullNS() {
385 this.removeAttributeNS(name.space, name.local);
387 function attrConstant() {
388 this.setAttribute(name, value);
390 function attrConstantNS() {
391 this.setAttributeNS(name.space, name.local, value);
393 function attrFunction() {
394 var x = value.apply(
this, arguments);
395 if (x == null) this.removeAttribute(name);
else this.setAttribute(name, x);
397 function attrFunctionNS() {
398 var x = value.apply(
this, arguments);
399 if (x == null) this.removeAttributeNS(name.space, name.local);
else this.setAttributeNS(name.space, name.local, x);
401 name = d3.ns.qualify(name);
402 return value == null ? name.local ? attrNullNS : attrNull : typeof value ===
"function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
404 function d3_selection_classedRe(name) {
405 return new RegExp(
"(?:^|\\s+)" + d3.requote(name) +
"(?:\\s+|$)",
"g");
407 function d3_selection_classed(name, value) {
408 function classedConstant() {
410 while (++i < n) name[i](
this, value);
412 function classedFunction() {
413 var i = -1, x = value.apply(
this, arguments);
414 while (++i < n) name[i](
this, x);
416 name = name.trim().split(/\s+/).map(d3_selection_classedName);
418 return typeof value ===
"function" ? classedFunction : classedConstant;
420 function d3_selection_classedName(name) {
421 var re = d3_selection_classedRe(name);
422 return function(node, value) {
423 if (c = node.classList)
return value ? c.add(name) : c.remove(name);
424 var c = node.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
428 cv = d3_collapse(cv +
" " + name);
429 if (cb) c.baseVal = cv;
else node.className = cv;
432 cv = d3_collapse(cv.replace(re,
" "));
433 if (cb) c.baseVal = cv;
else node.className = cv;
437 function d3_selection_style(name, value, priority) {
438 function styleNull() {
439 this.style.removeProperty(name);
441 function styleConstant() {
442 this.style.setProperty(name, value, priority);
444 function styleFunction() {
445 var x = value.apply(
this, arguments);
446 if (x == null) this.style.removeProperty(name);
else this.style.setProperty(name, x, priority);
448 return value == null ? styleNull : typeof value ===
"function" ? styleFunction : styleConstant;
450 function d3_selection_property(name, value) {
451 function propertyNull() {
454 function propertyConstant() {
457 function propertyFunction() {
458 var x = value.apply(
this, arguments);
459 if (x == null)
delete this[name];
else this[name] = x;
461 return value == null ? propertyNull : typeof value ===
"function" ? propertyFunction : propertyConstant;
463 function d3_selection_dataNode(data) {
468 function d3_selection_filter(selector) {
470 return d3_selectMatches(
this, selector);
473 function d3_selection_sortComparator(comparator) {
474 if (!arguments.length) comparator = d3.ascending;
475 return function(a, b) {
476 return comparator(a && a.__data__, b && b.__data__);
479 function d3_selection_on(type, listener, capture) {
480 function onRemove() {
481 var wrapper =
this[name];
483 this.removeEventListener(type, wrapper, wrapper.$);
488 function wrapper(e) {
491 args[0] = node.__data__;
493 listener.apply(node, args);
498 var node =
this, args = arguments;
500 this.addEventListener(type,
this[name] = wrapper, wrapper.$ = capture);
501 wrapper._ = listener;
503 var name =
"__on" + type, i = type.indexOf(
".");
504 if (i > 0) type = type.substring(0, i);
505 return listener ? onAdd : onRemove;
507 function d3_selection_each(groups, callback) {
508 for (var j = 0, m = groups.length; j < m; j++) {
509 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
510 if (node = group[i]) callback(node, i, j);
515 function d3_selection_enter(selection) {
516 d3_arraySubclass(selection, d3_selection_enterPrototype);
519 function d3_transition(groups,
id, time) {
520 d3_arraySubclass(groups, d3_transitionPrototype);
521 var tweens =
new d3_Map,
event = d3.dispatch(
"start",
"end"), ease = d3_transitionEase;
524 groups.tween =
function(name, tween) {
525 if (arguments.length < 2)
return tweens.get(name);
526 if (tween == null) tweens.remove(name);
else tweens.set(name, tween);
529 groups.ease =
function(value) {
530 if (!arguments.length)
return ease;
531 ease = typeof value ===
"function" ? value : d3.ease.apply(d3, arguments);
534 groups.each =
function(type, listener) {
535 if (arguments.length < 2)
return d3_transition_each.call(groups, type);
536 event.on(type, listener);
539 d3.timer(
function(elapsed) {
540 return d3_selection_each(groups,
function(node, i, j) {
541 function start(elapsed) {
542 if (lock.active >
id)
return stop();
544 tweens.forEach(
function(key, value) {
545 if (value = value.call(node, d, i)) {
549 event.start.call(node, d, i);
550 if (!tick(elapsed)) d3.timer(tick, 0, time);
553 function tick(elapsed) {
554 if (lock.active !==
id)
return stop();
555 var t = (elapsed - delay) / duration, e = ease(t), n = tweened.length;
557 tweened[--n].call(node, e);
561 d3_transitionId = id;
562 event.end.call(node, d, i);
568 if (!--lock.count)
delete node.__transition__;
571 var tweened = [], delay = node.delay, duration = node.duration, lock = (node = node.node).__transition__ || (node.__transition__ = {
574 }), d = node.__data__;
576 delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time);
581 function d3_transition_each(callback) {
582 var
id = d3_transitionId, ease = d3_transitionEase, delay = d3_transitionDelay, duration = d3_transitionDuration;
583 d3_transitionId = this.id;
584 d3_transitionEase = this.ease();
585 d3_selection_each(
this,
function(node, i, j) {
586 d3_transitionDelay = node.delay;
587 d3_transitionDuration = node.duration;
588 callback.call(node = node.node, node.__data__, i, j);
590 d3_transitionId = id;
591 d3_transitionEase = ease;
592 d3_transitionDelay = delay;
593 d3_transitionDuration = duration;
596 function d3_tweenNull(d, i, a) {
597 return a !=
"" && d3_tweenRemove;
599 function d3_tweenByName(b, name) {
600 return d3.tween(b, d3_interpolateByName(name));
602 function d3_timer_step() {
603 var elapsed, now = Date.now(), t1 = d3_timer_queue;
605 elapsed = now - t1.then;
606 if (elapsed >= t1.delay) t1.flush = t1.callback(elapsed);
609 var delay = d3_timer_flush() - now;
611 if (isFinite(delay)) {
612 clearTimeout(d3_timer_timeout);
613 d3_timer_timeout = setTimeout(d3_timer_step, delay);
615 d3_timer_interval = 0;
617 d3_timer_interval = 1;
618 d3_timer_frame(d3_timer_step);
621 function d3_timer_flush() {
622 var t0 = null, t1 = d3_timer_queue, then = Infinity;
625 delete d3_timer_byId[t1.callback.id];
626 t1 = t0 ? t0.next = t1.next : d3_timer_queue = t1.next;
628 then = Math.min(then, t1.then + t1.delay);
634 function d3_mousePoint(container, e) {
635 var svg = container.ownerSVGElement || container;
636 if (svg.createSVGPoint) {
637 var point = svg.createSVGPoint();
638 if (d3_mouse_bug44083 < 0 && (window.scrollX || window.scrollY)) {
639 svg = d3.select(document.body).append(
"svg").style(
"position",
"absolute").style(
"top", 0).style(
"left", 0);
640 var ctm = svg[0][0].getScreenCTM();
641 d3_mouse_bug44083 = !(ctm.f || ctm.e);
644 if (d3_mouse_bug44083) {
651 point = point.matrixTransform(container.getScreenCTM().inverse());
652 return [ point.x, point.y ];
654 var rect = container.getBoundingClientRect();
655 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
657 function d3_noop() {}
658 function d3_scaleExtent(domain) {
659 var start = domain[0], stop = domain[domain.length - 1];
660 return start < stop ? [ start, stop ] : [ stop, start ];
662 function d3_scaleRange(scale) {
663 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
665 function d3_scale_nice(domain, nice) {
666 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
668 dx = i0, i0 = i1, i1 = dx;
669 dx = x0, x0 = x1, x1 = dx;
671 if (nice = nice(x1 - x0)) {
672 domain[i0] = nice.floor(x0);
673 domain[i1] = nice.ceil(x1);
677 function d3_scale_niceDefault() {
680 function d3_scale_linear(domain, range, interpolate, clamp) {
682 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
683 output = linear(domain, range, uninterpolate, interpolate);
684 input = linear(range, domain, uninterpolate, d3.interpolate);
691 scale.invert =
function(y) {
694 scale.domain =
function(x) {
695 if (!arguments.length)
return domain;
696 domain = x.map(Number);
699 scale.range =
function(x) {
700 if (!arguments.length)
return range;
704 scale.rangeRound =
function(x) {
705 return scale.range(x).interpolate(d3.interpolateRound);
707 scale.clamp =
function(x) {
708 if (!arguments.length)
return clamp;
712 scale.interpolate =
function(x) {
713 if (!arguments.length)
return interpolate;
717 scale.ticks =
function(m) {
718 return d3_scale_linearTicks(domain, m);
720 scale.tickFormat =
function(m) {
721 return d3_scale_linearTickFormat(domain, m);
723 scale.nice =
function() {
724 d3_scale_nice(domain, d3_scale_linearNice);
727 scale.copy =
function() {
728 return d3_scale_linear(domain, range, interpolate, clamp);
732 function d3_scale_linearRebind(scale, linear) {
733 return d3.rebind(scale, linear,
"range",
"rangeRound",
"interpolate",
"clamp");
735 function d3_scale_linearNice(dx) {
736 dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
739 return Math.floor(x / dx) * dx;
742 return Math.ceil(x / dx) * dx;
746 function d3_scale_linearTickRange(domain, m) {
747 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;
748 if (err <= .15) step *= 10;
else if (err <= .35) step *= 5;
else if (err <= .75) step *= 2;
749 extent[0] = Math.ceil(extent[0] / step) * step;
750 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
754 function d3_scale_linearTicks(domain, m) {
755 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
757 function d3_scale_linearTickFormat(domain, m) {
758 return d3.format(
",." + Math.max(0, -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01)) +
"f");
760 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
761 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
766 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
767 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
768 if (domain[k] < domain[0]) {
769 domain = domain.slice().reverse();
770 range = range.slice().reverse();
773 u.push(uninterpolate(domain[j - 1], domain[j]));
774 i.push(interpolate(range[j - 1], range[j]));
777 var j = d3.bisect(domain, x, 1, k) - 1;
778 return i[j](u[j](x));
781 function d3_scale_log(linear, log) {
783 return linear(log(x));
786 scale.invert =
function(x) {
787 return pow(linear.invert(x));
789 scale.domain =
function(x) {
790 if (!arguments.length)
return linear.domain().map(pow);
791 log = x[0] < 0 ? d3_scale_logn : d3_scale_logp;
793 linear.domain(x.map(log));
796 scale.nice =
function() {
797 linear.domain(d3_scale_nice(linear.domain(), d3_scale_niceDefault));
800 scale.ticks =
function() {
801 var extent = d3_scaleExtent(linear.domain()), ticks = [];
802 if (extent.every(isFinite)) {
803 var i = Math.floor(extent[0]), j = Math.ceil(extent[1]), u = pow(extent[0]), v = pow(extent[1]);
804 if (log === d3_scale_logn) {
806 for (; i++ < j; )
for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
808 for (; i < j; i++)
for (var k = 1; k < 10; k++) ticks.push(pow(i) * k);
811 for (i = 0; ticks[i] < u; i++) {}
812 for (j = ticks.length; ticks[j - 1] > v; j--) {}
813 ticks = ticks.slice(i, j);
817 scale.tickFormat =
function(n, format) {
818 if (arguments.length < 2) format = d3_scale_logFormat;
819 if (arguments.length < 1)
return format;
820 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;
822 return d / pow(f(log(d) + e)) <= k ? format(d) :
"";
825 scale.copy =
function() {
826 return d3_scale_log(linear.copy(), log);
828 return d3_scale_linearRebind(scale, linear);
830 function d3_scale_logp(x) {
831 return Math.log(x < 0 ? 0 : x) / Math.LN10;
833 function d3_scale_logn(x) {
834 return -Math.log(x > 0 ? 0 : -x) / Math.LN10;
836 function d3_scale_pow(linear, exponent) {
838 return linear(powp(x));
840 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
841 scale.invert =
function(x) {
842 return powb(linear.invert(x));
844 scale.domain =
function(x) {
845 if (!arguments.length)
return linear.domain().map(powb);
846 linear.domain(x.map(powp));
849 scale.ticks =
function(m) {
850 return d3_scale_linearTicks(scale.domain(), m);
852 scale.tickFormat =
function(m) {
853 return d3_scale_linearTickFormat(scale.domain(), m);
855 scale.nice =
function() {
856 return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice));
858 scale.exponent =
function(x) {
859 if (!arguments.length)
return exponent;
860 var domain = scale.domain();
861 powp = d3_scale_powPow(exponent = x);
862 powb = d3_scale_powPow(1 / exponent);
863 return scale.domain(domain);
865 scale.copy =
function() {
866 return d3_scale_pow(linear.copy(), exponent);
868 return d3_scale_linearRebind(scale, linear);
870 function d3_scale_powPow(e) {
872 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
875 function d3_scale_ordinal(domain, ranger) {
877 return range[((index.get(x) || index.set(x, domain.push(x))) - 1) % range.length];
879 function steps(start, step) {
880 return d3.range(domain.length).map(
function(i) {
881 return start + step * i;
884 var index, range, rangeBand;
885 scale.domain =
function(x) {
886 if (!arguments.length)
return domain;
889 var i = -1, n = x.length, xi;
890 while (++i < n)
if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
891 return scale[ranger.t].apply(scale, ranger.a);
893 scale.range =
function(x) {
894 if (!arguments.length)
return range;
903 scale.rangePoints =
function(x, padding) {
904 if (arguments.length < 2) padding = 0;
905 var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
906 range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
914 scale.rangeBands =
function(x, padding, outerPadding) {
915 if (arguments.length < 2) padding = 0;
916 if (arguments.length < 3) outerPadding = padding;
917 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
918 range = steps(start + step * outerPadding, step);
919 if (reverse) range.reverse();
920 rangeBand = step * (1 - padding);
927 scale.rangeRoundBands =
function(x, padding, outerPadding) {
928 if (arguments.length < 2) padding = 0;
929 if (arguments.length < 3) outerPadding = padding;
930 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;
931 range = steps(start + Math.round(error / 2), step);
932 if (reverse) range.reverse();
933 rangeBand = Math.round(step * (1 - padding));
935 t:
"rangeRoundBands",
940 scale.rangeBand =
function() {
943 scale.rangeExtent =
function() {
944 return d3_scaleExtent(ranger.a[0]);
946 scale.copy =
function() {
947 return d3_scale_ordinal(domain, ranger);
949 return scale.domain(domain);
951 function d3_scale_quantile(domain, range) {
953 var k = 0, n = domain.length, q = range.length;
955 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
959 if (isNaN(x = +x))
return NaN;
960 return range[d3.bisect(thresholds, x)];
963 scale.domain =
function(x) {
964 if (!arguments.length)
return domain;
965 domain = x.filter(
function(d) {
967 }).sort(d3.ascending);
970 scale.range =
function(x) {
971 if (!arguments.length)
return range;
975 scale.quantiles =
function() {
978 scale.copy =
function() {
979 return d3_scale_quantile(domain, range);
983 function d3_scale_quantize(x0, x1, range) {
985 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
988 kx = range.length / (x1 - x0);
989 i = range.length - 1;
993 scale.domain =
function(x) {
994 if (!arguments.length)
return [ x0, x1 ];
996 x1 = +x[x.length - 1];
999 scale.range =
function(x) {
1000 if (!arguments.length)
return range;
1004 scale.copy =
function() {
1005 return d3_scale_quantize(x0, x1, range);
1009 function d3_scale_threshold(domain, range) {
1011 return range[d3.bisect(domain, x)];
1013 scale.domain =
function(_) {
1014 if (!arguments.length)
return domain;
1018 scale.range =
function(_) {
1019 if (!arguments.length)
return range;
1023 scale.copy =
function() {
1024 return d3_scale_threshold(domain, range);
1028 function d3_scale_identity(domain) {
1029 function identity(x) {
1032 identity.invert = identity;
1033 identity.domain = identity.range =
function(x) {
1034 if (!arguments.length)
return domain;
1035 domain = x.map(identity);
1038 identity.ticks =
function(m) {
1039 return d3_scale_linearTicks(domain, m);
1041 identity.tickFormat =
function(m) {
1042 return d3_scale_linearTickFormat(domain, m);
1044 identity.copy =
function() {
1045 return d3_scale_identity(domain);
1049 function d3_svg_arcInnerRadius(d) {
1050 return d.innerRadius;
1052 function d3_svg_arcOuterRadius(d) {
1053 return d.outerRadius;
1055 function d3_svg_arcStartAngle(d) {
1056 return d.startAngle;
1058 function d3_svg_arcEndAngle(d) {
1061 function d3_svg_line(projection) {
1062 function line(data) {
1063 function segment() {
1064 segments.push(
"M", interpolate(projection(points), tension));
1066 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
1068 if (defined.call(
this, d = data[i], i)) {
1069 points.push([ +fx.call(
this, d, i), +fy.call(
this, d, i) ]);
1070 }
else if (points.length) {
1075 if (points.length) segment();
1076 return segments.length ? segments.join(
"") : null;
1078 var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
1079 line.x =
function(_) {
1080 if (!arguments.length)
return x;
1084 line.y =
function(_) {
1085 if (!arguments.length)
return y;
1089 line.defined =
function(_) {
1090 if (!arguments.length)
return defined;
1094 line.interpolate =
function(_) {
1095 if (!arguments.length)
return interpolateKey;
1096 if (typeof _ ===
"function") interpolateKey = interpolate = _;
else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
1099 line.tension =
function(_) {
1100 if (!arguments.length)
return tension;
1106 function d3_svg_lineX(d) {
1109 function d3_svg_lineY(d) {
1112 function d3_svg_lineLinear(points) {
1113 return points.join(
"L");
1115 function d3_svg_lineLinearClosed(points) {
1116 return d3_svg_lineLinear(points) +
"Z";
1118 function d3_svg_lineStepBefore(points) {
1119 var i = 0, n = points.length, p = points[0], path = [ p[0],
",", p[1] ];
1120 while (++i < n) path.push(
"V", (p = points[i])[1],
"H", p[0]);
1121 return path.join(
"");
1123 function d3_svg_lineStepAfter(points) {
1124 var i = 0, n = points.length, p = points[0], path = [ p[0],
",", p[1] ];
1125 while (++i < n) path.push(
"H", (p = points[i])[0],
"V", p[1]);
1126 return path.join(
"");
1128 function d3_svg_lineCardinalOpen(points, tension) {
1129 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
1131 function d3_svg_lineCardinalClosed(points, tension) {
1132 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));
1134 function d3_svg_lineCardinal(points, tension, closed) {
1135 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
1137 function d3_svg_lineHermite(points, tangents) {
1138 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
1139 return d3_svg_lineLinear(points);
1141 var quad = points.length != tangents.length, path =
"", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
1143 path +=
"Q" + (p[0] - t0[0] * 2 / 3) +
"," + (p[1] - t0[1] * 2 / 3) +
"," + p[0] +
"," + p[1];
1147 if (tangents.length > 1) {
1151 path +=
"C" + (p0[0] + t0[0]) +
"," + (p0[1] + t0[1]) +
"," + (p[0] - t[0]) +
"," + (p[1] - t[1]) +
"," + p[0] +
"," + p[1];
1152 for (var i = 2; i < tangents.length; i++, pi++) {
1155 path +=
"S" + (p[0] - t[0]) +
"," + (p[1] - t[1]) +
"," + p[0] +
"," + p[1];
1159 var lp = points[pi];
1160 path +=
"Q" + (p[0] + t[0] * 2 / 3) +
"," + (p[1] + t[1] * 2 / 3) +
"," + lp[0] +
"," + lp[1];
1164 function d3_svg_lineCardinalTangents(points, tension) {
1165 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
1170 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
1174 function d3_svg_lineBasis(points) {
1175 if (points.length < 3)
return d3_svg_lineLinear(points);
1176 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 ];
1177 d3_svg_lineBasisBezier(path, px, py);
1184 d3_svg_lineBasisBezier(path, px, py);
1192 d3_svg_lineBasisBezier(path, px, py);
1194 return path.join(
"");
1196 function d3_svg_lineBasisOpen(points) {
1197 if (points.length < 4)
return d3_svg_lineLinear(points);
1198 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
1204 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) +
"," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
1212 d3_svg_lineBasisBezier(path, px, py);
1214 return path.join(
"");
1216 function d3_svg_lineBasisClosed(points) {
1217 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
1223 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px),
",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
1231 d3_svg_lineBasisBezier(path, px, py);
1233 return path.join(
"");
1235 function d3_svg_lineBundle(points, tension) {
1236 var n = points.length - 1;
1238 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
1242 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
1243 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
1246 return d3_svg_lineBasis(points);
1248 function d3_svg_lineDot4(a, b) {
1249 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
1251 function d3_svg_lineBasisBezier(path, x, y) {
1252 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));
1254 function d3_svg_lineSlope(p0, p1) {
1255 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
1257 function d3_svg_lineFiniteDifferences(points) {
1258 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
1260 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
1265 function d3_svg_lineMonotoneTangents(points) {
1266 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
1268 d = d3_svg_lineSlope(points[i], points[i + 1]);
1269 if (Math.abs(d) < 1e-6) {
1270 m[i] = m[i + 1] = 0;
1276 s = d * 3 / Math.sqrt(s);
1284 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
1285 tangents.push([ s || 0, m[i] * s || 0 ]);
1289 function d3_svg_lineMonotone(points) {
1290 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
1292 function d3_svg_lineRadial(points) {
1293 var point, i = -1, n = points.length, r, a;
1297 a = point[1] + d3_svg_arcOffset;
1298 point[0] = r * Math.cos(a);
1299 point[1] = r * Math.sin(a);
1303 function d3_svg_area(projection) {
1304 function area(data) {
1305 function segment() {
1306 segments.push(
"M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension),
"Z");
1308 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ?
function() {
1310 } : d3_functor(x1), fy1 = y0 === y1 ?
function() {
1312 } : d3_functor(y1), x, y;
1314 if (defined.call(
this, d = data[i], i)) {
1315 points0.push([ x = +fx0.call(
this, d, i), y = +fy0.call(
this, d, i) ]);
1316 points1.push([ +fx1.call(
this, d, i), +fy1.call(
this, d, i) ]);
1317 }
else if (points0.length) {
1323 if (points0.length) segment();
1324 return segments.length ? segments.join(
"") : null;
1326 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;
1327 area.x =
function(_) {
1328 if (!arguments.length)
return x1;
1332 area.x0 =
function(_) {
1333 if (!arguments.length)
return x0;
1337 area.x1 =
function(_) {
1338 if (!arguments.length)
return x1;
1342 area.y =
function(_) {
1343 if (!arguments.length)
return y1;
1347 area.y0 =
function(_) {
1348 if (!arguments.length)
return y0;
1352 area.y1 =
function(_) {
1353 if (!arguments.length)
return y1;
1357 area.defined =
function(_) {
1358 if (!arguments.length)
return defined;
1362 area.interpolate =
function(_) {
1363 if (!arguments.length)
return interpolateKey;
1364 if (typeof _ ===
"function") interpolateKey = interpolate = _;
else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
1365 interpolateReverse = interpolate.reverse || interpolate;
1366 L = interpolate.closed ?
"M" :
"L";
1369 area.tension =
function(_) {
1370 if (!arguments.length)
return tension;
1376 function d3_svg_chordSource(d) {
1379 function d3_svg_chordTarget(d) {
1382 function d3_svg_chordRadius(d) {
1385 function d3_svg_chordStartAngle(d) {
1386 return d.startAngle;
1388 function d3_svg_chordEndAngle(d) {
1391 function d3_svg_diagonalProjection(d) {
1392 return [ d.x, d.y ];
1394 function d3_svg_diagonalRadialProjection(projection) {
1396 var d = projection.apply(
this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
1397 return [ r * Math.cos(a), r * Math.sin(a) ];
1400 function d3_svg_symbolSize() {
1403 function d3_svg_symbolType() {
1406 function d3_svg_symbolCircle(size) {
1407 var r = Math.sqrt(size / Math.PI);
1408 return "M0," + r +
"A" + r +
"," + r +
" 0 1,1 0," + -r +
"A" + r +
"," + r +
" 0 1,1 0," + r +
"Z";
1410 function d3_svg_axisX(selection, x) {
1411 selection.attr(
"transform",
function(d) {
1412 return "translate(" + x(d) +
",0)";
1415 function d3_svg_axisY(selection, y) {
1416 selection.attr(
"transform",
function(d) {
1417 return "translate(0," + y(d) +
")";
1420 function d3_svg_axisSubdivide(scale, ticks, m) {
1422 if (m && ticks.length > 1) {
1423 var extent = d3_scaleExtent(scale.domain()), subticks, i = -1, n = ticks.length, d = (ticks[1] - ticks[0]) / ++m, j, v;
1425 for (j = m; --j > 0; ) {
1426 if ((v = +ticks[i] - j * d) >= extent[0]) {
1431 for (--i, j = 0; ++j < m && (v = +ticks[i] + j * d) < extent[1]; ) {
1437 function d3_behavior_zoomDelta() {
1438 if (!d3_behavior_zoomDiv) {
1439 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;
1441 var e = d3.event, delta;
1443 d3_behavior_zoomDiv.scrollTop = 1e3;
1444 d3_behavior_zoomDiv.dispatchEvent(e);
1445 delta = 1e3 - d3_behavior_zoomDiv.scrollTop;
1447 delta = e.wheelDelta || -e.detail * 5;
1451 function d3_layout_bundlePath(link) {
1452 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
1453 while (start !== lca) {
1454 start = start.parent;
1457 var k = points.length;
1458 while (end !== lca) {
1459 points.splice(k, 0, end);
1464 function d3_layout_bundleAncestors(node) {
1465 var ancestors = [], parent = node.parent;
1466 while (parent != null) {
1467 ancestors.push(node);
1469 parent = parent.parent;
1471 ancestors.push(node);
1474 function d3_layout_bundleLeastCommonAncestor(a, b) {
1475 if (a === b)
return a;
1476 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
1477 while (aNode === bNode) {
1479 aNode = aNodes.pop();
1480 bNode = bNodes.pop();
1484 function d3_layout_forceDragstart(d) {
1487 function d3_layout_forceDragend(d) {
1490 function d3_layout_forceMouseover(d) {
1493 function d3_layout_forceMouseout(d) {
1496 function d3_layout_forceAccumulate(quad, alpha, charges) {
1500 var nodes = quad.nodes, n = nodes.length, i = -1, c;
1503 if (c == null)
continue;
1504 d3_layout_forceAccumulate(c, alpha, charges);
1505 quad.charge += c.charge;
1506 cx += c.charge * c.cx;
1507 cy += c.charge * c.cy;
1512 quad.point.x += Math.random() - .5;
1513 quad.point.y += Math.random() - .5;
1515 var k = alpha * charges[quad.point.index];
1516 quad.charge += quad.pointCharge = k;
1517 cx += k * quad.point.x;
1518 cy += k * quad.point.y;
1520 quad.cx = cx / quad.charge;
1521 quad.cy = cy / quad.charge;
1523 function d3_layout_forceLinkDistance(link) {
1526 function d3_layout_forceLinkStrength(link) {
1529 function d3_layout_stackX(d) {
1532 function d3_layout_stackY(d) {
1535 function d3_layout_stackOut(d, y0, y) {
1539 function d3_layout_stackOrderDefault(data) {
1540 return d3.range(data.length);
1542 function d3_layout_stackOffsetZero(data) {
1543 var j = -1, m = data[0].length, y0 = [];
1544 while (++j < m) y0[j] = 0;
1547 function d3_layout_stackMaxIndex(array) {
1548 var i = 1, j = 0, v = array[0][1], k, n = array.length;
1549 for (; i < n; ++i) {
1550 if ((k = array[i][1]) > v) {
1557 function d3_layout_stackReduceSum(d) {
1558 return d.reduce(d3_layout_stackSum, 0);
1560 function d3_layout_stackSum(p, d) {
1563 function d3_layout_histogramBinSturges(range, values) {
1564 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
1566 function d3_layout_histogramBinFixed(range, n) {
1567 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
1568 while (++x <= n) f[x] = m * x + b;
1571 function d3_layout_histogramRange(values) {
1572 return [ d3.min(values), d3.max(values) ];
1574 function d3_layout_hierarchyRebind(
object, hierarchy) {
1575 d3.rebind(
object, hierarchy,
"sort",
"children",
"value");
1576 object.links = d3_layout_hierarchyLinks;
1577 object.nodes =
function(d) {
1578 d3_layout_hierarchyInline =
true;
1579 return (
object.nodes =
object)(d);
1583 function d3_layout_hierarchyChildren(d) {
1586 function d3_layout_hierarchyValue(d) {
1589 function d3_layout_hierarchySort(a, b) {
1590 return b.value - a.value;
1592 function d3_layout_hierarchyLinks(nodes) {
1593 return d3.merge(nodes.map(
function(parent) {
1594 return (parent.children || []).map(
function(child) {
1602 function d3_layout_packSort(a, b) {
1603 return a.value - b.value;
1605 function d3_layout_packInsert(a, b) {
1606 var c = a._pack_next;
1612 function d3_layout_packSplice(a, b) {
1616 function d3_layout_packIntersects(a, b) {
1617 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
1618 return dr * dr - dx * dx - dy * dy > .001;
1620 function d3_layout_packSiblings(node) {
1621 function bound(node) {
1622 xMin = Math.min(node.x - node.r, xMin);
1623 xMax = Math.max(node.x + node.r, xMax);
1624 yMin = Math.min(node.y - node.r, yMin);
1625 yMax = Math.max(node.y + node.r, yMax);
1627 if (!(nodes = node.children) || !(n = nodes.length))
return;
1628 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
1629 nodes.forEach(d3_layout_packLink);
1641 d3_layout_packPlace(a, b, c);
1643 d3_layout_packInsert(a, c);
1645 d3_layout_packInsert(c, b);
1647 for (i = 3; i < n; i++) {
1648 d3_layout_packPlace(a, b, c = nodes[i]);
1649 var isect = 0, s1 = 1, s2 = 1;
1650 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
1651 if (d3_layout_packIntersects(j, c)) {
1657 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
1658 if (d3_layout_packIntersects(k, c)) {
1664 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j);
else d3_layout_packSplice(a = k, b);
1667 d3_layout_packInsert(a, c);
1674 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
1675 for (i = 0; i < n; i++) {
1679 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
1682 nodes.forEach(d3_layout_packUnlink);
1684 function d3_layout_packLink(node) {
1685 node._pack_next = node._pack_prev = node;
1687 function d3_layout_packUnlink(node) {
1688 delete node._pack_next;
1689 delete node._pack_prev;
1691 function d3_layout_packTransform(node, x, y, k) {
1692 var children = node.children;
1693 node.x = x += k * node.x;
1694 node.y = y += k * node.y;
1697 var i = -1, n = children.length;
1698 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
1701 function d3_layout_packPlace(a, b, c) {
1702 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
1703 if (db && (dx || dy)) {
1704 var da = b.r + c.r, dc = dx * dx + dy * dy;
1707 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
1708 c.x = a.x + x * dx + y * dy;
1709 c.y = a.y + x * dy - y * dx;
1715 function d3_layout_clusterY(children) {
1716 return 1 + d3.max(children,
function(child) {
1720 function d3_layout_clusterX(children) {
1721 return children.reduce(
function(x, child) {
1723 }, 0) / children.length;
1725 function d3_layout_clusterLeft(node) {
1726 var children = node.children;
1727 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
1729 function d3_layout_clusterRight(node) {
1730 var children = node.children, n;
1731 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
1733 function d3_layout_treeSeparation(a, b) {
1734 return a.parent == b.parent ? 1 : 2;
1736 function d3_layout_treeLeft(node) {
1737 var children = node.children;
1738 return children && children.length ? children[0] : node._tree.thread;
1740 function d3_layout_treeRight(node) {
1741 var children = node.children, n;
1742 return children && (n = children.length) ? children[n - 1] : node._tree.thread;
1744 function d3_layout_treeSearch(node, compare) {
1745 var children = node.children;
1746 if (children && (n = children.length)) {
1747 var child, n, i = -1;
1749 if (compare(child = d3_layout_treeSearch(children[i], compare), node) > 0) {
1756 function d3_layout_treeRightmost(a, b) {
1759 function d3_layout_treeLeftmost(a, b) {
1762 function d3_layout_treeDeepest(a, b) {
1763 return a.depth - b.depth;
1765 function d3_layout_treeVisitAfter(node, callback) {
1766 function visit(node, previousSibling) {
1767 var children = node.children;
1768 if (children && (n = children.length)) {
1769 var child, previousChild = null, i = -1, n;
1771 child = children[i];
1772 visit(child, previousChild);
1773 previousChild = child;
1776 callback(node, previousSibling);
1780 function d3_layout_treeShift(node) {
1781 var shift = 0, change = 0, children = node.children, i = children.length, child;
1783 child = children[i]._tree;
1784 child.prelim += shift;
1786 shift += child.shift + (change += child.change);
1789 function d3_layout_treeMove(ancestor, node, shift) {
1790 ancestor = ancestor._tree;
1792 var change = shift / (node.number - ancestor.number);
1793 ancestor.change += change;
1794 node.change -= change;
1795 node.shift += shift;
1796 node.prelim += shift;
1799 function d3_layout_treeAncestor(vim, node, ancestor) {
1800 return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
1802 function d3_layout_treemapPadNull(node) {
1810 function d3_layout_treemapPad(node, padding) {
1811 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];
1827 function d3_dsv(delimiter, mimeType) {
1828 function dsv(url, callback) {
1829 d3.text(url, mimeType,
function(text) {
1830 callback(text && dsv.parse(text));
1833 function formatRow(row) {
1834 return row.map(formatValue).join(delimiter);
1836 function formatValue(text) {
1837 return reFormat.test(text) ?
'"' + text.replace(/\
"/g, '""') + '"' : text;
1839 var reParse = new RegExp("\r\n|[" + delimiter + "\r\n]", "g"), reFormat = new RegExp('[
"' + delimiter + "\n]
"), delimiterCode = delimiter.charCodeAt(0);
1840 dsv.parse = function(text) {
1842 return dsv.parseRows(text, function(row, i) {
1844 var o = {}, j = -1, m = header.length;
1845 while (++j < m) o[header[j]] = row[j];
1853 dsv.parseRows = function(text, f) {
1855 if (reParse.lastIndex >= text.length) return EOF;
1860 var j = reParse.lastIndex;
1861 if (text.charCodeAt(j) === 34) {
1863 while (i++ < text.length) {
1864 if (text.charCodeAt(i) === 34) {
1865 if (text.charCodeAt(i + 1) !== 34) break;
1869 reParse.lastIndex = i + 2;
1870 var c = text.charCodeAt(i + 1);
1873 if (text.charCodeAt(i + 2) === 10) reParse.lastIndex++;
1874 } else if (c === 10) {
1877 return text.substring(j + 1, i).replace(/""/g, '"');
1879 var m = reParse.exec(text);
1881 eol = m[0].charCodeAt(0) !== delimiterCode;
1882 return text.substring(j, m.index);
1884 reParse.lastIndex = text.length;
1885 return text.substring(j);
1887 var EOL = {}, EOF = {}, rows = [], n = 0, t, eol;
1888 reParse.lastIndex = 0;
1889 while ((t = token()) !== EOF) {
1891 while (t !== EOL && t !== EOF) {
1895 if (f && !(a = f(a, n++))) continue;
1900 dsv.format = function(rows) {
1901 return rows.map(formatRow).join("\n");
1905 function d3_geo_type(types, defaultValue) {
1906 return function(object) {
1907 return object && types.hasOwnProperty(object.type) ? types[object.type](object) : defaultValue;
1910 function d3_path_circle(radius) {
1911 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
1913 function d3_geo_bounds(o, f) {
1914 if (d3_geo_boundsTypes.hasOwnProperty(o.type)) d3_geo_boundsTypes[o.type](o, f);
1916 function d3_geo_boundsFeature(o, f) {
1917 d3_geo_bounds(o.geometry, f);
1919 function d3_geo_boundsFeatureCollection(o, f) {
1920 for (var a = o.features, i = 0, n = a.length; i < n; i++) {
1921 d3_geo_bounds(a[i].geometry, f);
1924 function d3_geo_boundsGeometryCollection(o, f) {
1925 for (var a = o.geometries, i = 0, n = a.length; i < n; i++) {
1926 d3_geo_bounds(a[i], f);
1929 function d3_geo_boundsLineString(o, f) {
1930 for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
1931 f.apply(null, a[i]);
1934 function d3_geo_boundsMultiLineString(o, f) {
1935 for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
1936 for (var b = a[i], j = 0, m = b.length; j < m; j++) {
1937 f.apply(null, b[j]);
1941 function d3_geo_boundsMultiPolygon(o, f) {
1942 for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
1943 for (var b = a[i][0], j = 0, m = b.length; j < m; j++) {
1944 f.apply(null, b[j]);
1948 function d3_geo_boundsPoint(o, f) {
1949 f.apply(null, o.coordinates);
1951 function d3_geo_boundsPolygon(o, f) {
1952 for (var a = o.coordinates[0], i = 0, n = a.length; i < n; i++) {
1953 f.apply(null, a[i]);
1956 function d3_geo_greatArcSource(d) {
1959 function d3_geo_greatArcTarget(d) {
1962 function d3_geo_greatArcInterpolator() {
1963 function interpolate(t) {
1964 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;
1965 return [ Math.atan2(y, x) / d3_geo_radians, Math.atan2(z, Math.sqrt(x * x + y * y)) / d3_geo_radians ];
1967 var x0, y0, cy0, sy0, kx0, ky0, x1, y1, cy1, sy1, kx1, ky1, d, k;
1968 interpolate.distance = function() {
1969 if (d == null) k = 1 / Math.sin(d = Math.acos(Math.max(-1, Math.min(1, sy0 * sy1 + cy0 * cy1 * Math.cos(x1 - x0)))));
1972 interpolate.source = function(_) {
1973 var cx0 = Math.cos(x0 = _[0] * d3_geo_radians), sx0 = Math.sin(x0);
1974 cy0 = Math.cos(y0 = _[1] * d3_geo_radians);
1981 interpolate.target = function(_) {
1982 var cx1 = Math.cos(x1 = _[0] * d3_geo_radians), sx1 = Math.sin(x1);
1983 cy1 = Math.cos(y1 = _[1] * d3_geo_radians);
1992 function d3_geo_greatArcInterpolate(a, b) {
1993 var i = d3_geo_greatArcInterpolator().source(a).target(b);
1997 function d3_geom_contourStart(grid) {
2012 function d3_geom_hullCCW(i1, i2, i3, v) {
2013 var t, a, b, c, d, e, f;
2023 return (f - b) * (c - a) - (d - b) * (e - a) > 0;
2025 function d3_geom_polygonInside(p, a, b) {
2026 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
2028 function d3_geom_polygonIntersect(c, d, a, b) {
2029 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);
2030 return [ x1 + ua * x21, y1 + ua * y21 ];
2032 function d3_voronoi_tessellate(vertices, callback) {
2034 list: vertices.map(function(v, i) {
2040 }).sort(function(a, b) {
2041 return a.y < b.y ? -1 : a.y > b.y ? 1 : a.x < b.x ? -1 : a.x > b.x ? 1 : 0;
2050 EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
2051 EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
2052 EdgeList.leftEnd.r = EdgeList.rightEnd;
2053 EdgeList.rightEnd.l = EdgeList.leftEnd;
2054 EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
2056 createHalfEdge: function(edge, side) {
2065 insert: function(lb, he) {
2071 leftBound: function(p) {
2072 var he = EdgeList.leftEnd;
2075 } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
2084 right: function(he) {
2087 left: function(he) {
2090 leftRegion: function(he) {
2091 return he.edge == null ? Sites.bottomSite : he.edge.region[he.side];
2093 rightRegion: function(he) {
2094 return he.edge == null ? Sites.bottomSite : he.edge.region[d3_voronoi_opposite[he.side]];
2098 bisect: function(s1, s2) {
2109 var dx = s2.x - s1.x, dy = s2.y - s1.y, adx = dx > 0 ? dx : -dx, ady = dy > 0 ? dy : -dy;
2110 newEdge.c = s1.x * dx + s1.y * dy + (dx * dx + dy * dy) * .5;
2113 newEdge.b = dy / dx;
2117 newEdge.a = dx / dy;
2122 intersect: function(el1, el2) {
2123 var e1 = el1.edge, e2 = el2.edge;
2124 if (!e1 || !e2 || e1.region.r == e2.region.r) {
2127 var d = e1.a * e2.b - e1.b * e2.a;
2128 if (Math.abs(d) < 1e-10) {
2131 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;
2132 if (e1r.y < e2r.y || e1r.y == e2r.y && e1r.x < e2r.x) {
2139 var rightOfSite = xint >= e.region.r.x;
2140 if (rightOfSite && el.side === "l" || !rightOfSite && el.side === "r") {
2148 rightOf: function(he, p) {
2149 var e = he.edge, topsite = e.region.r, rightOfSite = p.x > topsite.x;
2150 if (rightOfSite && he.side === "l") {
2153 if (!rightOfSite && he.side === "r") {
2157 var dyp = p.y - topsite.y, dxp = p.x - topsite.x, fast = 0, above = 0;
2158 if (!rightOfSite && e.b < 0 || rightOfSite && e.b >= 0) {
2159 above = fast = dyp >= e.b * dxp;
2161 above = p.x + p.y * e.b > e.c;
2170 var dxs = topsite.x - e.region.l.x;
2171 above = e.b * (dxp * dxp - dyp * dyp) < dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b);
2177 var yl = e.c - e.a * p.x, t1 = p.y - yl, t2 = p.x - topsite.x, t3 = yl - topsite.y;
2178 above = t1 * t1 > t2 * t2 + t3 * t3;
2180 return he.side === "l" ? above : !above;
2182 endPoint: function(edge, side, site) {
2183 edge.ep[side] = site;
2184 if (!edge.ep[d3_voronoi_opposite[side]]) return;
2187 distance: function(s, t) {
2188 var dx = s.x - t.x, dy = s.y - t.y;
2189 return Math.sqrt(dx * dx + dy * dy);
2194 insert: function(he, site, offset) {
2196 he.ystar = site.y + offset;
2197 for (var i = 0, list = EventQueue.list, l = list.length; i < l; i++) {
2199 if (he.ystar > next.ystar || he.ystar == next.ystar && site.x > next.vertex.x) {
2205 list.splice(i, 0, he);
2208 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l && ls[i] != he; ++i) {}
2212 return EventQueue.list.length === 0;
2214 nextEvent: function(he) {
2215 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l; ++i) {
2216 if (ls[i] == he) return ls[i + 1];
2221 var elem = EventQueue.list[0];
2227 extractMin: function() {
2228 return EventQueue.list.shift();
2232 Sites.bottomSite = Sites.list.shift();
2233 var newSite = Sites.list.shift(), newIntStar;
2234 var lbnd, rbnd, llbnd, rrbnd, bisector;
2235 var bot, top, temp, p, v;
2238 if (!EventQueue.empty()) {
2239 newIntStar = EventQueue.min();
2241 if (newSite && (EventQueue.empty() || newSite.y < newIntStar.y || newSite.y == newIntStar.y && newSite.x < newIntStar.x)) {
2242 lbnd = EdgeList.leftBound(newSite);
2243 rbnd = EdgeList.right(lbnd);
2244 bot = EdgeList.rightRegion(lbnd);
2245 e = Geom.bisect(bot, newSite);
2246 bisector = EdgeList.createHalfEdge(e, "l");
2247 EdgeList.insert(lbnd, bisector);
2248 p = Geom.intersect(lbnd, bisector);
2250 EventQueue.del(lbnd);
2251 EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
2254 bisector = EdgeList.createHalfEdge(e, "r");
2255 EdgeList.insert(lbnd, bisector);
2256 p = Geom.intersect(bisector, rbnd);
2258 EventQueue.insert(bisector, p, Geom.distance(p, newSite));
2260 newSite = Sites.list.shift();
2261 } else if (!EventQueue.empty()) {
2262 lbnd = EventQueue.extractMin();
2263 llbnd = EdgeList.left(lbnd);
2264 rbnd = EdgeList.right(lbnd);
2265 rrbnd = EdgeList.right(rbnd);
2266 bot = EdgeList.leftRegion(lbnd);
2267 top = EdgeList.rightRegion(rbnd);
2269 Geom.endPoint(lbnd.edge, lbnd.side, v);
2270 Geom.endPoint(rbnd.edge, rbnd.side, v);
2272 EventQueue.del(rbnd);
2275 if (bot.y > top.y) {
2281 e = Geom.bisect(bot, top);
2282 bisector = EdgeList.createHalfEdge(e, pm);
2283 EdgeList.insert(llbnd, bisector);
2284 Geom.endPoint(e, d3_voronoi_opposite[pm], v);
2285 p = Geom.intersect(llbnd, bisector);
2287 EventQueue.del(llbnd);
2288 EventQueue.insert(llbnd, p, Geom.distance(p, bot));
2290 p = Geom.intersect(bisector, rrbnd);
2292 EventQueue.insert(bisector, p, Geom.distance(p, bot));
2298 for (lbnd = EdgeList.right(EdgeList.leftEnd); lbnd != EdgeList.rightEnd; lbnd = EdgeList.right(lbnd)) {
2299 callback(lbnd.edge);
2302 function d3_geom_quadtreeNode() {
2309 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
2310 if (!f(node, x1, y1, x2, y2)) {
2311 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
2312 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
2313 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
2314 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
2315 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
2318 function d3_geom_quadtreePoint(p) {
2324 function d3_time_utc() {
2325 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2327 function d3_time_formatAbbreviate(name) {
2328 return name.substring(0, 3);
2330 function d3_time_parse(date, template, string, j) {
2331 var c, p, i = 0, n = template.length, m = string.length;
2333 if (j >= m) return -1;
2334 c = template.charCodeAt(i++);
2336 p = d3_time_parsers[template.charAt(i++)];
2337 if (!p || (j = p(date, string, j)) < 0) return -1;
2338 } else if (c != string.charCodeAt(j++)) {
2344 function d3_time_formatRe(names) {
2345 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2347 function d3_time_formatLookup(names) {
2348 var map = new d3_Map, i = -1, n = names.length;
2349 while (++i < n) map.set(names[i].toLowerCase(), i);
2352 function d3_time_parseWeekdayAbbrev(date, string, i) {
2353 d3_time_dayAbbrevRe.lastIndex = 0;
2354 var n = d3_time_dayAbbrevRe.exec(string.substring(i));
2355 return n ? i += n[0].length : -1;
2357 function d3_time_parseWeekday(date, string, i) {
2358 d3_time_dayRe.lastIndex = 0;
2359 var n = d3_time_dayRe.exec(string.substring(i));
2360 return n ? i += n[0].length : -1;
2362 function d3_time_parseMonthAbbrev(date, string, i) {
2363 d3_time_monthAbbrevRe.lastIndex = 0;
2364 var n = d3_time_monthAbbrevRe.exec(string.substring(i));
2365 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
2367 function d3_time_parseMonth(date, string, i) {
2368 d3_time_monthRe.lastIndex = 0;
2369 var n = d3_time_monthRe.exec(string.substring(i));
2370 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
2372 function d3_time_parseLocaleFull(date, string, i) {
2373 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2375 function d3_time_parseLocaleDate(date, string, i) {
2376 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2378 function d3_time_parseLocaleTime(date, string, i) {
2379 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2381 function d3_time_parseFullYear(date, string, i) {
2382 d3_time_numberRe.lastIndex = 0;
2383 var n = d3_time_numberRe.exec(string.substring(i, i + 4));
2384 return n ? (date.y = +n[0], i += n[0].length) : -1;
2386 function d3_time_parseYear(date, string, i) {
2387 d3_time_numberRe.lastIndex = 0;
2388 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2389 return n ? (date.y = d3_time_expandYear(+n[0]), i += n[0].length) : -1;
2391 function d3_time_expandYear(d) {
2392 return d + (d > 68 ? 1900 : 2e3);
2394 function d3_time_parseMonthNumber(date, string, i) {
2395 d3_time_numberRe.lastIndex = 0;
2396 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2397 return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
2399 function d3_time_parseDay(date, string, i) {
2400 d3_time_numberRe.lastIndex = 0;
2401 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2402 return n ? (date.d = +n[0], i += n[0].length) : -1;
2404 function d3_time_parseHour24(date, string, i) {
2405 d3_time_numberRe.lastIndex = 0;
2406 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2407 return n ? (date.H = +n[0], i += n[0].length) : -1;
2409 function d3_time_parseMinutes(date, string, i) {
2410 d3_time_numberRe.lastIndex = 0;
2411 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2412 return n ? (date.M = +n[0], i += n[0].length) : -1;
2414 function d3_time_parseSeconds(date, string, i) {
2415 d3_time_numberRe.lastIndex = 0;
2416 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2417 return n ? (date.S = +n[0], i += n[0].length) : -1;
2419 function d3_time_parseMilliseconds(date, string, i) {
2420 d3_time_numberRe.lastIndex = 0;
2421 var n = d3_time_numberRe.exec(string.substring(i, i + 3));
2422 return n ? (date.L = +n[0], i += n[0].length) : -1;
2424 function d3_time_parseAmPm(date, string, i) {
2425 var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
2426 return n == null ? -1 : (date.p = n, i);
2428 function d3_time_zone(d) {
2429 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
2430 return zs + d3_time_zfill2(zh) + d3_time_zfill2(zm);
2432 function d3_time_formatIsoNative(date) {
2433 return date.toISOString();
2435 function d3_time_interval(local, step, number) {
2436 function round(date) {
2437 var d0 = local(date), d1 = offset(d0, 1);
2438 return date - d0 < d1 - date ? d0 : d1;
2440 function ceil(date) {
2441 step(date = local(new d3_time(date - 1)), 1);
2444 function offset(date, k) {
2445 step(date = new d3_time(+date), k);
2448 function range(t0, t1, dt) {
2449 var time = ceil(t0), times = [];
2452 if (!(number(time) % dt)) times.push(new Date(+time));
2456 while (time < t1) times.push(new Date(+time)), step(time, 1);
2460 function range_utc(t0, t1, dt) {
2462 d3_time = d3_time_utc;
2463 var utc = new d3_time_utc;
2465 return range(utc, t1, dt);
2470 local.floor = local;
2471 local.round = round;
2473 local.offset = offset;
2474 local.range = range;
2475 var utc = local.utc = d3_time_interval_utc(local);
2477 utc.round = d3_time_interval_utc(round);
2478 utc.ceil = d3_time_interval_utc(ceil);
2479 utc.offset = d3_time_interval_utc(offset);
2480 utc.range = range_utc;
2483 function d3_time_interval_utc(method) {
2484 return function(date, k) {
2486 d3_time = d3_time_utc;
2487 var utc = new d3_time_utc;
2489 return method(utc, k)._;
2495 function d3_time_scale(linear, methods, format) {
2499 scale.invert = function(x) {
2500 return d3_time_scaleDate(linear.invert(x));
2502 scale.domain = function(x) {
2503 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
2507 scale.nice = function(m) {
2508 return scale.domain(d3_scale_nice(scale.domain(), function() {
2512 scale.ticks = function(m, k) {
2513 var extent = d3_time_scaleExtent(scale.domain());
2514 if (typeof m !== "function") {
2515 var span = extent[1] - extent[0], target = span / m, i = d3.bisect(d3_time_scaleSteps, target);
2516 if (i == d3_time_scaleSteps.length) return methods.year(extent, m);
2517 if (!i) return linear.ticks(m).map(d3_time_scaleDate);
2518 if (Math.log(target / d3_time_scaleSteps[i - 1]) < Math.log(d3_time_scaleSteps[i] / target)) --i;
2523 return m(extent[0], new Date(+extent[1] + 1), k);
2525 scale.tickFormat = function() {
2528 scale.copy = function() {
2529 return d3_time_scale(linear.copy(), methods, format);
2531 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
2533 function d3_time_scaleExtent(domain) {
2534 var start = domain[0], stop = domain[domain.length - 1];
2535 return start < stop ? [ start, stop ] : [ stop, start ];
2537 function d3_time_scaleDate(t) {
2540 function d3_time_scaleFormat(formats) {
2541 return function(date) {
2542 var i = formats.length - 1, f = formats[i];
2543 while (!f[1](date)) f = formats[--i];
2547 function d3_time_scaleSetYear(y) {
2548 var d = new Date(y, 0, 1);
2552 function d3_time_scaleGetYear(d) {
2553 var y = d.getFullYear(), d0 = d3_time_scaleSetYear(y), d1 = d3_time_scaleSetYear(y + 1);
2554 return y + (d - d0) / (d1 - d0);
2556 function d3_time_scaleUTCSetYear(y) {
2557 var d = new Date(Date.UTC(y, 0, 1));
2558 d.setUTCFullYear(y);
2561 function d3_time_scaleUTCGetYear(d) {
2562 var y = d.getUTCFullYear(), d0 = d3_time_scaleUTCSetYear(y), d1 = d3_time_scaleUTCSetYear(y + 1);
2563 return y + (d - d0) / (d1 - d0);
2565 if (!Date.now) Date.now = function() {
2569 document.createElement("div").style.setProperty("opacity", 0, "");
2571 var d3_style_prototype = CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
2572 d3_style_prototype.setProperty = function(name, value, priority) {
2573 d3_style_setProperty.call(this, name, value + "", priority);
2579 var d3_array = d3_arraySlice;
2581 d3_array(document.documentElement.childNodes)[0].nodeType;
2583 d3_array = d3_arrayCopy;
2585 var d3_arraySubclass = [].__proto__ ? function(array, prototype) {
2586 array.__proto__ = prototype;
2587 } : function(array, prototype) {
2588 for (var property in prototype) array[property] = prototype[property];
2590 d3.map = function(object) {
2591 var map = new d3_Map;
2592 for (var key in object) map.set(key, object[key]);
2596 has: function(key) {
2597 return d3_map_prefix + key in this;
2599 get: function(key) {
2600 return this[d3_map_prefix + key];
2602 set: function(key, value) {
2603 return this[d3_map_prefix + key] = value;
2605 remove: function(key) {
2606 key = d3_map_prefix + key;
2607 return key in this && delete this[key];
2611 this.forEach(function(key) {
2616 values: function() {
2618 this.forEach(function(key, value) {
2623 entries: function() {
2625 this.forEach(function(key, value) {
2633 forEach: function(f) {
2634 for (var key in this) {
2635 if (key.charCodeAt(0) === d3_map_prefixCode) {
2636 f.call(this, key.substring(1), this[key]);
2641 var d3_map_prefix = "\0", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
2642 d3.functor = d3_functor;
2643 d3.rebind = function(target, source) {
2644 var i = 1, n = arguments.length, method;
2645 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
2648 d3.ascending = function(a, b) {
2649 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
2651 d3.descending = function(a, b) {
2652 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
2654 d3.mean = function(array, f) {
2655 var n = array.length, a, m = 0, i = -1, j = 0;
2656 if (arguments.length === 1) {
2657 while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
2659 while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
2661 return j ? m : undefined;
2663 d3.median = function(array, f) {
2664 if (arguments.length > 1) array = array.map(f);
2665 array = array.filter(d3_number);
2666 return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
2668 d3.min = function(array, f) {
2669 var i = -1, n = array.length, a, b;
2670 if (arguments.length === 1) {
2671 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
2672 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
2674 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
2675 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
2679 d3.max = function(array, f) {
2680 var i = -1, n = array.length, a, b;
2681 if (arguments.length === 1) {
2682 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
2683 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
2685 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
2686 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
2690 d3.extent = function(array, f) {
2691 var i = -1, n = array.length, a, b, c;
2692 if (arguments.length === 1) {
2693 while (++i < n && ((a = c = array[i]) == null || a != a)) a = c = undefined;
2694 while (++i < n) if ((b = array[i]) != null) {
2699 while (++i < n && ((a = c = f.call(array, array[i], i)) == null || a != a)) a = undefined;
2700 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
2708 normal: function(µ, σ) {
2709 var n = arguments.length;
2715 x = Math.random() * 2 - 1;
2716 y = Math.random() * 2 - 1;
2718 } while (!r || r > 1);
2719 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
2722 logNormal: function(µ, σ) {
2723 var n = arguments.length;
2726 var random = d3.random.normal();
2728 return Math.exp(µ + σ * random());
2731 irwinHall: function(m) {
2733 for (var s = 0, j = 0; j < m; j++) s += Math.random();
2738 d3.sum = function(array, f) {
2739 var s = 0, n = array.length, a, i = -1;
2740 if (arguments.length === 1) {
2741 while (++i < n) if (!isNaN(a = +array[i])) s += a;
2743 while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
2747 d3.quantile = function(values, p) {
2748 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = values[h - 1], e = H - h;
2749 return e ? v + e * (values[h] - v) : v;
2751 d3.transpose = function(matrix) {
2752 return d3.zip.apply(d3, matrix);
2754 d3.zip = function() {
2755 if (!(n = arguments.length)) return [];
2756 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
2757 for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
2758 zip[j] = arguments[j][i];
2763 d3.bisector = function(f) {
2765 left: function(a, x, lo, hi) {
2766 if (arguments.length < 3) lo = 0;
2767 if (arguments.length < 4) hi = a.length;
2769 var mid = lo + hi >>> 1;
2770 if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid;
2774 right: function(a, x, lo, hi) {
2775 if (arguments.length < 3) lo = 0;
2776 if (arguments.length < 4) hi = a.length;
2778 var mid = lo + hi >>> 1;
2779 if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1;
2785 var d3_bisector = d3.bisector(function(d) {
2788 d3.bisectLeft = d3_bisector.left;
2789 d3.bisect = d3.bisectRight = d3_bisector.right;
2790 d3.first = function(array, f) {
2791 var i = 0, n = array.length, a = array[0], b;
2792 if (arguments.length === 1) f = d3.ascending;
2794 if (f.call(array, a, b = array[i]) > 0) {
2800 d3.last = function(array, f) {
2801 var i = 0, n = array.length, a = array[0], b;
2802 if (arguments.length === 1) f = d3.ascending;
2804 if (f.call(array, a, b = array[i]) <= 0) {
2810 d3.nest = function() {
2811 function map(array, depth) {
2812 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
2813 var i = -1, n = array.length, key = keys[depth++], keyValue, object, valuesByKey = new d3_Map, values, o = {};
2815 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
2816 values.push(object);
2818 valuesByKey.set(keyValue, [ object ]);
2821 valuesByKey.forEach(function(keyValue, values) {
2822 o[keyValue] = map(values, depth);
2826 function entries(map, depth) {
2827 if (depth >= keys.length) return map;
2828 var a = [], sortKey = sortKeys[depth++], key;
2832 values: entries(map[key], depth)
2835 if (sortKey) a.sort(function(a, b) {
2836 return sortKey(a.key, b.key);
2840 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
2841 nest.map = function(array) {
2842 return map(array, 0);
2844 nest.entries = function(array) {
2845 return entries(map(array, 0), 0);
2847 nest.key = function(d) {
2851 nest.sortKeys = function(order) {
2852 sortKeys[keys.length - 1] = order;
2855 nest.sortValues = function(order) {
2859 nest.rollup = function(f) {
2865 d3.keys = function(map) {
2867 for (var key in map) keys.push(key);
2870 d3.values = function(map) {
2872 for (var key in map) values.push(map[key]);
2875 d3.entries = function(map) {
2877 for (var key in map) entries.push({
2883 d3.permute = function(array, indexes) {
2884 var permutes = [], i = -1, n = indexes.length;
2885 while (++i < n) permutes[i] = array[indexes[i]];
2888 d3.merge = function(arrays) {
2889 return Array.prototype.concat.apply([], arrays);
2891 d3.split = function(array, f) {
2892 var arrays = [], values = [], value, i = -1, n = array.length;
2893 if (arguments.length < 2) f = d3_splitter;
2895 if (f.call(values, value = array[i], i)) {
2898 if (!values.length) arrays.push(values);
2904 d3.range = function(start, stop, step) {
2905 if (arguments.length < 3) {
2907 if (arguments.length < 2) {
2912 if ((stop - start) / step === Infinity) throw new Error("infinite range");
2913 var range = [], k = d3_range_integerScale(Math.abs(step)), i = -1, j;
2914 start *= k, stop *= k, step *= k;
2915 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
2918 d3.requote = function(s) {
2919 return s.replace(d3_requote_re, "\\$&");
2921 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
2922 d3.round = function(x, n) {
2923 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2925 d3.xhr = function(url, mime, callback) {
2926 var req = new XMLHttpRequest;
2927 if (arguments.length < 3) callback = mime, mime = null; else if (mime && req.overrideMimeType) req.overrideMimeType(mime);
2928 req.open("GET", url, true);
2929 if (mime) req.setRequestHeader("Accept", mime);
2930 req.onreadystatechange = function() {
2931 if (req.readyState === 4) {
2933 callback(!s && req.response || s >= 200 && s < 300 || s === 304 ? req : null);
2938 d3.text = function(url, mime, callback) {
2939 function ready(req) {
2940 callback(req && req.responseText);
2942 if (arguments.length < 3) {
2946 d3.xhr(url, mime, ready);
2948 d3.json = function(url, callback) {
2949 d3.text(url, "application/json", function(text) {
2950 callback(text ? JSON.parse(text) : null);
2953 d3.html = function(url, callback) {
2954 d3.text(url, "text/html", function(text) {
2956 var range = document.createRange();
2957 range.selectNode(document.body);
2958 text = range.createContextualFragment(text);
2963 d3.xml = function(url, mime, callback) {
2964 function ready(req) {
2965 callback(req && req.responseXML);
2967 if (arguments.length < 3) {
2971 d3.xhr(url, mime, ready);
2974 svg: "http://www.w3.org/2000/svg",
2975 xhtml: "http://www.w3.org/1999/xhtml",
2976 xlink: "http://www.w3.org/1999/xlink",
2977 xml: "http://www.w3.org/XML/1998/namespace",
2978 xmlns: "http://www.w3.org/2000/xmlns/"
2981 prefix: d3_nsPrefix,
2982 qualify: function(name) {
2983 var i = name.indexOf(":"), prefix = name;
2985 prefix = name.substring(0, i);
2986 name = name.substring(i + 1);
2988 return d3_nsPrefix.hasOwnProperty(prefix) ? {
2989 space: d3_nsPrefix[prefix],
2994 d3.dispatch = function() {
2995 var dispatch = new d3_dispatch, i = -1, n = arguments.length;
2996 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
2999 d3_dispatch.prototype.on = function(type, listener) {
3000 var i = type.indexOf("."), name = "";
3002 name = type.substring(i + 1);
3003 type = type.substring(0, i);
3005 return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
3007 d3.format = function(specifier) {
3008 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;
3009 if (precision) precision = +precision.substring(1);
3012 if (comma) width -= Math.floor((width - 1) / 4);
3038 if (type == "r" && !precision) type = "g";
3039 type = d3_format_types.get(type) || d3_format_typeDefault;
3040 return function(value) {
3041 if (integer && value % 1) return "";
3042 var negative = value < 0 && (value = -value) ? "-" : sign;
3044 var prefix = d3.formatPrefix(value, precision);
3045 value = prefix.scale(value);
3046 suffix = prefix.symbol;
3050 value = type(value, precision);
3052 var length = value.length + negative.length;
3053 if (length < width) value = (new Array(width - length + 1)).join(fill) + value;
3054 if (comma) value = d3_format_group(value);
3055 value = negative + value;
3057 if (comma) value = d3_format_group(value);
3058 value = negative + value;
3059 var length = value.length;
3060 if (length < width) value = (new Array(width - length + 1)).join(fill) + value;
3062 return value + suffix;
3065 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
3066 var d3_format_types = d3.map({
3068 return x.toPrecision(p);
3071 return x.toExponential(p);
3074 return x.toFixed(p);
3077 return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p)));
3080 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "μ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
3081 d3.formatPrefix = function(value, precision) {
3084 if (value < 0) value *= -1;
3085 if (precision) value = d3.round(value, d3_format_precision(value, precision));
3086 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
3087 i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
3089 return d3_formatPrefixes[8 + i / 3];
3091 var d3_ease_quad = d3_ease_poly(2), d3_ease_cubic = d3_ease_poly(3), d3_ease_default = function() {
3092 return d3_ease_identity;
3094 var d3_ease = d3.map({
3095 linear: d3_ease_default,
3098 return d3_ease_quad;
3101 return d3_ease_cubic;
3109 circle: function() {
3110 return d3_ease_circle;
3112 elastic: d3_ease_elastic,
3114 bounce: function() {
3115 return d3_ease_bounce;
3118 var d3_ease_mode = d3.map({
3119 "in": d3_ease_identity,
3120 out: d3_ease_reverse,
3121 "in-out": d3_ease_reflect,
3122 "out-in": function(f) {
3123 return d3_ease_reflect(d3_ease_reverse(f));
3126 d3.ease = function(name) {
3127 var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
3128 t = d3_ease.get(t) || d3_ease_default;
3129 m = d3_ease_mode.get(m) || d3_ease_identity;
3130 return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1))));
3133 d3.transform = function(string) {
3134 var g = document.createElementNS(d3.ns.prefix.svg, "g");
3135 return (d3.transform = function(string) {
3136 g.setAttribute("transform", string);
3137 var t = g.transform.baseVal.consolidate();
3138 return new d3_transform(t ? t.matrix : d3_transformIdentity);
3141 d3_transform.prototype.toString = function() {
3142 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
3144 var d3_transformDegrees = 180 / Math.PI, d3_transformIdentity = {
3152 d3.interpolate = function(a, b) {
3153 var i = d3.interpolators.length, f;
3154 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
3157 d3.interpolateNumber = function(a, b) {
3159 return function(t) {
3163 d3.interpolateRound = function(a, b) {
3165 return function(t) {
3166 return Math.round(a + b * t);
3169 d3.interpolateString = function(a, b) {
3170 var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
3171 d3_interpolate_number.lastIndex = 0;
3172 for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
3173 if (m.index) s.push(b.substring(s0, s1 = m.index));
3179 s0 = d3_interpolate_number.lastIndex;
3181 if (s0 < b.length) s.push(b.substring(s0));
3182 for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
3186 if (s[o.i + 1] == null) {
3189 for (j = i + 1; j < n; ++j) q[j].i--;
3191 s[o.i - 1] += o.x + s[o.i + 1];
3193 for (j = i + 1; j < n; ++j) q[j].i -= 2;
3196 if (s[o.i + 1] == null) {
3199 s[o.i] = o.x + s[o.i + 1];
3200 s.splice(o.i + 1, 1);
3201 for (j = i + 1; j < n; ++j) q[j].i--;
3208 o.x = d3.interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
3213 if (s[o.i + 1] == null) {
3216 s[o.i] = o.x + s[o.i + 1];
3217 s.splice(o.i + 1, 1);
3221 if (s.length === 1) {
3222 return s[0] == null ? q[0].x : function() {
3226 return function(t) {
3227 for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
3231 d3.interpolateTransform = function(a, b) {
3232 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;
3233 if (ta[0] != tb[0] || ta[1] != tb[1]) {
3234 s.push("translate(", null, ",", null, ")");
3237 x: d3.interpolateNumber(ta[0], tb[0])
3240 x: d3.interpolateNumber(ta[1], tb[1])
3242 } else if (tb[0] || tb[1]) {
3243 s.push("translate(" + tb + ")");
3248 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
3250 i: s.push(s.pop() + "rotate(", null, ")") - 2,
3251 x: d3.interpolateNumber(ra, rb)
3254 s.push(s.pop() + "rotate(" + rb + ")");
3258 i: s.push(s.pop() + "skewX(", null, ")") - 2,
3259 x: d3.interpolateNumber(wa, wb)
3262 s.push(s.pop() + "skewX(" + wb + ")");
3264 if (ka[0] != kb[0] || ka[1] != kb[1]) {
3265 n = s.push(s.pop() + "scale(", null, ",", null, ")");
3268 x: d3.interpolateNumber(ka[0], kb[0])
3271 x: d3.interpolateNumber(ka[1], kb[1])
3273 } else if (kb[0] != 1 || kb[1] != 1) {
3274 s.push(s.pop() + "scale(" + kb + ")");
3277 return function(t) {
3279 while (++i < n) s[(o = q[i]).i] = o.x(t);
3283 d3.interpolateRgb = function(a, b) {
3286 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
3287 return function(t) {
3288 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));
3291 d3.interpolateHsl = function(a, b) {
3294 var h0 = a.h, s0 = a.s, l0 = a.l, h1 = b.h - h0, s1 = b.s - s0, l1 = b.l - l0;
3295 if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360;
3296 return function(t) {
3297 return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t) + "";
3300 d3.interpolateLab = function(a, b) {
3303 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
3304 return function(t) {
3305 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
3308 d3.interpolateHcl = function(a, b) {
3311 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
3312 if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
3313 return function(t) {
3314 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
3317 d3.interpolateArray = function(a, b) {
3318 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
3319 for (i = 0; i < n0; ++i) x.push(d3.interpolate(a[i], b[i]));
3320 for (; i < na; ++i) c[i] = a[i];
3321 for (; i < nb; ++i) c[i] = b[i];
3322 return function(t) {
3323 for (i = 0; i < n0; ++i) c[i] = x[i](t);
3327 d3.interpolateObject = function(a, b) {
3328 var i = {}, c = {}, k;
3331 i[k] = d3_interpolateByName(k)(a[k], b[k]);
3341 return function(t) {
3342 for (k in i) c[k] = i[k](t);
3346 var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
3347 d3.interpolators = [ d3.interpolateObject, function(a, b) {
3348 return b instanceof Array && d3.interpolateArray(a, b);
3350 return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + "");
3352 return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Color) && d3.interpolateRgb(a, b);
3354 return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b);
3356 d3_Color.prototype.toString = function() {
3357 return this.rgb() + "";
3359 d3.rgb = function(r, g, b) {
3360 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);
3362 var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color;
3363 d3_rgbPrototype.brighter = function(k) {
3364 k = Math.pow(.7, arguments.length ? k : 1);
3365 var r = this.r, g = this.g, b = this.b, i = 30;
3366 if (!r && !g && !b) return d3_rgb(i, i, i);
3367 if (r && r < i) r = i;
3368 if (g && g < i) g = i;
3369 if (b && b < i) b = i;
3370 return d3_rgb(Math.min(255, Math.floor(r / k)), Math.min(255, Math.floor(g / k)), Math.min(255, Math.floor(b / k)));
3372 d3_rgbPrototype.darker = function(k) {
3373 k = Math.pow(.7, arguments.length ? k : 1);
3374 return d3_rgb(Math.floor(k * this.r), Math.floor(k * this.g), Math.floor(k * this.b));
3376 d3_rgbPrototype.hsl = function() {
3377 return d3_rgb_hsl(this.r, this.g, this.b);
3379 d3_rgbPrototype.toString = function() {
3380 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
3382 var d3_rgb_names = d3.map({
3383 aliceblue: "#f0f8ff",
3384 antiquewhite: "#faebd7",
3386 aquamarine: "#7fffd4",
3391 blanchedalmond: "#ffebcd",
3393 blueviolet: "#8a2be2",
3395 burlywood: "#deb887",
3396 cadetblue: "#5f9ea0",
3397 chartreuse: "#7fff00",
3398 chocolate: "#d2691e",
3400 cornflowerblue: "#6495ed",
3401 cornsilk: "#fff8dc",
3404 darkblue: "#00008b",
3405 darkcyan: "#008b8b",
3406 darkgoldenrod: "#b8860b",
3407 darkgray: "#a9a9a9",
3408 darkgreen: "#006400",
3409 darkgrey: "#a9a9a9",
3410 darkkhaki: "#bdb76b",
3411 darkmagenta: "#8b008b",
3412 darkolivegreen: "#556b2f",
3413 darkorange: "#ff8c00",
3414 darkorchid: "#9932cc",
3416 darksalmon: "#e9967a",
3417 darkseagreen: "#8fbc8f",
3418 darkslateblue: "#483d8b",
3419 darkslategray: "#2f4f4f",
3420 darkslategrey: "#2f4f4f",
3421 darkturquoise: "#00ced1",
3422 darkviolet: "#9400d3",
3423 deeppink: "#ff1493",
3424 deepskyblue: "#00bfff",
3427 dodgerblue: "#1e90ff",
3428 firebrick: "#b22222",
3429 floralwhite: "#fffaf0",
3430 forestgreen: "#228b22",
3432 gainsboro: "#dcdcdc",
3433 ghostwhite: "#f8f8ff",
3435 goldenrod: "#daa520",
3438 greenyellow: "#adff2f",
3440 honeydew: "#f0fff0",
3442 indianred: "#cd5c5c",
3446 lavender: "#e6e6fa",
3447 lavenderblush: "#fff0f5",
3448 lawngreen: "#7cfc00",
3449 lemonchiffon: "#fffacd",
3450 lightblue: "#add8e6",
3451 lightcoral: "#f08080",
3452 lightcyan: "#e0ffff",
3453 lightgoldenrodyellow: "#fafad2",
3454 lightgray: "#d3d3d3",
3455 lightgreen: "#90ee90",
3456 lightgrey: "#d3d3d3",
3457 lightpink: "#ffb6c1",
3458 lightsalmon: "#ffa07a",
3459 lightseagreen: "#20b2aa",
3460 lightskyblue: "#87cefa",
3461 lightslategray: "#778899",
3462 lightslategrey: "#778899",
3463 lightsteelblue: "#b0c4de",
3464 lightyellow: "#ffffe0",
3466 limegreen: "#32cd32",
3470 mediumaquamarine: "#66cdaa",
3471 mediumblue: "#0000cd",
3472 mediumorchid: "#ba55d3",
3473 mediumpurple: "#9370db",
3474 mediumseagreen: "#3cb371",
3475 mediumslateblue: "#7b68ee",
3476 mediumspringgreen: "#00fa9a",
3477 mediumturquoise: "#48d1cc",
3478 mediumvioletred: "#c71585",
3479 midnightblue: "#191970",
3480 mintcream: "#f5fffa",
3481 mistyrose: "#ffe4e1",
3482 moccasin: "#ffe4b5",
3483 navajowhite: "#ffdead",
3487 olivedrab: "#6b8e23",
3489 orangered: "#ff4500",
3491 palegoldenrod: "#eee8aa",
3492 palegreen: "#98fb98",
3493 paleturquoise: "#afeeee",
3494 palevioletred: "#db7093",
3495 papayawhip: "#ffefd5",
3496 peachpuff: "#ffdab9",
3500 powderblue: "#b0e0e6",
3503 rosybrown: "#bc8f8f",
3504 royalblue: "#4169e1",
3505 saddlebrown: "#8b4513",
3507 sandybrown: "#f4a460",
3508 seagreen: "#2e8b57",
3509 seashell: "#fff5ee",
3513 slateblue: "#6a5acd",
3514 slategray: "#708090",
3515 slategrey: "#708090",
3517 springgreen: "#00ff7f",
3518 steelblue: "#4682b4",
3523 turquoise: "#40e0d0",
3527 whitesmoke: "#f5f5f5",
3529 yellowgreen: "#9acd32"
3531 d3_rgb_names.forEach(function(key, value) {
3532 d3_rgb_names.set(key, d3_rgb_parse(value, d3_rgb, d3_hsl_rgb));
3534 d3.hsl = function(h, s, l) {
3535 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);
3537 var d3_hslPrototype = d3_Hsl.prototype = new d3_Color;
3538 d3_hslPrototype.brighter = function(k) {
3539 k = Math.pow(.7, arguments.length ? k : 1);
3540 return d3_hsl(this.h, this.s, this.l / k);
3542 d3_hslPrototype.darker = function(k) {
3543 k = Math.pow(.7, arguments.length ? k : 1);
3544 return d3_hsl(this.h, this.s, k * this.l);
3546 d3_hslPrototype.rgb = function() {
3547 return d3_hsl_rgb(this.h, this.s, this.l);
3549 d3.hcl = function(h, c, l) {
3550 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);
3552 var d3_hclPrototype = d3_Hcl.prototype = new d3_Color;
3553 d3_hclPrototype.brighter = function(k) {
3554 return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
3556 d3_hclPrototype.darker = function(k) {
3557 return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
3559 d3_hclPrototype.rgb = function() {
3560 return d3_hcl_lab(this.h, this.c, this.l).rgb();
3562 d3.lab = function(l, a, b) {
3563 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);
3566 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
3567 var d3_labPrototype = d3_Lab.prototype = new d3_Color;
3568 d3_labPrototype.brighter = function(k) {
3569 return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
3571 d3_labPrototype.darker = function(k) {
3572 return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
3574 d3_labPrototype.rgb = function() {
3575 return d3_lab_rgb(this.l, this.a, this.b);
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_id = 0, d3_timer_byId = {}, d3_timer_queue = null, d3_timer_interval, d3_timer_timeout;
4068 d3.timer = function(callback, delay, then) {
4069 if (arguments.length < 3) {
4070 if (arguments.length < 2) delay = 0; else if (!isFinite(delay)) return;
4073 var timer = d3_timer_byId[callback.id];
4074 if (timer && timer.callback === callback) {
4076 timer.delay = delay;
4077 } else d3_timer_byId[callback.id = ++d3_timer_id] = d3_timer_queue = {
4081 next: d3_timer_queue
4083 if (!d3_timer_interval) {
4084 d3_timer_timeout = clearTimeout(d3_timer_timeout);
4085 d3_timer_interval = 1;
4086 d3_timer_frame(d3_timer_step);
4089 d3.timer.flush = function() {
4090 var elapsed, now = Date.now(), t1 = d3_timer_queue;
4092 elapsed = now - t1.then;
4093 if (!t1.delay) t1.flush = t1.callback(elapsed);
4098 var d3_timer_frame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
4099 setTimeout(callback, 17);
4101 d3.mouse = function(container) {
4102 return d3_mousePoint(container, d3_eventSource());
4104 var d3_mouse_bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
4105 d3.touches = function(container, touches) {
4106 if (arguments.length < 2) touches = d3_eventSource().touches;
4107 return touches ? d3_array(touches).map(function(touch) {
4108 var point = d3_mousePoint(container, touch);
4109 point.identifier = touch.identifier;
4114 d3.scale.linear = function() {
4115 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3.interpolate, false);
4117 d3.scale.log = function() {
4118 return d3_scale_log(d3.scale.linear(), d3_scale_logp);
4120 var d3_scale_logFormat = d3.format(".0e");
4121 d3_scale_logp.pow = function(x) {
4122 return Math.pow(10, x);
4124 d3_scale_logn.pow = function(x) {
4125 return -Math.pow(10, -x);
4127 d3.scale.pow = function() {
4128 return d3_scale_pow(d3.scale.linear(), 1);
4130 d3.scale.sqrt = function() {
4131 return d3.scale.pow().exponent(.5);
4133 d3.scale.ordinal = function() {
4134 return d3_scale_ordinal([], {
4139 d3.scale.category10 = function() {
4140 return d3.scale.ordinal().range(d3_category10);
4142 d3.scale.category20 = function() {
4143 return d3.scale.ordinal().range(d3_category20);
4145 d3.scale.category20b = function() {
4146 return d3.scale.ordinal().range(d3_category20b);
4148 d3.scale.category20c = function() {
4149 return d3.scale.ordinal().range(d3_category20c);
4151 var d3_category10 = [ "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf" ];
4152 var d3_category20 = [ "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5" ];
4153 var d3_category20b = [ "#393b79", "#5254a3", "#6b6ecf", "#9c9ede", "#637939", "#8ca252", "#b5cf6b", "#cedb9c", "#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94", "#843c39", "#ad494a", "#d6616b", "#e7969c", "#7b4173", "#a55194", "#ce6dbd", "#de9ed6" ];
4154 var d3_category20c = [ "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" ];
4155 d3.scale.quantile = function() {
4156 return d3_scale_quantile([], []);
4158 d3.scale.quantize = function() {
4159 return d3_scale_quantize(0, 1, [ 0, 1 ]);
4161 d3.scale.threshold = function() {
4162 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
4164 d3.scale.identity = function() {
4165 return d3_scale_identity([ 0, 1 ]);
4168 d3.svg.arc = function() {
4170 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);
4171 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";
4173 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
4174 arc.innerRadius = function(v) {
4175 if (!arguments.length) return innerRadius;
4176 innerRadius = d3_functor(v);
4179 arc.outerRadius = function(v) {
4180 if (!arguments.length) return outerRadius;
4181 outerRadius = d3_functor(v);
4184 arc.startAngle = function(v) {
4185 if (!arguments.length) return startAngle;
4186 startAngle = d3_functor(v);
4189 arc.endAngle = function(v) {
4190 if (!arguments.length) return endAngle;
4191 endAngle = d3_functor(v);
4194 arc.centroid = function() {
4195 var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
4196 return [ Math.cos(a) * r, Math.sin(a) * r ];
4200 var d3_svg_arcOffset = -Math.PI / 2, d3_svg_arcMax = 2 * Math.PI - 1e-6;
4201 d3.svg.line = function() {
4202 return d3_svg_line(d3_identity);
4204 var d3_svg_lineInterpolators = d3.map({
4205 linear: d3_svg_lineLinear,
4206 "linear-closed": d3_svg_lineLinearClosed,
4207 "step-before": d3_svg_lineStepBefore,
4208 "step-after": d3_svg_lineStepAfter,
4209 basis: d3_svg_lineBasis,
4210 "basis-open": d3_svg_lineBasisOpen,
4211 "basis-closed": d3_svg_lineBasisClosed,
4212 bundle: d3_svg_lineBundle,
4213 cardinal: d3_svg_lineCardinal,
4214 "cardinal-open": d3_svg_lineCardinalOpen,
4215 "cardinal-closed": d3_svg_lineCardinalClosed,
4216 monotone: d3_svg_lineMonotone
4218 d3_svg_lineInterpolators.forEach(function(key, value) {
4220 value.closed = /-closed$/.test(key);
4222 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 ];
4223 d3.svg.line.radial = function() {
4224 var line = d3_svg_line(d3_svg_lineRadial);
4225 line.radius = line.x, delete line.x;
4226 line.angle = line.y, delete line.y;
4229 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
4230 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
4231 d3.svg.area = function() {
4232 return d3_svg_area(d3_identity);
4234 d3.svg.area.radial = function() {
4235 var area = d3_svg_area(d3_svg_lineRadial);
4236 area.radius = area.x, delete area.x;
4237 area.innerRadius = area.x0, delete area.x0;
4238 area.outerRadius = area.x1, delete area.x1;
4239 area.angle = area.y, delete area.y;
4240 area.startAngle = area.y0, delete area.y0;
4241 area.endAngle = area.y1, delete area.y1;
4244 d3.svg.chord = function() {
4245 function chord(d, i) {
4246 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
4247 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";
4249 function subgroup(self, f, d, i) {
4250 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;
4255 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
4256 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
4259 function equals(a, b) {
4260 return a.a0 == b.a0 && a.a1 == b.a1;
4262 function arc(r, p, a) {
4263 return "A" + r + "," + r + " 0 " + +(a > Math.PI) + ",1 " + p;
4265 function curve(r0, p0, r1, p1) {
4266 return "Q 0,0 " + p1;
4268 var source = d3_svg_chordSource, target = d3_svg_chordTarget, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
4269 chord.radius = function(v) {
4270 if (!arguments.length) return radius;
4271 radius = d3_functor(v);
4274 chord.source = function(v) {
4275 if (!arguments.length) return source;
4276 source = d3_functor(v);
4279 chord.target = function(v) {
4280 if (!arguments.length) return target;
4281 target = d3_functor(v);
4284 chord.startAngle = function(v) {
4285 if (!arguments.length) return startAngle;
4286 startAngle = d3_functor(v);
4289 chord.endAngle = function(v) {
4290 if (!arguments.length) return endAngle;
4291 endAngle = d3_functor(v);
4296 d3.svg.diagonal = function() {
4297 function diagonal(d, i) {
4298 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
4305 p = p.map(projection);
4306 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
4308 var source = d3_svg_chordSource, target = d3_svg_chordTarget, projection = d3_svg_diagonalProjection;
4309 diagonal.source = function(x) {
4310 if (!arguments.length) return source;
4311 source = d3_functor(x);
4314 diagonal.target = function(x) {
4315 if (!arguments.length) return target;
4316 target = d3_functor(x);
4319 diagonal.projection = function(x) {
4320 if (!arguments.length) return projection;
4326 d3.svg.diagonal.radial = function() {
4327 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
4328 diagonal.projection = function(x) {
4329 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
4333 d3.svg.mouse = d3.mouse;
4334 d3.svg.touches = d3.touches;
4335 d3.svg.symbol = function() {
4336 function symbol(d, i) {
4337 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
4339 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
4340 symbol.type = function(x) {
4341 if (!arguments.length) return type;
4342 type = d3_functor(x);
4345 symbol.size = function(x) {
4346 if (!arguments.length) return size;
4347 size = d3_functor(x);
4352 var d3_svg_symbols = d3.map({
4353 circle: d3_svg_symbolCircle,
4354 cross: function(size) {
4355 var r = Math.sqrt(size / 5) / 2;
4356 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";
4358 diamond: function(size) {
4359 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
4360 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
4362 square: function(size) {
4363 var r = Math.sqrt(size) / 2;
4364 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
4366 "triangle-down": function(size) {
4367 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
4368 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
4370 "triangle-up": function(size) {
4371 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
4372 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
4375 d3.svg.symbolTypes = d3_svg_symbols.keys();
4376 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * Math.PI / 180);
4377 d3.svg.axis = function() {
4380 var g = d3.select(this);
4381 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_;
4382 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);
4383 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;
4384 var range = d3_scaleRange(scale), path = g.selectAll(".domain").data([ 0 ]), pathEnter = path.enter().append("path").attr("class", "domain"), pathUpdate = d3.transition(path);
4385 var scale1 = scale.copy(), scale0 = this.__chart__ || scale1;
4386 this.__chart__ = scale1;
4387 tickEnter.append("line").attr("class", "tick");
4388 tickEnter.append("text");
4389 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
4393 tickTransform = d3_svg_axisX;
4394 subtickEnter.attr("y2", tickMinorSize);
4395 subtickUpdate.attr("x2", 0).attr("y2", tickMinorSize);
4396 lineEnter.attr("y2", tickMajorSize);
4397 textEnter.attr("y", Math.max(tickMajorSize, 0) + tickPadding);
4398 lineUpdate.attr("x2", 0).attr("y2", tickMajorSize);
4399 textUpdate.attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding);
4400 text.attr("dy", ".71em").attr("text-anchor", "middle");
4401 pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize);
4406 tickTransform = d3_svg_axisX;
4407 subtickEnter.attr("y2", -tickMinorSize);
4408 subtickUpdate.attr("x2", 0).attr("y2", -tickMinorSize);
4409 lineEnter.attr("y2", -tickMajorSize);
4410 textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
4411 lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize);
4412 textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
4413 text.attr("dy", "0em").attr("text-anchor", "middle");
4414 pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize);
4419 tickTransform = d3_svg_axisY;
4420 subtickEnter.attr("x2", -tickMinorSize);
4421 subtickUpdate.attr("x2", -tickMinorSize).attr("y2", 0);
4422 lineEnter.attr("x2", -tickMajorSize);
4423 textEnter.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding));
4424 lineUpdate.attr("x2", -tickMajorSize).attr("y2", 0);
4425 textUpdate.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0);
4426 text.attr("dy", ".32em").attr("text-anchor", "end");
4427 pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize);
4432 tickTransform = d3_svg_axisY;
4433 subtickEnter.attr("x2", tickMinorSize);
4434 subtickUpdate.attr("x2", tickMinorSize).attr("y2", 0);
4435 lineEnter.attr("x2", tickMajorSize);
4436 textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding);
4437 lineUpdate.attr("x2", tickMajorSize).attr("y2", 0);
4438 textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0);
4439 text.attr("dy", ".32em").attr("text-anchor", "start");
4440 pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize);
4445 tickEnter.call(tickTransform, scale0);
4446 tickUpdate.call(tickTransform, scale1);
4447 tickExit.call(tickTransform, scale1);
4448 subtickEnter.call(tickTransform, scale0);
4449 subtickUpdate.call(tickTransform, scale1);
4450 subtickExit.call(tickTransform, scale1);
4452 var dx = scale1.rangeBand() / 2, x = function(d) {
4453 return scale1(d) + dx;
4455 tickEnter.call(tickTransform, x);
4456 tickUpdate.call(tickTransform, x);
4460 var scale = d3.scale.linear(), orient = "bottom", tickMajorSize = 6, tickMinorSize = 6, tickEndSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_, tickSubdivide = 0;
4461 axis.scale = function(x) {
4462 if (!arguments.length) return scale;
4466 axis.orient = function(x) {
4467 if (!arguments.length) return orient;
4471 axis.ticks = function() {
4472 if (!arguments.length) return tickArguments_;
4473 tickArguments_ = arguments;
4476 axis.tickValues = function(x) {
4477 if (!arguments.length) return tickValues;
4481 axis.tickFormat = function(x) {
4482 if (!arguments.length) return tickFormat_;
4486 axis.tickSize = function(x, y, z) {
4487 if (!arguments.length) return tickMajorSize;
4488 var n = arguments.length - 1;
4490 tickMinorSize = n > 1 ? +y : tickMajorSize;
4491 tickEndSize = n > 0 ? +arguments[n] : tickMajorSize;
4494 axis.tickPadding = function(x) {
4495 if (!arguments.length) return tickPadding;
4499 axis.tickSubdivide = function(x) {
4500 if (!arguments.length) return tickSubdivide;
4506 d3.svg.brush = function() {
4509 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;
4510 g.style("pointer-events", "all").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
4511 bg.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
4512 fg.enter().append("rect").attr("class", "extent").style("cursor", "move");
4513 tz.enter().append("g").attr("class", function(d) {
4514 return "resize " + d;
4515 }).style("cursor", function(d) {
4516 return d3_svg_brushCursor[d];
4517 }).append("rect").attr("x", function(d) {
4518 return /[ew]$/.test(d) ? -3 : null;
4519 }).attr("y", function(d) {
4520 return /^[ns]/.test(d) ? -3 : null;
4521 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
4522 tz.style("display", brush.empty() ? "none" : null);
4525 e = d3_scaleRange(x);
4526 bg.attr("x", e[0]).attr("width", e[1] - e[0]);
4530 e = d3_scaleRange(y);
4531 bg.attr("y", e[0]).attr("height", e[1] - e[0]);
4537 function redraw(g) {
4538 g.selectAll(".resize").attr("transform", function(d) {
4539 return "translate(" + extent[+/e$/.test(d)][0] + "," + extent[+/^s/.test(d)][1] + ")";
4542 function redrawX(g) {
4543 g.select(".extent").attr("x", extent[0][0]);
4544 g.selectAll(".extent,.n>rect,.s>rect").attr("width", extent[1][0] - extent[0][0]);
4546 function redrawY(g) {
4547 g.select(".extent").attr("y", extent[0][1]);
4548 g.selectAll(".extent,.e>rect,.w>rect").attr("height", extent[1][1] - extent[0][1]);
4550 function brushstart() {
4552 var touches = d3.event.changedTouches;
4553 return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
4555 function keydown() {
4556 if (d3.event.keyCode == 32) {
4559 origin[0] -= extent[1][0];
4560 origin[1] -= extent[1][1];
4567 if (d3.event.keyCode == 32 && dragging == 2) {
4568 origin[0] += extent[1][0];
4569 origin[1] += extent[1][1];
4574 function brushmove() {
4575 var point = mouse(), moved = false;
4577 point[0] += offset[0];
4578 point[1] += offset[1];
4581 if (d3.event.altKey) {
4582 if (!center) center = [ (extent[0][0] + extent[1][0]) / 2, (extent[0][1] + extent[1][1]) / 2 ];
4583 origin[0] = extent[+(point[0] < center[0])][0];
4584 origin[1] = extent[+(point[1] < center[1])][1];
4585 } else center = null;
4587 if (resizingX && move1(point, x, 0)) {
4591 if (resizingY && move1(point, y, 1)) {
4599 mode: dragging ? "move" : "resize"
4603 function move1(point, scale, i) {
4604 var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], size = extent[1][i] - extent[0][i], min, max;
4607 r1 -= size + position;
4609 min = Math.max(r0, Math.min(r1, point[i]));
4611 max = (min += position) + size;
4613 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
4614 if (position < min) {
4621 if (extent[0][i] !== min || extent[1][i] !== max) {
4622 extentDomain = null;
4628 function brushend() {
4630 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
4631 d3.select("body").style("cursor", null);
4632 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);
4638 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;
4639 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);
4641 origin[0] = extent[0][0] - origin[0];
4642 origin[1] = extent[0][1] - origin[1];
4643 } else if (resizing) {
4644 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
4645 offset = [ extent[1 - ex][0] - origin[0], extent[1 - ey][1] - origin[1] ];
4646 origin[0] = extent[ex][0];
4647 origin[1] = extent[ey][1];
4648 } else if (d3.event.altKey) center = origin.slice();
4649 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
4650 d3.select("body").style("cursor", eventTarget.style("cursor"));
4657 var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, resizes = d3_svg_brushResizes[0], extent = [ [ 0, 0 ], [ 0, 0 ] ], extentDomain;
4658 brush.x = function(z) {
4659 if (!arguments.length) return x;
4661 resizes = d3_svg_brushResizes[!x << 1 | !y];
4664 brush.y = function(z) {
4665 if (!arguments.length) return y;
4667 resizes = d3_svg_brushResizes[!x << 1 | !y];
4670 brush.extent = function(z) {
4671 var x0, x1, y0, y1, t;
4672 if (!arguments.length) {
4673 z = extentDomain || extent;
4675 x0 = z[0][0], x1 = z[1][0];
4676 if (!extentDomain) {
4677 x0 = extent[0][0], x1 = extent[1][0];
4678 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
4679 if (x1 < x0) t = x0, x0 = x1, x1 = t;
4683 y0 = z[0][1], y1 = z[1][1];
4684 if (!extentDomain) {
4685 y0 = extent[0][1], y1 = extent[1][1];
4686 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
4687 if (y1 < y0) t = y0, y0 = y1, y1 = t;
4690 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
4692 extentDomain = [ [ 0, 0 ], [ 0, 0 ] ];
4694 x0 = z[0], x1 = z[1];
4695 if (y) x0 = x0[0], x1 = x1[0];
4696 extentDomain[0][0] = x0, extentDomain[1][0] = x1;
4697 if (x.invert) x0 = x(x0), x1 = x(x1);
4698 if (x1 < x0) t = x0, x0 = x1, x1 = t;
4699 extent[0][0] = x0 | 0, extent[1][0] = x1 | 0;
4702 y0 = z[0], y1 = z[1];
4703 if (x) y0 = y0[1], y1 = y1[1];
4704 extentDomain[0][1] = y0, extentDomain[1][1] = y1;
4705 if (y.invert) y0 = y(y0), y1 = y(y1);
4706 if (y1 < y0) t = y0, y0 = y1, y1 = t;
4707 extent[0][1] = y0 | 0, extent[1][1] = y1 | 0;
4711 brush.clear = function() {
4712 extentDomain = null;
4713 extent[0][0] = extent[0][1] = extent[1][0] = extent[1][1] = 0;
4716 brush.empty = function() {
4717 return x && extent[0][0] === extent[1][0] || y && extent[0][1] === extent[1][1];
4719 return d3.rebind(brush, event, "on");
4721 var d3_svg_brushCursor = {
4731 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
4733 d3.behavior.drag = function() {
4735 this.on("mousedown.drag", mousedown).on("touchstart.drag", mousedown);
4737 function mousedown() {
4739 var p = target.parentNode;
4740 return touchId ? d3.touches(p).filter(function(p) {
4741 return p.identifier === touchId;
4742 })[0] : d3.mouse(p);
4744 function dragmove() {
4745 if (!target.parentNode) return dragend();
4746 var p = point(), dx = p[0] - origin_[0], dy = p[1] - origin_[1];
4752 x: p[0] + offset[0],
4753 y: p[1] + offset[1],
4758 function dragend() {
4764 if (d3.event.target === eventTarget) w.on("click.drag", click, true);
4766 w.on(touchId ? "touchmove.drag-" + touchId : "mousemove.drag", null).on(touchId ? "touchend.drag-" + touchId : "mouseup.drag", null);
4770 w.on("click.drag", null);
4772 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;
4773 var w = d3.select(window).on(touchId ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
4775 offset = origin.apply(target, arguments);
4776 offset = [ offset.x - origin_[0], offset.y - origin_[1] ];
4780 if (!touchId) d3_eventCancel();
4785 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null;
4786 drag.origin = function(x) {
4787 if (!arguments.length) return origin;
4791 return d3.rebind(drag, event, "on");
4793 d3.behavior.zoom = function() {
4795 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);
4797 function location(p) {
4798 return [ (p[0] - translate[0]) / scale, (p[1] - translate[1]) / scale ];
4801 return [ l[0] * scale + translate[0], l[1] * scale + translate[1] ];
4803 function scaleTo(s) {
4804 scale = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
4806 function translateTo(p, l) {
4808 translate[0] += p[0] - l[0];
4809 translate[1] += p[1] - l[1];
4811 function dispatch(event) {
4812 if (x1) x1.domain(x0.range().map(function(x) {
4813 return (x - translate[0]) / scale;
4815 if (y1) y1.domain(y0.range().map(function(y) {
4816 return (y - translate[1]) / scale;
4818 d3.event.preventDefault();
4822 translate: translate
4825 function mousedown() {
4826 function mousemove() {
4828 translateTo(d3.mouse(target), l);
4831 function mouseup() {
4832 if (moved) d3_eventCancel();
4833 w.on("mousemove.zoom", null).on("mouseup.zoom", null);
4834 if (moved && d3.event.target === eventTarget) w.on("click.zoom", click, true);
4838 w.on("click.zoom", null);
4840 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));
4844 function mousewheel() {
4845 if (!translate0) translate0 = location(d3.mouse(this));
4846 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * scale);
4847 translateTo(d3.mouse(this), translate0);
4848 dispatch(event.of(this, arguments));
4850 function mousemove() {
4853 function dblclick() {
4854 var p = d3.mouse(this), l = location(p);
4855 scaleTo(d3.event.shiftKey ? scale / 2 : scale * 2);
4857 dispatch(event.of(this, arguments));
4859 function touchstart() {
4860 var touches = d3.touches(this), now = Date.now();
4863 touches.forEach(function(t) {
4864 translate0[t.identifier] = location(t);
4867 if (touches.length === 1) {
4868 if (now - touchtime < 500) {
4869 var p = touches[0], l = location(touches[0]);
4872 dispatch(event.of(this, arguments));
4877 function touchmove() {
4878 var touches = d3.touches(this), p0 = touches[0], l0 = translate0[p0.identifier];
4879 if (p1 = touches[1]) {
4880 var p1, l1 = translate0[p1.identifier];
4881 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
4882 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
4883 scaleTo(d3.event.scale * scale0);
4885 translateTo(p0, l0);
4887 dispatch(event.of(this, arguments));
4889 var translate = [ 0, 0 ], translate0, scale = 1, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
4890 zoom.translate = function(x) {
4891 if (!arguments.length) return translate;
4892 translate = x.map(Number);
4895 zoom.scale = function(x) {
4896 if (!arguments.length) return scale;
4900 zoom.scaleExtent = function(x) {
4901 if (!arguments.length) return scaleExtent;
4902 scaleExtent = x == null ? d3_behavior_zoomInfinity : x.map(Number);
4905 zoom.x = function(z) {
4906 if (!arguments.length) return x1;
4911 zoom.y = function(z) {
4912 if (!arguments.length) return y1;
4917 return d3.rebind(zoom, event, "on");
4919 var d3_behavior_zoomDiv, d3_behavior_zoomInfinity = [ 0, Infinity ];
4921 d3.layout.bundle = function() {
4922 return function(links) {
4923 var paths = [], i = -1, n = links.length;
4924 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
4928 d3.layout.chord = function() {
4929 function relayout() {
4930 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
4940 subgroupIndex.push(d3.range(n));
4944 groupIndex.sort(function(a, b) {
4945 return sortGroups(groupSums[a], groupSums[b]);
4948 if (sortSubgroups) {
4949 subgroupIndex.forEach(function(d, i) {
4950 d.sort(function(a, b) {
4951 return sortSubgroups(matrix[i][a], matrix[i][b]);
4955 k = (2 * Math.PI - padding * n) / k;
4960 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
4961 subgroups[di + "-" + dj] = {
4981 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
4982 if (source.value || target.value) {
4983 chords.push(source.value < target.value ? {
4993 if (sortChords) resort();
4996 chords.sort(function(a, b) {
4997 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
5000 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
5001 chord.matrix = function(x) {
5002 if (!arguments.length) return matrix;
5003 n = (matrix = x) && matrix.length;
5004 chords = groups = null;
5007 chord.padding = function(x) {
5008 if (!arguments.length) return padding;
5010 chords = groups = null;
5013 chord.sortGroups = function(x) {
5014 if (!arguments.length) return sortGroups;
5016 chords = groups = null;
5019 chord.sortSubgroups = function(x) {
5020 if (!arguments.length) return sortSubgroups;
5025 chord.sortChords = function(x) {
5026 if (!arguments.length) return sortChords;
5028 if (chords) resort();
5031 chord.chords = function() {
5032 if (!chords) relayout();
5035 chord.groups = function() {
5036 if (!groups) relayout();
5041 d3.layout.force = function() {
5042 function repulse(node) {
5043 return function(quad, x1, y1, x2, y2) {
5044 if (quad.point !== node) {
5045 var dx = quad.cx - node.x, dy = quad.cy - node.y, dn = 1 / Math.sqrt(dx * dx + dy * dy);
5046 if ((x2 - x1) * dn < theta) {
5047 var k = quad.charge * dn * dn;
5052 if (quad.point && isFinite(dn)) {
5053 var k = quad.pointCharge * dn * dn;
5058 return !quad.charge;
5061 function dragmove(d) {
5066 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;
5067 force.tick = function() {
5068 if ((alpha *= .99) < .005) {
5075 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
5076 for (i = 0; i < m; ++i) {
5082 if (l = x * x + y * y) {
5083 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
5086 t.x -= x * (k = s.weight / (t.weight + s.weight));
5088 s.x += x * (k = 1 - k);
5092 if (k = alpha * gravity) {
5096 if (k) while (++i < n) {
5098 o.x += (x - o.x) * k;
5099 o.y += (y - o.y) * k;
5103 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
5106 if (!(o = nodes[i]).fixed) {
5107 q.visit(repulse(o));
5118 o.x -= (o.px - (o.px = o.x)) * friction;
5119 o.y -= (o.py - (o.py = o.y)) * friction;
5127 force.nodes = function(x) {
5128 if (!arguments.length) return nodes;
5132 force.links = function(x) {
5133 if (!arguments.length) return links;
5137 force.size = function(x) {
5138 if (!arguments.length) return size;
5142 force.linkDistance = function(x) {
5143 if (!arguments.length) return linkDistance;
5144 linkDistance = d3_functor(x);
5147 force.distance = force.linkDistance;
5148 force.linkStrength = function(x) {
5149 if (!arguments.length) return linkStrength;
5150 linkStrength = d3_functor(x);
5153 force.friction = function(x) {
5154 if (!arguments.length) return friction;
5158 force.charge = function(x) {
5159 if (!arguments.length) return charge;
5160 charge = typeof x === "function" ? x : +x;
5163 force.gravity = function(x) {
5164 if (!arguments.length) return gravity;
5168 force.theta = function(x) {
5169 if (!arguments.length) return theta;
5173 force.alpha = function(x) {
5174 if (!arguments.length) return alpha;
5176 if (x > 0) alpha = x; else alpha = 0;
5182 d3.timer(force.tick);
5186 force.start = function() {
5187 function position(dimension, size) {
5188 var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
5189 while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
5190 return Math.random() * size;
5192 function neighbor() {
5195 for (j = 0; j < n; ++j) {
5198 for (j = 0; j < m; ++j) {
5200 neighbors[o.source.index].push(o.target);
5201 neighbors[o.target.index].push(o.source);
5204 return neighbors[i];
5206 var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
5207 for (i = 0; i < n; ++i) {
5208 (o = nodes[i]).index = i;
5213 for (i = 0; i < m; ++i) {
5215 if (typeof o.source == "number") o.source = nodes[o.source];
5216 if (typeof o.target == "number") o.target = nodes[o.target];
5217 distances[i] = linkDistance.call(this, o, i);
5218 strengths[i] = linkStrength.call(this, o, i);
5222 for (i = 0; i < n; ++i) {
5224 if (isNaN(o.x)) o.x = position("x", w);
5225 if (isNaN(o.y)) o.y = position("y", h);
5226 if (isNaN(o.px)) o.px = o.x;
5227 if (isNaN(o.py)) o.py = o.y;
5230 if (typeof charge === "function") {
5231 for (i = 0; i < n; ++i) {
5232 charges[i] = +charge.call(this, nodes[i], i);
5235 for (i = 0; i < n; ++i) {
5236 charges[i] = charge;
5239 return force.resume();
5241 force.resume = function() {
5242 return force.alpha(.1);
5244 force.stop = function() {
5245 return force.alpha(0);
5247 force.drag = function() {
5248 if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart", d3_layout_forceDragstart).on("drag", dragmove).on("dragend", d3_layout_forceDragend);
5249 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
5251 return d3.rebind(force, event, "on");
5253 d3.layout.partition = function() {
5254 function position(node, x, dx, dy) {
5255 var children = node.children;
5257 node.y = node.depth * dy;
5260 if (children && (n = children.length)) {
5261 var i = -1, n, c, d;
5262 dx = node.value ? dx / node.value : 0;
5264 position(c = children[i], x, d = c.value * dx, dy);
5269 function depth(node) {
5270 var children = node.children, d = 0;
5271 if (children && (n = children.length)) {
5273 while (++i < n) d = Math.max(d, depth(children[i]));
5277 function partition(d, i) {
5278 var nodes = hierarchy.call(this, d, i);
5279 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
5282 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
5283 partition.size = function(x) {
5284 if (!arguments.length) return size;
5288 return d3_layout_hierarchyRebind(partition, hierarchy);
5290 d3.layout.pie = function() {
5291 function pie(data, i) {
5292 var values = data.map(function(d, i) {
5293 return +value.call(pie, d, i);
5295 var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
5296 var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - startAngle) / d3.sum(values);
5297 var index = d3.range(data.length);
5298 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
5299 return values[j] - values[i];
5300 } : function(i, j) {
5301 return sort(data[i], data[j]);
5304 index.forEach(function(i) {
5308 value: d = values[i],
5310 endAngle: a += d * k
5315 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = 2 * Math.PI;
5316 pie.value = function(x) {
5317 if (!arguments.length) return value;
5321 pie.sort = function(x) {
5322 if (!arguments.length) return sort;
5326 pie.startAngle = function(x) {
5327 if (!arguments.length) return startAngle;
5331 pie.endAngle = function(x) {
5332 if (!arguments.length) return endAngle;
5338 var d3_layout_pieSortByValue = {};
5339 d3.layout.stack = function() {
5340 function stack(data, index) {
5341 var series = data.map(function(d, i) {
5342 return values.call(stack, d, i);
5344 var points = series.map(function(d, i) {
5345 return d.map(function(v, i) {
5346 return [ x.call(stack, v, i), y.call(stack, v, i) ];
5349 var orders = order.call(stack, points, index);
5350 series = d3.permute(series, orders);
5351 points = d3.permute(points, orders);
5352 var offsets = offset.call(stack, points, index);
5353 var n = series.length, m = series[0].length, i, j, o;
5354 for (j = 0; j < m; ++j) {
5355 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
5356 for (i = 1; i < n; ++i) {
5357 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
5362 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
5363 stack.values = function(x) {
5364 if (!arguments.length) return values;
5368 stack.order = function(x) {
5369 if (!arguments.length) return order;
5370 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
5373 stack.offset = function(x) {
5374 if (!arguments.length) return offset;
5375 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
5378 stack.x = function(z) {
5379 if (!arguments.length) return x;
5383 stack.y = function(z) {
5384 if (!arguments.length) return y;
5388 stack.out = function(z) {
5389 if (!arguments.length) return out;
5395 var d3_layout_stackOrders = d3.map({
5396 "inside-out": function(data) {
5397 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) {
5398 return max[a] - max[b];
5399 }), top = 0, bottom = 0, tops = [], bottoms = [];
5400 for (i = 0; i < n; ++i) {
5410 return bottoms.reverse().concat(tops);
5412 reverse: function(data) {
5413 return d3.range(data.length).reverse();
5415 "default": d3_layout_stackOrderDefault
5417 var d3_layout_stackOffsets = d3.map({
5418 silhouette: function(data) {
5419 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
5420 for (j = 0; j < m; ++j) {
5421 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
5422 if (o > max) max = o;
5425 for (j = 0; j < m; ++j) {
5426 y0[j] = (max - sums[j]) / 2;
5430 wiggle: function(data) {
5431 var n = data.length, x = data[0], m = x.length, max = 0, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
5433 for (j = 1; j < m; ++j) {
5434 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
5435 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
5436 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
5437 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
5439 s2 += s3 * data[i][j][1];
5441 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
5444 for (j = 0; j < m; ++j) y0[j] -= o0;
5447 expand: function(data) {
5448 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
5449 for (j = 0; j < m; ++j) {
5450 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
5451 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;
5453 for (j = 0; j < m; ++j) y0[j] = 0;
5456 zero: d3_layout_stackOffsetZero
5458 d3.layout.histogram = function() {
5459 function histogram(data, i) {
5460 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;
5463 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
5470 if (x >= range[0] && x <= range[1]) {
5471 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
5479 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
5480 histogram.value = function(x) {
5481 if (!arguments.length) return valuer;
5485 histogram.range = function(x) {
5486 if (!arguments.length) return ranger;
5487 ranger = d3_functor(x);
5490 histogram.bins = function(x) {
5491 if (!arguments.length) return binner;
5492 binner = typeof x === "number" ? function(range) {
5493 return d3_layout_histogramBinFixed(range, x);
5497 histogram.frequency = function(x) {
5498 if (!arguments.length) return frequency;
5504 d3.layout.hierarchy = function() {
5505 function recurse(data, depth, nodes) {
5506 var childs = children.call(hierarchy, data, depth), node = d3_layout_hierarchyInline ? data : {
5511 if (childs && (n = childs.length)) {
5512 var i = -1, n, c = node.children = [], v = 0, j = depth + 1, d;
5514 d = recurse(childs[i], j, nodes);
5519 if (sort) c.sort(sort);
5520 if (value) node.value = v;
5522 node.value = +value.call(hierarchy, data, depth) || 0;
5526 function revalue(node, depth) {
5527 var children = node.children, v = 0;
5528 if (children && (n = children.length)) {
5529 var i = -1, n, j = depth + 1;
5530 while (++i < n) v += revalue(children[i], j);
5532 v = +value.call(hierarchy, d3_layout_hierarchyInline ? node : node.data, depth) || 0;
5534 if (value) node.value = v;
5537 function hierarchy(d) {
5539 recurse(d, 0, nodes);
5542 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
5543 hierarchy.sort = function(x) {
5544 if (!arguments.length) return sort;
5548 hierarchy.children = function(x) {
5549 if (!arguments.length) return children;
5553 hierarchy.value = function(x) {
5554 if (!arguments.length) return value;
5558 hierarchy.revalue = function(root) {
5564 var d3_layout_hierarchyInline = false;
5565 d3.layout.pack = function() {
5566 function pack(d, i) {
5567 var nodes = hierarchy.call(this, d, i), root = nodes[0];
5570 d3_layout_treeVisitAfter(root, function(d) {
5571 d.r = Math.sqrt(d.value);
5573 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
5574 var w = size[0], h = size[1], k = Math.max(2 * root.r / w, 2 * root.r / h);
5576 var dr = padding * k / 2;
5577 d3_layout_treeVisitAfter(root, function(d) {
5580 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
5581 d3_layout_treeVisitAfter(root, function(d) {
5584 k = Math.max(2 * root.r / w, 2 * root.r / h);
5586 d3_layout_packTransform(root, w / 2, h / 2, 1 / k);
5589 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ];
5590 pack.size = function(x) {
5591 if (!arguments.length) return size;
5595 pack.padding = function(_) {
5596 if (!arguments.length) return padding;
5600 return d3_layout_hierarchyRebind(pack, hierarchy);
5602 d3.layout.cluster = function() {
5603 function cluster(d, i) {
5604 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0, kx, ky;
5605 d3_layout_treeVisitAfter(root, function(node) {
5606 var children = node.children;
5607 if (children && children.length) {
5608 node.x = d3_layout_clusterX(children);
5609 node.y = d3_layout_clusterY(children);
5611 node.x = previousNode ? x += separation(node, previousNode) : 0;
5613 previousNode = node;
5616 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;
5617 d3_layout_treeVisitAfter(root, function(node) {
5618 node.x = (node.x - x0) / (x1 - x0) * size[0];
5619 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
5623 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
5624 cluster.separation = function(x) {
5625 if (!arguments.length) return separation;
5629 cluster.size = function(x) {
5630 if (!arguments.length) return size;
5634 return d3_layout_hierarchyRebind(cluster, hierarchy);
5636 d3.layout.tree = function() {
5637 function tree(d, i) {
5638 function firstWalk(node, previousSibling) {
5639 var children = node.children, layout = node._tree;
5640 if (children && (n = children.length)) {
5641 var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
5643 child = children[i];
5644 firstWalk(child, previousChild);
5645 ancestor = apportion(child, previousChild, ancestor);
5646 previousChild = child;
5648 d3_layout_treeShift(node);
5649 var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
5650 if (previousSibling) {
5651 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5652 layout.mod = layout.prelim - midpoint;
5654 layout.prelim = midpoint;
5657 if (previousSibling) {
5658 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5662 function secondWalk(node, x) {
5663 node.x = node._tree.prelim + x;
5664 var children = node.children;
5665 if (children && (n = children.length)) {
5667 x += node._tree.mod;
5669 secondWalk(children[i], x);
5673 function apportion(node, previousSibling, ancestor) {
5674 if (previousSibling) {
5675 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;
5676 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
5677 vom = d3_layout_treeLeft(vom);
5678 vop = d3_layout_treeRight(vop);
5679 vop._tree.ancestor = node;
5680 shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
5682 d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
5686 sim += vim._tree.mod;
5687 sip += vip._tree.mod;
5688 som += vom._tree.mod;
5689 sop += vop._tree.mod;
5691 if (vim && !d3_layout_treeRight(vop)) {
5692 vop._tree.thread = vim;
5693 vop._tree.mod += sim - sop;
5695 if (vip && !d3_layout_treeLeft(vom)) {
5696 vom._tree.thread = vip;
5697 vom._tree.mod += sip - som;
5703 var nodes = hierarchy.call(this, d, i), root = nodes[0];
5704 d3_layout_treeVisitAfter(root, function(node, previousSibling) {
5711 number: previousSibling ? previousSibling._tree.number + 1 : 0
5715 secondWalk(root, -root._tree.prelim);
5716 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;
5717 d3_layout_treeVisitAfter(root, function(node) {
5718 node.x = (node.x - x0) / (x1 - x0) * size[0];
5719 node.y = node.depth / y1 * size[1];
5724 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
5725 tree.separation = function(x) {
5726 if (!arguments.length) return separation;
5730 tree.size = function(x) {
5731 if (!arguments.length) return size;
5735 return d3_layout_hierarchyRebind(tree, hierarchy);
5737 d3.layout.treemap = function() {
5738 function scale(children, k) {
5739 var i = -1, n = children.length, child, area;
5741 area = (child = children[i]).value * (k < 0 ? 0 : k);
5742 child.area = isNaN(area) || area <= 0 ? 0 : area;
5745 function squarify(node) {
5746 var children = node.children;
5747 if (children && children.length) {
5748 var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = Math.min(rect.dx, rect.dy), n;
5749 scale(remaining, rect.dx * rect.dy / node.value);
5751 while ((n = remaining.length) > 0) {
5752 row.push(child = remaining[n - 1]);
5753 row.area += child.area;
5754 if ((score = worst(row, u)) <= best) {
5758 row.area -= row.pop().area;
5759 position(row, u, rect, false);
5760 u = Math.min(rect.dx, rect.dy);
5761 row.length = row.area = 0;
5766 position(row, u, rect, true);
5767 row.length = row.area = 0;
5769 children.forEach(squarify);
5772 function stickify(node) {
5773 var children = node.children;
5774 if (children && children.length) {
5775 var rect = pad(node), remaining = children.slice(), child, row = [];
5776 scale(remaining, rect.dx * rect.dy / node.value);
5778 while (child = remaining.pop()) {
5780 row.area += child.area;
5781 if (child.z != null) {
5782 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
5783 row.length = row.area = 0;
5786 children.forEach(stickify);
5789 function worst(row, u) {
5790 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
5792 if (!(r = row[i].area)) continue;
5793 if (r < rmin) rmin = r;
5794 if (r > rmax) rmax = r;
5798 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
5800 function position(row, u, rect, flush) {
5801 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
5803 if (flush || v > rect.dy) v = rect.dy;
5809 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
5812 o.dx += rect.x + rect.dx - x;
5816 if (flush || v > rect.dx) v = rect.dx;
5822 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
5825 o.dy += rect.y + rect.dy - y;
5830 function treemap(d) {
5831 var nodes = stickies || hierarchy(d), root = nodes[0];
5836 if (stickies) hierarchy.revalue(root);
5837 scale([ root ], root.dx * root.dy / root.value);
5838 (stickies ? stickify : squarify)(root);
5839 if (sticky) stickies = nodes;
5842 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));
5843 treemap.size = function(x) {
5844 if (!arguments.length) return size;
5848 treemap.padding = function(x) {
5849 function padFunction(node) {
5850 var p = x.call(treemap, node, node.depth);
5851 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
5853 function padConstant(node) {
5854 return d3_layout_treemapPad(node, x);
5856 if (!arguments.length) return padding;
5858 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ], padConstant) : padConstant;
5861 treemap.round = function(x) {
5862 if (!arguments.length) return round != Number;
5863 round = x ? Math.round : Number;
5866 treemap.sticky = function(x) {
5867 if (!arguments.length) return sticky;
5872 treemap.ratio = function(x) {
5873 if (!arguments.length) return ratio;
5877 return d3_layout_hierarchyRebind(treemap, hierarchy);
5879 d3.csv = d3_dsv(",", "text/csv");
5880 d3.tsv = d3_dsv(" ", "text/tab-separated-values");
5882 var d3_geo_radians = Math.PI / 180;
5883 d3.geo.azimuthal = function() {
5884 function azimuthal(coordinates) {
5885 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);
5886 return [ scale * x + translate[0], scale * y + translate[1] ];
5888 var mode = "orthographic", origin, scale = 200, translate = [ 480, 250 ], x0, y0, cy0, sy0;
5889 azimuthal.invert = function(coordinates) {
5890 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);
5891 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 ];
5893 azimuthal.mode = function(x) {
5894 if (!arguments.length) return mode;
5898 azimuthal.origin = function(x) {
5899 if (!arguments.length) return origin;
5901 x0 = origin[0] * d3_geo_radians;
5902 y0 = origin[1] * d3_geo_radians;
5907 azimuthal.scale = function(x) {
5908 if (!arguments.length) return scale;
5912 azimuthal.translate = function(x) {
5913 if (!arguments.length) return translate;
5914 translate = [ +x[0], +x[1] ];
5917 return azimuthal.origin([ 0, 0 ]);
5919 d3.geo.albers = function() {
5920 function albers(coordinates) {
5921 var t = n * (d3_geo_radians * coordinates[0] - lng0), p = Math.sqrt(C - 2 * n * Math.sin(d3_geo_radians * coordinates[1])) / n;
5922 return [ scale * p * Math.sin(t) + translate[0], scale * (p * Math.cos(t) - p0) + translate[1] ];
5925 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);
5926 lng0 = d3_geo_radians * origin[0];
5927 n = .5 * (s + Math.sin(phi2));
5928 C = c * c + 2 * n * s;
5929 p0 = Math.sqrt(C - 2 * n * Math.sin(lat0)) / n;
5932 var origin = [ -98, 38 ], parallels = [ 29.5, 45.5 ], scale = 1e3, translate = [ 480, 250 ], lng0, n, C, p0;
5933 albers.invert = function(coordinates) {
5934 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);
5935 return [ (lng0 + t / n) / d3_geo_radians, Math.asin((C - p * p * n * n) / (2 * n)) / d3_geo_radians ];
5937 albers.origin = function(x) {
5938 if (!arguments.length) return origin;
5939 origin = [ +x[0], +x[1] ];
5942 albers.parallels = function(x) {
5943 if (!arguments.length) return parallels;
5944 parallels = [ +x[0], +x[1] ];
5947 albers.scale = function(x) {
5948 if (!arguments.length) return scale;
5952 albers.translate = function(x) {
5953 if (!arguments.length) return translate;
5954 translate = [ +x[0], +x[1] ];
5959 d3.geo.albersUsa = function() {
5960 function albersUsa(coordinates) {
5961 var lon = coordinates[0], lat = coordinates[1];
5962 return (lat > 50 ? alaska : lon < -140 ? hawaii : lat < 21 ? puertoRico : lower48)(coordinates);
5964 var lower48 = d3.geo.albers();
5965 var alaska = d3.geo.albers().origin([ -160, 60 ]).parallels([ 55, 65 ]);
5966 var hawaii = d3.geo.albers().origin([ -160, 20 ]).parallels([ 8, 18 ]);
5967 var puertoRico = d3.geo.albers().origin([ -60, 10 ]).parallels([ 8, 18 ]);
5968 albersUsa.scale = function(x) {
5969 if (!arguments.length) return lower48.scale();
5971 alaska.scale(x * .6);
5973 puertoRico.scale(x * 1.5);
5974 return albersUsa.translate(lower48.translate());
5976 albersUsa.translate = function(x) {
5977 if (!arguments.length) return lower48.translate();
5978 var dz = lower48.scale() / 1e3, dx = x[0], dy = x[1];
5979 lower48.translate(x);
5980 alaska.translate([ dx - 400 * dz, dy + 170 * dz ]);
5981 hawaii.translate([ dx - 190 * dz, dy + 200 * dz ]);
5982 puertoRico.translate([ dx + 580 * dz, dy + 430 * dz ]);
5985 return albersUsa.scale(lower48.scale());
5987 d3.geo.bonne = function() {
5988 function bonne(coordinates) {
5989 var x = coordinates[0] * d3_geo_radians - x0, y = coordinates[1] * d3_geo_radians - y0;
5991 var p = c1 + y1 - y, E = x * Math.cos(y) / p;
5992 x = p * Math.sin(E);
5993 y = p * Math.cos(E) - c1;
5998 return [ scale * x + translate[0], scale * y + translate[1] ];
6000 var scale = 200, translate = [ 480, 250 ], x0, y0, y1, c1;
6001 bonne.invert = function(coordinates) {
6002 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale;
6004 var c = c1 + y, p = Math.sqrt(x * x + c * c);
6006 x = x0 + p * Math.atan2(x, c) / Math.cos(y);
6011 return [ x / d3_geo_radians, y / d3_geo_radians ];
6013 bonne.parallel = function(x) {
6014 if (!arguments.length) return y1 / d3_geo_radians;
6015 c1 = 1 / Math.tan(y1 = x * d3_geo_radians);
6018 bonne.origin = function(x) {
6019 if (!arguments.length) return [ x0 / d3_geo_radians, y0 / d3_geo_radians ];
6020 x0 = x[0] * d3_geo_radians;
6021 y0 = x[1] * d3_geo_radians;
6024 bonne.scale = function(x) {
6025 if (!arguments.length) return scale;
6029 bonne.translate = function(x) {
6030 if (!arguments.length) return translate;
6031 translate = [ +x[0], +x[1] ];
6034 return bonne.origin([ 0, 0 ]).parallel(45);
6036 d3.geo.equirectangular = function() {
6037 function equirectangular(coordinates) {
6038 var x = coordinates[0] / 360, y = -coordinates[1] / 360;
6039 return [ scale * x + translate[0], scale * y + translate[1] ];
6041 var scale = 500, translate = [ 480, 250 ];
6042 equirectangular.invert = function(coordinates) {
6043 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale;
6044 return [ 360 * x, -360 * y ];
6046 equirectangular.scale = function(x) {
6047 if (!arguments.length) return scale;
6049 return equirectangular;
6051 equirectangular.translate = function(x) {
6052 if (!arguments.length) return translate;
6053 translate = [ +x[0], +x[1] ];
6054 return equirectangular;
6056 return equirectangular;
6058 d3.geo.mercator = function() {
6059 function mercator(coordinates) {
6060 var x = coordinates[0] / 360, y = -(Math.log(Math.tan(Math.PI / 4 + coordinates[1] * d3_geo_radians / 2)) / d3_geo_radians) / 360;
6061 return [ scale * x + translate[0], scale * Math.max(-.5, Math.min(.5, y)) + translate[1] ];
6063 var scale = 500, translate = [ 480, 250 ];
6064 mercator.invert = function(coordinates) {
6065 var x = (coordinates[0] - translate[0]) / scale, y = (coordinates[1] - translate[1]) / scale;
6066 return [ 360 * x, 2 * Math.atan(Math.exp(-360 * y * d3_geo_radians)) / d3_geo_radians - 90 ];
6068 mercator.scale = function(x) {
6069 if (!arguments.length) return scale;
6073 mercator.translate = function(x) {
6074 if (!arguments.length) return translate;
6075 translate = [ +x[0], +x[1] ];
6080 d3.geo.path = function() {
6081 function path(d, i) {
6082 if (typeof pointRadius === "function") pointCircle = d3_path_circle(pointRadius.apply(this, arguments));
6084 var result = buffer.length ? buffer.join("") : null;
6088 function project(coordinates) {
6089 return projection(coordinates).join(",");
6091 function polygonArea(coordinates) {
6092 var sum = area(coordinates[0]), i = 0, n = coordinates.length;
6093 while (++i < n) sum -= area(coordinates[i]);
6096 function polygonCentroid(coordinates) {
6097 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;
6099 polygon = d3.geom.polygon(coordinates[i].map(projection));
6100 area = polygon.area();
6101 centroid = polygon.centroid(area < 0 ? (area *= -1, 1) : -1);
6106 return [ x, y, 6 * z ];
6108 function area(coordinates) {
6109 return Math.abs(d3.geom.polygon(coordinates.map(projection)).area());
6111 var pointRadius = 4.5, pointCircle = d3_path_circle(pointRadius), projection = d3.geo.albersUsa(), buffer = [];
6112 var pathType = d3_geo_type({
6113 FeatureCollection: function(o) {
6114 var features = o.features, i = -1, n = features.length;
6115 while (++i < n) buffer.push(pathType(features[i].geometry));
6117 Feature: function(o) {
6118 pathType(o.geometry);
6120 Point: function(o) {
6121 buffer.push("M", project(o.coordinates), pointCircle);
6123 MultiPoint: function(o) {
6124 var coordinates = o.coordinates, i = -1, n = coordinates.length;
6125 while (++i < n) buffer.push("M", project(coordinates[i]), pointCircle);
6127 LineString: function(o) {
6128 var coordinates = o.coordinates, i = -1, n = coordinates.length;
6130 while (++i < n) buffer.push(project(coordinates[i]), "L");
6133 MultiLineString: function(o) {
6134 var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m;
6136 subcoordinates = coordinates[i];
6138 m = subcoordinates.length;
6140 while (++j < m) buffer.push(project(subcoordinates[j]), "L");
6144 Polygon: function(o) {
6145 var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m;
6147 subcoordinates = coordinates[i];
6149 if ((m = subcoordinates.length - 1) > 0) {
6151 while (++j < m) buffer.push(project(subcoordinates[j]), "L");
6152 buffer[buffer.length - 1] = "Z";
6156 MultiPolygon: function(o) {
6157 var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m, subsubcoordinates, k, p;
6159 subcoordinates = coordinates[i];
6161 m = subcoordinates.length;
6163 subsubcoordinates = subcoordinates[j];
6165 if ((p = subsubcoordinates.length - 1) > 0) {
6167 while (++k < p) buffer.push(project(subsubcoordinates[k]), "L");
6168 buffer[buffer.length - 1] = "Z";
6173 GeometryCollection: function(o) {
6174 var geometries = o.geometries, i = -1, n = geometries.length;
6175 while (++i < n) buffer.push(pathType(geometries[i]));
6178 var areaType = path.area = d3_geo_type({
6179 FeatureCollection: function(o) {
6180 var area = 0, features = o.features, i = -1, n = features.length;
6181 while (++i < n) area += areaType(features[i]);
6184 Feature: function(o) {
6185 return areaType(o.geometry);
6187 Polygon: function(o) {
6188 return polygonArea(o.coordinates);
6190 MultiPolygon: function(o) {
6191 var sum = 0, coordinates = o.coordinates, i = -1, n = coordinates.length;
6192 while (++i < n) sum += polygonArea(coordinates[i]);
6195 GeometryCollection: function(o) {
6196 var sum = 0, geometries = o.geometries, i = -1, n = geometries.length;
6197 while (++i < n) sum += areaType(geometries[i]);
6201 var centroidType = path.centroid = d3_geo_type({
6202 Feature: function(o) {
6203 return centroidType(o.geometry);
6205 Polygon: function(o) {
6206 var centroid = polygonCentroid(o.coordinates);
6207 return [ centroid[0] / centroid[2], centroid[1] / centroid[2] ];
6209 MultiPolygon: function(o) {
6210 var area = 0, coordinates = o.coordinates, centroid, x = 0, y = 0, z = 0, i = -1, n = coordinates.length;
6212 centroid = polygonCentroid(coordinates[i]);
6217 return [ x / z, y / z ];
6220 path.projection = function(x) {
6224 path.pointRadius = function(x) {
6225 if (typeof x === "function") pointRadius = x; else {
6227 pointCircle = d3_path_circle(pointRadius);
6233 d3.geo.bounds = function(feature) {
6234 var left = Infinity, bottom = Infinity, right = -Infinity, top = -Infinity;
6235 d3_geo_bounds(feature, function(x, y) {
6236 if (x < left) left = x;
6237 if (x > right) right = x;
6238 if (y < bottom) bottom = y;
6239 if (y > top) top = y;
6241 return [ [ left, bottom ], [ right, top ] ];
6243 var d3_geo_boundsTypes = {
6244 Feature: d3_geo_boundsFeature,
6245 FeatureCollection: d3_geo_boundsFeatureCollection,
6246 GeometryCollection: d3_geo_boundsGeometryCollection,
6247 LineString: d3_geo_boundsLineString,
6248 MultiLineString: d3_geo_boundsMultiLineString,
6249 MultiPoint: d3_geo_boundsLineString,
6250 MultiPolygon: d3_geo_boundsMultiPolygon,
6251 Point: d3_geo_boundsPoint,
6252 Polygon: d3_geo_boundsPolygon
6254 d3.geo.circle = function() {
6255 function circle() {}
6256 function visible(point) {
6257 return arc.distance(point) < radians;
6259 function clip(coordinates) {
6260 var i = -1, n = coordinates.length, clipped = [], p0, p1, p2, d0, d1;
6262 d1 = arc.distance(p2 = coordinates[i]);
6264 if (p1) clipped.push(d3_geo_greatArcInterpolate(p1, p2)((d0 - radians) / (d0 - d1)));
6269 if (!p0 && clipped.length) {
6270 clipped.push(d3_geo_greatArcInterpolate(clipped[clipped.length - 1], p1)((radians - d0) / (d1 - d0)));
6276 p0 = coordinates[0];
6278 if (p1 && p2[0] === p0[0] && p2[1] === p0[1] && !(p2[0] === p1[0] && p2[1] === p1[1])) {
6281 return resample(clipped);
6283 function resample(coordinates) {
6284 var i = 0, n = coordinates.length, j, m, resampled = n ? [ coordinates[0] ] : coordinates, resamples, origin = arc.source();
6286 resamples = arc.source(coordinates[i - 1])(coordinates[i]).coordinates;
6287 for (j = 0, m = resamples.length; ++j < m; ) resampled.push(resamples[j]);
6292 var origin = [ 0, 0 ], degrees = 90 - .01, radians = degrees * d3_geo_radians, arc = d3.geo.greatArc().source(origin).target(d3_identity);
6293 circle.clip = function(d) {
6294 if (typeof origin === "function") arc.source(origin.apply(this, arguments));
6295 return clipType(d) || null;
6297 var clipType = d3_geo_type({
6298 FeatureCollection: function(o) {
6299 var features = o.features.map(clipType).filter(d3_identity);
6300 return features && (o = Object.create(o), o.features = features, o);
6302 Feature: function(o) {
6303 var geometry = clipType(o.geometry);
6304 return geometry && (o = Object.create(o), o.geometry = geometry, o);
6306 Point: function(o) {
6307 return visible(o.coordinates) && o;
6309 MultiPoint: function(o) {
6310 var coordinates = o.coordinates.filter(visible);
6311 return coordinates.length && {
6313 coordinates: coordinates
6316 LineString: function(o) {
6317 var coordinates = clip(o.coordinates);
6318 return coordinates.length && (o = Object.create(o), o.coordinates = coordinates, o);
6320 MultiLineString: function(o) {
6321 var coordinates = o.coordinates.map(clip).filter(function(d) {
6324 return coordinates.length && (o = Object.create(o), o.coordinates = coordinates, o);
6326 Polygon: function(o) {
6327 var coordinates = o.coordinates.map(clip);
6328 return coordinates[0].length && (o = Object.create(o), o.coordinates = coordinates, o);
6330 MultiPolygon: function(o) {
6331 var coordinates = o.coordinates.map(function(d) {
6333 }).filter(function(d) {
6336 return coordinates.length && (o = Object.create(o), o.coordinates = coordinates, o);
6338 GeometryCollection: function(o) {
6339 var geometries = o.geometries.map(clipType).filter(d3_identity);
6340 return geometries.length && (o = Object.create(o), o.geometries = geometries, o);
6343 circle.origin = function(x) {
6344 if (!arguments.length) return origin;
6346 if (typeof origin !== "function") arc.source(origin);
6349 circle.angle = function(x) {
6350 if (!arguments.length) return degrees;
6351 radians = (degrees = +x) * d3_geo_radians;
6354 return d3.rebind(circle, arc, "precision");
6356 d3.geo.greatArc = function() {
6357 function greatArc() {
6358 var d = greatArc.distance.apply(this, arguments), t = 0, dt = precision / d, coordinates = [ p0 ];
6359 while ((t += dt) < 1) coordinates.push(interpolate(t));
6360 coordinates.push(p1);
6363 coordinates: coordinates
6366 var source = d3_geo_greatArcSource, p0, target = d3_geo_greatArcTarget, p1, precision = 6 * d3_geo_radians, interpolate = d3_geo_greatArcInterpolator();
6367 greatArc.distance = function() {
6368 if (typeof source === "function") interpolate.source(p0 = source.apply(this, arguments));
6369 if (typeof target === "function") interpolate.target(p1 = target.apply(this, arguments));
6370 return interpolate.distance();
6372 greatArc.source = function(_) {
6373 if (!arguments.length) return source;
6375 if (typeof source !== "function") interpolate.source(p0 = source);
6378 greatArc.target = function(_) {
6379 if (!arguments.length) return target;
6381 if (typeof target !== "function") interpolate.target(p1 = target);
6384 greatArc.precision = function(_) {
6385 if (!arguments.length) return precision / d3_geo_radians;
6386 precision = _ * d3_geo_radians;
6391 d3.geo.greatCircle = d3.geo.circle;
6393 d3.geom.contour = function(grid, start) {
6394 var s = start || d3_geom_contourStart(grid), c = [], x = s[0], y = s[1], dx = 0, dy = 0, pdx = NaN, pdy = NaN, i = 0;
6397 if (grid(x - 1, y - 1)) i += 1;
6398 if (grid(x, y - 1)) i += 2;
6399 if (grid(x - 1, y)) i += 4;
6400 if (grid(x, y)) i += 8;
6402 dx = pdy === -1 ? -1 : 1;
6404 } else if (i === 9) {
6406 dy = pdx === 1 ? -1 : 1;
6408 dx = d3_geom_contourDx[i];
6409 dy = d3_geom_contourDy[i];
6411 if (dx != pdx && dy != pdy) {
6418 } while (s[0] != x || s[1] != y);
6421 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 ];
6422 d3.geom.hull = function(vertices) {
6423 if (vertices.length < 3) return [];
6424 var len = vertices.length, plen = len - 1, points = [], stack = [], i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
6425 for (i = 1; i < len; ++i) {
6426 if (vertices[i][1] < vertices[h][1]) {
6428 } else if (vertices[i][1] == vertices[h][1]) {
6429 h = vertices[i][0] < vertices[h][0] ? i : h;
6432 for (i = 0; i < len; ++i) {
6433 if (i === h) continue;
6434 y1 = vertices[i][1] - vertices[h][1];
6435 x1 = vertices[i][0] - vertices[h][0];
6437 angle: Math.atan2(y1, x1),
6441 points.sort(function(a, b) {
6442 return a.angle - b.angle;
6444 a = points[0].angle;
6445 v = points[0].index;
6447 for (i = 1; i < plen; ++i) {
6448 j = points[i].index;
6449 if (a == points[i].angle) {
6450 x1 = vertices[v][0] - vertices[h][0];
6451 y1 = vertices[v][1] - vertices[h][1];
6452 x2 = vertices[j][0] - vertices[h][0];
6453 y2 = vertices[j][1] - vertices[h][1];
6454 if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
6455 points[i].index = -1;
6457 points[u].index = -1;
6458 a = points[i].angle;
6463 a = points[i].angle;
6469 for (i = 0, j = 0; i < 2; ++j) {
6470 if (points[j].index !== -1) {
6471 stack.push(points[j].index);
6476 for (; j < plen; ++j) {
6477 if (points[j].index === -1) continue;
6478 while (!d3_geom_hullCCW(stack[sp - 2], stack[sp - 1], points[j].index, vertices)) {
6481 stack[sp++] = points[j].index;
6484 for (i = 0; i < sp; ++i) {
6485 poly.push(vertices[stack[i]]);
6489 d3.geom.polygon = function(coordinates) {
6490 coordinates.area = function() {
6491 var i = 0, n = coordinates.length, a = coordinates[n - 1][0] * coordinates[0][1], b = coordinates[n - 1][1] * coordinates[0][0];
6493 a += coordinates[i - 1][0] * coordinates[i][1];
6494 b += coordinates[i - 1][1] * coordinates[i][0];
6496 return (b - a) * .5;
6498 coordinates.centroid = function(k) {
6499 var i = -1, n = coordinates.length, x = 0, y = 0, a, b = coordinates[n - 1], c;
6500 if (!arguments.length) k = -1 / (6 * coordinates.area());
6504 c = a[0] * b[1] - b[0] * a[1];
6505 x += (a[0] + b[0]) * c;
6506 y += (a[1] + b[1]) * c;
6508 return [ x * k, y * k ];
6510 coordinates.clip = function(subject) {
6511 var input, i = -1, n = coordinates.length, j, m, a = coordinates[n - 1], b, c, d;
6513 input = subject.slice();
6516 c = input[(m = input.length) - 1];
6520 if (d3_geom_polygonInside(d, a, b)) {
6521 if (!d3_geom_polygonInside(c, a, b)) {
6522 subject.push(d3_geom_polygonIntersect(c, d, a, b));
6525 } else if (d3_geom_polygonInside(c, a, b)) {
6526 subject.push(d3_geom_polygonIntersect(c, d, a, b));
6536 d3.geom.voronoi = function(vertices) {
6537 var polygons = vertices.map(function() {
6540 d3_voronoi_tessellate(vertices, function(e) {
6541 var s1, s2, x1, x2, y1, y2;
6542 if (e.a === 1 && e.b >= 0) {
6550 y1 = s1 ? s1.y : -1e6;
6551 x1 = e.c - e.b * y1;
6552 y2 = s2 ? s2.y : 1e6;
6553 x2 = e.c - e.b * y2;
6555 x1 = s1 ? s1.x : -1e6;
6556 y1 = e.c - e.a * x1;
6557 x2 = s2 ? s2.x : 1e6;
6558 y2 = e.c - e.a * x2;
6560 var v1 = [ x1, y1 ], v2 = [ x2, y2 ];
6561 polygons[e.region.l.index].push(v1, v2);
6562 polygons[e.region.r.index].push(v1, v2);
6564 return polygons.map(function(polygon, i) {
6565 var cx = vertices[i][0], cy = vertices[i][1];
6566 polygon.forEach(function(v) {
6567 v.angle = Math.atan2(v[0] - cx, v[1] - cy);
6569 return polygon.sort(function(a, b) {
6570 return a.angle - b.angle;
6571 }).filter(function(d, i) {
6572 return !i || d.angle - polygon[i - 1].angle > 1e-10;
6576 var d3_voronoi_opposite = {
6580 d3.geom.delaunay = function(vertices) {
6581 var edges = vertices.map(function() {
6584 d3_voronoi_tessellate(vertices, function(e) {
6585 edges[e.region.l.index].push(vertices[e.region.r.index]);
6587 edges.forEach(function(edge, i) {
6588 var v = vertices[i], cx = v[0], cy = v[1];
6589 edge.forEach(function(v) {
6590 v.angle = Math.atan2(v[0] - cx, v[1] - cy);
6592 edge.sort(function(a, b) {
6593 return a.angle - b.angle;
6595 for (var j = 0, m = edge.length - 1; j < m; j++) {
6596 triangles.push([ v, edge[j], edge[j + 1] ]);
6601 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
6602 function insert(n, p, x1, y1, x2, y2) {
6603 if (isNaN(p.x) || isNaN(p.y)) return;
6607 if (Math.abs(v.x - p.x) + Math.abs(v.y - p.y) < .01) {
6608 insertChild(n, p, x1, y1, x2, y2);
6611 insertChild(n, v, x1, y1, x2, y2);
6612 insertChild(n, p, x1, y1, x2, y2);
6618 insertChild(n, p, x1, y1, x2, y2);
6621 function insertChild(n, p, x1, y1, x2, y2) {
6622 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = p.x >= sx, bottom = p.y >= sy, i = (bottom << 1) + right;
6624 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
6625 if (right) x1 = sx; else x2 = sx;
6626 if (bottom) y1 = sy; else y2 = sy;
6627 insert(n, p, x1, y1, x2, y2);
6629 var p, i = -1, n = points.length;
6630 if (n && isNaN(points[0].x)) points = points.map(d3_geom_quadtreePoint);
6631 if (arguments.length < 5) {
6632 if (arguments.length === 3) {
6637 x2 = y2 = -Infinity;
6640 if (p.x < x1) x1 = p.x;
6641 if (p.y < y1) y1 = p.y;
6642 if (p.x > x2) x2 = p.x;
6643 if (p.y > y2) y2 = p.y;
6645 var dx = x2 - x1, dy = y2 - y1;
6646 if (dx > dy) y2 = y1 + dx; else x2 = x1 + dy;
6649 var root = d3_geom_quadtreeNode();
6650 root.add = function(p) {
6651 insert(root, p, x1, y1, x2, y2);
6653 root.visit = function(f) {
6654 d3_geom_quadtreeVisit(f, root, x1, y1, x2, y2);
6656 points.forEach(root.add);
6660 var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
6661 d3_time_utc.prototype = {
6662 getDate: function() {
6663 return this._.getUTCDate();
6665 getDay: function() {
6666 return this._.getUTCDay();
6668 getFullYear: function() {
6669 return this._.getUTCFullYear();
6671 getHours: function() {
6672 return this._.getUTCHours();
6674 getMilliseconds: function() {
6675 return this._.getUTCMilliseconds();
6677 getMinutes: function() {
6678 return this._.getUTCMinutes();
6680 getMonth: function() {
6681 return this._.getUTCMonth();
6683 getSeconds: function() {
6684 return this._.getUTCSeconds();
6686 getTime: function() {
6687 return this._.getTime();
6689 getTimezoneOffset: function() {
6692 valueOf: function() {
6693 return this._.valueOf();
6695 setDate: function() {
6696 d3_time_prototype.setUTCDate.apply(this._, arguments);
6698 setDay: function() {
6699 d3_time_prototype.setUTCDay.apply(this._, arguments);
6701 setFullYear: function() {
6702 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
6704 setHours: function() {
6705 d3_time_prototype.setUTCHours.apply(this._, arguments);
6707 setMilliseconds: function() {
6708 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
6710 setMinutes: function() {
6711 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
6713 setMonth: function() {
6714 d3_time_prototype.setUTCMonth.apply(this._, arguments);
6716 setSeconds: function() {
6717 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
6719 setTime: function() {
6720 d3_time_prototype.setTime.apply(this._, arguments);
6723 var d3_time_prototype = Date.prototype;
6724 var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y", d3_time_formatDate = "%m/%d/%y", d3_time_formatTime = "%H:%M:%S";
6725 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);
6726 d3.time.format = function(template) {
6727 function format(date) {
6728 var string = [], i = -1, j = 0, c, f;
6730 if (template.charCodeAt(i) == 37) {
6731 string.push(template.substring(j, i), (f = d3_time_formats[c = template.charAt(++i)]) ? f(date) : c);
6735 string.push(template.substring(j, i));
6736 return string.join("");
6738 var n = template.length;
6739 format.parse = function(string) {
6748 }, i = d3_time_parse(d, template, string, 0);
6749 if (i != string.length) return null;
6750 if ("p" in d) d.H = d.H % 12 + d.p * 12;
6751 var date = new d3_time;
6752 date.setFullYear(d.y, d.m, d.d);
6753 date.setHours(d.H, d.M, d.S, d.L);
6756 format.toString = function() {
6761 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");
6762 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);
6763 var d3_time_formats = {
6765 return d3_time_dayAbbreviations[d.getDay()];
6768 return d3_time_days[d.getDay()];
6771 return d3_time_monthAbbreviations[d.getMonth()];
6774 return d3_time_months[d.getMonth()];
6776 c: d3.time.format(d3_time_formatDateTime),
6778 return d3_time_zfill2(d.getDate());
6781 return d3_time_sfill2(d.getDate());
6784 return d3_time_zfill2(d.getHours());
6787 return d3_time_zfill2(d.getHours() % 12 || 12);
6790 return d3_time_zfill3(1 + d3.time.dayOfYear(d));
6793 return d3_time_zfill3(d.getMilliseconds());
6796 return d3_time_zfill2(d.getMonth() + 1);
6799 return d3_time_zfill2(d.getMinutes());
6802 return d.getHours() >= 12 ? "PM" : "AM";
6805 return d3_time_zfill2(d.getSeconds());
6808 return d3_time_zfill2(d3.time.sundayOfYear(d));
6814 return d3_time_zfill2(d3.time.mondayOfYear(d));
6816 x: d3.time.format(d3_time_formatDate),
6817 X: d3.time.format(d3_time_formatTime),
6819 return d3_time_zfill2(d.getFullYear() % 100);
6822 return d3_time_zfill4(d.getFullYear() % 1e4);
6829 var d3_time_parsers = {
6830 a: d3_time_parseWeekdayAbbrev,
6831 A: d3_time_parseWeekday,
6832 b: d3_time_parseMonthAbbrev,
6833 B: d3_time_parseMonth,
6834 c: d3_time_parseLocaleFull,
6835 d: d3_time_parseDay,
6836 e: d3_time_parseDay,
6837 H: d3_time_parseHour24,
6838 I: d3_time_parseHour24,
6839 L: d3_time_parseMilliseconds,
6840 m: d3_time_parseMonthNumber,
6841 M: d3_time_parseMinutes,
6842 p: d3_time_parseAmPm,
6843 S: d3_time_parseSeconds,
6844 x: d3_time_parseLocaleDate,
6845 X: d3_time_parseLocaleTime,
6846 y: d3_time_parseYear,
6847 Y: d3_time_parseFullYear
6849 var d3_time_numberRe = /^\s*\d+/;
6850 var d3_time_amPmLookup = d3.map({
6854 d3.time.format.utc = function(template) {
6855 function format(date) {
6857 d3_time = d3_time_utc;
6858 var utc = new d3_time;
6865 var local = d3.time.format(template);
6866 format.parse = function(string) {
6868 d3_time = d3_time_utc;
6869 var date = local.parse(string);
6870 return date && date._;
6875 format.toString = local.toString;
6878 var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
6879 d3.time.format.iso = Date.prototype.toISOString ? d3_time_formatIsoNative : d3_time_formatIso;
6880 d3_time_formatIsoNative.parse = function(string) {
6881 var date = new Date(string);
6882 return isNaN(date) ? null : date;
6884 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
6885 d3.time.second = d3_time_interval(function(date) {
6886 return new d3_time(Math.floor(date / 1e3) * 1e3);
6887 }, function(date, offset) {
6888 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
6890 return date.getSeconds();
6892 d3.time.seconds = d3.time.second.range;
6893 d3.time.seconds.utc = d3.time.second.utc.range;
6894 d3.time.minute = d3_time_interval(function(date) {
6895 return new d3_time(Math.floor(date / 6e4) * 6e4);
6896 }, function(date, offset) {
6897 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
6899 return date.getMinutes();
6901 d3.time.minutes = d3.time.minute.range;
6902 d3.time.minutes.utc = d3.time.minute.utc.range;
6903 d3.time.hour = d3_time_interval(function(date) {
6904 var timezone = date.getTimezoneOffset() / 60;
6905 return new d3_time((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
6906 }, function(date, offset) {
6907 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
6909 return date.getHours();
6911 d3.time.hours = d3.time.hour.range;
6912 d3.time.hours.utc = d3.time.hour.utc.range;
6913 d3.time.day = d3_time_interval(function(date) {
6914 var day = new d3_time(1970, 0);
6915 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
6917 }, function(date, offset) {
6918 date.setDate(date.getDate() + offset);
6920 return date.getDate() - 1;
6922 d3.time.days = d3.time.day.range;
6923 d3.time.days.utc = d3.time.day.utc.range;
6924 d3.time.dayOfYear = function(date) {
6925 var year = d3.time.year(date);
6926 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
6928 d3_time_daySymbols.forEach(function(day, i) {
6929 day = day.toLowerCase();
6931 var interval = d3.time[day] = d3_time_interval(function(date) {
6932 (date = d3.time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
6934 }, function(date, offset) {
6935 date.setDate(date.getDate() + Math.floor(offset) * 7);
6937 var day = d3.time.year(date).getDay();
6938 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
6940 d3.time[day + "s"] = interval.range;
6941 d3.time[day + "s"].utc = interval.utc.range;
6942 d3.time[day + "OfYear"] = function(date) {
6943 var day = d3.time.year(date).getDay();
6944 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7);
6947 d3.time.week = d3.time.sunday;
6948 d3.time.weeks = d3.time.sunday.range;
6949 d3.time.weeks.utc = d3.time.sunday.utc.range;
6950 d3.time.weekOfYear = d3.time.sundayOfYear;
6951 d3.time.month = d3_time_interval(function(date) {
6952 date = d3.time.day(date);
6955 }, function(date, offset) {
6956 date.setMonth(date.getMonth() + offset);
6958 return date.getMonth();
6960 d3.time.months = d3.time.month.range;
6961 d3.time.months.utc = d3.time.month.utc.range;
6962 d3.time.year = d3_time_interval(function(date) {
6963 date = d3.time.day(date);
6964 date.setMonth(0, 1);
6966 }, function(date, offset) {
6967 date.setFullYear(date.getFullYear() + offset);
6969 return date.getFullYear();
6971 d3.time.years = d3.time.year.range;
6972 d3.time.years.utc = d3.time.year.utc.range;
6973 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
6974 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 ] ];
6975 var d3_time_scaleLocalFormats = [ [ d3.time.format("%Y"), function(d) {
6977 } ], [ d3.time.format("%B"), function(d) {
6978 return d.getMonth();
6979 } ], [ d3.time.format("%b %d"), function(d) {
6980 return d.getDate() != 1;
6981 } ], [ d3.time.format("%a %d"), function(d) {
6982 return d.getDay() && d.getDate() != 1;
6983 } ], [ d3.time.format("%I %p"), function(d) {
6984 return d.getHours();
6985 } ], [ d3.time.format("%I:%M"), function(d) {
6986 return d.getMinutes();
6987 } ], [ d3.time.format(":%S"), function(d) {
6988 return d.getSeconds();
6989 } ], [ d3.time.format(".%L"), function(d) {
6990 return d.getMilliseconds();
6992 var d3_time_scaleLinear = d3.scale.linear(), d3_time_scaleLocalFormat = d3_time_scaleFormat(d3_time_scaleLocalFormats);
6993 d3_time_scaleLocalMethods.year = function(extent, m) {
6994 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleGetYear)).ticks(m).map(d3_time_scaleSetYear);
6996 d3.time.scale = function() {
6997 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
6999 var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
7000 return [ m[0].utc, m[1] ];
7002 var d3_time_scaleUTCFormats = [ [ d3.time.format.utc("%Y"), function(d) {
7004 } ], [ d3.time.format.utc("%B"), function(d) {
7005 return d.getUTCMonth();
7006 } ], [ d3.time.format.utc("%b %d"), function(d) {
7007 return d.getUTCDate() != 1;
7008 } ], [ d3.time.format.utc("%a %d"), function(d) {
7009 return d.getUTCDay() && d.getUTCDate() != 1;
7010 } ], [ d3.time.format.utc("%I %p"), function(d) {
7011 return d.getUTCHours();
7012 } ], [ d3.time.format.utc("%I:%M"), function(d) {
7013 return d.getUTCMinutes();
7014 } ], [ d3.time.format.utc(":%S"), function(d) {
7015 return d.getUTCSeconds();
7016 } ], [ d3.time.format.utc(".%L"), function(d) {
7017 return d.getUTCMilliseconds();
7019 var d3_time_scaleUTCFormat = d3_time_scaleFormat(d3_time_scaleUTCFormats);
7020 d3_time_scaleUTCMethods.year = function(extent, m) {
7021 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleUTCGetYear)).ticks(m).map(d3_time_scaleUTCSetYear);
7023 d3.time.scale.utc = function() {
7024 return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);