blob: 372665274829c311a99c2e87302bab8b8f6dfcb0 [file] [log] [blame]
Paul Greyson277162e2013-04-09 16:59:55 -07001d3 = function() {
2 var π = Math.PI, ε = 1e-6, d3 = {
3 version: "3.0.8"
4 }, d3_radians = π / 180, d3_degrees = 180 / π, d3_document = document, d3_window = window;
5 function d3_target(d) {
6 return d.target;
7 }
8 function d3_source(d) {
9 return d.source;
10 }
11 var d3_format_decimalPoint = ".", d3_format_thousandsSeparator = ",", d3_format_grouping = [ 3, 3 ];
12 if (!Date.now) Date.now = function() {
13 return +new Date();
14 };
15 try {
16 d3_document.createElement("div").style.setProperty("opacity", 0, "");
17 } catch (error) {
18 var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
19 d3_style_prototype.setProperty = function(name, value, priority) {
20 d3_style_setProperty.call(this, name, value + "", priority);
21 };
22 }
23 function d3_class(ctor, properties) {
24 try {
25 for (var key in properties) {
26 Object.defineProperty(ctor.prototype, key, {
27 value: properties[key],
28 enumerable: false
29 });
30 }
31 } catch (e) {
32 ctor.prototype = properties;
33 }
34 }
35 var d3_array = d3_arraySlice;
36 function d3_arrayCopy(pseudoarray) {
37 var i = -1, n = pseudoarray.length, array = [];
38 while (++i < n) array.push(pseudoarray[i]);
39 return array;
40 }
41 function d3_arraySlice(pseudoarray) {
42 return Array.prototype.slice.call(pseudoarray);
43 }
44 try {
45 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
46 } catch (e) {
47 d3_array = d3_arrayCopy;
48 }
49 var d3_arraySubclass = [].__proto__ ? function(array, prototype) {
50 array.__proto__ = prototype;
51 } : function(array, prototype) {
52 for (var property in prototype) array[property] = prototype[property];
53 };
54 d3.map = function(object) {
55 var map = new d3_Map();
56 for (var key in object) map.set(key, object[key]);
57 return map;
58 };
59 function d3_Map() {}
60 d3_class(d3_Map, {
61 has: function(key) {
62 return d3_map_prefix + key in this;
63 },
64 get: function(key) {
65 return this[d3_map_prefix + key];
66 },
67 set: function(key, value) {
68 return this[d3_map_prefix + key] = value;
69 },
70 remove: function(key) {
71 key = d3_map_prefix + key;
72 return key in this && delete this[key];
73 },
74 keys: function() {
75 var keys = [];
76 this.forEach(function(key) {
77 keys.push(key);
78 });
79 return keys;
80 },
81 values: function() {
82 var values = [];
83 this.forEach(function(key, value) {
84 values.push(value);
85 });
86 return values;
87 },
88 entries: function() {
89 var entries = [];
90 this.forEach(function(key, value) {
91 entries.push({
92 key: key,
93 value: value
94 });
95 });
96 return entries;
97 },
98 forEach: function(f) {
99 for (var key in this) {
100 if (key.charCodeAt(0) === d3_map_prefixCode) {
101 f.call(this, key.substring(1), this[key]);
102 }
103 }
104 }
105 });
106 var d3_map_prefix = "\0", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
107 function d3_identity(d) {
108 return d;
109 }
110 function d3_true() {
111 return true;
112 }
113 function d3_functor(v) {
114 return typeof v === "function" ? v : function() {
115 return v;
116 };
117 }
118 d3.functor = d3_functor;
119 d3.rebind = function(target, source) {
120 var i = 1, n = arguments.length, method;
121 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
122 return target;
123 };
124 function d3_rebind(target, source, method) {
125 return function() {
126 var value = method.apply(source, arguments);
127 return value === source ? target : value;
128 };
129 }
130 d3.ascending = function(a, b) {
131 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
132 };
133 d3.descending = function(a, b) {
134 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
135 };
136 d3.mean = function(array, f) {
137 var n = array.length, a, m = 0, i = -1, j = 0;
138 if (arguments.length === 1) {
139 while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
140 } else {
141 while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
142 }
143 return j ? m : undefined;
144 };
145 d3.median = function(array, f) {
146 if (arguments.length > 1) array = array.map(f);
147 array = array.filter(d3_number);
148 return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
149 };
150 d3.min = function(array, f) {
151 var i = -1, n = array.length, a, b;
152 if (arguments.length === 1) {
153 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
154 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
155 } else {
156 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
157 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
158 }
159 return a;
160 };
161 d3.max = function(array, f) {
162 var i = -1, n = array.length, a, b;
163 if (arguments.length === 1) {
164 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
165 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
166 } else {
167 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
168 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
169 }
170 return a;
171 };
172 d3.extent = function(array, f) {
173 var i = -1, n = array.length, a, b, c;
174 if (arguments.length === 1) {
175 while (++i < n && ((a = c = array[i]) == null || a != a)) a = c = undefined;
176 while (++i < n) if ((b = array[i]) != null) {
177 if (a > b) a = b;
178 if (c < b) c = b;
179 }
180 } else {
181 while (++i < n && ((a = c = f.call(array, array[i], i)) == null || a != a)) a = undefined;
182 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
183 if (a > b) a = b;
184 if (c < b) c = b;
185 }
186 }
187 return [ a, c ];
188 };
189 d3.random = {
190 normal: function(µ, σ) {
191 var n = arguments.length;
192 if (n < 2) σ = 1;
193 if (n < 1) µ = 0;
194 return function() {
195 var x, y, r;
196 do {
197 x = Math.random() * 2 - 1;
198 y = Math.random() * 2 - 1;
199 r = x * x + y * y;
200 } while (!r || r > 1);
201 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
202 };
203 },
204 logNormal: function() {
205 var random = d3.random.normal.apply(d3, arguments);
206 return function() {
207 return Math.exp(random());
208 };
209 },
210 irwinHall: function(m) {
211 return function() {
212 for (var s = 0, j = 0; j < m; j++) s += Math.random();
213 return s / m;
214 };
215 }
216 };
217 function d3_number(x) {
218 return x != null && !isNaN(x);
219 }
220 d3.sum = function(array, f) {
221 var s = 0, n = array.length, a, i = -1;
222 if (arguments.length === 1) {
223 while (++i < n) if (!isNaN(a = +array[i])) s += a;
224 } else {
225 while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
226 }
227 return s;
228 };
229 d3.quantile = function(values, p) {
230 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
231 return e ? v + e * (values[h] - v) : v;
232 };
233 d3.shuffle = function(array) {
234 var m = array.length, t, i;
235 while (m) {
236 i = Math.random() * m-- | 0;
237 t = array[m], array[m] = array[i], array[i] = t;
238 }
239 return array;
240 };
241 d3.transpose = function(matrix) {
242 return d3.zip.apply(d3, matrix);
243 };
244 d3.zip = function() {
245 if (!(n = arguments.length)) return [];
246 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
247 for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
248 zip[j] = arguments[j][i];
249 }
250 }
251 return zips;
252 };
253 function d3_zipLength(d) {
254 return d.length;
255 }
256 d3.bisector = function(f) {
257 return {
258 left: function(a, x, lo, hi) {
259 if (arguments.length < 3) lo = 0;
260 if (arguments.length < 4) hi = a.length;
261 while (lo < hi) {
262 var mid = lo + hi >>> 1;
263 if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid;
264 }
265 return lo;
266 },
267 right: function(a, x, lo, hi) {
268 if (arguments.length < 3) lo = 0;
269 if (arguments.length < 4) hi = a.length;
270 while (lo < hi) {
271 var mid = lo + hi >>> 1;
272 if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1;
273 }
274 return lo;
275 }
276 };
277 };
278 var d3_bisector = d3.bisector(function(d) {
279 return d;
280 });
281 d3.bisectLeft = d3_bisector.left;
282 d3.bisect = d3.bisectRight = d3_bisector.right;
283 d3.nest = function() {
284 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
285 function map(array, depth) {
286 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
287 var i = -1, n = array.length, key = keys[depth++], keyValue, object, valuesByKey = new d3_Map(), values, o = {};
288 while (++i < n) {
289 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
290 values.push(object);
291 } else {
292 valuesByKey.set(keyValue, [ object ]);
293 }
294 }
295 valuesByKey.forEach(function(keyValue, values) {
296 o[keyValue] = map(values, depth);
297 });
298 return o;
299 }
300 function entries(map, depth) {
301 if (depth >= keys.length) return map;
302 var a = [], sortKey = sortKeys[depth++], key;
303 for (key in map) {
304 a.push({
305 key: key,
306 values: entries(map[key], depth)
307 });
308 }
309 if (sortKey) a.sort(function(a, b) {
310 return sortKey(a.key, b.key);
311 });
312 return a;
313 }
314 nest.map = function(array) {
315 return map(array, 0);
316 };
317 nest.entries = function(array) {
318 return entries(map(array, 0), 0);
319 };
320 nest.key = function(d) {
321 keys.push(d);
322 return nest;
323 };
324 nest.sortKeys = function(order) {
325 sortKeys[keys.length - 1] = order;
326 return nest;
327 };
328 nest.sortValues = function(order) {
329 sortValues = order;
330 return nest;
331 };
332 nest.rollup = function(f) {
333 rollup = f;
334 return nest;
335 };
336 return nest;
337 };
338 d3.keys = function(map) {
339 var keys = [];
340 for (var key in map) keys.push(key);
341 return keys;
342 };
343 d3.values = function(map) {
344 var values = [];
345 for (var key in map) values.push(map[key]);
346 return values;
347 };
348 d3.entries = function(map) {
349 var entries = [];
350 for (var key in map) entries.push({
351 key: key,
352 value: map[key]
353 });
354 return entries;
355 };
356 d3.permute = function(array, indexes) {
357 var permutes = [], i = -1, n = indexes.length;
358 while (++i < n) permutes[i] = array[indexes[i]];
359 return permutes;
360 };
361 d3.merge = function(arrays) {
362 return Array.prototype.concat.apply([], arrays);
363 };
364 function d3_collapse(s) {
365 return s.trim().replace(/\s+/g, " ");
366 }
367 d3.range = function(start, stop, step) {
368 if (arguments.length < 3) {
369 step = 1;
370 if (arguments.length < 2) {
371 stop = start;
372 start = 0;
373 }
374 }
375 if ((stop - start) / step === Infinity) throw new Error("infinite range");
376 var range = [], k = d3_range_integerScale(Math.abs(step)), i = -1, j;
377 start *= k, stop *= k, step *= k;
378 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
379 return range;
380 };
381 function d3_range_integerScale(x) {
382 var k = 1;
383 while (x * k % 1) k *= 10;
384 return k;
385 }
386 d3.requote = function(s) {
387 return s.replace(d3_requote_re, "\\$&");
388 };
389 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
390 d3.round = function(x, n) {
391 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
392 };
393 d3.xhr = function(url, mimeType, callback) {
394 var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, response = d3_identity, request = new (d3_window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest)();
395 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
396 request.readyState > 3 && respond();
397 };
398 function respond() {
399 var s = request.status;
400 !s && request.responseText || s >= 200 && s < 300 || s === 304 ? dispatch.load.call(xhr, response.call(xhr, request)) : dispatch.error.call(xhr, request);
401 }
402 request.onprogress = function(event) {
403 var o = d3.event;
404 d3.event = event;
405 try {
406 dispatch.progress.call(xhr, request);
407 } finally {
408 d3.event = o;
409 }
410 };
411 xhr.header = function(name, value) {
412 name = (name + "").toLowerCase();
413 if (arguments.length < 2) return headers[name];
414 if (value == null) delete headers[name]; else headers[name] = value + "";
415 return xhr;
416 };
417 xhr.mimeType = function(value) {
418 if (!arguments.length) return mimeType;
419 mimeType = value == null ? null : value + "";
420 return xhr;
421 };
422 xhr.response = function(value) {
423 response = value;
424 return xhr;
425 };
426 [ "get", "post" ].forEach(function(method) {
427 xhr[method] = function() {
428 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
429 };
430 });
431 xhr.send = function(method, data, callback) {
432 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
433 request.open(method, url, true);
434 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
435 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
436 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
437 if (callback != null) xhr.on("error", callback).on("load", function(request) {
438 callback(null, request);
439 });
440 request.send(data == null ? null : data);
441 return xhr;
442 };
443 xhr.abort = function() {
444 request.abort();
445 return xhr;
446 };
447 d3.rebind(xhr, dispatch, "on");
448 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
449 mimeType = null;
450 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
451 };
452 function d3_xhr_fixCallback(callback) {
453 return callback.length === 1 ? function(error, request) {
454 callback(error == null ? request : null);
455 } : callback;
456 }
457 d3.text = function() {
458 return d3.xhr.apply(d3, arguments).response(d3_text);
459 };
460 function d3_text(request) {
461 return request.responseText;
462 }
463 d3.json = function(url, callback) {
464 return d3.xhr(url, "application/json", callback).response(d3_json);
465 };
466 function d3_json(request) {
467 return JSON.parse(request.responseText);
468 }
469 d3.html = function(url, callback) {
470 return d3.xhr(url, "text/html", callback).response(d3_html);
471 };
472 function d3_html(request) {
473 var range = d3_document.createRange();
474 range.selectNode(d3_document.body);
475 return range.createContextualFragment(request.responseText);
476 }
477 d3.xml = function() {
478 return d3.xhr.apply(d3, arguments).response(d3_xml);
479 };
480 function d3_xml(request) {
481 return request.responseXML;
482 }
483 var d3_nsPrefix = {
484 svg: "http://www.w3.org/2000/svg",
485 xhtml: "http://www.w3.org/1999/xhtml",
486 xlink: "http://www.w3.org/1999/xlink",
487 xml: "http://www.w3.org/XML/1998/namespace",
488 xmlns: "http://www.w3.org/2000/xmlns/"
489 };
490 d3.ns = {
491 prefix: d3_nsPrefix,
492 qualify: function(name) {
493 var i = name.indexOf(":"), prefix = name;
494 if (i >= 0) {
495 prefix = name.substring(0, i);
496 name = name.substring(i + 1);
497 }
498 return d3_nsPrefix.hasOwnProperty(prefix) ? {
499 space: d3_nsPrefix[prefix],
500 local: name
501 } : name;
502 }
503 };
504 d3.dispatch = function() {
505 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
506 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
507 return dispatch;
508 };
509 function d3_dispatch() {}
510 d3_dispatch.prototype.on = function(type, listener) {
511 var i = type.indexOf("."), name = "";
512 if (i > 0) {
513 name = type.substring(i + 1);
514 type = type.substring(0, i);
515 }
516 return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
517 };
518 function d3_dispatch_event(dispatch) {
519 var listeners = [], listenerByName = new d3_Map();
520 function event() {
521 var z = listeners, i = -1, n = z.length, l;
522 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
523 return dispatch;
524 }
525 event.on = function(name, listener) {
526 var l = listenerByName.get(name), i;
527 if (arguments.length < 2) return l && l.on;
528 if (l) {
529 l.on = null;
530 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
531 listenerByName.remove(name);
532 }
533 if (listener) listeners.push(listenerByName.set(name, {
534 on: listener
535 }));
536 return dispatch;
537 };
538 return event;
539 }
540 d3.format = function(specifier) {
541 var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "", basePrefix = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, suffix = "", integer = false;
542 if (precision) precision = +precision.substring(1);
543 if (zfill || fill === "0" && align === "=") {
544 zfill = fill = "0";
545 align = "=";
546 if (comma) width -= Math.floor((width - 1) / 4);
547 }
548 switch (type) {
549 case "n":
550 comma = true;
551 type = "g";
552 break;
553
554 case "%":
555 scale = 100;
556 suffix = "%";
557 type = "f";
558 break;
559
560 case "p":
561 scale = 100;
562 suffix = "%";
563 type = "r";
564 break;
565
566 case "b":
567 case "o":
568 case "x":
569 case "X":
570 if (basePrefix) basePrefix = "0" + type.toLowerCase();
571
572 case "c":
573 case "d":
574 integer = true;
575 precision = 0;
576 break;
577
578 case "s":
579 scale = -1;
580 type = "r";
581 break;
582 }
583 if (basePrefix === "#") basePrefix = "";
584 if (type == "r" && !precision) type = "g";
585 type = d3_format_types.get(type) || d3_format_typeDefault;
586 var zcomma = zfill && comma;
587 return function(value) {
588 if (integer && value % 1) return "";
589 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
590 if (scale < 0) {
591 var prefix = d3.formatPrefix(value, precision);
592 value = prefix.scale(value);
593 suffix = prefix.symbol;
594 } else {
595 value *= scale;
596 }
597 value = type(value, precision);
598 if (!zfill && comma) value = d3_format_group(value);
599 var length = basePrefix.length + value.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
600 if (zcomma) value = d3_format_group(padding + value);
601 if (d3_format_decimalPoint) value.replace(".", d3_format_decimalPoint);
602 negative += basePrefix;
603 return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + suffix;
604 };
605 };
606 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
607 var d3_format_types = d3.map({
608 b: function(x) {
609 return x.toString(2);
610 },
611 c: function(x) {
612 return String.fromCharCode(x);
613 },
614 o: function(x) {
615 return x.toString(8);
616 },
617 x: function(x) {
618 return x.toString(16);
619 },
620 X: function(x) {
621 return x.toString(16).toUpperCase();
622 },
623 g: function(x, p) {
624 return x.toPrecision(p);
625 },
626 e: function(x, p) {
627 return x.toExponential(p);
628 },
629 f: function(x, p) {
630 return x.toFixed(p);
631 },
632 r: function(x, p) {
633 return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));
634 }
635 });
636 function d3_format_precision(x, p) {
637 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
638 }
639 function d3_format_typeDefault(x) {
640 return x + "";
641 }
642 var d3_format_group = d3_identity;
643 if (d3_format_grouping) {
644 var d3_format_groupingLength = d3_format_grouping.length;
645 d3_format_group = function(value) {
646 var i = value.lastIndexOf("."), f = i >= 0 ? "." + value.substring(i + 1) : (i = value.length,
647 ""), t = [], j = 0, g = d3_format_grouping[0];
648 while (i > 0 && g > 0) {
649 t.push(value.substring(i -= g, i + g));
650 g = d3_format_grouping[j = (j + 1) % d3_format_groupingLength];
651 }
652 return t.reverse().join(d3_format_thousandsSeparator || "") + f;
653 };
654 }
655 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
656 d3.formatPrefix = function(value, precision) {
657 var i = 0;
658 if (value) {
659 if (value < 0) value *= -1;
660 if (precision) value = d3.round(value, d3_format_precision(value, precision));
661 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
662 i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
663 }
664 return d3_formatPrefixes[8 + i / 3];
665 };
666 function d3_formatPrefix(d, i) {
667 var k = Math.pow(10, Math.abs(8 - i) * 3);
668 return {
669 scale: i > 8 ? function(d) {
670 return d / k;
671 } : function(d) {
672 return d * k;
673 },
674 symbol: d
675 };
676 }
677 var d3_ease_default = function() {
678 return d3_identity;
679 };
680 var d3_ease = d3.map({
681 linear: d3_ease_default,
682 poly: d3_ease_poly,
683 quad: function() {
684 return d3_ease_quad;
685 },
686 cubic: function() {
687 return d3_ease_cubic;
688 },
689 sin: function() {
690 return d3_ease_sin;
691 },
692 exp: function() {
693 return d3_ease_exp;
694 },
695 circle: function() {
696 return d3_ease_circle;
697 },
698 elastic: d3_ease_elastic,
699 back: d3_ease_back,
700 bounce: function() {
701 return d3_ease_bounce;
702 }
703 });
704 var d3_ease_mode = d3.map({
705 "in": d3_identity,
706 out: d3_ease_reverse,
707 "in-out": d3_ease_reflect,
708 "out-in": function(f) {
709 return d3_ease_reflect(d3_ease_reverse(f));
710 }
711 });
712 d3.ease = function(name) {
713 var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
714 t = d3_ease.get(t) || d3_ease_default;
715 m = d3_ease_mode.get(m) || d3_identity;
716 return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1))));
717 };
718 function d3_ease_clamp(f) {
719 return function(t) {
720 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
721 };
722 }
723 function d3_ease_reverse(f) {
724 return function(t) {
725 return 1 - f(1 - t);
726 };
727 }
728 function d3_ease_reflect(f) {
729 return function(t) {
730 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
731 };
732 }
733 function d3_ease_quad(t) {
734 return t * t;
735 }
736 function d3_ease_cubic(t) {
737 return t * t * t;
738 }
739 function d3_ease_cubicInOut(t) {
740 if (t <= 0) return 0;
741 if (t >= 1) return 1;
742 var t2 = t * t, t3 = t2 * t;
743 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
744 }
745 function d3_ease_poly(e) {
746 return function(t) {
747 return Math.pow(t, e);
748 };
749 }
750 function d3_ease_sin(t) {
751 return 1 - Math.cos(t * π / 2);
752 }
753 function d3_ease_exp(t) {
754 return Math.pow(2, 10 * (t - 1));
755 }
756 function d3_ease_circle(t) {
757 return 1 - Math.sqrt(1 - t * t);
758 }
759 function d3_ease_elastic(a, p) {
760 var s;
761 if (arguments.length < 2) p = .45;
762 if (arguments.length) s = p / (2 * π) * Math.asin(1 / a); else a = 1, s = p / 4;
763 return function(t) {
764 return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * π / p);
765 };
766 }
767 function d3_ease_back(s) {
768 if (!s) s = 1.70158;
769 return function(t) {
770 return t * t * ((s + 1) * t - s);
771 };
772 }
773 function d3_ease_bounce(t) {
774 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;
775 }
776 d3.event = null;
777 function d3_eventCancel() {
778 d3.event.stopPropagation();
779 d3.event.preventDefault();
780 }
781 function d3_eventSource() {
782 var e = d3.event, s;
783 while (s = e.sourceEvent) e = s;
784 return e;
785 }
786 function d3_eventDispatch(target) {
787 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
788 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
789 dispatch.of = function(thiz, argumentz) {
790 return function(e1) {
791 try {
792 var e0 = e1.sourceEvent = d3.event;
793 e1.target = target;
794 d3.event = e1;
795 dispatch[e1.type].apply(thiz, argumentz);
796 } finally {
797 d3.event = e0;
798 }
799 };
800 };
801 return dispatch;
802 }
803 d3.transform = function(string) {
804 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
805 return (d3.transform = function(string) {
806 g.setAttribute("transform", string);
807 var t = g.transform.baseVal.consolidate();
808 return new d3_transform(t ? t.matrix : d3_transformIdentity);
809 })(string);
810 };
811 function d3_transform(m) {
812 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;
813 if (r0[0] * r1[1] < r1[0] * r0[1]) {
814 r0[0] *= -1;
815 r0[1] *= -1;
816 kx *= -1;
817 kz *= -1;
818 }
819 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
820 this.translate = [ m.e, m.f ];
821 this.scale = [ kx, ky ];
822 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
823 }
824 d3_transform.prototype.toString = function() {
825 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
826 };
827 function d3_transformDot(a, b) {
828 return a[0] * b[0] + a[1] * b[1];
829 }
830 function d3_transformNormalize(a) {
831 var k = Math.sqrt(d3_transformDot(a, a));
832 if (k) {
833 a[0] /= k;
834 a[1] /= k;
835 }
836 return k;
837 }
838 function d3_transformCombine(a, b, k) {
839 a[0] += k * b[0];
840 a[1] += k * b[1];
841 return a;
842 }
843 var d3_transformIdentity = {
844 a: 1,
845 b: 0,
846 c: 0,
847 d: 1,
848 e: 0,
849 f: 0
850 };
851 d3.interpolate = function(a, b) {
852 var i = d3.interpolators.length, f;
853 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
854 return f;
855 };
856 d3.interpolateNumber = function(a, b) {
857 b -= a;
858 return function(t) {
859 return a + b * t;
860 };
861 };
862 d3.interpolateRound = function(a, b) {
863 b -= a;
864 return function(t) {
865 return Math.round(a + b * t);
866 };
867 };
868 d3.interpolateString = function(a, b) {
869 var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
870 d3_interpolate_number.lastIndex = 0;
871 for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
872 if (m.index) s.push(b.substring(s0, s1 = m.index));
873 q.push({
874 i: s.length,
875 x: m[0]
876 });
877 s.push(null);
878 s0 = d3_interpolate_number.lastIndex;
879 }
880 if (s0 < b.length) s.push(b.substring(s0));
881 for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
882 o = q[i];
883 if (o.x == m[0]) {
884 if (o.i) {
885 if (s[o.i + 1] == null) {
886 s[o.i - 1] += o.x;
887 s.splice(o.i, 1);
888 for (j = i + 1; j < n; ++j) q[j].i--;
889 } else {
890 s[o.i - 1] += o.x + s[o.i + 1];
891 s.splice(o.i, 2);
892 for (j = i + 1; j < n; ++j) q[j].i -= 2;
893 }
894 } else {
895 if (s[o.i + 1] == null) {
896 s[o.i] = o.x;
897 } else {
898 s[o.i] = o.x + s[o.i + 1];
899 s.splice(o.i + 1, 1);
900 for (j = i + 1; j < n; ++j) q[j].i--;
901 }
902 }
903 q.splice(i, 1);
904 n--;
905 i--;
906 } else {
907 o.x = d3.interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
908 }
909 }
910 while (i < n) {
911 o = q.pop();
912 if (s[o.i + 1] == null) {
913 s[o.i] = o.x;
914 } else {
915 s[o.i] = o.x + s[o.i + 1];
916 s.splice(o.i + 1, 1);
917 }
918 n--;
919 }
920 if (s.length === 1) {
921 return s[0] == null ? q[0].x : function() {
922 return b;
923 };
924 }
925 return function(t) {
926 for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
927 return s.join("");
928 };
929 };
930 d3.interpolateTransform = function(a, b) {
931 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;
932 if (ta[0] != tb[0] || ta[1] != tb[1]) {
933 s.push("translate(", null, ",", null, ")");
934 q.push({
935 i: 1,
936 x: d3.interpolateNumber(ta[0], tb[0])
937 }, {
938 i: 3,
939 x: d3.interpolateNumber(ta[1], tb[1])
940 });
941 } else if (tb[0] || tb[1]) {
942 s.push("translate(" + tb + ")");
943 } else {
944 s.push("");
945 }
946 if (ra != rb) {
947 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
948 q.push({
949 i: s.push(s.pop() + "rotate(", null, ")") - 2,
950 x: d3.interpolateNumber(ra, rb)
951 });
952 } else if (rb) {
953 s.push(s.pop() + "rotate(" + rb + ")");
954 }
955 if (wa != wb) {
956 q.push({
957 i: s.push(s.pop() + "skewX(", null, ")") - 2,
958 x: d3.interpolateNumber(wa, wb)
959 });
960 } else if (wb) {
961 s.push(s.pop() + "skewX(" + wb + ")");
962 }
963 if (ka[0] != kb[0] || ka[1] != kb[1]) {
964 n = s.push(s.pop() + "scale(", null, ",", null, ")");
965 q.push({
966 i: n - 4,
967 x: d3.interpolateNumber(ka[0], kb[0])
968 }, {
969 i: n - 2,
970 x: d3.interpolateNumber(ka[1], kb[1])
971 });
972 } else if (kb[0] != 1 || kb[1] != 1) {
973 s.push(s.pop() + "scale(" + kb + ")");
974 }
975 n = q.length;
976 return function(t) {
977 var i = -1, o;
978 while (++i < n) s[(o = q[i]).i] = o.x(t);
979 return s.join("");
980 };
981 };
982 d3.interpolateRgb = function(a, b) {
983 a = d3.rgb(a);
984 b = d3.rgb(b);
985 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
986 return function(t) {
987 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));
988 };
989 };
990 d3.interpolateHsl = function(a, b) {
991 a = d3.hsl(a);
992 b = d3.hsl(b);
993 var h0 = a.h, s0 = a.s, l0 = a.l, h1 = b.h - h0, s1 = b.s - s0, l1 = b.l - l0;
994 if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360;
995 return function(t) {
996 return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t) + "";
997 };
998 };
999 d3.interpolateLab = function(a, b) {
1000 a = d3.lab(a);
1001 b = d3.lab(b);
1002 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
1003 return function(t) {
1004 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
1005 };
1006 };
1007 d3.interpolateHcl = function(a, b) {
1008 a = d3.hcl(a);
1009 b = d3.hcl(b);
1010 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
1011 if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
1012 return function(t) {
1013 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
1014 };
1015 };
1016 d3.interpolateArray = function(a, b) {
1017 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
1018 for (i = 0; i < n0; ++i) x.push(d3.interpolate(a[i], b[i]));
1019 for (;i < na; ++i) c[i] = a[i];
1020 for (;i < nb; ++i) c[i] = b[i];
1021 return function(t) {
1022 for (i = 0; i < n0; ++i) c[i] = x[i](t);
1023 return c;
1024 };
1025 };
1026 d3.interpolateObject = function(a, b) {
1027 var i = {}, c = {}, k;
1028 for (k in a) {
1029 if (k in b) {
1030 i[k] = d3_interpolateByName(k)(a[k], b[k]);
1031 } else {
1032 c[k] = a[k];
1033 }
1034 }
1035 for (k in b) {
1036 if (!(k in a)) {
1037 c[k] = b[k];
1038 }
1039 }
1040 return function(t) {
1041 for (k in i) c[k] = i[k](t);
1042 return c;
1043 };
1044 };
1045 var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
1046 function d3_interpolateByName(name) {
1047 return name == "transform" ? d3.interpolateTransform : d3.interpolate;
1048 }
1049 d3.interpolators = [ d3.interpolateObject, function(a, b) {
1050 return b instanceof Array && d3.interpolateArray(a, b);
1051 }, function(a, b) {
1052 return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + "");
1053 }, function(a, b) {
1054 return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Color) && d3.interpolateRgb(a, b);
1055 }, function(a, b) {
1056 return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b);
1057 } ];
1058 function d3_uninterpolateNumber(a, b) {
1059 b = b - (a = +a) ? 1 / (b - a) : 0;
1060 return function(x) {
1061 return (x - a) * b;
1062 };
1063 }
1064 function d3_uninterpolateClamp(a, b) {
1065 b = b - (a = +a) ? 1 / (b - a) : 0;
1066 return function(x) {
1067 return Math.max(0, Math.min(1, (x - a) * b));
1068 };
1069 }
1070 function d3_Color() {}
1071 d3_Color.prototype.toString = function() {
1072 return this.rgb() + "";
1073 };
1074 d3.rgb = function(r, g, b) {
1075 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);
1076 };
1077 function d3_rgb(r, g, b) {
1078 return new d3_Rgb(r, g, b);
1079 }
1080 function d3_Rgb(r, g, b) {
1081 this.r = r;
1082 this.g = g;
1083 this.b = b;
1084 }
1085 var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color();
1086 d3_rgbPrototype.brighter = function(k) {
1087 k = Math.pow(.7, arguments.length ? k : 1);
1088 var r = this.r, g = this.g, b = this.b, i = 30;
1089 if (!r && !g && !b) return d3_rgb(i, i, i);
1090 if (r && r < i) r = i;
1091 if (g && g < i) g = i;
1092 if (b && b < i) b = i;
1093 return d3_rgb(Math.min(255, Math.floor(r / k)), Math.min(255, Math.floor(g / k)), Math.min(255, Math.floor(b / k)));
1094 };
1095 d3_rgbPrototype.darker = function(k) {
1096 k = Math.pow(.7, arguments.length ? k : 1);
1097 return d3_rgb(Math.floor(k * this.r), Math.floor(k * this.g), Math.floor(k * this.b));
1098 };
1099 d3_rgbPrototype.hsl = function() {
1100 return d3_rgb_hsl(this.r, this.g, this.b);
1101 };
1102 d3_rgbPrototype.toString = function() {
1103 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1104 };
1105 function d3_rgb_hex(v) {
1106 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1107 }
1108 function d3_rgb_parse(format, rgb, hsl) {
1109 var r = 0, g = 0, b = 0, m1, m2, name;
1110 m1 = /([a-z]+)\((.*)\)/i.exec(format);
1111 if (m1) {
1112 m2 = m1[2].split(",");
1113 switch (m1[1]) {
1114 case "hsl":
1115 {
1116 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1117 }
1118
1119 case "rgb":
1120 {
1121 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1122 }
1123 }
1124 }
1125 if (name = d3_rgb_names.get(format)) return rgb(name.r, name.g, name.b);
1126 if (format != null && format.charAt(0) === "#") {
1127 if (format.length === 4) {
1128 r = format.charAt(1);
1129 r += r;
1130 g = format.charAt(2);
1131 g += g;
1132 b = format.charAt(3);
1133 b += b;
1134 } else if (format.length === 7) {
1135 r = format.substring(1, 3);
1136 g = format.substring(3, 5);
1137 b = format.substring(5, 7);
1138 }
1139 r = parseInt(r, 16);
1140 g = parseInt(g, 16);
1141 b = parseInt(b, 16);
1142 }
1143 return rgb(r, g, b);
1144 }
1145 function d3_rgb_hsl(r, g, b) {
1146 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;
1147 if (d) {
1148 s = l < .5 ? d / (max + min) : d / (2 - max - min);
1149 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;
1150 h *= 60;
1151 } else {
1152 s = h = 0;
1153 }
1154 return d3_hsl(h, s, l);
1155 }
1156 function d3_rgb_lab(r, g, b) {
1157 r = d3_rgb_xyz(r);
1158 g = d3_rgb_xyz(g);
1159 b = d3_rgb_xyz(b);
1160 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);
1161 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1162 }
1163 function d3_rgb_xyz(r) {
1164 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1165 }
1166 function d3_rgb_parseNumber(c) {
1167 var f = parseFloat(c);
1168 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1169 }
1170 var d3_rgb_names = d3.map({
1171 aliceblue: "#f0f8ff",
1172 antiquewhite: "#faebd7",
1173 aqua: "#00ffff",
1174 aquamarine: "#7fffd4",
1175 azure: "#f0ffff",
1176 beige: "#f5f5dc",
1177 bisque: "#ffe4c4",
1178 black: "#000000",
1179 blanchedalmond: "#ffebcd",
1180 blue: "#0000ff",
1181 blueviolet: "#8a2be2",
1182 brown: "#a52a2a",
1183 burlywood: "#deb887",
1184 cadetblue: "#5f9ea0",
1185 chartreuse: "#7fff00",
1186 chocolate: "#d2691e",
1187 coral: "#ff7f50",
1188 cornflowerblue: "#6495ed",
1189 cornsilk: "#fff8dc",
1190 crimson: "#dc143c",
1191 cyan: "#00ffff",
1192 darkblue: "#00008b",
1193 darkcyan: "#008b8b",
1194 darkgoldenrod: "#b8860b",
1195 darkgray: "#a9a9a9",
1196 darkgreen: "#006400",
1197 darkgrey: "#a9a9a9",
1198 darkkhaki: "#bdb76b",
1199 darkmagenta: "#8b008b",
1200 darkolivegreen: "#556b2f",
1201 darkorange: "#ff8c00",
1202 darkorchid: "#9932cc",
1203 darkred: "#8b0000",
1204 darksalmon: "#e9967a",
1205 darkseagreen: "#8fbc8f",
1206 darkslateblue: "#483d8b",
1207 darkslategray: "#2f4f4f",
1208 darkslategrey: "#2f4f4f",
1209 darkturquoise: "#00ced1",
1210 darkviolet: "#9400d3",
1211 deeppink: "#ff1493",
1212 deepskyblue: "#00bfff",
1213 dimgray: "#696969",
1214 dimgrey: "#696969",
1215 dodgerblue: "#1e90ff",
1216 firebrick: "#b22222",
1217 floralwhite: "#fffaf0",
1218 forestgreen: "#228b22",
1219 fuchsia: "#ff00ff",
1220 gainsboro: "#dcdcdc",
1221 ghostwhite: "#f8f8ff",
1222 gold: "#ffd700",
1223 goldenrod: "#daa520",
1224 gray: "#808080",
1225 green: "#008000",
1226 greenyellow: "#adff2f",
1227 grey: "#808080",
1228 honeydew: "#f0fff0",
1229 hotpink: "#ff69b4",
1230 indianred: "#cd5c5c",
1231 indigo: "#4b0082",
1232 ivory: "#fffff0",
1233 khaki: "#f0e68c",
1234 lavender: "#e6e6fa",
1235 lavenderblush: "#fff0f5",
1236 lawngreen: "#7cfc00",
1237 lemonchiffon: "#fffacd",
1238 lightblue: "#add8e6",
1239 lightcoral: "#f08080",
1240 lightcyan: "#e0ffff",
1241 lightgoldenrodyellow: "#fafad2",
1242 lightgray: "#d3d3d3",
1243 lightgreen: "#90ee90",
1244 lightgrey: "#d3d3d3",
1245 lightpink: "#ffb6c1",
1246 lightsalmon: "#ffa07a",
1247 lightseagreen: "#20b2aa",
1248 lightskyblue: "#87cefa",
1249 lightslategray: "#778899",
1250 lightslategrey: "#778899",
1251 lightsteelblue: "#b0c4de",
1252 lightyellow: "#ffffe0",
1253 lime: "#00ff00",
1254 limegreen: "#32cd32",
1255 linen: "#faf0e6",
1256 magenta: "#ff00ff",
1257 maroon: "#800000",
1258 mediumaquamarine: "#66cdaa",
1259 mediumblue: "#0000cd",
1260 mediumorchid: "#ba55d3",
1261 mediumpurple: "#9370db",
1262 mediumseagreen: "#3cb371",
1263 mediumslateblue: "#7b68ee",
1264 mediumspringgreen: "#00fa9a",
1265 mediumturquoise: "#48d1cc",
1266 mediumvioletred: "#c71585",
1267 midnightblue: "#191970",
1268 mintcream: "#f5fffa",
1269 mistyrose: "#ffe4e1",
1270 moccasin: "#ffe4b5",
1271 navajowhite: "#ffdead",
1272 navy: "#000080",
1273 oldlace: "#fdf5e6",
1274 olive: "#808000",
1275 olivedrab: "#6b8e23",
1276 orange: "#ffa500",
1277 orangered: "#ff4500",
1278 orchid: "#da70d6",
1279 palegoldenrod: "#eee8aa",
1280 palegreen: "#98fb98",
1281 paleturquoise: "#afeeee",
1282 palevioletred: "#db7093",
1283 papayawhip: "#ffefd5",
1284 peachpuff: "#ffdab9",
1285 peru: "#cd853f",
1286 pink: "#ffc0cb",
1287 plum: "#dda0dd",
1288 powderblue: "#b0e0e6",
1289 purple: "#800080",
1290 red: "#ff0000",
1291 rosybrown: "#bc8f8f",
1292 royalblue: "#4169e1",
1293 saddlebrown: "#8b4513",
1294 salmon: "#fa8072",
1295 sandybrown: "#f4a460",
1296 seagreen: "#2e8b57",
1297 seashell: "#fff5ee",
1298 sienna: "#a0522d",
1299 silver: "#c0c0c0",
1300 skyblue: "#87ceeb",
1301 slateblue: "#6a5acd",
1302 slategray: "#708090",
1303 slategrey: "#708090",
1304 snow: "#fffafa",
1305 springgreen: "#00ff7f",
1306 steelblue: "#4682b4",
1307 tan: "#d2b48c",
1308 teal: "#008080",
1309 thistle: "#d8bfd8",
1310 tomato: "#ff6347",
1311 turquoise: "#40e0d0",
1312 violet: "#ee82ee",
1313 wheat: "#f5deb3",
1314 white: "#ffffff",
1315 whitesmoke: "#f5f5f5",
1316 yellow: "#ffff00",
1317 yellowgreen: "#9acd32"
1318 });
1319 d3_rgb_names.forEach(function(key, value) {
1320 d3_rgb_names.set(key, d3_rgb_parse(value, d3_rgb, d3_hsl_rgb));
1321 });
1322 d3.hsl = function(h, s, l) {
1323 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);
1324 };
1325 function d3_hsl(h, s, l) {
1326 return new d3_Hsl(h, s, l);
1327 }
1328 function d3_Hsl(h, s, l) {
1329 this.h = h;
1330 this.s = s;
1331 this.l = l;
1332 }
1333 var d3_hslPrototype = d3_Hsl.prototype = new d3_Color();
1334 d3_hslPrototype.brighter = function(k) {
1335 k = Math.pow(.7, arguments.length ? k : 1);
1336 return d3_hsl(this.h, this.s, this.l / k);
1337 };
1338 d3_hslPrototype.darker = function(k) {
1339 k = Math.pow(.7, arguments.length ? k : 1);
1340 return d3_hsl(this.h, this.s, k * this.l);
1341 };
1342 d3_hslPrototype.rgb = function() {
1343 return d3_hsl_rgb(this.h, this.s, this.l);
1344 };
1345 function d3_hsl_rgb(h, s, l) {
1346 var m1, m2;
1347 h = h % 360;
1348 if (h < 0) h += 360;
1349 s = s < 0 ? 0 : s > 1 ? 1 : s;
1350 l = l < 0 ? 0 : l > 1 ? 1 : l;
1351 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1352 m1 = 2 * l - m2;
1353 function v(h) {
1354 if (h > 360) h -= 360; else if (h < 0) h += 360;
1355 if (h < 60) return m1 + (m2 - m1) * h / 60;
1356 if (h < 180) return m2;
1357 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
1358 return m1;
1359 }
1360 function vv(h) {
1361 return Math.round(v(h) * 255);
1362 }
1363 return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1364 }
1365 d3.hcl = function(h, c, l) {
1366 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);
1367 };
1368 function d3_hcl(h, c, l) {
1369 return new d3_Hcl(h, c, l);
1370 }
1371 function d3_Hcl(h, c, l) {
1372 this.h = h;
1373 this.c = c;
1374 this.l = l;
1375 }
1376 var d3_hclPrototype = d3_Hcl.prototype = new d3_Color();
1377 d3_hclPrototype.brighter = function(k) {
1378 return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1379 };
1380 d3_hclPrototype.darker = function(k) {
1381 return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1382 };
1383 d3_hclPrototype.rgb = function() {
1384 return d3_hcl_lab(this.h, this.c, this.l).rgb();
1385 };
1386 function d3_hcl_lab(h, c, l) {
1387 return d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1388 }
1389 d3.lab = function(l, a, b) {
1390 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);
1391 };
1392 function d3_lab(l, a, b) {
1393 return new d3_Lab(l, a, b);
1394 }
1395 function d3_Lab(l, a, b) {
1396 this.l = l;
1397 this.a = a;
1398 this.b = b;
1399 }
1400 var d3_lab_K = 18;
1401 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1402 var d3_labPrototype = d3_Lab.prototype = new d3_Color();
1403 d3_labPrototype.brighter = function(k) {
1404 return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1405 };
1406 d3_labPrototype.darker = function(k) {
1407 return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1408 };
1409 d3_labPrototype.rgb = function() {
1410 return d3_lab_rgb(this.l, this.a, this.b);
1411 };
1412 function d3_lab_rgb(l, a, b) {
1413 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1414 x = d3_lab_xyz(x) * d3_lab_X;
1415 y = d3_lab_xyz(y) * d3_lab_Y;
1416 z = d3_lab_xyz(z) * d3_lab_Z;
1417 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));
1418 }
1419 function d3_lab_hcl(l, a, b) {
1420 return d3_hcl(Math.atan2(b, a) / π * 180, Math.sqrt(a * a + b * b), l);
1421 }
1422 function d3_lab_xyz(x) {
1423 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1424 }
1425 function d3_xyz_lab(x) {
1426 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1427 }
1428 function d3_xyz_rgb(r) {
1429 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1430 }
1431 function d3_selection(groups) {
1432 d3_arraySubclass(groups, d3_selectionPrototype);
1433 return groups;
1434 }
1435 var d3_select = function(s, n) {
1436 return n.querySelector(s);
1437 }, d3_selectAll = function(s, n) {
1438 return n.querySelectorAll(s);
1439 }, d3_selectRoot = d3_document.documentElement, d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) {
1440 return d3_selectMatcher.call(n, s);
1441 };
1442 if (typeof Sizzle === "function") {
1443 d3_select = function(s, n) {
1444 return Sizzle(s, n)[0] || null;
1445 };
1446 d3_selectAll = function(s, n) {
1447 return Sizzle.uniqueSort(Sizzle(s, n));
1448 };
1449 d3_selectMatches = Sizzle.matchesSelector;
1450 }
1451 var d3_selectionPrototype = [];
1452 d3.selection = function() {
1453 return d3_selectionRoot;
1454 };
1455 d3.selection.prototype = d3_selectionPrototype;
1456 d3_selectionPrototype.select = function(selector) {
1457 var subgroups = [], subgroup, subnode, group, node;
1458 if (typeof selector !== "function") selector = d3_selection_selector(selector);
1459 for (var j = -1, m = this.length; ++j < m; ) {
1460 subgroups.push(subgroup = []);
1461 subgroup.parentNode = (group = this[j]).parentNode;
1462 for (var i = -1, n = group.length; ++i < n; ) {
1463 if (node = group[i]) {
1464 subgroup.push(subnode = selector.call(node, node.__data__, i));
1465 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
1466 } else {
1467 subgroup.push(null);
1468 }
1469 }
1470 }
1471 return d3_selection(subgroups);
1472 };
1473 function d3_selection_selector(selector) {
1474 return function() {
1475 return d3_select(selector, this);
1476 };
1477 }
1478 d3_selectionPrototype.selectAll = function(selector) {
1479 var subgroups = [], subgroup, node;
1480 if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
1481 for (var j = -1, m = this.length; ++j < m; ) {
1482 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
1483 if (node = group[i]) {
1484 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
1485 subgroup.parentNode = node;
1486 }
1487 }
1488 }
1489 return d3_selection(subgroups);
1490 };
1491 function d3_selection_selectorAll(selector) {
1492 return function() {
1493 return d3_selectAll(selector, this);
1494 };
1495 }
1496 d3_selectionPrototype.attr = function(name, value) {
1497 if (arguments.length < 2) {
1498 if (typeof name === "string") {
1499 var node = this.node();
1500 name = d3.ns.qualify(name);
1501 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
1502 }
1503 for (value in name) this.each(d3_selection_attr(value, name[value]));
1504 return this;
1505 }
1506 return this.each(d3_selection_attr(name, value));
1507 };
1508 function d3_selection_attr(name, value) {
1509 name = d3.ns.qualify(name);
1510 function attrNull() {
1511 this.removeAttribute(name);
1512 }
1513 function attrNullNS() {
1514 this.removeAttributeNS(name.space, name.local);
1515 }
1516 function attrConstant() {
1517 this.setAttribute(name, value);
1518 }
1519 function attrConstantNS() {
1520 this.setAttributeNS(name.space, name.local, value);
1521 }
1522 function attrFunction() {
1523 var x = value.apply(this, arguments);
1524 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
1525 }
1526 function attrFunctionNS() {
1527 var x = value.apply(this, arguments);
1528 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
1529 }
1530 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
1531 }
1532 d3_selectionPrototype.classed = function(name, value) {
1533 if (arguments.length < 2) {
1534 if (typeof name === "string") {
1535 var node = this.node(), n = (name = name.trim().split(/^|\s+/g)).length, i = -1;
1536 if (value = node.classList) {
1537 while (++i < n) if (!value.contains(name[i])) return false;
1538 } else {
1539 value = node.className;
1540 if (value.baseVal != null) value = value.baseVal;
1541 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
1542 }
1543 return true;
1544 }
1545 for (value in name) this.each(d3_selection_classed(value, name[value]));
1546 return this;
1547 }
1548 return this.each(d3_selection_classed(name, value));
1549 };
1550 function d3_selection_classedRe(name) {
1551 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
1552 }
1553 function d3_selection_classed(name, value) {
1554 name = name.trim().split(/\s+/).map(d3_selection_classedName);
1555 var n = name.length;
1556 function classedConstant() {
1557 var i = -1;
1558 while (++i < n) name[i](this, value);
1559 }
1560 function classedFunction() {
1561 var i = -1, x = value.apply(this, arguments);
1562 while (++i < n) name[i](this, x);
1563 }
1564 return typeof value === "function" ? classedFunction : classedConstant;
1565 }
1566 function d3_selection_classedName(name) {
1567 var re = d3_selection_classedRe(name);
1568 return function(node, value) {
1569 if (c = node.classList) return value ? c.add(name) : c.remove(name);
1570 var c = node.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
1571 if (value) {
1572 re.lastIndex = 0;
1573 if (!re.test(cv)) {
1574 cv = d3_collapse(cv + " " + name);
1575 if (cb) c.baseVal = cv; else node.className = cv;
1576 }
1577 } else if (cv) {
1578 cv = d3_collapse(cv.replace(re, " "));
1579 if (cb) c.baseVal = cv; else node.className = cv;
1580 }
1581 };
1582 }
1583 d3_selectionPrototype.style = function(name, value, priority) {
1584 var n = arguments.length;
1585 if (n < 3) {
1586 if (typeof name !== "string") {
1587 if (n < 2) value = "";
1588 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
1589 return this;
1590 }
1591 if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
1592 priority = "";
1593 }
1594 return this.each(d3_selection_style(name, value, priority));
1595 };
1596 function d3_selection_style(name, value, priority) {
1597 function styleNull() {
1598 this.style.removeProperty(name);
1599 }
1600 function styleConstant() {
1601 this.style.setProperty(name, value, priority);
1602 }
1603 function styleFunction() {
1604 var x = value.apply(this, arguments);
1605 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
1606 }
1607 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
1608 }
1609 d3_selectionPrototype.property = function(name, value) {
1610 if (arguments.length < 2) {
1611 if (typeof name === "string") return this.node()[name];
1612 for (value in name) this.each(d3_selection_property(value, name[value]));
1613 return this;
1614 }
1615 return this.each(d3_selection_property(name, value));
1616 };
1617 function d3_selection_property(name, value) {
1618 function propertyNull() {
1619 delete this[name];
1620 }
1621 function propertyConstant() {
1622 this[name] = value;
1623 }
1624 function propertyFunction() {
1625 var x = value.apply(this, arguments);
1626 if (x == null) delete this[name]; else this[name] = x;
1627 }
1628 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
1629 }
1630 d3_selectionPrototype.text = function(value) {
1631 return arguments.length ? this.each(typeof value === "function" ? function() {
1632 var v = value.apply(this, arguments);
1633 this.textContent = v == null ? "" : v;
1634 } : value == null ? function() {
1635 this.textContent = "";
1636 } : function() {
1637 this.textContent = value;
1638 }) : this.node().textContent;
1639 };
1640 d3_selectionPrototype.html = function(value) {
1641 return arguments.length ? this.each(typeof value === "function" ? function() {
1642 var v = value.apply(this, arguments);
1643 this.innerHTML = v == null ? "" : v;
1644 } : value == null ? function() {
1645 this.innerHTML = "";
1646 } : function() {
1647 this.innerHTML = value;
1648 }) : this.node().innerHTML;
1649 };
1650 d3_selectionPrototype.append = function(name) {
1651 name = d3.ns.qualify(name);
1652 function append() {
1653 return this.appendChild(d3_document.createElementNS(this.namespaceURI, name));
1654 }
1655 function appendNS() {
1656 return this.appendChild(d3_document.createElementNS(name.space, name.local));
1657 }
1658 return this.select(name.local ? appendNS : append);
1659 };
1660 d3_selectionPrototype.insert = function(name, before) {
1661 name = d3.ns.qualify(name);
1662 function insert() {
1663 return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), d3_select(before, this));
1664 }
1665 function insertNS() {
1666 return this.insertBefore(d3_document.createElementNS(name.space, name.local), d3_select(before, this));
1667 }
1668 return this.select(name.local ? insertNS : insert);
1669 };
1670 d3_selectionPrototype.remove = function() {
1671 return this.each(function() {
1672 var parent = this.parentNode;
1673 if (parent) parent.removeChild(this);
1674 });
1675 };
1676 d3_selectionPrototype.data = function(value, key) {
1677 var i = -1, n = this.length, group, node;
1678 if (!arguments.length) {
1679 value = new Array(n = (group = this[0]).length);
1680 while (++i < n) {
1681 if (node = group[i]) {
1682 value[i] = node.__data__;
1683 }
1684 }
1685 return value;
1686 }
1687 function bind(group, groupData) {
1688 var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;
1689 if (key) {
1690 var nodeByKeyValue = new d3_Map(), dataByKeyValue = new d3_Map(), keyValues = [], keyValue;
1691 for (i = -1; ++i < n; ) {
1692 keyValue = key.call(node = group[i], node.__data__, i);
1693 if (nodeByKeyValue.has(keyValue)) {
1694 exitNodes[i] = node;
1695 } else {
1696 nodeByKeyValue.set(keyValue, node);
1697 }
1698 keyValues.push(keyValue);
1699 }
1700 for (i = -1; ++i < m; ) {
1701 keyValue = key.call(groupData, nodeData = groupData[i], i);
1702 if (node = nodeByKeyValue.get(keyValue)) {
1703 updateNodes[i] = node;
1704 node.__data__ = nodeData;
1705 } else if (!dataByKeyValue.has(keyValue)) {
1706 enterNodes[i] = d3_selection_dataNode(nodeData);
1707 }
1708 dataByKeyValue.set(keyValue, nodeData);
1709 nodeByKeyValue.remove(keyValue);
1710 }
1711 for (i = -1; ++i < n; ) {
1712 if (nodeByKeyValue.has(keyValues[i])) {
1713 exitNodes[i] = group[i];
1714 }
1715 }
1716 } else {
1717 for (i = -1; ++i < n0; ) {
1718 node = group[i];
1719 nodeData = groupData[i];
1720 if (node) {
1721 node.__data__ = nodeData;
1722 updateNodes[i] = node;
1723 } else {
1724 enterNodes[i] = d3_selection_dataNode(nodeData);
1725 }
1726 }
1727 for (;i < m; ++i) {
1728 enterNodes[i] = d3_selection_dataNode(groupData[i]);
1729 }
1730 for (;i < n; ++i) {
1731 exitNodes[i] = group[i];
1732 }
1733 }
1734 enterNodes.update = updateNodes;
1735 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
1736 enter.push(enterNodes);
1737 update.push(updateNodes);
1738 exit.push(exitNodes);
1739 }
1740 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
1741 if (typeof value === "function") {
1742 while (++i < n) {
1743 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
1744 }
1745 } else {
1746 while (++i < n) {
1747 bind(group = this[i], value);
1748 }
1749 }
1750 update.enter = function() {
1751 return enter;
1752 };
1753 update.exit = function() {
1754 return exit;
1755 };
1756 return update;
1757 };
1758 function d3_selection_dataNode(data) {
1759 return {
1760 __data__: data
1761 };
1762 }
1763 d3_selectionPrototype.datum = function(value) {
1764 return arguments.length ? this.property("__data__", value) : this.property("__data__");
1765 };
1766 d3_selectionPrototype.filter = function(filter) {
1767 var subgroups = [], subgroup, group, node;
1768 if (typeof filter !== "function") filter = d3_selection_filter(filter);
1769 for (var j = 0, m = this.length; j < m; j++) {
1770 subgroups.push(subgroup = []);
1771 subgroup.parentNode = (group = this[j]).parentNode;
1772 for (var i = 0, n = group.length; i < n; i++) {
1773 if ((node = group[i]) && filter.call(node, node.__data__, i)) {
1774 subgroup.push(node);
1775 }
1776 }
1777 }
1778 return d3_selection(subgroups);
1779 };
1780 function d3_selection_filter(selector) {
1781 return function() {
1782 return d3_selectMatches(this, selector);
1783 };
1784 }
1785 d3_selectionPrototype.order = function() {
1786 for (var j = -1, m = this.length; ++j < m; ) {
1787 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
1788 if (node = group[i]) {
1789 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
1790 next = node;
1791 }
1792 }
1793 }
1794 return this;
1795 };
1796 d3_selectionPrototype.sort = function(comparator) {
1797 comparator = d3_selection_sortComparator.apply(this, arguments);
1798 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
1799 return this.order();
1800 };
1801 function d3_selection_sortComparator(comparator) {
1802 if (!arguments.length) comparator = d3.ascending;
1803 return function(a, b) {
1804 return !a - !b || comparator(a.__data__, b.__data__);
1805 };
1806 }
1807 d3_selectionPrototype.on = function(type, listener, capture) {
1808 var n = arguments.length;
1809 if (n < 3) {
1810 if (typeof type !== "string") {
1811 if (n < 2) listener = false;
1812 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
1813 return this;
1814 }
1815 if (n < 2) return (n = this.node()["__on" + type]) && n._;
1816 capture = false;
1817 }
1818 return this.each(d3_selection_on(type, listener, capture));
1819 };
1820 function d3_selection_on(type, listener, capture) {
1821 var name = "__on" + type, i = type.indexOf(".");
1822 if (i > 0) type = type.substring(0, i);
1823 function onRemove() {
1824 var wrapper = this[name];
1825 if (wrapper) {
1826 this.removeEventListener(type, wrapper, wrapper.$);
1827 delete this[name];
1828 }
1829 }
1830 function onAdd() {
1831 var node = this, args = d3_array(arguments);
1832 onRemove.call(this);
1833 this.addEventListener(type, this[name] = wrapper, wrapper.$ = capture);
1834 wrapper._ = listener;
1835 function wrapper(e) {
1836 var o = d3.event;
1837 d3.event = e;
1838 args[0] = node.__data__;
1839 try {
1840 listener.apply(node, args);
1841 } finally {
1842 d3.event = o;
1843 }
1844 }
1845 }
1846 return listener ? onAdd : onRemove;
1847 }
1848 d3_selectionPrototype.each = function(callback) {
1849 return d3_selection_each(this, function(node, i, j) {
1850 callback.call(node, node.__data__, i, j);
1851 });
1852 };
1853 function d3_selection_each(groups, callback) {
1854 for (var j = 0, m = groups.length; j < m; j++) {
1855 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
1856 if (node = group[i]) callback(node, i, j);
1857 }
1858 }
1859 return groups;
1860 }
1861 d3_selectionPrototype.call = function(callback) {
1862 var args = d3_array(arguments);
1863 callback.apply(args[0] = this, args);
1864 return this;
1865 };
1866 d3_selectionPrototype.empty = function() {
1867 return !this.node();
1868 };
1869 d3_selectionPrototype.node = function() {
1870 for (var j = 0, m = this.length; j < m; j++) {
1871 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
1872 var node = group[i];
1873 if (node) return node;
1874 }
1875 }
1876 return null;
1877 };
1878 d3_selectionPrototype.transition = function() {
1879 var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = Object.create(d3_transitionInherit);
1880 transition.time = Date.now();
1881 for (var j = -1, m = this.length; ++j < m; ) {
1882 subgroups.push(subgroup = []);
1883 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
1884 if (node = group[i]) d3_transitionNode(node, i, id, transition);
1885 subgroup.push(node);
1886 }
1887 }
1888 return d3_transition(subgroups, id);
1889 };
1890 var d3_selectionRoot = d3_selection([ [ d3_document ] ]);
1891 d3_selectionRoot[0].parentNode = d3_selectRoot;
1892 d3.select = function(selector) {
1893 return typeof selector === "string" ? d3_selectionRoot.select(selector) : d3_selection([ [ selector ] ]);
1894 };
1895 d3.selectAll = function(selector) {
1896 return typeof selector === "string" ? d3_selectionRoot.selectAll(selector) : d3_selection([ d3_array(selector) ]);
1897 };
1898 function d3_selection_enter(selection) {
1899 d3_arraySubclass(selection, d3_selection_enterPrototype);
1900 return selection;
1901 }
1902 var d3_selection_enterPrototype = [];
1903 d3.selection.enter = d3_selection_enter;
1904 d3.selection.enter.prototype = d3_selection_enterPrototype;
1905 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
1906 d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
1907 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1908 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1909 d3_selection_enterPrototype.select = function(selector) {
1910 var subgroups = [], subgroup, subnode, upgroup, group, node;
1911 for (var j = -1, m = this.length; ++j < m; ) {
1912 upgroup = (group = this[j]).update;
1913 subgroups.push(subgroup = []);
1914 subgroup.parentNode = group.parentNode;
1915 for (var i = -1, n = group.length; ++i < n; ) {
1916 if (node = group[i]) {
1917 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i));
1918 subnode.__data__ = node.__data__;
1919 } else {
1920 subgroup.push(null);
1921 }
1922 }
1923 }
1924 return d3_selection(subgroups);
1925 };
1926 function d3_transition(groups, id) {
1927 d3_arraySubclass(groups, d3_transitionPrototype);
1928 groups.id = id;
1929 return groups;
1930 }
1931 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit = {
1932 ease: d3_ease_cubicInOut,
1933 delay: 0,
1934 duration: 250
1935 };
1936 d3_transitionPrototype.call = d3_selectionPrototype.call;
1937 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
1938 d3_transitionPrototype.node = d3_selectionPrototype.node;
1939 d3.transition = function(selection) {
1940 return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
1941 };
1942 d3.transition.prototype = d3_transitionPrototype;
1943 function d3_transitionNode(node, i, id, inherit) {
1944 var lock = node.__transition__ || (node.__transition__ = {
1945 active: 0,
1946 count: 0
1947 }), transition = lock[id];
1948 if (!transition) {
1949 var time = inherit.time;
1950 transition = lock[id] = {
1951 tween: new d3_Map(),
1952 event: d3.dispatch("start", "end"),
1953 time: time,
1954 ease: inherit.ease,
1955 delay: inherit.delay,
1956 duration: inherit.duration
1957 };
1958 ++lock.count;
1959 d3.timer(function(elapsed) {
1960 var d = node.__data__, ease = transition.ease, event = transition.event, delay = transition.delay, duration = transition.duration, tweened = [];
1961 return delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time), 1;
1962 function start(elapsed) {
1963 if (lock.active > id) return stop();
1964 lock.active = id;
1965 event.start.call(node, d, i);
1966 transition.tween.forEach(function(key, value) {
1967 if (value = value.call(node, d, i)) {
1968 tweened.push(value);
1969 }
1970 });
1971 if (!tick(elapsed)) d3.timer(tick, 0, time);
1972 return 1;
1973 }
1974 function tick(elapsed) {
1975 if (lock.active !== id) return stop();
1976 var t = (elapsed - delay) / duration, e = ease(t), n = tweened.length;
1977 while (n > 0) {
1978 tweened[--n].call(node, e);
1979 }
1980 if (t >= 1) {
1981 stop();
1982 event.end.call(node, d, i);
1983 return 1;
1984 }
1985 }
1986 function stop() {
1987 if (--lock.count) delete lock[id]; else delete node.__transition__;
1988 return 1;
1989 }
1990 }, 0, time);
1991 return transition;
1992 }
1993 }
1994 d3_transitionPrototype.select = function(selector) {
1995 var id = this.id, subgroups = [], subgroup, subnode, node;
1996 if (typeof selector !== "function") selector = d3_selection_selector(selector);
1997 for (var j = -1, m = this.length; ++j < m; ) {
1998 subgroups.push(subgroup = []);
1999 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
2000 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i))) {
2001 if ("__data__" in node) subnode.__data__ = node.__data__;
2002 d3_transitionNode(subnode, i, id, node.__transition__[id]);
2003 subgroup.push(subnode);
2004 } else {
2005 subgroup.push(null);
2006 }
2007 }
2008 }
2009 return d3_transition(subgroups, id);
2010 };
2011 d3_transitionPrototype.selectAll = function(selector) {
2012 var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
2013 if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
2014 for (var j = -1, m = this.length; ++j < m; ) {
2015 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
2016 if (node = group[i]) {
2017 transition = node.__transition__[id];
2018 subnodes = selector.call(node, node.__data__, i);
2019 subgroups.push(subgroup = []);
2020 for (var k = -1, o = subnodes.length; ++k < o; ) {
2021 d3_transitionNode(subnode = subnodes[k], k, id, transition);
2022 subgroup.push(subnode);
2023 }
2024 }
2025 }
2026 }
2027 return d3_transition(subgroups, id);
2028 };
2029 d3_transitionPrototype.filter = function(filter) {
2030 var subgroups = [], subgroup, group, node;
2031 if (typeof filter !== "function") filter = d3_selection_filter(filter);
2032 for (var j = 0, m = this.length; j < m; j++) {
2033 subgroups.push(subgroup = []);
2034 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
2035 if ((node = group[i]) && filter.call(node, node.__data__, i)) {
2036 subgroup.push(node);
2037 }
2038 }
2039 }
2040 return d3_transition(subgroups, this.id, this.time).ease(this.ease());
2041 };
2042 d3_transitionPrototype.attr = function(nameNS, value) {
2043 if (arguments.length < 2) {
2044 for (value in nameNS) this.attr(value, nameNS[value]);
2045 return this;
2046 }
2047 var interpolate = d3_interpolateByName(nameNS), name = d3.ns.qualify(nameNS);
2048 function attrNull() {
2049 this.removeAttribute(name);
2050 }
2051 function attrNullNS() {
2052 this.removeAttributeNS(name.space, name.local);
2053 }
2054 return d3_transition_tween(this, "attr." + nameNS, value, function(b) {
2055 function attrString() {
2056 var a = this.getAttribute(name), i;
2057 return a !== b && (i = interpolate(a, b), function(t) {
2058 this.setAttribute(name, i(t));
2059 });
2060 }
2061 function attrStringNS() {
2062 var a = this.getAttributeNS(name.space, name.local), i;
2063 return a !== b && (i = interpolate(a, b), function(t) {
2064 this.setAttributeNS(name.space, name.local, i(t));
2065 });
2066 }
2067 return b == null ? name.local ? attrNullNS : attrNull : (b += "", name.local ? attrStringNS : attrString);
2068 });
2069 };
2070 d3_transitionPrototype.attrTween = function(nameNS, tween) {
2071 var name = d3.ns.qualify(nameNS);
2072 function attrTween(d, i) {
2073 var f = tween.call(this, d, i, this.getAttribute(name));
2074 return f && function(t) {
2075 this.setAttribute(name, f(t));
2076 };
2077 }
2078 function attrTweenNS(d, i) {
2079 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
2080 return f && function(t) {
2081 this.setAttributeNS(name.space, name.local, f(t));
2082 };
2083 }
2084 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
2085 };
2086 d3_transitionPrototype.style = function(name, value, priority) {
2087 var n = arguments.length;
2088 if (n < 3) {
2089 if (typeof name !== "string") {
2090 if (n < 2) value = "";
2091 for (priority in name) this.style(priority, name[priority], value);
2092 return this;
2093 }
2094 priority = "";
2095 }
2096 var interpolate = d3_interpolateByName(name);
2097 function styleNull() {
2098 this.style.removeProperty(name);
2099 }
2100 return d3_transition_tween(this, "style." + name, value, function(b) {
2101 function styleString() {
2102 var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
2103 return a !== b && (i = interpolate(a, b), function(t) {
2104 this.style.setProperty(name, i(t), priority);
2105 });
2106 }
2107 return b == null ? styleNull : (b += "", styleString);
2108 });
2109 };
2110 d3_transitionPrototype.styleTween = function(name, tween, priority) {
2111 if (arguments.length < 3) priority = "";
2112 return this.tween("style." + name, function(d, i) {
2113 var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
2114 return f && function(t) {
2115 this.style.setProperty(name, f(t), priority);
2116 };
2117 });
2118 };
2119 d3_transitionPrototype.text = function(value) {
2120 return d3_transition_tween(this, "text", value, d3_transition_text);
2121 };
2122 function d3_transition_text(b) {
2123 if (b == null) b = "";
2124 return function() {
2125 this.textContent = b;
2126 };
2127 }
2128 d3_transitionPrototype.remove = function() {
2129 return this.each("end.transition", function() {
2130 var p;
2131 if (!this.__transition__ && (p = this.parentNode)) p.removeChild(this);
2132 });
2133 };
2134 d3_transitionPrototype.ease = function(value) {
2135 var id = this.id;
2136 if (arguments.length < 1) return this.node().__transition__[id].ease;
2137 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
2138 return d3_selection_each(this, function(node) {
2139 node.__transition__[id].ease = value;
2140 });
2141 };
2142 d3_transitionPrototype.delay = function(value) {
2143 var id = this.id;
2144 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
2145 node.__transition__[id].delay = value.call(node, node.__data__, i, j) | 0;
2146 } : (value |= 0, function(node) {
2147 node.__transition__[id].delay = value;
2148 }));
2149 };
2150 d3_transitionPrototype.duration = function(value) {
2151 var id = this.id;
2152 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
2153 node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j) | 0);
2154 } : (value = Math.max(1, value | 0), function(node) {
2155 node.__transition__[id].duration = value;
2156 }));
2157 };
2158 d3_transitionPrototype.each = function(type, listener) {
2159 var id = this.id;
2160 if (arguments.length < 2) {
2161 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
2162 d3_transitionInheritId = id;
2163 d3_selection_each(this, function(node, i, j) {
2164 d3_transitionInherit = node.__transition__[id];
2165 type.call(node, node.__data__, i, j);
2166 });
2167 d3_transitionInherit = inherit;
2168 d3_transitionInheritId = inheritId;
2169 } else {
2170 d3_selection_each(this, function(node) {
2171 node.__transition__[id].event.on(type, listener);
2172 });
2173 }
2174 return this;
2175 };
2176 d3_transitionPrototype.transition = function() {
2177 var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
2178 for (var j = 0, m = this.length; j < m; j++) {
2179 subgroups.push(subgroup = []);
2180 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
2181 if (node = group[i]) {
2182 transition = Object.create(node.__transition__[id0]);
2183 transition.delay += transition.duration;
2184 d3_transitionNode(node, i, id1, transition);
2185 }
2186 subgroup.push(node);
2187 }
2188 }
2189 return d3_transition(subgroups, id1);
2190 };
2191 d3_transitionPrototype.tween = function(name, tween) {
2192 var id = this.id;
2193 if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
2194 return d3_selection_each(this, tween == null ? function(node) {
2195 node.__transition__[id].tween.remove(name);
2196 } : function(node) {
2197 node.__transition__[id].tween.set(name, tween);
2198 });
2199 };
2200 function d3_transition_tween(groups, name, value, tween) {
2201 var id = groups.id;
2202 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
2203 node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
2204 } : (value = tween(value), function(node) {
2205 node.__transition__[id].tween.set(name, value);
2206 }));
2207 }
2208 var d3_timer_id = 0, d3_timer_byId = {}, d3_timer_queue = null, d3_timer_interval, d3_timer_timeout;
2209 d3.timer = function(callback, delay, then) {
2210 if (arguments.length < 3) {
2211 if (arguments.length < 2) delay = 0; else if (!isFinite(delay)) return;
2212 then = Date.now();
2213 }
2214 var timer = d3_timer_byId[callback.id];
2215 if (timer && timer.callback === callback) {
2216 timer.then = then;
2217 timer.delay = delay;
2218 } else d3_timer_byId[callback.id = ++d3_timer_id] = d3_timer_queue = {
2219 callback: callback,
2220 then: then,
2221 delay: delay,
2222 next: d3_timer_queue
2223 };
2224 if (!d3_timer_interval) {
2225 d3_timer_timeout = clearTimeout(d3_timer_timeout);
2226 d3_timer_interval = 1;
2227 d3_timer_frame(d3_timer_step);
2228 }
2229 };
2230 function d3_timer_step() {
2231 var elapsed, now = Date.now(), t1 = d3_timer_queue;
2232 while (t1) {
2233 elapsed = now - t1.then;
2234 if (elapsed >= t1.delay) t1.flush = t1.callback(elapsed);
2235 t1 = t1.next;
2236 }
2237 var delay = d3_timer_flush() - now;
2238 if (delay > 24) {
2239 if (isFinite(delay)) {
2240 clearTimeout(d3_timer_timeout);
2241 d3_timer_timeout = setTimeout(d3_timer_step, delay);
2242 }
2243 d3_timer_interval = 0;
2244 } else {
2245 d3_timer_interval = 1;
2246 d3_timer_frame(d3_timer_step);
2247 }
2248 }
2249 d3.timer.flush = function() {
2250 var elapsed, now = Date.now(), t1 = d3_timer_queue;
2251 while (t1) {
2252 elapsed = now - t1.then;
2253 if (!t1.delay) t1.flush = t1.callback(elapsed);
2254 t1 = t1.next;
2255 }
2256 d3_timer_flush();
2257 };
2258 function d3_timer_flush() {
2259 var t0 = null, t1 = d3_timer_queue, then = Infinity;
2260 while (t1) {
2261 if (t1.flush) {
2262 delete d3_timer_byId[t1.callback.id];
2263 t1 = t0 ? t0.next = t1.next : d3_timer_queue = t1.next;
2264 } else {
2265 then = Math.min(then, t1.then + t1.delay);
2266 t1 = (t0 = t1).next;
2267 }
2268 }
2269 return then;
2270 }
2271 var d3_timer_frame = d3_window.requestAnimationFrame || d3_window.webkitRequestAnimationFrame || d3_window.mozRequestAnimationFrame || d3_window.oRequestAnimationFrame || d3_window.msRequestAnimationFrame || function(callback) {
2272 setTimeout(callback, 17);
2273 };
2274 d3.mouse = function(container) {
2275 return d3_mousePoint(container, d3_eventSource());
2276 };
2277 var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
2278 function d3_mousePoint(container, e) {
2279 var svg = container.ownerSVGElement || container;
2280 if (svg.createSVGPoint) {
2281 var point = svg.createSVGPoint();
2282 if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
2283 svg = d3.select(d3_document.body).append("svg").style("position", "absolute").style("top", 0).style("left", 0);
2284 var ctm = svg[0][0].getScreenCTM();
2285 d3_mouse_bug44083 = !(ctm.f || ctm.e);
2286 svg.remove();
2287 }
2288 if (d3_mouse_bug44083) {
2289 point.x = e.pageX;
2290 point.y = e.pageY;
2291 } else {
2292 point.x = e.clientX;
2293 point.y = e.clientY;
2294 }
2295 point = point.matrixTransform(container.getScreenCTM().inverse());
2296 return [ point.x, point.y ];
2297 }
2298 var rect = container.getBoundingClientRect();
2299 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
2300 }
2301 d3.touches = function(container, touches) {
2302 if (arguments.length < 2) touches = d3_eventSource().touches;
2303 return touches ? d3_array(touches).map(function(touch) {
2304 var point = d3_mousePoint(container, touch);
2305 point.identifier = touch.identifier;
2306 return point;
2307 }) : [];
2308 };
2309 function d3_noop() {}
2310 d3.scale = {};
2311 function d3_scaleExtent(domain) {
2312 var start = domain[0], stop = domain[domain.length - 1];
2313 return start < stop ? [ start, stop ] : [ stop, start ];
2314 }
2315 function d3_scaleRange(scale) {
2316 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
2317 }
2318 function d3_scale_nice(domain, nice) {
2319 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
2320 if (x1 < x0) {
2321 dx = i0, i0 = i1, i1 = dx;
2322 dx = x0, x0 = x1, x1 = dx;
2323 }
2324 if (nice = nice(x1 - x0)) {
2325 domain[i0] = nice.floor(x0);
2326 domain[i1] = nice.ceil(x1);
2327 }
2328 return domain;
2329 }
2330 function d3_scale_niceDefault() {
2331 return Math;
2332 }
2333 d3.scale.linear = function() {
2334 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3.interpolate, false);
2335 };
2336 function d3_scale_linear(domain, range, interpolate, clamp) {
2337 var output, input;
2338 function rescale() {
2339 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
2340 output = linear(domain, range, uninterpolate, interpolate);
2341 input = linear(range, domain, uninterpolate, d3.interpolate);
2342 return scale;
2343 }
2344 function scale(x) {
2345 return output(x);
2346 }
2347 scale.invert = function(y) {
2348 return input(y);
2349 };
2350 scale.domain = function(x) {
2351 if (!arguments.length) return domain;
2352 domain = x.map(Number);
2353 return rescale();
2354 };
2355 scale.range = function(x) {
2356 if (!arguments.length) return range;
2357 range = x;
2358 return rescale();
2359 };
2360 scale.rangeRound = function(x) {
2361 return scale.range(x).interpolate(d3.interpolateRound);
2362 };
2363 scale.clamp = function(x) {
2364 if (!arguments.length) return clamp;
2365 clamp = x;
2366 return rescale();
2367 };
2368 scale.interpolate = function(x) {
2369 if (!arguments.length) return interpolate;
2370 interpolate = x;
2371 return rescale();
2372 };
2373 scale.ticks = function(m) {
2374 return d3_scale_linearTicks(domain, m);
2375 };
2376 scale.tickFormat = function(m) {
2377 return d3_scale_linearTickFormat(domain, m);
2378 };
2379 scale.nice = function() {
2380 d3_scale_nice(domain, d3_scale_linearNice);
2381 return rescale();
2382 };
2383 scale.copy = function() {
2384 return d3_scale_linear(domain, range, interpolate, clamp);
2385 };
2386 return rescale();
2387 }
2388 function d3_scale_linearRebind(scale, linear) {
2389 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
2390 }
2391 function d3_scale_linearNice(dx) {
2392 dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
2393 return dx && {
2394 floor: function(x) {
2395 return Math.floor(x / dx) * dx;
2396 },
2397 ceil: function(x) {
2398 return Math.ceil(x / dx) * dx;
2399 }
2400 };
2401 }
2402 function d3_scale_linearTickRange(domain, m) {
2403 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;
2404 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
2405 extent[0] = Math.ceil(extent[0] / step) * step;
2406 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
2407 extent[2] = step;
2408 return extent;
2409 }
2410 function d3_scale_linearTicks(domain, m) {
2411 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
2412 }
2413 function d3_scale_linearTickFormat(domain, m) {
2414 return d3.format(",." + Math.max(0, -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01)) + "f");
2415 }
2416 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
2417 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
2418 return function(x) {
2419 return i(u(x));
2420 };
2421 }
2422 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
2423 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
2424 if (domain[k] < domain[0]) {
2425 domain = domain.slice().reverse();
2426 range = range.slice().reverse();
2427 }
2428 while (++j <= k) {
2429 u.push(uninterpolate(domain[j - 1], domain[j]));
2430 i.push(interpolate(range[j - 1], range[j]));
2431 }
2432 return function(x) {
2433 var j = d3.bisect(domain, x, 1, k) - 1;
2434 return i[j](u[j](x));
2435 };
2436 }
2437 d3.scale.log = function() {
2438 return d3_scale_log(d3.scale.linear(), d3_scale_logp);
2439 };
2440 function d3_scale_log(linear, log) {
2441 var pow = log.pow;
2442 function scale(x) {
2443 return linear(log(x));
2444 }
2445 scale.invert = function(x) {
2446 return pow(linear.invert(x));
2447 };
2448 scale.domain = function(x) {
2449 if (!arguments.length) return linear.domain().map(pow);
2450 log = x[0] < 0 ? d3_scale_logn : d3_scale_logp;
2451 pow = log.pow;
2452 linear.domain(x.map(log));
2453 return scale;
2454 };
2455 scale.nice = function() {
2456 linear.domain(d3_scale_nice(linear.domain(), d3_scale_niceDefault));
2457 return scale;
2458 };
2459 scale.ticks = function() {
2460 var extent = d3_scaleExtent(linear.domain()), ticks = [];
2461 if (extent.every(isFinite)) {
2462 var i = Math.floor(extent[0]), j = Math.ceil(extent[1]), u = pow(extent[0]), v = pow(extent[1]);
2463 if (log === d3_scale_logn) {
2464 ticks.push(pow(i));
2465 for (;i++ < j; ) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
2466 } else {
2467 for (;i < j; i++) for (var k = 1; k < 10; k++) ticks.push(pow(i) * k);
2468 ticks.push(pow(i));
2469 }
2470 for (i = 0; ticks[i] < u; i++) {}
2471 for (j = ticks.length; ticks[j - 1] > v; j--) {}
2472 ticks = ticks.slice(i, j);
2473 }
2474 return ticks;
2475 };
2476 scale.tickFormat = function(n, format) {
2477 if (arguments.length < 2) format = d3_scale_logFormat;
2478 if (!arguments.length) return format;
2479 var k = Math.max(.1, n / scale.ticks().length), f = log === d3_scale_logn ? (e = -1e-12,
2480 Math.floor) : (e = 1e-12, Math.ceil), e;
2481 return function(d) {
2482 return d / pow(f(log(d) + e)) <= k ? format(d) : "";
2483 };
2484 };
2485 scale.copy = function() {
2486 return d3_scale_log(linear.copy(), log);
2487 };
2488 return d3_scale_linearRebind(scale, linear);
2489 }
2490 var d3_scale_logFormat = d3.format(".0e");
2491 function d3_scale_logp(x) {
2492 return Math.log(x < 0 ? 0 : x) / Math.LN10;
2493 }
2494 function d3_scale_logn(x) {
2495 return -Math.log(x > 0 ? 0 : -x) / Math.LN10;
2496 }
2497 d3_scale_logp.pow = function(x) {
2498 return Math.pow(10, x);
2499 };
2500 d3_scale_logn.pow = function(x) {
2501 return -Math.pow(10, -x);
2502 };
2503 d3.scale.pow = function() {
2504 return d3_scale_pow(d3.scale.linear(), 1);
2505 };
2506 function d3_scale_pow(linear, exponent) {
2507 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
2508 function scale(x) {
2509 return linear(powp(x));
2510 }
2511 scale.invert = function(x) {
2512 return powb(linear.invert(x));
2513 };
2514 scale.domain = function(x) {
2515 if (!arguments.length) return linear.domain().map(powb);
2516 linear.domain(x.map(powp));
2517 return scale;
2518 };
2519 scale.ticks = function(m) {
2520 return d3_scale_linearTicks(scale.domain(), m);
2521 };
2522 scale.tickFormat = function(m) {
2523 return d3_scale_linearTickFormat(scale.domain(), m);
2524 };
2525 scale.nice = function() {
2526 return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice));
2527 };
2528 scale.exponent = function(x) {
2529 if (!arguments.length) return exponent;
2530 var domain = scale.domain();
2531 powp = d3_scale_powPow(exponent = x);
2532 powb = d3_scale_powPow(1 / exponent);
2533 return scale.domain(domain);
2534 };
2535 scale.copy = function() {
2536 return d3_scale_pow(linear.copy(), exponent);
2537 };
2538 return d3_scale_linearRebind(scale, linear);
2539 }
2540 function d3_scale_powPow(e) {
2541 return function(x) {
2542 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
2543 };
2544 }
2545 d3.scale.sqrt = function() {
2546 return d3.scale.pow().exponent(.5);
2547 };
2548 d3.scale.ordinal = function() {
2549 return d3_scale_ordinal([], {
2550 t: "range",
2551 a: [ [] ]
2552 });
2553 };
2554 function d3_scale_ordinal(domain, ranger) {
2555 var index, range, rangeBand;
2556 function scale(x) {
2557 return range[((index.get(x) || index.set(x, domain.push(x))) - 1) % range.length];
2558 }
2559 function steps(start, step) {
2560 return d3.range(domain.length).map(function(i) {
2561 return start + step * i;
2562 });
2563 }
2564 scale.domain = function(x) {
2565 if (!arguments.length) return domain;
2566 domain = [];
2567 index = new d3_Map();
2568 var i = -1, n = x.length, xi;
2569 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
2570 return scale[ranger.t].apply(scale, ranger.a);
2571 };
2572 scale.range = function(x) {
2573 if (!arguments.length) return range;
2574 range = x;
2575 rangeBand = 0;
2576 ranger = {
2577 t: "range",
2578 a: arguments
2579 };
2580 return scale;
2581 };
2582 scale.rangePoints = function(x, padding) {
2583 if (arguments.length < 2) padding = 0;
2584 var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
2585 range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
2586 rangeBand = 0;
2587 ranger = {
2588 t: "rangePoints",
2589 a: arguments
2590 };
2591 return scale;
2592 };
2593 scale.rangeBands = function(x, padding, outerPadding) {
2594 if (arguments.length < 2) padding = 0;
2595 if (arguments.length < 3) outerPadding = padding;
2596 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
2597 range = steps(start + step * outerPadding, step);
2598 if (reverse) range.reverse();
2599 rangeBand = step * (1 - padding);
2600 ranger = {
2601 t: "rangeBands",
2602 a: arguments
2603 };
2604 return scale;
2605 };
2606 scale.rangeRoundBands = function(x, padding, outerPadding) {
2607 if (arguments.length < 2) padding = 0;
2608 if (arguments.length < 3) outerPadding = padding;
2609 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;
2610 range = steps(start + Math.round(error / 2), step);
2611 if (reverse) range.reverse();
2612 rangeBand = Math.round(step * (1 - padding));
2613 ranger = {
2614 t: "rangeRoundBands",
2615 a: arguments
2616 };
2617 return scale;
2618 };
2619 scale.rangeBand = function() {
2620 return rangeBand;
2621 };
2622 scale.rangeExtent = function() {
2623 return d3_scaleExtent(ranger.a[0]);
2624 };
2625 scale.copy = function() {
2626 return d3_scale_ordinal(domain, ranger);
2627 };
2628 return scale.domain(domain);
2629 }
2630 d3.scale.category10 = function() {
2631 return d3.scale.ordinal().range(d3_category10);
2632 };
2633 d3.scale.category20 = function() {
2634 return d3.scale.ordinal().range(d3_category20);
2635 };
2636 d3.scale.category20b = function() {
2637 return d3.scale.ordinal().range(d3_category20b);
2638 };
2639 d3.scale.category20c = function() {
2640 return d3.scale.ordinal().range(d3_category20c);
2641 };
2642 var d3_category10 = [ "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf" ];
2643 var d3_category20 = [ "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5" ];
2644 var d3_category20b = [ "#393b79", "#5254a3", "#6b6ecf", "#9c9ede", "#637939", "#8ca252", "#b5cf6b", "#cedb9c", "#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94", "#843c39", "#ad494a", "#d6616b", "#e7969c", "#7b4173", "#a55194", "#ce6dbd", "#de9ed6" ];
2645 var d3_category20c = [ "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" ];
2646 d3.scale.quantile = function() {
2647 return d3_scale_quantile([], []);
2648 };
2649 function d3_scale_quantile(domain, range) {
2650 var thresholds;
2651 function rescale() {
2652 var k = 0, q = range.length;
2653 thresholds = [];
2654 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
2655 return scale;
2656 }
2657 function scale(x) {
2658 if (isNaN(x = +x)) return NaN;
2659 return range[d3.bisect(thresholds, x)];
2660 }
2661 scale.domain = function(x) {
2662 if (!arguments.length) return domain;
2663 domain = x.filter(function(d) {
2664 return !isNaN(d);
2665 }).sort(d3.ascending);
2666 return rescale();
2667 };
2668 scale.range = function(x) {
2669 if (!arguments.length) return range;
2670 range = x;
2671 return rescale();
2672 };
2673 scale.quantiles = function() {
2674 return thresholds;
2675 };
2676 scale.copy = function() {
2677 return d3_scale_quantile(domain, range);
2678 };
2679 return rescale();
2680 }
2681 d3.scale.quantize = function() {
2682 return d3_scale_quantize(0, 1, [ 0, 1 ]);
2683 };
2684 function d3_scale_quantize(x0, x1, range) {
2685 var kx, i;
2686 function scale(x) {
2687 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
2688 }
2689 function rescale() {
2690 kx = range.length / (x1 - x0);
2691 i = range.length - 1;
2692 return scale;
2693 }
2694 scale.domain = function(x) {
2695 if (!arguments.length) return [ x0, x1 ];
2696 x0 = +x[0];
2697 x1 = +x[x.length - 1];
2698 return rescale();
2699 };
2700 scale.range = function(x) {
2701 if (!arguments.length) return range;
2702 range = x;
2703 return rescale();
2704 };
2705 scale.copy = function() {
2706 return d3_scale_quantize(x0, x1, range);
2707 };
2708 return rescale();
2709 }
2710 d3.scale.threshold = function() {
2711 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
2712 };
2713 function d3_scale_threshold(domain, range) {
2714 function scale(x) {
2715 return range[d3.bisect(domain, x)];
2716 }
2717 scale.domain = function(_) {
2718 if (!arguments.length) return domain;
2719 domain = _;
2720 return scale;
2721 };
2722 scale.range = function(_) {
2723 if (!arguments.length) return range;
2724 range = _;
2725 return scale;
2726 };
2727 scale.copy = function() {
2728 return d3_scale_threshold(domain, range);
2729 };
2730 return scale;
2731 }
2732 d3.scale.identity = function() {
2733 return d3_scale_identity([ 0, 1 ]);
2734 };
2735 function d3_scale_identity(domain) {
2736 function identity(x) {
2737 return +x;
2738 }
2739 identity.invert = identity;
2740 identity.domain = identity.range = function(x) {
2741 if (!arguments.length) return domain;
2742 domain = x.map(identity);
2743 return identity;
2744 };
2745 identity.ticks = function(m) {
2746 return d3_scale_linearTicks(domain, m);
2747 };
2748 identity.tickFormat = function(m) {
2749 return d3_scale_linearTickFormat(domain, m);
2750 };
2751 identity.copy = function() {
2752 return d3_scale_identity(domain);
2753 };
2754 return identity;
2755 }
2756 d3.svg = {};
2757 d3.svg.arc = function() {
2758 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
2759 function arc() {
2760 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,
2761 a0 = a1, a1 = da), a1 - a0), df = da < π ? "0" : "1", c0 = Math.cos(a0), s0 = Math.sin(a0), c1 = Math.cos(a1), s1 = Math.sin(a1);
2762 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";
2763 }
2764 arc.innerRadius = function(v) {
2765 if (!arguments.length) return innerRadius;
2766 innerRadius = d3_functor(v);
2767 return arc;
2768 };
2769 arc.outerRadius = function(v) {
2770 if (!arguments.length) return outerRadius;
2771 outerRadius = d3_functor(v);
2772 return arc;
2773 };
2774 arc.startAngle = function(v) {
2775 if (!arguments.length) return startAngle;
2776 startAngle = d3_functor(v);
2777 return arc;
2778 };
2779 arc.endAngle = function(v) {
2780 if (!arguments.length) return endAngle;
2781 endAngle = d3_functor(v);
2782 return arc;
2783 };
2784 arc.centroid = function() {
2785 var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
2786 return [ Math.cos(a) * r, Math.sin(a) * r ];
2787 };
2788 return arc;
2789 };
2790 var d3_svg_arcOffset = / 2, d3_svg_arcMax = 2 * π - 1e-6;
2791 function d3_svg_arcInnerRadius(d) {
2792 return d.innerRadius;
2793 }
2794 function d3_svg_arcOuterRadius(d) {
2795 return d.outerRadius;
2796 }
2797 function d3_svg_arcStartAngle(d) {
2798 return d.startAngle;
2799 }
2800 function d3_svg_arcEndAngle(d) {
2801 return d.endAngle;
2802 }
2803 function d3_svg_line(projection) {
2804 var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
2805 function line(data) {
2806 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
2807 function segment() {
2808 segments.push("M", interpolate(projection(points), tension));
2809 }
2810 while (++i < n) {
2811 if (defined.call(this, d = data[i], i)) {
2812 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
2813 } else if (points.length) {
2814 segment();
2815 points = [];
2816 }
2817 }
2818 if (points.length) segment();
2819 return segments.length ? segments.join("") : null;
2820 }
2821 line.x = function(_) {
2822 if (!arguments.length) return x;
2823 x = _;
2824 return line;
2825 };
2826 line.y = function(_) {
2827 if (!arguments.length) return y;
2828 y = _;
2829 return line;
2830 };
2831 line.defined = function(_) {
2832 if (!arguments.length) return defined;
2833 defined = _;
2834 return line;
2835 };
2836 line.interpolate = function(_) {
2837 if (!arguments.length) return interpolateKey;
2838 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
2839 return line;
2840 };
2841 line.tension = function(_) {
2842 if (!arguments.length) return tension;
2843 tension = _;
2844 return line;
2845 };
2846 return line;
2847 }
2848 d3.svg.line = function() {
2849 return d3_svg_line(d3_identity);
2850 };
2851 function d3_svg_lineX(d) {
2852 return d[0];
2853 }
2854 function d3_svg_lineY(d) {
2855 return d[1];
2856 }
2857 var d3_svg_lineInterpolators = d3.map({
2858 linear: d3_svg_lineLinear,
2859 "linear-closed": d3_svg_lineLinearClosed,
2860 "step-before": d3_svg_lineStepBefore,
2861 "step-after": d3_svg_lineStepAfter,
2862 basis: d3_svg_lineBasis,
2863 "basis-open": d3_svg_lineBasisOpen,
2864 "basis-closed": d3_svg_lineBasisClosed,
2865 bundle: d3_svg_lineBundle,
2866 cardinal: d3_svg_lineCardinal,
2867 "cardinal-open": d3_svg_lineCardinalOpen,
2868 "cardinal-closed": d3_svg_lineCardinalClosed,
2869 monotone: d3_svg_lineMonotone
2870 });
2871 d3_svg_lineInterpolators.forEach(function(key, value) {
2872 value.key = key;
2873 value.closed = /-closed$/.test(key);
2874 });
2875 function d3_svg_lineLinear(points) {
2876 return points.join("L");
2877 }
2878 function d3_svg_lineLinearClosed(points) {
2879 return d3_svg_lineLinear(points) + "Z";
2880 }
2881 function d3_svg_lineStepBefore(points) {
2882 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
2883 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
2884 return path.join("");
2885 }
2886 function d3_svg_lineStepAfter(points) {
2887 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
2888 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
2889 return path.join("");
2890 }
2891 function d3_svg_lineCardinalOpen(points, tension) {
2892 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
2893 }
2894 function d3_svg_lineCardinalClosed(points, tension) {
2895 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
2896 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
2897 }
2898 function d3_svg_lineCardinal(points, tension) {
2899 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
2900 }
2901 function d3_svg_lineHermite(points, tangents) {
2902 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
2903 return d3_svg_lineLinear(points);
2904 }
2905 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
2906 if (quad) {
2907 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
2908 p0 = points[1];
2909 pi = 2;
2910 }
2911 if (tangents.length > 1) {
2912 t = tangents[1];
2913 p = points[pi];
2914 pi++;
2915 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
2916 for (var i = 2; i < tangents.length; i++, pi++) {
2917 p = points[pi];
2918 t = tangents[i];
2919 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
2920 }
2921 }
2922 if (quad) {
2923 var lp = points[pi];
2924 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
2925 }
2926 return path;
2927 }
2928 function d3_svg_lineCardinalTangents(points, tension) {
2929 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
2930 while (++i < n) {
2931 p0 = p1;
2932 p1 = p2;
2933 p2 = points[i];
2934 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
2935 }
2936 return tangents;
2937 }
2938 function d3_svg_lineBasis(points) {
2939 if (points.length < 3) return d3_svg_lineLinear(points);
2940 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 ];
2941 d3_svg_lineBasisBezier(path, px, py);
2942 while (++i < n) {
2943 pi = points[i];
2944 px.shift();
2945 px.push(pi[0]);
2946 py.shift();
2947 py.push(pi[1]);
2948 d3_svg_lineBasisBezier(path, px, py);
2949 }
2950 i = -1;
2951 while (++i < 2) {
2952 px.shift();
2953 px.push(pi[0]);
2954 py.shift();
2955 py.push(pi[1]);
2956 d3_svg_lineBasisBezier(path, px, py);
2957 }
2958 return path.join("");
2959 }
2960 function d3_svg_lineBasisOpen(points) {
2961 if (points.length < 4) return d3_svg_lineLinear(points);
2962 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
2963 while (++i < 3) {
2964 pi = points[i];
2965 px.push(pi[0]);
2966 py.push(pi[1]);
2967 }
2968 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
2969 --i;
2970 while (++i < n) {
2971 pi = points[i];
2972 px.shift();
2973 px.push(pi[0]);
2974 py.shift();
2975 py.push(pi[1]);
2976 d3_svg_lineBasisBezier(path, px, py);
2977 }
2978 return path.join("");
2979 }
2980 function d3_svg_lineBasisClosed(points) {
2981 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
2982 while (++i < 4) {
2983 pi = points[i % n];
2984 px.push(pi[0]);
2985 py.push(pi[1]);
2986 }
2987 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
2988 --i;
2989 while (++i < m) {
2990 pi = points[i % n];
2991 px.shift();
2992 px.push(pi[0]);
2993 py.shift();
2994 py.push(pi[1]);
2995 d3_svg_lineBasisBezier(path, px, py);
2996 }
2997 return path.join("");
2998 }
2999 function d3_svg_lineBundle(points, tension) {
3000 var n = points.length - 1;
3001 if (n) {
3002 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
3003 while (++i <= n) {
3004 p = points[i];
3005 t = i / n;
3006 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
3007 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
3008 }
3009 }
3010 return d3_svg_lineBasis(points);
3011 }
3012 function d3_svg_lineDot4(a, b) {
3013 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
3014 }
3015 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 ];
3016 function d3_svg_lineBasisBezier(path, x, y) {
3017 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));
3018 }
3019 function d3_svg_lineSlope(p0, p1) {
3020 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
3021 }
3022 function d3_svg_lineFiniteDifferences(points) {
3023 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
3024 while (++i < j) {
3025 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
3026 }
3027 m[i] = d;
3028 return m;
3029 }
3030 function d3_svg_lineMonotoneTangents(points) {
3031 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
3032 while (++i < j) {
3033 d = d3_svg_lineSlope(points[i], points[i + 1]);
3034 if (Math.abs(d) < 1e-6) {
3035 m[i] = m[i + 1] = 0;
3036 } else {
3037 a = m[i] / d;
3038 b = m[i + 1] / d;
3039 s = a * a + b * b;
3040 if (s > 9) {
3041 s = d * 3 / Math.sqrt(s);
3042 m[i] = s * a;
3043 m[i + 1] = s * b;
3044 }
3045 }
3046 }
3047 i = -1;
3048 while (++i <= j) {
3049 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
3050 tangents.push([ s || 0, m[i] * s || 0 ]);
3051 }
3052 return tangents;
3053 }
3054 function d3_svg_lineMonotone(points) {
3055 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
3056 }
3057 d3.svg.line.radial = function() {
3058 var line = d3_svg_line(d3_svg_lineRadial);
3059 line.radius = line.x, delete line.x;
3060 line.angle = line.y, delete line.y;
3061 return line;
3062 };
3063 function d3_svg_lineRadial(points) {
3064 var point, i = -1, n = points.length, r, a;
3065 while (++i < n) {
3066 point = points[i];
3067 r = point[0];
3068 a = point[1] + d3_svg_arcOffset;
3069 point[0] = r * Math.cos(a);
3070 point[1] = r * Math.sin(a);
3071 }
3072 return points;
3073 }
3074 function d3_svg_area(projection) {
3075 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;
3076 function area(data) {
3077 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
3078 return x;
3079 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
3080 return y;
3081 } : d3_functor(y1), x, y;
3082 function segment() {
3083 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
3084 }
3085 while (++i < n) {
3086 if (defined.call(this, d = data[i], i)) {
3087 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
3088 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
3089 } else if (points0.length) {
3090 segment();
3091 points0 = [];
3092 points1 = [];
3093 }
3094 }
3095 if (points0.length) segment();
3096 return segments.length ? segments.join("") : null;
3097 }
3098 area.x = function(_) {
3099 if (!arguments.length) return x1;
3100 x0 = x1 = _;
3101 return area;
3102 };
3103 area.x0 = function(_) {
3104 if (!arguments.length) return x0;
3105 x0 = _;
3106 return area;
3107 };
3108 area.x1 = function(_) {
3109 if (!arguments.length) return x1;
3110 x1 = _;
3111 return area;
3112 };
3113 area.y = function(_) {
3114 if (!arguments.length) return y1;
3115 y0 = y1 = _;
3116 return area;
3117 };
3118 area.y0 = function(_) {
3119 if (!arguments.length) return y0;
3120 y0 = _;
3121 return area;
3122 };
3123 area.y1 = function(_) {
3124 if (!arguments.length) return y1;
3125 y1 = _;
3126 return area;
3127 };
3128 area.defined = function(_) {
3129 if (!arguments.length) return defined;
3130 defined = _;
3131 return area;
3132 };
3133 area.interpolate = function(_) {
3134 if (!arguments.length) return interpolateKey;
3135 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
3136 interpolateReverse = interpolate.reverse || interpolate;
3137 L = interpolate.closed ? "M" : "L";
3138 return area;
3139 };
3140 area.tension = function(_) {
3141 if (!arguments.length) return tension;
3142 tension = _;
3143 return area;
3144 };
3145 return area;
3146 }
3147 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
3148 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
3149 d3.svg.area = function() {
3150 return d3_svg_area(d3_identity);
3151 };
3152 d3.svg.area.radial = function() {
3153 var area = d3_svg_area(d3_svg_lineRadial);
3154 area.radius = area.x, delete area.x;
3155 area.innerRadius = area.x0, delete area.x0;
3156 area.outerRadius = area.x1, delete area.x1;
3157 area.angle = area.y, delete area.y;
3158 area.startAngle = area.y0, delete area.y0;
3159 area.endAngle = area.y1, delete area.y1;
3160 return area;
3161 };
3162 d3.svg.chord = function() {
3163 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
3164 function chord(d, i) {
3165 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
3166 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";
3167 }
3168 function subgroup(self, f, d, i) {
3169 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;
3170 return {
3171 r: r,
3172 a0: a0,
3173 a1: a1,
3174 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
3175 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
3176 };
3177 }
3178 function equals(a, b) {
3179 return a.a0 == b.a0 && a.a1 == b.a1;
3180 }
3181 function arc(r, p, a) {
3182 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
3183 }
3184 function curve(r0, p0, r1, p1) {
3185 return "Q 0,0 " + p1;
3186 }
3187 chord.radius = function(v) {
3188 if (!arguments.length) return radius;
3189 radius = d3_functor(v);
3190 return chord;
3191 };
3192 chord.source = function(v) {
3193 if (!arguments.length) return source;
3194 source = d3_functor(v);
3195 return chord;
3196 };
3197 chord.target = function(v) {
3198 if (!arguments.length) return target;
3199 target = d3_functor(v);
3200 return chord;
3201 };
3202 chord.startAngle = function(v) {
3203 if (!arguments.length) return startAngle;
3204 startAngle = d3_functor(v);
3205 return chord;
3206 };
3207 chord.endAngle = function(v) {
3208 if (!arguments.length) return endAngle;
3209 endAngle = d3_functor(v);
3210 return chord;
3211 };
3212 return chord;
3213 };
3214 function d3_svg_chordRadius(d) {
3215 return d.radius;
3216 }
3217 d3.svg.diagonal = function() {
3218 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
3219 function diagonal(d, i) {
3220 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
3221 x: p0.x,
3222 y: m
3223 }, {
3224 x: p3.x,
3225 y: m
3226 }, p3 ];
3227 p = p.map(projection);
3228 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
3229 }
3230 diagonal.source = function(x) {
3231 if (!arguments.length) return source;
3232 source = d3_functor(x);
3233 return diagonal;
3234 };
3235 diagonal.target = function(x) {
3236 if (!arguments.length) return target;
3237 target = d3_functor(x);
3238 return diagonal;
3239 };
3240 diagonal.projection = function(x) {
3241 if (!arguments.length) return projection;
3242 projection = x;
3243 return diagonal;
3244 };
3245 return diagonal;
3246 };
3247 function d3_svg_diagonalProjection(d) {
3248 return [ d.x, d.y ];
3249 }
3250 d3.svg.diagonal.radial = function() {
3251 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
3252 diagonal.projection = function(x) {
3253 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
3254 };
3255 return diagonal;
3256 };
3257 function d3_svg_diagonalRadialProjection(projection) {
3258 return function() {
3259 var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
3260 return [ r * Math.cos(a), r * Math.sin(a) ];
3261 };
3262 }
3263 d3.svg.symbol = function() {
3264 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
3265 function symbol(d, i) {
3266 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
3267 }
3268 symbol.type = function(x) {
3269 if (!arguments.length) return type;
3270 type = d3_functor(x);
3271 return symbol;
3272 };
3273 symbol.size = function(x) {
3274 if (!arguments.length) return size;
3275 size = d3_functor(x);
3276 return symbol;
3277 };
3278 return symbol;
3279 };
3280 function d3_svg_symbolSize() {
3281 return 64;
3282 }
3283 function d3_svg_symbolType() {
3284 return "circle";
3285 }
3286 function d3_svg_symbolCircle(size) {
3287 var r = Math.sqrt(size / π);
3288 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
3289 }
3290 var d3_svg_symbols = d3.map({
3291 circle: d3_svg_symbolCircle,
3292 cross: function(size) {
3293 var r = Math.sqrt(size / 5) / 2;
3294 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";
3295 },
3296 diamond: function(size) {
3297 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
3298 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
3299 },
3300 square: function(size) {
3301 var r = Math.sqrt(size) / 2;
3302 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
3303 },
3304 "triangle-down": function(size) {
3305 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
3306 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
3307 },
3308 "triangle-up": function(size) {
3309 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
3310 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
3311 }
3312 });
3313 d3.svg.symbolTypes = d3_svg_symbols.keys();
3314 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
3315 d3.svg.axis = function() {
3316 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, tickMajorSize = 6, tickMinorSize = 6, tickEndSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_, tickSubdivide = 0;
3317 function axis(g) {
3318 g.each(function() {
3319 var g = d3.select(this);
3320 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_;
3321 var subticks = d3_svg_axisSubdivide(scale, ticks, tickSubdivide), subtick = g.selectAll(".tick.minor").data(subticks, String), subtickEnter = subtick.enter().insert("line", ".tick").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);
3322 var tick = g.selectAll(".tick.major").data(ticks, String), tickEnter = tick.enter().insert("g", "path").attr("class", "tick major").style("opacity", 1e-6), tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
3323 var range = d3_scaleRange(scale), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
3324 d3.transition(path));
3325 var scale1 = scale.copy(), scale0 = this.__chart__ || scale1;
3326 this.__chart__ = scale1;
3327 tickEnter.append("line");
3328 tickEnter.append("text");
3329 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
3330 switch (orient) {
3331 case "bottom":
3332 {
3333 tickTransform = d3_svg_axisX;
3334 subtickEnter.attr("y2", tickMinorSize);
3335 subtickUpdate.attr("x2", 0).attr("y2", tickMinorSize);
3336 lineEnter.attr("y2", tickMajorSize);
3337 textEnter.attr("y", Math.max(tickMajorSize, 0) + tickPadding);
3338 lineUpdate.attr("x2", 0).attr("y2", tickMajorSize);
3339 textUpdate.attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding);
3340 text.attr("dy", ".71em").style("text-anchor", "middle");
3341 pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize);
3342 break;
3343 }
3344
3345 case "top":
3346 {
3347 tickTransform = d3_svg_axisX;
3348 subtickEnter.attr("y2", -tickMinorSize);
3349 subtickUpdate.attr("x2", 0).attr("y2", -tickMinorSize);
3350 lineEnter.attr("y2", -tickMajorSize);
3351 textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
3352 lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize);
3353 textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
3354 text.attr("dy", "0em").style("text-anchor", "middle");
3355 pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize);
3356 break;
3357 }
3358
3359 case "left":
3360 {
3361 tickTransform = d3_svg_axisY;
3362 subtickEnter.attr("x2", -tickMinorSize);
3363 subtickUpdate.attr("x2", -tickMinorSize).attr("y2", 0);
3364 lineEnter.attr("x2", -tickMajorSize);
3365 textEnter.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding));
3366 lineUpdate.attr("x2", -tickMajorSize).attr("y2", 0);
3367 textUpdate.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0);
3368 text.attr("dy", ".32em").style("text-anchor", "end");
3369 pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize);
3370 break;
3371 }
3372
3373 case "right":
3374 {
3375 tickTransform = d3_svg_axisY;
3376 subtickEnter.attr("x2", tickMinorSize);
3377 subtickUpdate.attr("x2", tickMinorSize).attr("y2", 0);
3378 lineEnter.attr("x2", tickMajorSize);
3379 textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding);
3380 lineUpdate.attr("x2", tickMajorSize).attr("y2", 0);
3381 textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0);
3382 text.attr("dy", ".32em").style("text-anchor", "start");
3383 pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize);
3384 break;
3385 }
3386 }
3387 if (scale.ticks) {
3388 tickEnter.call(tickTransform, scale0);
3389 tickUpdate.call(tickTransform, scale1);
3390 tickExit.call(tickTransform, scale1);
3391 subtickEnter.call(tickTransform, scale0);
3392 subtickUpdate.call(tickTransform, scale1);
3393 subtickExit.call(tickTransform, scale1);
3394 } else {
3395 var dx = scale1.rangeBand() / 2, x = function(d) {
3396 return scale1(d) + dx;
3397 };
3398 tickEnter.call(tickTransform, x);
3399 tickUpdate.call(tickTransform, x);
3400 }
3401 });
3402 }
3403 axis.scale = function(x) {
3404 if (!arguments.length) return scale;
3405 scale = x;
3406 return axis;
3407 };
3408 axis.orient = function(x) {
3409 if (!arguments.length) return orient;
3410 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
3411 return axis;
3412 };
3413 axis.ticks = function() {
3414 if (!arguments.length) return tickArguments_;
3415 tickArguments_ = arguments;
3416 return axis;
3417 };
3418 axis.tickValues = function(x) {
3419 if (!arguments.length) return tickValues;
3420 tickValues = x;
3421 return axis;
3422 };
3423 axis.tickFormat = function(x) {
3424 if (!arguments.length) return tickFormat_;
3425 tickFormat_ = x;
3426 return axis;
3427 };
3428 axis.tickSize = function(x, y) {
3429 if (!arguments.length) return tickMajorSize;
3430 var n = arguments.length - 1;
3431 tickMajorSize = +x;
3432 tickMinorSize = n > 1 ? +y : tickMajorSize;
3433 tickEndSize = n > 0 ? +arguments[n] : tickMajorSize;
3434 return axis;
3435 };
3436 axis.tickPadding = function(x) {
3437 if (!arguments.length) return tickPadding;
3438 tickPadding = +x;
3439 return axis;
3440 };
3441 axis.tickSubdivide = function(x) {
3442 if (!arguments.length) return tickSubdivide;
3443 tickSubdivide = +x;
3444 return axis;
3445 };
3446 return axis;
3447 };
3448 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
3449 top: 1,
3450 right: 1,
3451 bottom: 1,
3452 left: 1
3453 };
3454 function d3_svg_axisX(selection, x) {
3455 selection.attr("transform", function(d) {
3456 return "translate(" + x(d) + ",0)";
3457 });
3458 }
3459 function d3_svg_axisY(selection, y) {
3460 selection.attr("transform", function(d) {
3461 return "translate(0," + y(d) + ")";
3462 });
3463 }
3464 function d3_svg_axisSubdivide(scale, ticks, m) {
3465 subticks = [];
3466 if (m && ticks.length > 1) {
3467 var extent = d3_scaleExtent(scale.domain()), subticks, i = -1, n = ticks.length, d = (ticks[1] - ticks[0]) / ++m, j, v;
3468 while (++i < n) {
3469 for (j = m; --j > 0; ) {
3470 if ((v = +ticks[i] - j * d) >= extent[0]) {
3471 subticks.push(v);
3472 }
3473 }
3474 }
3475 for (--i, j = 0; ++j < m && (v = +ticks[i] + j * d) < extent[1]; ) {
3476 subticks.push(v);
3477 }
3478 }
3479 return subticks;
3480 }
3481 d3.svg.brush = function() {
3482 var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, resizes = d3_svg_brushResizes[0], extent = [ [ 0, 0 ], [ 0, 0 ] ], extentDomain;
3483 function brush(g) {
3484 g.each(function() {
3485 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;
3486 g.style("pointer-events", "all").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
3487 bg.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
3488 fg.enter().append("rect").attr("class", "extent").style("cursor", "move");
3489 tz.enter().append("g").attr("class", function(d) {
3490 return "resize " + d;
3491 }).style("cursor", function(d) {
3492 return d3_svg_brushCursor[d];
3493 }).append("rect").attr("x", function(d) {
3494 return /[ew]$/.test(d) ? -3 : null;
3495 }).attr("y", function(d) {
3496 return /^[ns]/.test(d) ? -3 : null;
3497 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
3498 tz.style("display", brush.empty() ? "none" : null);
3499 tz.exit().remove();
3500 if (x) {
3501 e = d3_scaleRange(x);
3502 bg.attr("x", e[0]).attr("width", e[1] - e[0]);
3503 redrawX(g);
3504 }
3505 if (y) {
3506 e = d3_scaleRange(y);
3507 bg.attr("y", e[0]).attr("height", e[1] - e[0]);
3508 redrawY(g);
3509 }
3510 redraw(g);
3511 });
3512 }
3513 function redraw(g) {
3514 g.selectAll(".resize").attr("transform", function(d) {
3515 return "translate(" + extent[+/e$/.test(d)][0] + "," + extent[+/^s/.test(d)][1] + ")";
3516 });
3517 }
3518 function redrawX(g) {
3519 g.select(".extent").attr("x", extent[0][0]);
3520 g.selectAll(".extent,.n>rect,.s>rect").attr("width", extent[1][0] - extent[0][0]);
3521 }
3522 function redrawY(g) {
3523 g.select(".extent").attr("y", extent[0][1]);
3524 g.selectAll(".extent,.e>rect,.w>rect").attr("height", extent[1][1] - extent[0][1]);
3525 }
3526 function brushstart() {
3527 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;
3528 var w = d3.select(d3_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);
3529 if (dragging) {
3530 origin[0] = extent[0][0] - origin[0];
3531 origin[1] = extent[0][1] - origin[1];
3532 } else if (resizing) {
3533 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
3534 offset = [ extent[1 - ex][0] - origin[0], extent[1 - ey][1] - origin[1] ];
3535 origin[0] = extent[ex][0];
3536 origin[1] = extent[ey][1];
3537 } else if (d3.event.altKey) center = origin.slice();
3538 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
3539 d3.select("body").style("cursor", eventTarget.style("cursor"));
3540 event_({
3541 type: "brushstart"
3542 });
3543 brushmove();
3544 d3_eventCancel();
3545 function mouse() {
3546 var touches = d3.event.changedTouches;
3547 return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
3548 }
3549 function keydown() {
3550 if (d3.event.keyCode == 32) {
3551 if (!dragging) {
3552 center = null;
3553 origin[0] -= extent[1][0];
3554 origin[1] -= extent[1][1];
3555 dragging = 2;
3556 }
3557 d3_eventCancel();
3558 }
3559 }
3560 function keyup() {
3561 if (d3.event.keyCode == 32 && dragging == 2) {
3562 origin[0] += extent[1][0];
3563 origin[1] += extent[1][1];
3564 dragging = 0;
3565 d3_eventCancel();
3566 }
3567 }
3568 function brushmove() {
3569 var point = mouse(), moved = false;
3570 if (offset) {
3571 point[0] += offset[0];
3572 point[1] += offset[1];
3573 }
3574 if (!dragging) {
3575 if (d3.event.altKey) {
3576 if (!center) center = [ (extent[0][0] + extent[1][0]) / 2, (extent[0][1] + extent[1][1]) / 2 ];
3577 origin[0] = extent[+(point[0] < center[0])][0];
3578 origin[1] = extent[+(point[1] < center[1])][1];
3579 } else center = null;
3580 }
3581 if (resizingX && move1(point, x, 0)) {
3582 redrawX(g);
3583 moved = true;
3584 }
3585 if (resizingY && move1(point, y, 1)) {
3586 redrawY(g);
3587 moved = true;
3588 }
3589 if (moved) {
3590 redraw(g);
3591 event_({
3592 type: "brush",
3593 mode: dragging ? "move" : "resize"
3594 });
3595 }
3596 }
3597 function move1(point, scale, i) {
3598 var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], size = extent[1][i] - extent[0][i], min, max;
3599 if (dragging) {
3600 r0 -= position;
3601 r1 -= size + position;
3602 }
3603 min = Math.max(r0, Math.min(r1, point[i]));
3604 if (dragging) {
3605 max = (min += position) + size;
3606 } else {
3607 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
3608 if (position < min) {
3609 max = min;
3610 min = position;
3611 } else {
3612 max = position;
3613 }
3614 }
3615 if (extent[0][i] !== min || extent[1][i] !== max) {
3616 extentDomain = null;
3617 extent[0][i] = min;
3618 extent[1][i] = max;
3619 return true;
3620 }
3621 }
3622 function brushend() {
3623 brushmove();
3624 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
3625 d3.select("body").style("cursor", null);
3626 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);
3627 event_({
3628 type: "brushend"
3629 });
3630 d3_eventCancel();
3631 }
3632 }
3633 brush.x = function(z) {
3634 if (!arguments.length) return x;
3635 x = z;
3636 resizes = d3_svg_brushResizes[!x << 1 | !y];
3637 return brush;
3638 };
3639 brush.y = function(z) {
3640 if (!arguments.length) return y;
3641 y = z;
3642 resizes = d3_svg_brushResizes[!x << 1 | !y];
3643 return brush;
3644 };
3645 brush.extent = function(z) {
3646 var x0, x1, y0, y1, t;
3647 if (!arguments.length) {
3648 z = extentDomain || extent;
3649 if (x) {
3650 x0 = z[0][0], x1 = z[1][0];
3651 if (!extentDomain) {
3652 x0 = extent[0][0], x1 = extent[1][0];
3653 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
3654 if (x1 < x0) t = x0, x0 = x1, x1 = t;
3655 }
3656 }
3657 if (y) {
3658 y0 = z[0][1], y1 = z[1][1];
3659 if (!extentDomain) {
3660 y0 = extent[0][1], y1 = extent[1][1];
3661 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
3662 if (y1 < y0) t = y0, y0 = y1, y1 = t;
3663 }
3664 }
3665 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
3666 }
3667 extentDomain = [ [ 0, 0 ], [ 0, 0 ] ];
3668 if (x) {
3669 x0 = z[0], x1 = z[1];
3670 if (y) x0 = x0[0], x1 = x1[0];
3671 extentDomain[0][0] = x0, extentDomain[1][0] = x1;
3672 if (x.invert) x0 = x(x0), x1 = x(x1);
3673 if (x1 < x0) t = x0, x0 = x1, x1 = t;
3674 extent[0][0] = x0 | 0, extent[1][0] = x1 | 0;
3675 }
3676 if (y) {
3677 y0 = z[0], y1 = z[1];
3678 if (x) y0 = y0[1], y1 = y1[1];
3679 extentDomain[0][1] = y0, extentDomain[1][1] = y1;
3680 if (y.invert) y0 = y(y0), y1 = y(y1);
3681 if (y1 < y0) t = y0, y0 = y1, y1 = t;
3682 extent[0][1] = y0 | 0, extent[1][1] = y1 | 0;
3683 }
3684 return brush;
3685 };
3686 brush.clear = function() {
3687 extentDomain = null;
3688 extent[0][0] = extent[0][1] = extent[1][0] = extent[1][1] = 0;
3689 return brush;
3690 };
3691 brush.empty = function() {
3692 return x && extent[0][0] === extent[1][0] || y && extent[0][1] === extent[1][1];
3693 };
3694 return d3.rebind(brush, event, "on");
3695 };
3696 var d3_svg_brushCursor = {
3697 n: "ns-resize",
3698 e: "ew-resize",
3699 s: "ns-resize",
3700 w: "ew-resize",
3701 nw: "nwse-resize",
3702 ne: "nesw-resize",
3703 se: "nwse-resize",
3704 sw: "nesw-resize"
3705 };
3706 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
3707 d3.behavior = {};
3708 d3.behavior.drag = function() {
3709 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null;
3710 function drag() {
3711 this.on("mousedown.drag", mousedown).on("touchstart.drag", mousedown);
3712 }
3713 function mousedown() {
3714 var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, touchId = d3.event.touches ? d3.event.changedTouches[0].identifier : null, offset, origin_ = point(), moved = 0;
3715 var w = d3.select(d3_window).on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
3716 if (origin) {
3717 offset = origin.apply(target, arguments);
3718 offset = [ offset.x - origin_[0], offset.y - origin_[1] ];
3719 } else {
3720 offset = [ 0, 0 ];
3721 }
3722 if (touchId == null) d3_eventCancel();
3723 event_({
3724 type: "dragstart"
3725 });
3726 function point() {
3727 var p = target.parentNode;
3728 return touchId != null ? d3.touches(p).filter(function(p) {
3729 return p.identifier === touchId;
3730 })[0] : d3.mouse(p);
3731 }
3732 function dragmove() {
3733 if (!target.parentNode) return dragend();
3734 var p = point(), dx = p[0] - origin_[0], dy = p[1] - origin_[1];
3735 moved |= dx | dy;
3736 origin_ = p;
3737 d3_eventCancel();
3738 event_({
3739 type: "drag",
3740 x: p[0] + offset[0],
3741 y: p[1] + offset[1],
3742 dx: dx,
3743 dy: dy
3744 });
3745 }
3746 function dragend() {
3747 event_({
3748 type: "dragend"
3749 });
3750 if (moved) {
3751 d3_eventCancel();
3752 if (d3.event.target === eventTarget) w.on("click.drag", click, true);
3753 }
3754 w.on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", null).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", null);
3755 }
3756 function click() {
3757 d3_eventCancel();
3758 w.on("click.drag", null);
3759 }
3760 }
3761 drag.origin = function(x) {
3762 if (!arguments.length) return origin;
3763 origin = x;
3764 return drag;
3765 };
3766 return d3.rebind(drag, event, "on");
3767 };
3768 d3.behavior.zoom = function() {
3769 var translate = [ 0, 0 ], translate0, scale = 1, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
3770 function zoom() {
3771 this.on("mousedown.zoom", mousedown).on("mousemove.zoom", mousemove).on(d3_behavior_zoomWheel + ".zoom", mousewheel).on("dblclick.zoom", dblclick).on("touchstart.zoom", touchstart).on("touchmove.zoom", touchmove).on("touchend.zoom", touchstart);
3772 }
3773 zoom.translate = function(x) {
3774 if (!arguments.length) return translate;
3775 translate = x.map(Number);
3776 rescale();
3777 return zoom;
3778 };
3779 zoom.scale = function(x) {
3780 if (!arguments.length) return scale;
3781 scale = +x;
3782 rescale();
3783 return zoom;
3784 };
3785 zoom.scaleExtent = function(x) {
3786 if (!arguments.length) return scaleExtent;
3787 scaleExtent = x == null ? d3_behavior_zoomInfinity : x.map(Number);
3788 return zoom;
3789 };
3790 zoom.x = function(z) {
3791 if (!arguments.length) return x1;
3792 x1 = z;
3793 x0 = z.copy();
3794 translate = [ 0, 0 ];
3795 scale = 1;
3796 return zoom;
3797 };
3798 zoom.y = function(z) {
3799 if (!arguments.length) return y1;
3800 y1 = z;
3801 y0 = z.copy();
3802 translate = [ 0, 0 ];
3803 scale = 1;
3804 return zoom;
3805 };
3806 function location(p) {
3807 return [ (p[0] - translate[0]) / scale, (p[1] - translate[1]) / scale ];
3808 }
3809 function point(l) {
3810 return [ l[0] * scale + translate[0], l[1] * scale + translate[1] ];
3811 }
3812 function scaleTo(s) {
3813 scale = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
3814 }
3815 function translateTo(p, l) {
3816 l = point(l);
3817 translate[0] += p[0] - l[0];
3818 translate[1] += p[1] - l[1];
3819 }
3820 function rescale() {
3821 if (x1) x1.domain(x0.range().map(function(x) {
3822 return (x - translate[0]) / scale;
3823 }).map(x0.invert));
3824 if (y1) y1.domain(y0.range().map(function(y) {
3825 return (y - translate[1]) / scale;
3826 }).map(y0.invert));
3827 }
3828 function dispatch(event) {
3829 rescale();
3830 d3.event.preventDefault();
3831 event({
3832 type: "zoom",
3833 scale: scale,
3834 translate: translate
3835 });
3836 }
3837 function mousedown() {
3838 var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target));
3839 d3_window.focus();
3840 d3_eventCancel();
3841 function mousemove() {
3842 moved = 1;
3843 translateTo(d3.mouse(target), l);
3844 dispatch(event_);
3845 }
3846 function mouseup() {
3847 if (moved) d3_eventCancel();
3848 w.on("mousemove.zoom", null).on("mouseup.zoom", null);
3849 if (moved && d3.event.target === eventTarget) w.on("click.zoom", click, true);
3850 }
3851 function click() {
3852 d3_eventCancel();
3853 w.on("click.zoom", null);
3854 }
3855 }
3856 function mousewheel() {
3857 if (!translate0) translate0 = location(d3.mouse(this));
3858 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * scale);
3859 translateTo(d3.mouse(this), translate0);
3860 dispatch(event.of(this, arguments));
3861 }
3862 function mousemove() {
3863 translate0 = null;
3864 }
3865 function dblclick() {
3866 var p = d3.mouse(this), l = location(p), k = Math.log(scale) / Math.LN2;
3867 scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
3868 translateTo(p, l);
3869 dispatch(event.of(this, arguments));
3870 }
3871 function touchstart() {
3872 var touches = d3.touches(this), now = Date.now();
3873 scale0 = scale;
3874 translate0 = {};
3875 touches.forEach(function(t) {
3876 translate0[t.identifier] = location(t);
3877 });
3878 d3_eventCancel();
3879 if (touches.length === 1) {
3880 if (now - touchtime < 500) {
3881 var p = touches[0], l = location(touches[0]);
3882 scaleTo(scale * 2);
3883 translateTo(p, l);
3884 dispatch(event.of(this, arguments));
3885 }
3886 touchtime = now;
3887 }
3888 }
3889 function touchmove() {
3890 var touches = d3.touches(this), p0 = touches[0], l0 = translate0[p0.identifier];
3891 if (p1 = touches[1]) {
3892 var p1, l1 = translate0[p1.identifier];
3893 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
3894 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
3895 scaleTo(d3.event.scale * scale0);
3896 }
3897 translateTo(p0, l0);
3898 touchtime = null;
3899 dispatch(event.of(this, arguments));
3900 }
3901 return d3.rebind(zoom, event, "on");
3902 };
3903 var d3_behavior_zoomInfinity = [ 0, Infinity ];
3904 var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in document ? (d3_behavior_zoomDelta = function() {
3905 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
3906 }, "wheel") : "onmousewheel" in document ? (d3_behavior_zoomDelta = function() {
3907 return d3.event.wheelDelta;
3908 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
3909 return -d3.event.detail;
3910 }, "MozMousePixelScroll");
3911 d3.layout = {};
3912 d3.layout.bundle = function() {
3913 return function(links) {
3914 var paths = [], i = -1, n = links.length;
3915 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
3916 return paths;
3917 };
3918 };
3919 function d3_layout_bundlePath(link) {
3920 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
3921 while (start !== lca) {
3922 start = start.parent;
3923 points.push(start);
3924 }
3925 var k = points.length;
3926 while (end !== lca) {
3927 points.splice(k, 0, end);
3928 end = end.parent;
3929 }
3930 return points;
3931 }
3932 function d3_layout_bundleAncestors(node) {
3933 var ancestors = [], parent = node.parent;
3934 while (parent != null) {
3935 ancestors.push(node);
3936 node = parent;
3937 parent = parent.parent;
3938 }
3939 ancestors.push(node);
3940 return ancestors;
3941 }
3942 function d3_layout_bundleLeastCommonAncestor(a, b) {
3943 if (a === b) return a;
3944 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
3945 while (aNode === bNode) {
3946 sharedNode = aNode;
3947 aNode = aNodes.pop();
3948 bNode = bNodes.pop();
3949 }
3950 return sharedNode;
3951 }
3952 d3.layout.chord = function() {
3953 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
3954 function relayout() {
3955 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
3956 chords = [];
3957 groups = [];
3958 k = 0, i = -1;
3959 while (++i < n) {
3960 x = 0, j = -1;
3961 while (++j < n) {
3962 x += matrix[i][j];
3963 }
3964 groupSums.push(x);
3965 subgroupIndex.push(d3.range(n));
3966 k += x;
3967 }
3968 if (sortGroups) {
3969 groupIndex.sort(function(a, b) {
3970 return sortGroups(groupSums[a], groupSums[b]);
3971 });
3972 }
3973 if (sortSubgroups) {
3974 subgroupIndex.forEach(function(d, i) {
3975 d.sort(function(a, b) {
3976 return sortSubgroups(matrix[i][a], matrix[i][b]);
3977 });
3978 });
3979 }
3980 k = (2 * π - padding * n) / k;
3981 x = 0, i = -1;
3982 while (++i < n) {
3983 x0 = x, j = -1;
3984 while (++j < n) {
3985 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
3986 subgroups[di + "-" + dj] = {
3987 index: di,
3988 subindex: dj,
3989 startAngle: a0,
3990 endAngle: a1,
3991 value: v
3992 };
3993 }
3994 groups[di] = {
3995 index: di,
3996 startAngle: x0,
3997 endAngle: x,
3998 value: (x - x0) / k
3999 };
4000 x += padding;
4001 }
4002 i = -1;
4003 while (++i < n) {
4004 j = i - 1;
4005 while (++j < n) {
4006 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
4007 if (source.value || target.value) {
4008 chords.push(source.value < target.value ? {
4009 source: target,
4010 target: source
4011 } : {
4012 source: source,
4013 target: target
4014 });
4015 }
4016 }
4017 }
4018 if (sortChords) resort();
4019 }
4020 function resort() {
4021 chords.sort(function(a, b) {
4022 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
4023 });
4024 }
4025 chord.matrix = function(x) {
4026 if (!arguments.length) return matrix;
4027 n = (matrix = x) && matrix.length;
4028 chords = groups = null;
4029 return chord;
4030 };
4031 chord.padding = function(x) {
4032 if (!arguments.length) return padding;
4033 padding = x;
4034 chords = groups = null;
4035 return chord;
4036 };
4037 chord.sortGroups = function(x) {
4038 if (!arguments.length) return sortGroups;
4039 sortGroups = x;
4040 chords = groups = null;
4041 return chord;
4042 };
4043 chord.sortSubgroups = function(x) {
4044 if (!arguments.length) return sortSubgroups;
4045 sortSubgroups = x;
4046 chords = null;
4047 return chord;
4048 };
4049 chord.sortChords = function(x) {
4050 if (!arguments.length) return sortChords;
4051 sortChords = x;
4052 if (chords) resort();
4053 return chord;
4054 };
4055 chord.chords = function() {
4056 if (!chords) relayout();
4057 return chords;
4058 };
4059 chord.groups = function() {
4060 if (!groups) relayout();
4061 return groups;
4062 };
4063 return chord;
4064 };
4065 d3.layout.force = function() {
4066 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, nodes = [], links = [], distances, strengths, charges;
4067 function repulse(node) {
4068 return function(quad, x1, _, x2) {
4069 if (quad.point !== node) {
4070 var dx = quad.cx - node.x, dy = quad.cy - node.y, dn = 1 / Math.sqrt(dx * dx + dy * dy);
4071 if ((x2 - x1) * dn < theta) {
4072 var k = quad.charge * dn * dn;
4073 node.px -= dx * k;
4074 node.py -= dy * k;
4075 return true;
4076 }
4077 if (quad.point && isFinite(dn)) {
4078 var k = quad.pointCharge * dn * dn;
4079 node.px -= dx * k;
4080 node.py -= dy * k;
4081 }
4082 }
4083 return !quad.charge;
4084 };
4085 }
4086 force.tick = function() {
4087 if ((alpha *= .99) < .005) {
4088 event.end({
4089 type: "end",
4090 alpha: alpha = 0
4091 });
4092 return true;
4093 }
4094 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
4095 for (i = 0; i < m; ++i) {
4096 o = links[i];
4097 s = o.source;
4098 t = o.target;
4099 x = t.x - s.x;
4100 y = t.y - s.y;
4101 if (l = x * x + y * y) {
4102 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
4103 x *= l;
4104 y *= l;
4105 t.x -= x * (k = s.weight / (t.weight + s.weight));
4106 t.y -= y * k;
4107 s.x += x * (k = 1 - k);
4108 s.y += y * k;
4109 }
4110 }
4111 if (k = alpha * gravity) {
4112 x = size[0] / 2;
4113 y = size[1] / 2;
4114 i = -1;
4115 if (k) while (++i < n) {
4116 o = nodes[i];
4117 o.x += (x - o.x) * k;
4118 o.y += (y - o.y) * k;
4119 }
4120 }
4121 if (charge) {
4122 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
4123 i = -1;
4124 while (++i < n) {
4125 if (!(o = nodes[i]).fixed) {
4126 q.visit(repulse(o));
4127 }
4128 }
4129 }
4130 i = -1;
4131 while (++i < n) {
4132 o = nodes[i];
4133 if (o.fixed) {
4134 o.x = o.px;
4135 o.y = o.py;
4136 } else {
4137 o.x -= (o.px - (o.px = o.x)) * friction;
4138 o.y -= (o.py - (o.py = o.y)) * friction;
4139 }
4140 }
4141 event.tick({
4142 type: "tick",
4143 alpha: alpha
4144 });
4145 };
4146 force.nodes = function(x) {
4147 if (!arguments.length) return nodes;
4148 nodes = x;
4149 return force;
4150 };
4151 force.links = function(x) {
4152 if (!arguments.length) return links;
4153 links = x;
4154 return force;
4155 };
4156 force.size = function(x) {
4157 if (!arguments.length) return size;
4158 size = x;
4159 return force;
4160 };
4161 force.linkDistance = function(x) {
4162 if (!arguments.length) return linkDistance;
4163 linkDistance = typeof x === "function" ? x : +x;
4164 return force;
4165 };
4166 force.distance = force.linkDistance;
4167 force.linkStrength = function(x) {
4168 if (!arguments.length) return linkStrength;
4169 linkStrength = typeof x === "function" ? x : +x;
4170 return force;
4171 };
4172 force.friction = function(x) {
4173 if (!arguments.length) return friction;
4174 friction = +x;
4175 return force;
4176 };
4177 force.charge = function(x) {
4178 if (!arguments.length) return charge;
4179 charge = typeof x === "function" ? x : +x;
4180 return force;
4181 };
4182 force.gravity = function(x) {
4183 if (!arguments.length) return gravity;
4184 gravity = +x;
4185 return force;
4186 };
4187 force.theta = function(x) {
4188 if (!arguments.length) return theta;
4189 theta = +x;
4190 return force;
4191 };
4192 force.alpha = function(x) {
4193 if (!arguments.length) return alpha;
4194 x = +x;
4195 if (alpha) {
4196 if (x > 0) alpha = x; else alpha = 0;
4197 } else if (x > 0) {
4198 event.start({
4199 type: "start",
4200 alpha: alpha = x
4201 });
4202 d3.timer(force.tick);
4203 }
4204 return force;
4205 };
4206 force.start = function() {
4207 var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
4208 for (i = 0; i < n; ++i) {
4209 (o = nodes[i]).index = i;
4210 o.weight = 0;
4211 }
4212 for (i = 0; i < m; ++i) {
4213 o = links[i];
4214 if (typeof o.source == "number") o.source = nodes[o.source];
4215 if (typeof o.target == "number") o.target = nodes[o.target];
4216 ++o.source.weight;
4217 ++o.target.weight;
4218 }
4219 for (i = 0; i < n; ++i) {
4220 o = nodes[i];
4221 if (isNaN(o.x)) o.x = position("x", w);
4222 if (isNaN(o.y)) o.y = position("y", h);
4223 if (isNaN(o.px)) o.px = o.x;
4224 if (isNaN(o.py)) o.py = o.y;
4225 }
4226 distances = [];
4227 if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;
4228 strengths = [];
4229 if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
4230 charges = [];
4231 if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
4232 function position(dimension, size) {
4233 var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
4234 while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
4235 return Math.random() * size;
4236 }
4237 function neighbor() {
4238 if (!neighbors) {
4239 neighbors = [];
4240 for (j = 0; j < n; ++j) {
4241 neighbors[j] = [];
4242 }
4243 for (j = 0; j < m; ++j) {
4244 var o = links[j];
4245 neighbors[o.source.index].push(o.target);
4246 neighbors[o.target.index].push(o.source);
4247 }
4248 }
4249 return neighbors[i];
4250 }
4251 return force.resume();
4252 };
4253 force.resume = function() {
4254 return force.alpha(.1);
4255 };
4256 force.stop = function() {
4257 return force.alpha(0);
4258 };
4259 force.drag = function() {
4260 if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend);
4261 if (!arguments.length) return drag;
4262 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
4263 };
4264 function dragmove(d) {
4265 d.px = d3.event.x, d.py = d3.event.y;
4266 force.resume();
4267 }
4268 return d3.rebind(force, event, "on");
4269 };
4270 function d3_layout_forceDragstart(d) {
4271 d.fixed |= 2;
4272 }
4273 function d3_layout_forceDragend(d) {
4274 d.fixed &= ~6;
4275 }
4276 function d3_layout_forceMouseover(d) {
4277 d.fixed |= 4;
4278 d.px = d.x, d.py = d.y;
4279 }
4280 function d3_layout_forceMouseout(d) {
4281 d.fixed &= ~4;
4282 }
4283 function d3_layout_forceAccumulate(quad, alpha, charges) {
4284 var cx = 0, cy = 0;
4285 quad.charge = 0;
4286 if (!quad.leaf) {
4287 var nodes = quad.nodes, n = nodes.length, i = -1, c;
4288 while (++i < n) {
4289 c = nodes[i];
4290 if (c == null) continue;
4291 d3_layout_forceAccumulate(c, alpha, charges);
4292 quad.charge += c.charge;
4293 cx += c.charge * c.cx;
4294 cy += c.charge * c.cy;
4295 }
4296 }
4297 if (quad.point) {
4298 if (!quad.leaf) {
4299 quad.point.x += Math.random() - .5;
4300 quad.point.y += Math.random() - .5;
4301 }
4302 var k = alpha * charges[quad.point.index];
4303 quad.charge += quad.pointCharge = k;
4304 cx += k * quad.point.x;
4305 cy += k * quad.point.y;
4306 }
4307 quad.cx = cx / quad.charge;
4308 quad.cy = cy / quad.charge;
4309 }
4310 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1;
4311 d3.layout.partition = function() {
4312 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
4313 function position(node, x, dx, dy) {
4314 var children = node.children;
4315 node.x = x;
4316 node.y = node.depth * dy;
4317 node.dx = dx;
4318 node.dy = dy;
4319 if (children && (n = children.length)) {
4320 var i = -1, n, c, d;
4321 dx = node.value ? dx / node.value : 0;
4322 while (++i < n) {
4323 position(c = children[i], x, d = c.value * dx, dy);
4324 x += d;
4325 }
4326 }
4327 }
4328 function depth(node) {
4329 var children = node.children, d = 0;
4330 if (children && (n = children.length)) {
4331 var i = -1, n;
4332 while (++i < n) d = Math.max(d, depth(children[i]));
4333 }
4334 return 1 + d;
4335 }
4336 function partition(d, i) {
4337 var nodes = hierarchy.call(this, d, i);
4338 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
4339 return nodes;
4340 }
4341 partition.size = function(x) {
4342 if (!arguments.length) return size;
4343 size = x;
4344 return partition;
4345 };
4346 return d3_layout_hierarchyRebind(partition, hierarchy);
4347 };
4348 d3.layout.pie = function() {
4349 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = 2 * π;
4350 function pie(data) {
4351 var values = data.map(function(d, i) {
4352 return +value.call(pie, d, i);
4353 });
4354 var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
4355 var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - startAngle) / d3.sum(values);
4356 var index = d3.range(data.length);
4357 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
4358 return values[j] - values[i];
4359 } : function(i, j) {
4360 return sort(data[i], data[j]);
4361 });
4362 var arcs = [];
4363 index.forEach(function(i) {
4364 var d;
4365 arcs[i] = {
4366 data: data[i],
4367 value: d = values[i],
4368 startAngle: a,
4369 endAngle: a += d * k
4370 };
4371 });
4372 return arcs;
4373 }
4374 pie.value = function(x) {
4375 if (!arguments.length) return value;
4376 value = x;
4377 return pie;
4378 };
4379 pie.sort = function(x) {
4380 if (!arguments.length) return sort;
4381 sort = x;
4382 return pie;
4383 };
4384 pie.startAngle = function(x) {
4385 if (!arguments.length) return startAngle;
4386 startAngle = x;
4387 return pie;
4388 };
4389 pie.endAngle = function(x) {
4390 if (!arguments.length) return endAngle;
4391 endAngle = x;
4392 return pie;
4393 };
4394 return pie;
4395 };
4396 var d3_layout_pieSortByValue = {};
4397 d3.layout.stack = function() {
4398 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
4399 function stack(data, index) {
4400 var series = data.map(function(d, i) {
4401 return values.call(stack, d, i);
4402 });
4403 var points = series.map(function(d) {
4404 return d.map(function(v, i) {
4405 return [ x.call(stack, v, i), y.call(stack, v, i) ];
4406 });
4407 });
4408 var orders = order.call(stack, points, index);
4409 series = d3.permute(series, orders);
4410 points = d3.permute(points, orders);
4411 var offsets = offset.call(stack, points, index);
4412 var n = series.length, m = series[0].length, i, j, o;
4413 for (j = 0; j < m; ++j) {
4414 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
4415 for (i = 1; i < n; ++i) {
4416 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
4417 }
4418 }
4419 return data;
4420 }
4421 stack.values = function(x) {
4422 if (!arguments.length) return values;
4423 values = x;
4424 return stack;
4425 };
4426 stack.order = function(x) {
4427 if (!arguments.length) return order;
4428 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
4429 return stack;
4430 };
4431 stack.offset = function(x) {
4432 if (!arguments.length) return offset;
4433 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
4434 return stack;
4435 };
4436 stack.x = function(z) {
4437 if (!arguments.length) return x;
4438 x = z;
4439 return stack;
4440 };
4441 stack.y = function(z) {
4442 if (!arguments.length) return y;
4443 y = z;
4444 return stack;
4445 };
4446 stack.out = function(z) {
4447 if (!arguments.length) return out;
4448 out = z;
4449 return stack;
4450 };
4451 return stack;
4452 };
4453 function d3_layout_stackX(d) {
4454 return d.x;
4455 }
4456 function d3_layout_stackY(d) {
4457 return d.y;
4458 }
4459 function d3_layout_stackOut(d, y0, y) {
4460 d.y0 = y0;
4461 d.y = y;
4462 }
4463 var d3_layout_stackOrders = d3.map({
4464 "inside-out": function(data) {
4465 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) {
4466 return max[a] - max[b];
4467 }), top = 0, bottom = 0, tops = [], bottoms = [];
4468 for (i = 0; i < n; ++i) {
4469 j = index[i];
4470 if (top < bottom) {
4471 top += sums[j];
4472 tops.push(j);
4473 } else {
4474 bottom += sums[j];
4475 bottoms.push(j);
4476 }
4477 }
4478 return bottoms.reverse().concat(tops);
4479 },
4480 reverse: function(data) {
4481 return d3.range(data.length).reverse();
4482 },
4483 "default": d3_layout_stackOrderDefault
4484 });
4485 var d3_layout_stackOffsets = d3.map({
4486 silhouette: function(data) {
4487 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
4488 for (j = 0; j < m; ++j) {
4489 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
4490 if (o > max) max = o;
4491 sums.push(o);
4492 }
4493 for (j = 0; j < m; ++j) {
4494 y0[j] = (max - sums[j]) / 2;
4495 }
4496 return y0;
4497 },
4498 wiggle: function(data) {
4499 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
4500 y0[0] = o = o0 = 0;
4501 for (j = 1; j < m; ++j) {
4502 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
4503 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
4504 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
4505 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
4506 }
4507 s2 += s3 * data[i][j][1];
4508 }
4509 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
4510 if (o < o0) o0 = o;
4511 }
4512 for (j = 0; j < m; ++j) y0[j] -= o0;
4513 return y0;
4514 },
4515 expand: function(data) {
4516 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
4517 for (j = 0; j < m; ++j) {
4518 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
4519 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;
4520 }
4521 for (j = 0; j < m; ++j) y0[j] = 0;
4522 return y0;
4523 },
4524 zero: d3_layout_stackOffsetZero
4525 });
4526 function d3_layout_stackOrderDefault(data) {
4527 return d3.range(data.length);
4528 }
4529 function d3_layout_stackOffsetZero(data) {
4530 var j = -1, m = data[0].length, y0 = [];
4531 while (++j < m) y0[j] = 0;
4532 return y0;
4533 }
4534 function d3_layout_stackMaxIndex(array) {
4535 var i = 1, j = 0, v = array[0][1], k, n = array.length;
4536 for (;i < n; ++i) {
4537 if ((k = array[i][1]) > v) {
4538 j = i;
4539 v = k;
4540 }
4541 }
4542 return j;
4543 }
4544 function d3_layout_stackReduceSum(d) {
4545 return d.reduce(d3_layout_stackSum, 0);
4546 }
4547 function d3_layout_stackSum(p, d) {
4548 return p + d[1];
4549 }
4550 d3.layout.histogram = function() {
4551 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
4552 function histogram(data, i) {
4553 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;
4554 while (++i < m) {
4555 bin = bins[i] = [];
4556 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
4557 bin.y = 0;
4558 }
4559 if (m > 0) {
4560 i = -1;
4561 while (++i < n) {
4562 x = values[i];
4563 if (x >= range[0] && x <= range[1]) {
4564 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
4565 bin.y += k;
4566 bin.push(data[i]);
4567 }
4568 }
4569 }
4570 return bins;
4571 }
4572 histogram.value = function(x) {
4573 if (!arguments.length) return valuer;
4574 valuer = x;
4575 return histogram;
4576 };
4577 histogram.range = function(x) {
4578 if (!arguments.length) return ranger;
4579 ranger = d3_functor(x);
4580 return histogram;
4581 };
4582 histogram.bins = function(x) {
4583 if (!arguments.length) return binner;
4584 binner = typeof x === "number" ? function(range) {
4585 return d3_layout_histogramBinFixed(range, x);
4586 } : d3_functor(x);
4587 return histogram;
4588 };
4589 histogram.frequency = function(x) {
4590 if (!arguments.length) return frequency;
4591 frequency = !!x;
4592 return histogram;
4593 };
4594 return histogram;
4595 };
4596 function d3_layout_histogramBinSturges(range, values) {
4597 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
4598 }
4599 function d3_layout_histogramBinFixed(range, n) {
4600 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
4601 while (++x <= n) f[x] = m * x + b;
4602 return f;
4603 }
4604 function d3_layout_histogramRange(values) {
4605 return [ d3.min(values), d3.max(values) ];
4606 }
4607 d3.layout.hierarchy = function() {
4608 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
4609 function recurse(node, depth, nodes) {
4610 var childs = children.call(hierarchy, node, depth);
4611 node.depth = depth;
4612 nodes.push(node);
4613 if (childs && (n = childs.length)) {
4614 var i = -1, n, c = node.children = [], v = 0, j = depth + 1, d;
4615 while (++i < n) {
4616 d = recurse(childs[i], j, nodes);
4617 d.parent = node;
4618 c.push(d);
4619 v += d.value;
4620 }
4621 if (sort) c.sort(sort);
4622 if (value) node.value = v;
4623 } else if (value) {
4624 node.value = +value.call(hierarchy, node, depth) || 0;
4625 }
4626 return node;
4627 }
4628 function revalue(node, depth) {
4629 var children = node.children, v = 0;
4630 if (children && (n = children.length)) {
4631 var i = -1, n, j = depth + 1;
4632 while (++i < n) v += revalue(children[i], j);
4633 } else if (value) {
4634 v = +value.call(hierarchy, node, depth) || 0;
4635 }
4636 if (value) node.value = v;
4637 return v;
4638 }
4639 function hierarchy(d) {
4640 var nodes = [];
4641 recurse(d, 0, nodes);
4642 return nodes;
4643 }
4644 hierarchy.sort = function(x) {
4645 if (!arguments.length) return sort;
4646 sort = x;
4647 return hierarchy;
4648 };
4649 hierarchy.children = function(x) {
4650 if (!arguments.length) return children;
4651 children = x;
4652 return hierarchy;
4653 };
4654 hierarchy.value = function(x) {
4655 if (!arguments.length) return value;
4656 value = x;
4657 return hierarchy;
4658 };
4659 hierarchy.revalue = function(root) {
4660 revalue(root, 0);
4661 return root;
4662 };
4663 return hierarchy;
4664 };
4665 function d3_layout_hierarchyRebind(object, hierarchy) {
4666 d3.rebind(object, hierarchy, "sort", "children", "value");
4667 object.nodes = object;
4668 object.links = d3_layout_hierarchyLinks;
4669 return object;
4670 }
4671 function d3_layout_hierarchyChildren(d) {
4672 return d.children;
4673 }
4674 function d3_layout_hierarchyValue(d) {
4675 return d.value;
4676 }
4677 function d3_layout_hierarchySort(a, b) {
4678 return b.value - a.value;
4679 }
4680 function d3_layout_hierarchyLinks(nodes) {
4681 return d3.merge(nodes.map(function(parent) {
4682 return (parent.children || []).map(function(child) {
4683 return {
4684 source: parent,
4685 target: child
4686 };
4687 });
4688 }));
4689 }
4690 d3.layout.pack = function() {
4691 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ];
4692 function pack(d, i) {
4693 var nodes = hierarchy.call(this, d, i), root = nodes[0];
4694 root.x = 0;
4695 root.y = 0;
4696 d3_layout_treeVisitAfter(root, function(d) {
4697 d.r = Math.sqrt(d.value);
4698 });
4699 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
4700 var w = size[0], h = size[1], k = Math.max(2 * root.r / w, 2 * root.r / h);
4701 if (padding > 0) {
4702 var dr = padding * k / 2;
4703 d3_layout_treeVisitAfter(root, function(d) {
4704 d.r += dr;
4705 });
4706 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
4707 d3_layout_treeVisitAfter(root, function(d) {
4708 d.r -= dr;
4709 });
4710 k = Math.max(2 * root.r / w, 2 * root.r / h);
4711 }
4712 d3_layout_packTransform(root, w / 2, h / 2, 1 / k);
4713 return nodes;
4714 }
4715 pack.size = function(x) {
4716 if (!arguments.length) return size;
4717 size = x;
4718 return pack;
4719 };
4720 pack.padding = function(_) {
4721 if (!arguments.length) return padding;
4722 padding = +_;
4723 return pack;
4724 };
4725 return d3_layout_hierarchyRebind(pack, hierarchy);
4726 };
4727 function d3_layout_packSort(a, b) {
4728 return a.value - b.value;
4729 }
4730 function d3_layout_packInsert(a, b) {
4731 var c = a._pack_next;
4732 a._pack_next = b;
4733 b._pack_prev = a;
4734 b._pack_next = c;
4735 c._pack_prev = b;
4736 }
4737 function d3_layout_packSplice(a, b) {
4738 a._pack_next = b;
4739 b._pack_prev = a;
4740 }
4741 function d3_layout_packIntersects(a, b) {
4742 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
4743 return dr * dr - dx * dx - dy * dy > .001;
4744 }
4745 function d3_layout_packSiblings(node) {
4746 if (!(nodes = node.children) || !(n = nodes.length)) return;
4747 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
4748 function bound(node) {
4749 xMin = Math.min(node.x - node.r, xMin);
4750 xMax = Math.max(node.x + node.r, xMax);
4751 yMin = Math.min(node.y - node.r, yMin);
4752 yMax = Math.max(node.y + node.r, yMax);
4753 }
4754 nodes.forEach(d3_layout_packLink);
4755 a = nodes[0];
4756 a.x = -a.r;
4757 a.y = 0;
4758 bound(a);
4759 if (n > 1) {
4760 b = nodes[1];
4761 b.x = b.r;
4762 b.y = 0;
4763 bound(b);
4764 if (n > 2) {
4765 c = nodes[2];
4766 d3_layout_packPlace(a, b, c);
4767 bound(c);
4768 d3_layout_packInsert(a, c);
4769 a._pack_prev = c;
4770 d3_layout_packInsert(c, b);
4771 b = a._pack_next;
4772 for (i = 3; i < n; i++) {
4773 d3_layout_packPlace(a, b, c = nodes[i]);
4774 var isect = 0, s1 = 1, s2 = 1;
4775 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
4776 if (d3_layout_packIntersects(j, c)) {
4777 isect = 1;
4778 break;
4779 }
4780 }
4781 if (isect == 1) {
4782 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
4783 if (d3_layout_packIntersects(k, c)) {
4784 break;
4785 }
4786 }
4787 }
4788 if (isect) {
4789 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
4790 i--;
4791 } else {
4792 d3_layout_packInsert(a, c);
4793 b = c;
4794 bound(c);
4795 }
4796 }
4797 }
4798 }
4799 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
4800 for (i = 0; i < n; i++) {
4801 c = nodes[i];
4802 c.x -= cx;
4803 c.y -= cy;
4804 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
4805 }
4806 node.r = cr;
4807 nodes.forEach(d3_layout_packUnlink);
4808 }
4809 function d3_layout_packLink(node) {
4810 node._pack_next = node._pack_prev = node;
4811 }
4812 function d3_layout_packUnlink(node) {
4813 delete node._pack_next;
4814 delete node._pack_prev;
4815 }
4816 function d3_layout_packTransform(node, x, y, k) {
4817 var children = node.children;
4818 node.x = x += k * node.x;
4819 node.y = y += k * node.y;
4820 node.r *= k;
4821 if (children) {
4822 var i = -1, n = children.length;
4823 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
4824 }
4825 }
4826 function d3_layout_packPlace(a, b, c) {
4827 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
4828 if (db && (dx || dy)) {
4829 var da = b.r + c.r, dc = dx * dx + dy * dy;
4830 da *= da;
4831 db *= db;
4832 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
4833 c.x = a.x + x * dx + y * dy;
4834 c.y = a.y + x * dy - y * dx;
4835 } else {
4836 c.x = a.x + db;
4837 c.y = a.y;
4838 }
4839 }
4840 d3.layout.cluster = function() {
4841 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
4842 function cluster(d, i) {
4843 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
4844 d3_layout_treeVisitAfter(root, function(node) {
4845 var children = node.children;
4846 if (children && children.length) {
4847 node.x = d3_layout_clusterX(children);
4848 node.y = d3_layout_clusterY(children);
4849 } else {
4850 node.x = previousNode ? x += separation(node, previousNode) : 0;
4851 node.y = 0;
4852 previousNode = node;
4853 }
4854 });
4855 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;
4856 d3_layout_treeVisitAfter(root, function(node) {
4857 node.x = (node.x - x0) / (x1 - x0) * size[0];
4858 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
4859 });
4860 return nodes;
4861 }
4862 cluster.separation = function(x) {
4863 if (!arguments.length) return separation;
4864 separation = x;
4865 return cluster;
4866 };
4867 cluster.size = function(x) {
4868 if (!arguments.length) return size;
4869 size = x;
4870 return cluster;
4871 };
4872 return d3_layout_hierarchyRebind(cluster, hierarchy);
4873 };
4874 function d3_layout_clusterY(children) {
4875 return 1 + d3.max(children, function(child) {
4876 return child.y;
4877 });
4878 }
4879 function d3_layout_clusterX(children) {
4880 return children.reduce(function(x, child) {
4881 return x + child.x;
4882 }, 0) / children.length;
4883 }
4884 function d3_layout_clusterLeft(node) {
4885 var children = node.children;
4886 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
4887 }
4888 function d3_layout_clusterRight(node) {
4889 var children = node.children, n;
4890 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
4891 }
4892 d3.layout.tree = function() {
4893 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
4894 function tree(d, i) {
4895 var nodes = hierarchy.call(this, d, i), root = nodes[0];
4896 function firstWalk(node, previousSibling) {
4897 var children = node.children, layout = node._tree;
4898 if (children && (n = children.length)) {
4899 var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
4900 while (++i < n) {
4901 child = children[i];
4902 firstWalk(child, previousChild);
4903 ancestor = apportion(child, previousChild, ancestor);
4904 previousChild = child;
4905 }
4906 d3_layout_treeShift(node);
4907 var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
4908 if (previousSibling) {
4909 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
4910 layout.mod = layout.prelim - midpoint;
4911 } else {
4912 layout.prelim = midpoint;
4913 }
4914 } else {
4915 if (previousSibling) {
4916 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
4917 }
4918 }
4919 }
4920 function secondWalk(node, x) {
4921 node.x = node._tree.prelim + x;
4922 var children = node.children;
4923 if (children && (n = children.length)) {
4924 var i = -1, n;
4925 x += node._tree.mod;
4926 while (++i < n) {
4927 secondWalk(children[i], x);
4928 }
4929 }
4930 }
4931 function apportion(node, previousSibling, ancestor) {
4932 if (previousSibling) {
4933 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;
4934 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
4935 vom = d3_layout_treeLeft(vom);
4936 vop = d3_layout_treeRight(vop);
4937 vop._tree.ancestor = node;
4938 shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
4939 if (shift > 0) {
4940 d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
4941 sip += shift;
4942 sop += shift;
4943 }
4944 sim += vim._tree.mod;
4945 sip += vip._tree.mod;
4946 som += vom._tree.mod;
4947 sop += vop._tree.mod;
4948 }
4949 if (vim && !d3_layout_treeRight(vop)) {
4950 vop._tree.thread = vim;
4951 vop._tree.mod += sim - sop;
4952 }
4953 if (vip && !d3_layout_treeLeft(vom)) {
4954 vom._tree.thread = vip;
4955 vom._tree.mod += sip - som;
4956 ancestor = node;
4957 }
4958 }
4959 return ancestor;
4960 }
4961 d3_layout_treeVisitAfter(root, function(node, previousSibling) {
4962 node._tree = {
4963 ancestor: node,
4964 prelim: 0,
4965 mod: 0,
4966 change: 0,
4967 shift: 0,
4968 number: previousSibling ? previousSibling._tree.number + 1 : 0
4969 };
4970 });
4971 firstWalk(root);
4972 secondWalk(root, -root._tree.prelim);
4973 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;
4974 d3_layout_treeVisitAfter(root, function(node) {
4975 node.x = (node.x - x0) / (x1 - x0) * size[0];
4976 node.y = node.depth / y1 * size[1];
4977 delete node._tree;
4978 });
4979 return nodes;
4980 }
4981 tree.separation = function(x) {
4982 if (!arguments.length) return separation;
4983 separation = x;
4984 return tree;
4985 };
4986 tree.size = function(x) {
4987 if (!arguments.length) return size;
4988 size = x;
4989 return tree;
4990 };
4991 return d3_layout_hierarchyRebind(tree, hierarchy);
4992 };
4993 function d3_layout_treeSeparation(a, b) {
4994 return a.parent == b.parent ? 1 : 2;
4995 }
4996 function d3_layout_treeLeft(node) {
4997 var children = node.children;
4998 return children && children.length ? children[0] : node._tree.thread;
4999 }
5000 function d3_layout_treeRight(node) {
5001 var children = node.children, n;
5002 return children && (n = children.length) ? children[n - 1] : node._tree.thread;
5003 }
5004 function d3_layout_treeSearch(node, compare) {
5005 var children = node.children;
5006 if (children && (n = children.length)) {
5007 var child, n, i = -1;
5008 while (++i < n) {
5009 if (compare(child = d3_layout_treeSearch(children[i], compare), node) > 0) {
5010 node = child;
5011 }
5012 }
5013 }
5014 return node;
5015 }
5016 function d3_layout_treeRightmost(a, b) {
5017 return a.x - b.x;
5018 }
5019 function d3_layout_treeLeftmost(a, b) {
5020 return b.x - a.x;
5021 }
5022 function d3_layout_treeDeepest(a, b) {
5023 return a.depth - b.depth;
5024 }
5025 function d3_layout_treeVisitAfter(node, callback) {
5026 function visit(node, previousSibling) {
5027 var children = node.children;
5028 if (children && (n = children.length)) {
5029 var child, previousChild = null, i = -1, n;
5030 while (++i < n) {
5031 child = children[i];
5032 visit(child, previousChild);
5033 previousChild = child;
5034 }
5035 }
5036 callback(node, previousSibling);
5037 }
5038 visit(node, null);
5039 }
5040 function d3_layout_treeShift(node) {
5041 var shift = 0, change = 0, children = node.children, i = children.length, child;
5042 while (--i >= 0) {
5043 child = children[i]._tree;
5044 child.prelim += shift;
5045 child.mod += shift;
5046 shift += child.shift + (change += child.change);
5047 }
5048 }
5049 function d3_layout_treeMove(ancestor, node, shift) {
5050 ancestor = ancestor._tree;
5051 node = node._tree;
5052 var change = shift / (node.number - ancestor.number);
5053 ancestor.change += change;
5054 node.change -= change;
5055 node.shift += shift;
5056 node.prelim += shift;
5057 node.mod += shift;
5058 }
5059 function d3_layout_treeAncestor(vim, node, ancestor) {
5060 return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
5061 }
5062 d3.layout.treemap = function() {
5063 var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5));
5064 function scale(children, k) {
5065 var i = -1, n = children.length, child, area;
5066 while (++i < n) {
5067 area = (child = children[i]).value * (k < 0 ? 0 : k);
5068 child.area = isNaN(area) || area <= 0 ? 0 : area;
5069 }
5070 }
5071 function squarify(node) {
5072 var children = node.children;
5073 if (children && children.length) {
5074 var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
5075 scale(remaining, rect.dx * rect.dy / node.value);
5076 row.area = 0;
5077 while ((n = remaining.length) > 0) {
5078 row.push(child = remaining[n - 1]);
5079 row.area += child.area;
5080 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
5081 remaining.pop();
5082 best = score;
5083 } else {
5084 row.area -= row.pop().area;
5085 position(row, u, rect, false);
5086 u = Math.min(rect.dx, rect.dy);
5087 row.length = row.area = 0;
5088 best = Infinity;
5089 }
5090 }
5091 if (row.length) {
5092 position(row, u, rect, true);
5093 row.length = row.area = 0;
5094 }
5095 children.forEach(squarify);
5096 }
5097 }
5098 function stickify(node) {
5099 var children = node.children;
5100 if (children && children.length) {
5101 var rect = pad(node), remaining = children.slice(), child, row = [];
5102 scale(remaining, rect.dx * rect.dy / node.value);
5103 row.area = 0;
5104 while (child = remaining.pop()) {
5105 row.push(child);
5106 row.area += child.area;
5107 if (child.z != null) {
5108 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
5109 row.length = row.area = 0;
5110 }
5111 }
5112 children.forEach(stickify);
5113 }
5114 }
5115 function worst(row, u) {
5116 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
5117 while (++i < n) {
5118 if (!(r = row[i].area)) continue;
5119 if (r < rmin) rmin = r;
5120 if (r > rmax) rmax = r;
5121 }
5122 s *= s;
5123 u *= u;
5124 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
5125 }
5126 function position(row, u, rect, flush) {
5127 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
5128 if (u == rect.dx) {
5129 if (flush || v > rect.dy) v = rect.dy;
5130 while (++i < n) {
5131 o = row[i];
5132 o.x = x;
5133 o.y = y;
5134 o.dy = v;
5135 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
5136 }
5137 o.z = true;
5138 o.dx += rect.x + rect.dx - x;
5139 rect.y += v;
5140 rect.dy -= v;
5141 } else {
5142 if (flush || v > rect.dx) v = rect.dx;
5143 while (++i < n) {
5144 o = row[i];
5145 o.x = x;
5146 o.y = y;
5147 o.dx = v;
5148 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
5149 }
5150 o.z = false;
5151 o.dy += rect.y + rect.dy - y;
5152 rect.x += v;
5153 rect.dx -= v;
5154 }
5155 }
5156 function treemap(d) {
5157 var nodes = stickies || hierarchy(d), root = nodes[0];
5158 root.x = 0;
5159 root.y = 0;
5160 root.dx = size[0];
5161 root.dy = size[1];
5162 if (stickies) hierarchy.revalue(root);
5163 scale([ root ], root.dx * root.dy / root.value);
5164 (stickies ? stickify : squarify)(root);
5165 if (sticky) stickies = nodes;
5166 return nodes;
5167 }
5168 treemap.size = function(x) {
5169 if (!arguments.length) return size;
5170 size = x;
5171 return treemap;
5172 };
5173 treemap.padding = function(x) {
5174 if (!arguments.length) return padding;
5175 function padFunction(node) {
5176 var p = x.call(treemap, node, node.depth);
5177 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
5178 }
5179 function padConstant(node) {
5180 return d3_layout_treemapPad(node, x);
5181 }
5182 var type;
5183 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
5184 padConstant) : padConstant;
5185 return treemap;
5186 };
5187 treemap.round = function(x) {
5188 if (!arguments.length) return round != Number;
5189 round = x ? Math.round : Number;
5190 return treemap;
5191 };
5192 treemap.sticky = function(x) {
5193 if (!arguments.length) return sticky;
5194 sticky = x;
5195 stickies = null;
5196 return treemap;
5197 };
5198 treemap.ratio = function(x) {
5199 if (!arguments.length) return ratio;
5200 ratio = x;
5201 return treemap;
5202 };
5203 treemap.mode = function(x) {
5204 if (!arguments.length) return mode;
5205 mode = x + "";
5206 return treemap;
5207 };
5208 return d3_layout_hierarchyRebind(treemap, hierarchy);
5209 };
5210 function d3_layout_treemapPadNull(node) {
5211 return {
5212 x: node.x,
5213 y: node.y,
5214 dx: node.dx,
5215 dy: node.dy
5216 };
5217 }
5218 function d3_layout_treemapPad(node, padding) {
5219 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];
5220 if (dx < 0) {
5221 x += dx / 2;
5222 dx = 0;
5223 }
5224 if (dy < 0) {
5225 y += dy / 2;
5226 dy = 0;
5227 }
5228 return {
5229 x: x,
5230 y: y,
5231 dx: dx,
5232 dy: dy
5233 };
5234 }
5235 function d3_dsv(delimiter, mimeType) {
5236 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
5237 function dsv(url, callback) {
5238 return d3.xhr(url, mimeType, callback).response(response);
5239 }
5240 function response(request) {
5241 return dsv.parse(request.responseText);
5242 }
5243 dsv.parse = function(text) {
5244 var o;
5245 return dsv.parseRows(text, function(row) {
5246 if (o) return o(row);
5247 o = new Function("d", "return {" + row.map(function(name, i) {
5248 return JSON.stringify(name) + ": d[" + i + "]";
5249 }).join(",") + "}");
5250 });
5251 };
5252 dsv.parseRows = function(text, f) {
5253 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
5254 function token() {
5255 if (I >= N) return EOF;
5256 if (eol) return eol = false, EOL;
5257 var j = I;
5258 if (text.charCodeAt(j) === 34) {
5259 var i = j;
5260 while (i++ < N) {
5261 if (text.charCodeAt(i) === 34) {
5262 if (text.charCodeAt(i + 1) !== 34) break;
5263 ++i;
5264 }
5265 }
5266 I = i + 2;
5267 var c = text.charCodeAt(i + 1);
5268 if (c === 13) {
5269 eol = true;
5270 if (text.charCodeAt(i + 2) === 10) ++I;
5271 } else if (c === 10) {
5272 eol = true;
5273 }
5274 return text.substring(j + 1, i).replace(/""/g, '"');
5275 }
5276 while (I < N) {
5277 var c = text.charCodeAt(I++), k = 1;
5278 if (c === 10) eol = true; else if (c === 13) {
5279 eol = true;
5280 if (text.charCodeAt(I) === 10) ++I, ++k;
5281 } else if (c !== delimiterCode) continue;
5282 return text.substring(j, I - k);
5283 }
5284 return text.substring(j);
5285 }
5286 while ((t = token()) !== EOF) {
5287 var a = [];
5288 while (t !== EOL && t !== EOF) {
5289 a.push(t);
5290 t = token();
5291 }
5292 if (f && !(a = f(a, n++))) continue;
5293 rows.push(a);
5294 }
5295 return rows;
5296 };
5297 dsv.format = function(rows) {
5298 return rows.map(formatRow).join("\n");
5299 };
5300 function formatRow(row) {
5301 return row.map(formatValue).join(delimiter);
5302 }
5303 function formatValue(text) {
5304 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
5305 }
5306 return dsv;
5307 }
5308 d3.csv = d3_dsv(",", "text/csv");
5309 d3.tsv = d3_dsv(" ", "text/tab-separated-values");
5310 d3.geo = {};
5311 d3.geo.stream = function(object, listener) {
5312 if (d3_geo_streamObjectType.hasOwnProperty(object.type)) {
5313 d3_geo_streamObjectType[object.type](object, listener);
5314 } else {
5315 d3_geo_streamGeometry(object, listener);
5316 }
5317 };
5318 function d3_geo_streamGeometry(geometry, listener) {
5319 if (d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
5320 d3_geo_streamGeometryType[geometry.type](geometry, listener);
5321 }
5322 }
5323 var d3_geo_streamObjectType = {
5324 Feature: function(feature, listener) {
5325 d3_geo_streamGeometry(feature.geometry, listener);
5326 },
5327 FeatureCollection: function(object, listener) {
5328 var features = object.features, i = -1, n = features.length;
5329 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
5330 }
5331 };
5332 var d3_geo_streamGeometryType = {
5333 Sphere: function(object, listener) {
5334 listener.sphere();
5335 },
5336 Point: function(object, listener) {
5337 var coordinate = object.coordinates;
5338 listener.point(coordinate[0], coordinate[1]);
5339 },
5340 MultiPoint: function(object, listener) {
5341 var coordinates = object.coordinates, i = -1, n = coordinates.length, coordinate;
5342 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]);
5343 },
5344 LineString: function(object, listener) {
5345 d3_geo_streamLine(object.coordinates, listener, 0);
5346 },
5347 MultiLineString: function(object, listener) {
5348 var coordinates = object.coordinates, i = -1, n = coordinates.length;
5349 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
5350 },
5351 Polygon: function(object, listener) {
5352 d3_geo_streamPolygon(object.coordinates, listener);
5353 },
5354 MultiPolygon: function(object, listener) {
5355 var coordinates = object.coordinates, i = -1, n = coordinates.length;
5356 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
5357 },
5358 GeometryCollection: function(object, listener) {
5359 var geometries = object.geometries, i = -1, n = geometries.length;
5360 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
5361 }
5362 };
5363 function d3_geo_streamLine(coordinates, listener, closed) {
5364 var i = -1, n = coordinates.length - closed, coordinate;
5365 listener.lineStart();
5366 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]);
5367 listener.lineEnd();
5368 }
5369 function d3_geo_streamPolygon(coordinates, listener) {
5370 var i = -1, n = coordinates.length;
5371 listener.polygonStart();
5372 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
5373 listener.polygonEnd();
5374 }
5375 function d3_geo_spherical(cartesian) {
5376 return [ Math.atan2(cartesian[1], cartesian[0]), Math.asin(Math.max(-1, Math.min(1, cartesian[2]))) ];
5377 }
5378 function d3_geo_sphericalEqual(a, b) {
5379 return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
5380 }
5381 function d3_geo_cartesian(spherical) {
5382 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
5383 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
5384 }
5385 function d3_geo_cartesianDot(a, b) {
5386 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
5387 }
5388 function d3_geo_cartesianCross(a, b) {
5389 return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ];
5390 }
5391 function d3_geo_cartesianAdd(a, b) {
5392 a[0] += b[0];
5393 a[1] += b[1];
5394 a[2] += b[2];
5395 }
5396 function d3_geo_cartesianScale(vector, k) {
5397 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
5398 }
5399 function d3_geo_cartesianNormalize(d) {
5400 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
5401 d[0] /= l;
5402 d[1] /= l;
5403 d[2] /= l;
5404 }
5405 function d3_geo_resample(project) {
5406 var δ2 = .5, maxDepth = 16;
5407 function resample(stream) {
5408 var λ0, x0, y0, a0, b0, c0;
5409 var resample = {
5410 point: point,
5411 lineStart: lineStart,
5412 lineEnd: lineEnd,
5413 polygonStart: function() {
5414 stream.polygonStart();
5415 resample.lineStart = polygonLineStart;
5416 },
5417 polygonEnd: function() {
5418 stream.polygonEnd();
5419 resample.lineStart = lineStart;
5420 }
5421 };
5422 function point(x, y) {
5423 x = project(x, y);
5424 stream.point(x[0], x[1]);
5425 }
5426 function lineStart() {
5427 x0 = NaN;
5428 resample.point = linePoint;
5429 stream.lineStart();
5430 }
5431 function linePoint(λ, φ) {
5432 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
5433 resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
5434 stream.point(x0, y0);
5435 }
5436 function lineEnd() {
5437 resample.point = point;
5438 stream.lineEnd();
5439 }
5440 function polygonLineStart() {
5441 var λ00, φ00, x00, y00, a00, b00, c00;
5442 lineStart();
5443 resample.point = function(λ, φ) {
5444 linePoint00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
5445 resample.point = linePoint;
5446 };
5447 resample.lineEnd = function() {
5448 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
5449 resample.lineEnd = lineEnd;
5450 lineEnd();
5451 };
5452 }
5453 return resample;
5454 }
5455 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
5456 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
5457 if (d2 > 4 * δ2 && depth--) {
5458 var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = Math.abs(Math.abs(c) - 1) < ε ? 0 + λ1) / 2 : Math.atan2(b, a), p = project2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
5459 if (dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3) {
5460 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
5461 stream.point(x2, y2);
5462 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
5463 }
5464 }
5465 }
5466 resample.precision = function(_) {
5467 if (!arguments.length) return Math.sqrt2);
5468 maxDepth = 2 = _ * _) > 0 && 16;
5469 return resample;
5470 };
5471 return resample;
5472 }
5473 d3.geo.albersUsa = function() {
5474 var lower48 = d3.geo.albers();
5475 var alaska = d3.geo.albers().rotate([ 160, 0 ]).center([ 0, 60 ]).parallels([ 55, 65 ]);
5476 var hawaii = d3.geo.albers().rotate([ 160, 0 ]).center([ 0, 20 ]).parallels([ 8, 18 ]);
5477 var puertoRico = d3.geo.albers().rotate([ 60, 0 ]).center([ 0, 10 ]).parallels([ 8, 18 ]);
5478 function albersUsa(coordinates) {
5479 return projection(coordinates)(coordinates);
5480 }
5481 function projection(point) {
5482 var lon = point[0], lat = point[1];
5483 return lat > 50 ? alaska : lon < -140 ? hawaii : lat < 21 ? puertoRico : lower48;
5484 }
5485 albersUsa.scale = function(x) {
5486 if (!arguments.length) return lower48.scale();
5487 lower48.scale(x);
5488 alaska.scale(x * .6);
5489 hawaii.scale(x);
5490 puertoRico.scale(x * 1.5);
5491 return albersUsa.translate(lower48.translate());
5492 };
5493 albersUsa.translate = function(x) {
5494 if (!arguments.length) return lower48.translate();
5495 var dz = lower48.scale(), dx = x[0], dy = x[1];
5496 lower48.translate(x);
5497 alaska.translate([ dx - .4 * dz, dy + .17 * dz ]);
5498 hawaii.translate([ dx - .19 * dz, dy + .2 * dz ]);
5499 puertoRico.translate([ dx + .58 * dz, dy + .43 * dz ]);
5500 return albersUsa;
5501 };
5502 return albersUsa.scale(lower48.scale());
5503 };
5504 function d3_geo_albers0, φ1) {
5505 var sinφ0 = Math.sin0), n = (sinφ0 + Math.sin1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
5506 function albers(λ, φ) {
5507 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
5508 return [ ρ * Math.sin *= n), ρ0 - ρ * Math.cos(λ) ];
5509 }
5510 albers.invert = function(x, y) {
5511 var ρ0_y = ρ0 - y;
5512 return [ Math.atan2(x, ρ0_y) / n, Math.asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
5513 };
5514 return albers;
5515 }
5516 (d3.geo.albers = function() {
5517 var φ0 = 29.5 * d3_radians, φ1 = 45.5 * d3_radians, m = d3_geo_projectionMutator(d3_geo_albers), p = m0, φ1);
5518 p.parallels = function(_) {
5519 if (!arguments.length) return [ φ0 * d3_degrees, φ1 * d3_degrees ];
5520 return m0 = _[0] * d3_radians, φ1 = _[1] * d3_radians);
5521 };
5522 return p.rotate([ 98, 0 ]).center([ 0, 38 ]).scale(1e3);
5523 }).raw = d3_geo_albers;
5524 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
5525 return Math.sqrt(2 / (1 + cosλcosφ));
5526 }, function(ρ) {
5527 return 2 * Math.asin / 2);
5528 });
5529 (d3.geo.azimuthalEqualArea = function() {
5530 return d3_geo_projection(d3_geo_azimuthalEqualArea);
5531 }).raw = d3_geo_azimuthalEqualArea;
5532 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
5533 var c = Math.acos(cosλcosφ);
5534 return c && c / Math.sin(c);
5535 }, d3_identity);
5536 (d3.geo.azimuthalEquidistant = function() {
5537 return d3_geo_projection(d3_geo_azimuthalEquidistant);
5538 }).raw = d3_geo_azimuthalEquidistant;
5539 d3.geo.bounds = d3_geo_bounds(d3_identity);
5540 function d3_geo_bounds(projectStream) {
5541 var x0, y0, x1, y1;
5542 var bound = {
5543 point: boundPoint,
5544 lineStart: d3_noop,
5545 lineEnd: d3_noop,
5546 polygonStart: function() {
5547 bound.lineEnd = boundPolygonLineEnd;
5548 },
5549 polygonEnd: function() {
5550 bound.point = boundPoint;
5551 }
5552 };
5553 function boundPoint(x, y) {
5554 if (x < x0) x0 = x;
5555 if (x > x1) x1 = x;
5556 if (y < y0) y0 = y;
5557 if (y > y1) y1 = y;
5558 }
5559 function boundPolygonLineEnd() {
5560 bound.point = bound.lineEnd = d3_noop;
5561 }
5562 return function(feature) {
5563 y1 = x1 = -(x0 = y0 = Infinity);
5564 d3.geo.stream(feature, projectStream(bound));
5565 return [ [ x0, y0 ], [ x1, y1 ] ];
5566 };
5567 }
5568 d3.geo.centroid = function(object) {
5569 d3_geo_centroidDimension = d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
5570 d3.geo.stream(object, d3_geo_centroid);
5571 var m;
5572 if (d3_geo_centroidW && Math.abs(m = Math.sqrt(d3_geo_centroidX * d3_geo_centroidX + d3_geo_centroidY * d3_geo_centroidY + d3_geo_centroidZ * d3_geo_centroidZ)) > ε) {
5573 return [ Math.atan2(d3_geo_centroidY, d3_geo_centroidX) * d3_degrees, Math.asin(Math.max(-1, Math.min(1, d3_geo_centroidZ / m))) * d3_degrees ];
5574 }
5575 };
5576 var d3_geo_centroidDimension, d3_geo_centroidW, d3_geo_centroidX, d3_geo_centroidY, d3_geo_centroidZ;
5577 var d3_geo_centroid = {
5578 sphere: function() {
5579 if (d3_geo_centroidDimension < 2) {
5580 d3_geo_centroidDimension = 2;
5581 d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
5582 }
5583 },
5584 point: d3_geo_centroidPoint,
5585 lineStart: d3_geo_centroidLineStart,
5586 lineEnd: d3_geo_centroidLineEnd,
5587 polygonStart: function() {
5588 if (d3_geo_centroidDimension < 2) {
5589 d3_geo_centroidDimension = 2;
5590 d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
5591 }
5592 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
5593 },
5594 polygonEnd: function() {
5595 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
5596 }
5597 };
5598 function d3_geo_centroidPoint(λ, φ) {
5599 if (d3_geo_centroidDimension) return;
5600 ++d3_geo_centroidW;
5601 λ *= d3_radians;
5602 var cosφ = Math.cos *= d3_radians);
5603 d3_geo_centroidX += (cosφ * Math.cos(λ) - d3_geo_centroidX) / d3_geo_centroidW;
5604 d3_geo_centroidY += (cosφ * Math.sin(λ) - d3_geo_centroidY) / d3_geo_centroidW;
5605 d3_geo_centroidZ += (Math.sin(φ) - d3_geo_centroidZ) / d3_geo_centroidW;
5606 }
5607 function d3_geo_centroidRingStart() {
5608 var λ00, φ00;
5609 d3_geo_centroidDimension = 1;
5610 d3_geo_centroidLineStart();
5611 d3_geo_centroidDimension = 2;
5612 var linePoint = d3_geo_centroid.point;
5613 d3_geo_centroid.point = function(λ, φ) {
5614 linePoint00 = λ, φ00 = φ);
5615 };
5616 d3_geo_centroid.lineEnd = function() {
5617 d3_geo_centroid.point00, φ00);
5618 d3_geo_centroidLineEnd();
5619 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
5620 };
5621 }
5622 function d3_geo_centroidLineStart() {
5623 var x0, y0, z0;
5624 if (d3_geo_centroidDimension > 1) return;
5625 if (d3_geo_centroidDimension < 1) {
5626 d3_geo_centroidDimension = 1;
5627 d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
5628 }
5629 d3_geo_centroid.point = function(λ, φ) {
5630 λ *= d3_radians;
5631 var cosφ = Math.cos *= d3_radians);
5632 x0 = cosφ * Math.cos(λ);
5633 y0 = cosφ * Math.sin(λ);
5634 z0 = Math.sin(φ);
5635 d3_geo_centroid.point = nextPoint;
5636 };
5637 function nextPoint(λ, φ) {
5638 λ *= d3_radians;
5639 var cosφ = Math.cos *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), w = Math.atan2(Math.sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
5640 d3_geo_centroidW += w;
5641 d3_geo_centroidX += w * (x0 + (x0 = x));
5642 d3_geo_centroidY += w * (y0 + (y0 = y));
5643 d3_geo_centroidZ += w * (z0 + (z0 = z));
5644 }
5645 }
5646 function d3_geo_centroidLineEnd() {
5647 d3_geo_centroid.point = d3_geo_centroidPoint;
5648 }
5649 d3.geo.circle = function() {
5650 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
5651 function circle() {
5652 var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
5653 interpolate(null, null, 1, {
5654 point: function(x, y) {
5655 ring.push(x = rotate(x, y));
5656 x[0] *= d3_degrees, x[1] *= d3_degrees;
5657 }
5658 });
5659 return {
5660 type: "Polygon",
5661 coordinates: [ ring ]
5662 };
5663 }
5664 circle.origin = function(x) {
5665 if (!arguments.length) return origin;
5666 origin = x;
5667 return circle;
5668 };
5669 circle.angle = function(x) {
5670 if (!arguments.length) return angle;
5671 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
5672 return circle;
5673 };
5674 circle.precision = function(_) {
5675 if (!arguments.length) return precision;
5676 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
5677 return circle;
5678 };
5679 return circle.angle(90);
5680 };
5681 function d3_geo_circleInterpolate(radians, precision) {
5682 var cr = Math.cos(radians), sr = Math.sin(radians);
5683 return function(from, to, direction, listener) {
5684 if (from != null) {
5685 from = d3_geo_circleAngle(cr, from);
5686 to = d3_geo_circleAngle(cr, to);
5687 if (direction > 0 ? from < to : from > to) from += direction * 2 * π;
5688 } else {
5689 from = radians + direction * 2 * π;
5690 to = radians;
5691 }
5692 var point;
5693 for (var step = direction * precision, t = from; direction > 0 ? t > to : t < to; t -= step) {
5694 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
5695 }
5696 };
5697 }
5698 function d3_geo_circleAngle(cr, point) {
5699 var a = d3_geo_cartesian(point);
5700 a[0] -= cr;
5701 d3_geo_cartesianNormalize(a);
5702 var angle = Math.acos(Math.max(-1, Math.min(1, -a[1])));
5703 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
5704 }
5705 function d3_geo_clip(pointVisible, clipLine, interpolate) {
5706 return function(listener) {
5707 var line = clipLine(listener);
5708 var clip = {
5709 point: point,
5710 lineStart: lineStart,
5711 lineEnd: lineEnd,
5712 polygonStart: function() {
5713 clip.point = pointRing;
5714 clip.lineStart = ringStart;
5715 clip.lineEnd = ringEnd;
5716 invisible = false;
5717 invisibleArea = visibleArea = 0;
5718 segments = [];
5719 listener.polygonStart();
5720 },
5721 polygonEnd: function() {
5722 clip.point = point;
5723 clip.lineStart = lineStart;
5724 clip.lineEnd = lineEnd;
5725 segments = d3.merge(segments);
5726 if (segments.length) {
5727 d3_geo_clipPolygon(segments, interpolate, listener);
5728 } else if (visibleArea < || invisible && invisibleArea < -ε) {
5729 listener.lineStart();
5730 interpolate(null, null, 1, listener);
5731 listener.lineEnd();
5732 }
5733 listener.polygonEnd();
5734 segments = null;
5735 },
5736 sphere: function() {
5737 listener.polygonStart();
5738 listener.lineStart();
5739 interpolate(null, null, 1, listener);
5740 listener.lineEnd();
5741 listener.polygonEnd();
5742 }
5743 };
5744 function point(λ, φ) {
5745 if (pointVisible(λ, φ)) listener.point(λ, φ);
5746 }
5747 function pointLine(λ, φ) {
5748 line.point(λ, φ);
5749 }
5750 function lineStart() {
5751 clip.point = pointLine;
5752 line.lineStart();
5753 }
5754 function lineEnd() {
5755 clip.point = point;
5756 line.lineEnd();
5757 }
5758 var segments, visibleArea, invisibleArea, invisible;
5759 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), ring;
5760 function pointRing(λ, φ) {
5761 ringListener.point(λ, φ);
5762 ring.push([ λ, φ ]);
5763 }
5764 function ringStart() {
5765 ringListener.lineStart();
5766 ring = [];
5767 }
5768 function ringEnd() {
5769 pointRing(ring[0][0], ring[0][1]);
5770 ringListener.lineEnd();
5771 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
5772 if (!n) {
5773 invisible = true;
5774 invisibleArea += d3_geo_clipAreaRing(ring, -1);
5775 ring = null;
5776 return;
5777 }
5778 ring = null;
5779 if (clean & 1) {
5780 segment = ringSegments[0];
5781 visibleArea += d3_geo_clipAreaRing(segment, 1);
5782 var n = segment.length - 1, i = -1, point;
5783 listener.lineStart();
5784 while (++i < n) listener.point((point = segment[i])[0], point[1]);
5785 listener.lineEnd();
5786 return;
5787 }
5788 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
5789 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
5790 }
5791 return clip;
5792 };
5793 }
5794 function d3_geo_clipPolygon(segments, interpolate, listener) {
5795 var subject = [], clip = [];
5796 segments.forEach(function(segment) {
5797 if ((n = segment.length) <= 1) return;
5798 var n, p0 = segment[0], p1 = segment[n - 1];
5799 if (d3_geo_sphericalEqual(p0, p1)) {
5800 listener.lineStart();
5801 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
5802 listener.lineEnd();
5803 return;
5804 }
5805 var a = {
5806 point: p0,
5807 points: segment,
5808 other: null,
5809 visited: false,
5810 entry: true,
5811 subject: true
5812 }, b = {
5813 point: p0,
5814 points: [ p0 ],
5815 other: a,
5816 visited: false,
5817 entry: false,
5818 subject: false
5819 };
5820 a.other = b;
5821 subject.push(a);
5822 clip.push(b);
5823 a = {
5824 point: p1,
5825 points: [ p1 ],
5826 other: null,
5827 visited: false,
5828 entry: false,
5829 subject: true
5830 };
5831 b = {
5832 point: p1,
5833 points: [ p1 ],
5834 other: a,
5835 visited: false,
5836 entry: true,
5837 subject: false
5838 };
5839 a.other = b;
5840 subject.push(a);
5841 clip.push(b);
5842 });
5843 clip.sort(d3_geo_clipSort);
5844 d3_geo_clipLinkCircular(subject);
5845 d3_geo_clipLinkCircular(clip);
5846 if (!subject.length) return;
5847 var start = subject[0], current, points, point;
5848 while (1) {
5849 current = start;
5850 while (current.visited) if ((current = current.next) === start) return;
5851 points = current.points;
5852 listener.lineStart();
5853 do {
5854 current.visited = current.other.visited = true;
5855 if (current.entry) {
5856 if (current.subject) {
5857 for (var i = 0; i < points.length; i++) listener.point((point = points[i])[0], point[1]);
5858 } else {
5859 interpolate(current.point, current.next.point, 1, listener);
5860 }
5861 current = current.next;
5862 } else {
5863 if (current.subject) {
5864 points = current.prev.points;
5865 for (var i = points.length; --i >= 0; ) listener.point((point = points[i])[0], point[1]);
5866 } else {
5867 interpolate(current.point, current.prev.point, -1, listener);
5868 }
5869 current = current.prev;
5870 }
5871 current = current.other;
5872 points = current.points;
5873 } while (!current.visited);
5874 listener.lineEnd();
5875 }
5876 }
5877 function d3_geo_clipLinkCircular(array) {
5878 if (!(n = array.length)) return;
5879 var n, i = 0, a = array[0], b;
5880 while (++i < n) {
5881 a.next = b = array[i];
5882 b.prev = a;
5883 a = b;
5884 }
5885 a.next = b = array[0];
5886 b.prev = a;
5887 }
5888 function d3_geo_clipSort(a, b) {
5889 return ((a = a.point)[0] < 0 ? a[1] - π / 2 - ε : π / 2 - a[1]) - ((b = b.point)[0] < 0 ? b[1] - π / 2 - ε : π / 2 - b[1]);
5890 }
5891 function d3_geo_clipSegmentLength1(segment) {
5892 return segment.length > 1;
5893 }
5894 function d3_geo_clipBufferListener() {
5895 var lines = [], line;
5896 return {
5897 lineStart: function() {
5898 lines.push(line = []);
5899 },
5900 point: function(λ, φ) {
5901 line.push([ λ, φ ]);
5902 },
5903 lineEnd: d3_noop,
5904 buffer: function() {
5905 var buffer = lines;
5906 lines = [];
5907 line = null;
5908 return buffer;
5909 }
5910 };
5911 }
5912 function d3_geo_clipAreaRing(ring, invisible) {
5913 if (!(n = ring.length)) return 0;
5914 var n, i = 0, area = 0, p = ring[0], λ = p[0], φ = p[1], cosφ = Math.cos(φ), x0 = Math.atan2(invisible * Math.sin(λ) * cosφ, Math.sin(φ)), y0 = 1 - invisible * Math.cos(λ) * cosφ, x1 = x0, x, y;
5915 while (++i < n) {
5916 p = ring[i];
5917 cosφ = Math.cos = p[1]);
5918 x = Math.atan2(invisible * Math.sin = p[0]) * cosφ, Math.sin(φ));
5919 y = 1 - invisible * Math.cos(λ) * cosφ;
5920 if (Math.abs(y0 - 2) < ε && Math.abs(y - 2) < ε) continue;
5921 if (Math.abs(y) < ε || Math.abs(y0) < ε) {} else if (Math.abs(Math.abs(x - x0) - π) < ε) {
5922 if (y + y0 > 2) area += 4 * (x - x0);
5923 } else if (Math.abs(y0 - 2) < ε) area += 4 * (x - x1); else area += ((3 * π + x - x0) % (2 * π) - π) * (y0 + y);
5924 x1 = x0, x0 = x, y0 = y;
5925 }
5926 return area;
5927 }
5928 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate);
5929 function d3_geo_clipAntimeridianLine(listener) {
5930 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
5931 return {
5932 lineStart: function() {
5933 listener.lineStart();
5934 clean = 1;
5935 },
5936 point: function1, φ1) {
5937 var sλ1 = λ1 > 0 ? π : -π, dλ = Math.abs1 - λ0);
5938 if (Math.abs(dλ - π) < ε) {
5939 listener.point0, φ0 = 0 + φ1) / 2 > 0 ? π / 2 : / 2);
5940 listener.point(sλ0, φ0);
5941 listener.lineEnd();
5942 listener.lineStart();
5943 listener.point(sλ1, φ0);
5944 listener.point1, φ0);
5945 clean = 0;
5946 } else if (sλ0 !== sλ1 && dλ >= π) {
5947 if (Math.abs0 - sλ0) < ε) λ0 -= sλ0 * ε;
5948 if (Math.abs1 - sλ1) < ε) λ1 -= sλ1 * ε;
5949 φ0 = d3_geo_clipAntimeridianIntersect0, φ0, λ1, φ1);
5950 listener.point(sλ0, φ0);
5951 listener.lineEnd();
5952 listener.lineStart();
5953 listener.point(sλ1, φ0);
5954 clean = 0;
5955 }
5956 listener.point0 = λ1, φ0 = φ1);
5957 sλ0 = sλ1;
5958 },
5959 lineEnd: function() {
5960 listener.lineEnd();
5961 λ0 = φ0 = NaN;
5962 },
5963 clean: function() {
5964 return 2 - clean;
5965 }
5966 };
5967 }
5968 function d3_geo_clipAntimeridianIntersect0, φ0, λ1, φ1) {
5969 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin0 - λ1);
5970 return Math.abs(sinλ0_λ1) > ε ? Math.atan((Math.sin0) * (cosφ1 = Math.cos1)) * Math.sin1) - Math.sin1) * (cosφ0 = Math.cos0)) * Math.sin0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : 0 + φ1) / 2;
5971 }
5972 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
5973 var φ;
5974 if (from == null) {
5975 φ = direction * π / 2;
5976 listener.point(-π, φ);
5977 listener.point(0, φ);
5978 listener.point(π, φ);
5979 listener.point(π, 0);
5980 listener.point(π, -φ);
5981 listener.point(0, -φ);
5982 listener.point(-π, -φ);
5983 listener.point(-π, 0);
5984 listener.point(-π, φ);
5985 } else if (Math.abs(from[0] - to[0]) > ε) {
5986 var s = (from[0] < to[0] ? 1 : -1) * π;
5987 φ = direction * s / 2;
5988 listener.point(-s, φ);
5989 listener.point(0, φ);
5990 listener.point(s, φ);
5991 } else {
5992 listener.point(to[0], to[1]);
5993 }
5994 }
5995 function d3_geo_clipCircle(degrees) {
5996 var radians = degrees * d3_radians, cr = Math.cos(radians), interpolate = d3_geo_circleInterpolate(radians, 6 * d3_radians);
5997 return d3_geo_clip(visible, clipLine, interpolate);
5998 function visible(λ, φ) {
5999 return Math.cos(λ) * Math.cos(φ) > cr;
6000 }
6001 function clipLine(listener) {
6002 var point0, v0, v00, clean;
6003 return {
6004 lineStart: function() {
6005 v00 = v0 = false;
6006 clean = 1;
6007 },
6008 point: function(λ, φ) {
6009 var point1 = [ λ, φ ], point2, v = visible(λ, φ);
6010 if (!point0 && (v00 = v0 = v)) listener.lineStart();
6011 if (v !== v0) {
6012 point2 = intersect(point0, point1);
6013 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
6014 point1[0] += ε;
6015 point1[1] += ε;
6016 v = visible(point1[0], point1[1]);
6017 }
6018 }
6019 if (v !== v0) {
6020 clean = 0;
6021 if (v0 = v) {
6022 listener.lineStart();
6023 point2 = intersect(point1, point0);
6024 listener.point(point2[0], point2[1]);
6025 } else {
6026 point2 = intersect(point0, point1);
6027 listener.point(point2[0], point2[1]);
6028 listener.lineEnd();
6029 }
6030 point0 = point2;
6031 }
6032 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) listener.point(point1[0], point1[1]);
6033 point0 = point1;
6034 },
6035 lineEnd: function() {
6036 if (v0) listener.lineEnd();
6037 point0 = null;
6038 },
6039 clean: function() {
6040 return clean | (v00 && v0) << 1;
6041 }
6042 };
6043 }
6044 function intersect(a, b) {
6045 var pa = d3_geo_cartesian(a, 0), pb = d3_geo_cartesian(b, 0);
6046 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
6047 if (!determinant) return a;
6048 var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);
6049 d3_geo_cartesianAdd(A, B);
6050 var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t = Math.sqrt(w * w - uu * (d3_geo_cartesianDot(A, A) - 1)), q = d3_geo_cartesianScale(u, (-w - t) / uu);
6051 d3_geo_cartesianAdd(q, A);
6052 return d3_geo_spherical(q);
6053 }
6054 }
6055 function d3_geo_compose(a, b) {
6056 function compose(x, y) {
6057 return x = a(x, y), b(x[0], x[1]);
6058 }
6059 if (a.invert && b.invert) compose.invert = function(x, y) {
6060 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
6061 };
6062 return compose;
6063 }
6064 function d3_geo_equirectangular(λ, φ) {
6065 return [ λ, φ ];
6066 }
6067 (d3.geo.equirectangular = function() {
6068 return d3_geo_projection(d3_geo_equirectangular).scale(250 / π);
6069 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
6070 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
6071 return 1 / cosλcosφ;
6072 }, Math.atan);
6073 (d3.geo.gnomonic = function() {
6074 return d3_geo_projection(d3_geo_gnomonic);
6075 }).raw = d3_geo_gnomonic;
6076 d3.geo.graticule = function() {
6077 var x1, x0, y1, y0, dx = 22.5, dy = dx, x, y, precision = 2.5;
6078 function graticule() {
6079 return {
6080 type: "MultiLineString",
6081 coordinates: lines()
6082 };
6083 }
6084 function lines() {
6085 return d3.range(Math.ceil(x0 / dx) * dx, x1, dx).map(x).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).map(y));
6086 }
6087 graticule.lines = function() {
6088 return lines().map(function(coordinates) {
6089 return {
6090 type: "LineString",
6091 coordinates: coordinates
6092 };
6093 });
6094 };
6095 graticule.outline = function() {
6096 return {
6097 type: "Polygon",
6098 coordinates: [ x(x0).concat(y(y1).slice(1), x(x1).reverse().slice(1), y(y0).reverse().slice(1)) ]
6099 };
6100 };
6101 graticule.extent = function(_) {
6102 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
6103 x0 = +_[0][0], x1 = +_[1][0];
6104 y0 = +_[0][1], y1 = +_[1][1];
6105 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
6106 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
6107 return graticule.precision(precision);
6108 };
6109 graticule.step = function(_) {
6110 if (!arguments.length) return [ dx, dy ];
6111 dx = +_[0], dy = +_[1];
6112 return graticule;
6113 };
6114 graticule.precision = function(_) {
6115 if (!arguments.length) return precision;
6116 precision = +_;
6117 x = d3_geo_graticuleX(y0, y1, precision);
6118 y = d3_geo_graticuleY(x0, x1, precision);
6119 return graticule;
6120 };
6121 return graticule.extent([ [ -180 + ε, -90 + ε ], [ 180 - ε, 90 - ε ] ]);
6122 };
6123 function d3_geo_graticuleX(y0, y1, dy) {
6124 var y = d3.range(y0, y1 - ε, dy).concat(y1);
6125 return function(x) {
6126 return y.map(function(y) {
6127 return [ x, y ];
6128 });
6129 };
6130 }
6131 function d3_geo_graticuleY(x0, x1, dx) {
6132 var x = d3.range(x0, x1 - ε, dx).concat(x1);
6133 return function(y) {
6134 return x.map(function(x) {
6135 return [ x, y ];
6136 });
6137 };
6138 }
6139 function d3_geo_haversin(x) {
6140 return (x = Math.sin(x / 2)) * x;
6141 }
6142 d3.geo.interpolate = function(source, target) {
6143 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
6144 };
6145 function d3_geo_interpolate(x0, y0, x1, y1) {
6146 var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_geo_haversin(y1 - y0) + cy0 * cy1 * d3_geo_haversin(x1 - x0))), k = 1 / Math.sin(d);
6147 var interpolate = d ? function(t) {
6148 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;
6149 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
6150 } : function() {
6151 return [ x0 * d3_degrees, y0 * d3_degrees ];
6152 };
6153 interpolate.distance = d;
6154 return interpolate;
6155 }
6156 d3.geo.greatArc = function() {
6157 var source = d3_source, source_, target = d3_target, target_, precision = 6 * d3_radians, interpolate;
6158 function greatArc() {
6159 var p0 = source_ || source.apply(this, arguments), p1 = target_ || target.apply(this, arguments), i = interpolate || d3.geo.interpolate(p0, p1), t = 0, dt = precision / i.distance, coordinates = [ p0 ];
6160 while ((t += dt) < 1) coordinates.push(i(t));
6161 coordinates.push(p1);
6162 return {
6163 type: "LineString",
6164 coordinates: coordinates
6165 };
6166 }
6167 greatArc.distance = function() {
6168 return (interpolate || d3.geo.interpolate(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments))).distance;
6169 };
6170 greatArc.source = function(_) {
6171 if (!arguments.length) return source;
6172 source = _, source_ = typeof _ === "function" ? null : _;
6173 interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null;
6174 return greatArc;
6175 };
6176 greatArc.target = function(_) {
6177 if (!arguments.length) return target;
6178 target = _, target_ = typeof _ === "function" ? null : _;
6179 interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null;
6180 return greatArc;
6181 };
6182 greatArc.precision = function(_) {
6183 if (!arguments.length) return precision / d3_radians;
6184 precision = _ * d3_radians;
6185 return greatArc;
6186 };
6187 return greatArc;
6188 };
6189 function d3_geo_mercator(λ, φ) {
6190 return [ λ / (2 * π), Math.max(-.5, Math.min(+.5, Math.log(Math.tan / 4 + φ / 2)) / (2 * π))) ];
6191 }
6192 d3_geo_mercator.invert = function(x, y) {
6193 return [ 2 * π * x, 2 * Math.atan(Math.exp(2 * π * y)) - π / 2 ];
6194 };
6195 (d3.geo.mercator = function() {
6196 return d3_geo_projection(d3_geo_mercator).scale(500);
6197 }).raw = d3_geo_mercator;
6198 var d3_geo_orthographic = d3_geo_azimuthal(function() {
6199 return 1;
6200 }, Math.asin);
6201 (d3.geo.orthographic = function() {
6202 return d3_geo_projection(d3_geo_orthographic);
6203 }).raw = d3_geo_orthographic;
6204 d3.geo.path = function() {
6205 var pointRadius = 4.5, projection, context, projectStream, contextStream;
6206 function path(object) {
6207 if (object) d3.geo.stream(object, projectStream(contextStream.pointRadius(typeof pointRadius === "function" ? +pointRadius.apply(this, arguments) : pointRadius)));
6208 return contextStream.result();
6209 }
6210 path.area = function(object) {
6211 d3_geo_pathAreaSum = 0;
6212 d3.geo.stream(object, projectStream(d3_geo_pathArea));
6213 return d3_geo_pathAreaSum;
6214 };
6215 path.centroid = function(object) {
6216 d3_geo_centroidDimension = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
6217 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
6218 return d3_geo_centroidZ ? [ d3_geo_centroidX / d3_geo_centroidZ, d3_geo_centroidY / d3_geo_centroidZ ] : undefined;
6219 };
6220 path.bounds = function(object) {
6221 return d3_geo_bounds(projectStream)(object);
6222 };
6223 path.projection = function(_) {
6224 if (!arguments.length) return projection;
6225 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
6226 return path;
6227 };
6228 path.context = function(_) {
6229 if (!arguments.length) return context;
6230 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
6231 return path;
6232 };
6233 path.pointRadius = function(_) {
6234 if (!arguments.length) return pointRadius;
6235 pointRadius = typeof _ === "function" ? _ : +_;
6236 return path;
6237 };
6238 return path.projection(d3.geo.albersUsa()).context(null);
6239 };
6240 function d3_geo_pathCircle(radius) {
6241 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
6242 }
6243 function d3_geo_pathProjectStream(project) {
6244 var resample = d3_geo_resample(function(λ, φ) {
6245 return project([ λ * d3_degrees, φ * d3_degrees ]);
6246 });
6247 return function(stream) {
6248 stream = resample(stream);
6249 return {
6250 point: function(λ, φ) {
6251 stream.point * d3_radians, φ * d3_radians);
6252 },
6253 sphere: function() {
6254 stream.sphere();
6255 },
6256 lineStart: function() {
6257 stream.lineStart();
6258 },
6259 lineEnd: function() {
6260 stream.lineEnd();
6261 },
6262 polygonStart: function() {
6263 stream.polygonStart();
6264 },
6265 polygonEnd: function() {
6266 stream.polygonEnd();
6267 }
6268 };
6269 };
6270 }
6271 function d3_geo_pathBuffer() {
6272 var pointCircle = d3_geo_pathCircle(4.5), buffer = [];
6273 var stream = {
6274 point: point,
6275 lineStart: function() {
6276 stream.point = pointLineStart;
6277 },
6278 lineEnd: lineEnd,
6279 polygonStart: function() {
6280 stream.lineEnd = lineEndPolygon;
6281 },
6282 polygonEnd: function() {
6283 stream.lineEnd = lineEnd;
6284 stream.point = point;
6285 },
6286 pointRadius: function(_) {
6287 pointCircle = d3_geo_pathCircle(_);
6288 return stream;
6289 },
6290 result: function() {
6291 if (buffer.length) {
6292 var result = buffer.join("");
6293 buffer = [];
6294 return result;
6295 }
6296 }
6297 };
6298 function point(x, y) {
6299 buffer.push("M", x, ",", y, pointCircle);
6300 }
6301 function pointLineStart(x, y) {
6302 buffer.push("M", x, ",", y);
6303 stream.point = pointLine;
6304 }
6305 function pointLine(x, y) {
6306 buffer.push("L", x, ",", y);
6307 }
6308 function lineEnd() {
6309 stream.point = point;
6310 }
6311 function lineEndPolygon() {
6312 buffer.push("Z");
6313 }
6314 return stream;
6315 }
6316 function d3_geo_pathContext(context) {
6317 var pointRadius = 4.5;
6318 var stream = {
6319 point: point,
6320 lineStart: function() {
6321 stream.point = pointLineStart;
6322 },
6323 lineEnd: lineEnd,
6324 polygonStart: function() {
6325 stream.lineEnd = lineEndPolygon;
6326 },
6327 polygonEnd: function() {
6328 stream.lineEnd = lineEnd;
6329 stream.point = point;
6330 },
6331 pointRadius: function(_) {
6332 pointRadius = _;
6333 return stream;
6334 },
6335 result: d3_noop
6336 };
6337 function point(x, y) {
6338 context.moveTo(x, y);
6339 context.arc(x, y, pointRadius, 0, 2 * π);
6340 }
6341 function pointLineStart(x, y) {
6342 context.moveTo(x, y);
6343 stream.point = pointLine;
6344 }
6345 function pointLine(x, y) {
6346 context.lineTo(x, y);
6347 }
6348 function lineEnd() {
6349 stream.point = point;
6350 }
6351 function lineEndPolygon() {
6352 context.closePath();
6353 }
6354 return stream;
6355 }
6356 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
6357 point: d3_noop,
6358 lineStart: d3_noop,
6359 lineEnd: d3_noop,
6360 polygonStart: function() {
6361 d3_geo_pathAreaPolygon = 0;
6362 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
6363 },
6364 polygonEnd: function() {
6365 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
6366 d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
6367 }
6368 };
6369 function d3_geo_pathAreaRingStart() {
6370 var x00, y00, x0, y0;
6371 d3_geo_pathArea.point = function(x, y) {
6372 d3_geo_pathArea.point = nextPoint;
6373 x00 = x0 = x, y00 = y0 = y;
6374 };
6375 function nextPoint(x, y) {
6376 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
6377 x0 = x, y0 = y;
6378 }
6379 d3_geo_pathArea.lineEnd = function() {
6380 nextPoint(x00, y00);
6381 };
6382 }
6383 var d3_geo_pathCentroid = {
6384 point: d3_geo_pathCentroidPoint,
6385 lineStart: d3_geo_pathCentroidLineStart,
6386 lineEnd: d3_geo_pathCentroidLineEnd,
6387 polygonStart: function() {
6388 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
6389 },
6390 polygonEnd: function() {
6391 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
6392 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
6393 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
6394 }
6395 };
6396 function d3_geo_pathCentroidPoint(x, y) {
6397 if (d3_geo_centroidDimension) return;
6398 d3_geo_centroidX += x;
6399 d3_geo_centroidY += y;
6400 ++d3_geo_centroidZ;
6401 }
6402 function d3_geo_pathCentroidLineStart() {
6403 var x0, y0;
6404 if (d3_geo_centroidDimension !== 1) {
6405 if (d3_geo_centroidDimension < 1) {
6406 d3_geo_centroidDimension = 1;
6407 d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
6408 } else return;
6409 }
6410 d3_geo_pathCentroid.point = function(x, y) {
6411 d3_geo_pathCentroid.point = nextPoint;
6412 x0 = x, y0 = y;
6413 };
6414 function nextPoint(x, y) {
6415 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
6416 d3_geo_centroidX += z * (x0 + x) / 2;
6417 d3_geo_centroidY += z * (y0 + y) / 2;
6418 d3_geo_centroidZ += z;
6419 x0 = x, y0 = y;
6420 }
6421 }
6422 function d3_geo_pathCentroidLineEnd() {
6423 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
6424 }
6425 function d3_geo_pathCentroidRingStart() {
6426 var x00, y00, x0, y0;
6427 if (d3_geo_centroidDimension < 2) {
6428 d3_geo_centroidDimension = 2;
6429 d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
6430 }
6431 d3_geo_pathCentroid.point = function(x, y) {
6432 d3_geo_pathCentroid.point = nextPoint;
6433 x00 = x0 = x, y00 = y0 = y;
6434 };
6435 function nextPoint(x, y) {
6436 var z = y0 * x - x0 * y;
6437 d3_geo_centroidX += z * (x0 + x);
6438 d3_geo_centroidY += z * (y0 + y);
6439 d3_geo_centroidZ += z * 3;
6440 x0 = x, y0 = y;
6441 }
6442 d3_geo_pathCentroid.lineEnd = function() {
6443 nextPoint(x00, y00);
6444 };
6445 }
6446 d3.geo.area = function(object) {
6447 d3_geo_areaSum = 0;
6448 d3.geo.stream(object, d3_geo_area);
6449 return d3_geo_areaSum;
6450 };
6451 var d3_geo_areaSum, d3_geo_areaRingU, d3_geo_areaRingV;
6452 var d3_geo_area = {
6453 sphere: function() {
6454 d3_geo_areaSum += 4 * π;
6455 },
6456 point: d3_noop,
6457 lineStart: d3_noop,
6458 lineEnd: d3_noop,
6459 polygonStart: function() {
6460 d3_geo_areaRingU = 1, d3_geo_areaRingV = 0;
6461 d3_geo_area.lineStart = d3_geo_areaRingStart;
6462 },
6463 polygonEnd: function() {
6464 var area = 2 * Math.atan2(d3_geo_areaRingV, d3_geo_areaRingU);
6465 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
6466 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
6467 }
6468 };
6469 function d3_geo_areaRingStart() {
6470 var λ00, φ00, λ0, cosφ0, sinφ0;
6471 d3_geo_area.point = function(λ, φ) {
6472 d3_geo_area.point = nextPoint;
6473 λ0 = 00 = λ) * d3_radians, cosφ0 = Math.cos = 00 = φ) * d3_radians / 2 + π / 4),
6474 sinφ0 = Math.sin(φ);
6475 };
6476 function nextPoint(λ, φ) {
6477 λ *= d3_radians;
6478 φ = φ * d3_radians / 2 + π / 4;
6479 var dλ = λ - λ0, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u0 = d3_geo_areaRingU, v0 = d3_geo_areaRingV, u = cosφ0 * cosφ + k * Math.cos(dλ), v = k * Math.sin(dλ);
6480 d3_geo_areaRingU = u0 * u - v0 * v;
6481 d3_geo_areaRingV = v0 * u + u0 * v;
6482 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
6483 }
6484 d3_geo_area.lineEnd = function() {
6485 nextPoint00, φ00);
6486 };
6487 }
6488 d3.geo.projection = d3_geo_projection;
6489 d3.geo.projectionMutator = d3_geo_projectionMutator;
6490 function d3_geo_projection(project) {
6491 return d3_geo_projectionMutator(function() {
6492 return project;
6493 })();
6494 }
6495 function d3_geo_projectionMutator(projectAt) {
6496 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
6497 x = project(x, y);
6498 return [ x[0] * k + δx, δy - x[1] * k ];
6499 }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, clip = d3_geo_clipAntimeridian, clipAngle = null;
6500 function projection(point) {
6501 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
6502 return [ point[0] * k + δx, δy - point[1] * k ];
6503 }
6504 function invert(point) {
6505 point = projectRotate.invert((point[0] - δx) / k, y - point[1]) / k);
6506 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
6507 }
6508 projection.stream = function(stream) {
6509 return d3_geo_projectionRadiansRotate(rotate, clip(projectResample(stream)));
6510 };
6511 projection.clipAngle = function(_) {
6512 if (!arguments.length) return clipAngle;
6513 clip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle(clipAngle = +_);
6514 return projection;
6515 };
6516 projection.scale = function(_) {
6517 if (!arguments.length) return k;
6518 k = +_;
6519 return reset();
6520 };
6521 projection.translate = function(_) {
6522 if (!arguments.length) return [ x, y ];
6523 x = +_[0];
6524 y = +_[1];
6525 return reset();
6526 };
6527 projection.center = function(_) {
6528 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
6529 λ = _[0] % 360 * d3_radians;
6530 φ = _[1] % 360 * d3_radians;
6531 return reset();
6532 };
6533 projection.rotate = function(_) {
6534 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
6535 δλ = _[0] % 360 * d3_radians;
6536 δφ = _[1] % 360 * d3_radians;
6537 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
6538 return reset();
6539 };
6540 d3.rebind(projection, projectResample, "precision");
6541 function reset() {
6542 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
6543 var center = project(λ, φ);
6544 δx = x - center[0] * k;
6545 δy = y + center[1] * k;
6546 return projection;
6547 }
6548 return function() {
6549 project = projectAt.apply(this, arguments);
6550 projection.invert = project.invert && invert;
6551 return reset();
6552 };
6553 }
6554 function d3_geo_projectionRadiansRotate(rotate, stream) {
6555 return {
6556 point: function(x, y) {
6557 y = rotate(x * d3_radians, y * d3_radians), x = y[0];
6558 stream.point(x > π ? x - 2 * π : x < ? x + 2 * π : x, y[1]);
6559 },
6560 sphere: function() {
6561 stream.sphere();
6562 },
6563 lineStart: function() {
6564 stream.lineStart();
6565 },
6566 lineEnd: function() {
6567 stream.lineEnd();
6568 },
6569 polygonStart: function() {
6570 stream.polygonStart();
6571 },
6572 polygonEnd: function() {
6573 stream.polygonEnd();
6574 }
6575 };
6576 }
6577 function d3_geo_rotation(δλ, δφ, δγ) {
6578 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_equirectangular;
6579 }
6580 function d3_geo_forwardRotationλ(δλ) {
6581 return function(λ, φ) {
6582 return λ += δλ, [ λ > π ? λ - 2 * π : λ < ? λ + 2 * π : λ, φ ];
6583 };
6584 }
6585 function d3_geo_rotationλ(δλ) {
6586 var rotation = d3_geo_forwardRotationλ(δλ);
6587 rotation.invert = d3_geo_forwardRotationλ(-δλ);
6588 return rotation;
6589 }
6590 function d3_geo_rotationφγ(δφ, δγ) {
6591 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
6592 function rotation(λ, φ) {
6593 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
6594 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδγ + y * sinδγ))) ];
6595 }
6596 rotation.invert = function(λ, φ) {
6597 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
6598 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδφ - x * sinδφ))) ];
6599 };
6600 return rotation;
6601 }
6602 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
6603 return 1 / (1 + cosλcosφ);
6604 }, function(ρ) {
6605 return 2 * Math.atan(ρ);
6606 });
6607 (d3.geo.stereographic = function() {
6608 return d3_geo_projection(d3_geo_stereographic);
6609 }).raw = d3_geo_stereographic;
6610 function d3_geo_azimuthal(scale, angle) {
6611 function azimuthal(λ, φ) {
6612 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
6613 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
6614 }
6615 azimuthal.invert = function(x, y) {
6616 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
6617 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin && y * sinc / ρ) ];
6618 };
6619 return azimuthal;
6620 }
6621 d3.geom = {};
6622 d3.geom.hull = function(vertices) {
6623 if (vertices.length < 3) return [];
6624 var len = vertices.length, plen = len - 1, points = [], stack = [], i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
6625 for (i = 1; i < len; ++i) {
6626 if (vertices[i][1] < vertices[h][1]) {
6627 h = i;
6628 } else if (vertices[i][1] == vertices[h][1]) {
6629 h = vertices[i][0] < vertices[h][0] ? i : h;
6630 }
6631 }
6632 for (i = 0; i < len; ++i) {
6633 if (i === h) continue;
6634 y1 = vertices[i][1] - vertices[h][1];
6635 x1 = vertices[i][0] - vertices[h][0];
6636 points.push({
6637 angle: Math.atan2(y1, x1),
6638 index: i
6639 });
6640 }
6641 points.sort(function(a, b) {
6642 return a.angle - b.angle;
6643 });
6644 a = points[0].angle;
6645 v = points[0].index;
6646 u = 0;
6647 for (i = 1; i < plen; ++i) {
6648 j = points[i].index;
6649 if (a == points[i].angle) {
6650 x1 = vertices[v][0] - vertices[h][0];
6651 y1 = vertices[v][1] - vertices[h][1];
6652 x2 = vertices[j][0] - vertices[h][0];
6653 y2 = vertices[j][1] - vertices[h][1];
6654 if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
6655 points[i].index = -1;
6656 } else {
6657 points[u].index = -1;
6658 a = points[i].angle;
6659 u = i;
6660 v = j;
6661 }
6662 } else {
6663 a = points[i].angle;
6664 u = i;
6665 v = j;
6666 }
6667 }
6668 stack.push(h);
6669 for (i = 0, j = 0; i < 2; ++j) {
6670 if (points[j].index !== -1) {
6671 stack.push(points[j].index);
6672 i++;
6673 }
6674 }
6675 sp = stack.length;
6676 for (;j < plen; ++j) {
6677 if (points[j].index === -1) continue;
6678 while (!d3_geom_hullCCW(stack[sp - 2], stack[sp - 1], points[j].index, vertices)) {
6679 --sp;
6680 }
6681 stack[sp++] = points[j].index;
6682 }
6683 var poly = [];
6684 for (i = 0; i < sp; ++i) {
6685 poly.push(vertices[stack[i]]);
6686 }
6687 return poly;
6688 };
6689 function d3_geom_hullCCW(i1, i2, i3, v) {
6690 var t, a, b, c, d, e, f;
6691 t = v[i1];
6692 a = t[0];
6693 b = t[1];
6694 t = v[i2];
6695 c = t[0];
6696 d = t[1];
6697 t = v[i3];
6698 e = t[0];
6699 f = t[1];
6700 return (f - b) * (c - a) - (d - b) * (e - a) > 0;
6701 }
6702 d3.geom.polygon = function(coordinates) {
6703 coordinates.area = function() {
6704 var i = 0, n = coordinates.length, area = coordinates[n - 1][1] * coordinates[0][0] - coordinates[n - 1][0] * coordinates[0][1];
6705 while (++i < n) {
6706 area += coordinates[i - 1][1] * coordinates[i][0] - coordinates[i - 1][0] * coordinates[i][1];
6707 }
6708 return area * .5;
6709 };
6710 coordinates.centroid = function(k) {
6711 var i = -1, n = coordinates.length, x = 0, y = 0, a, b = coordinates[n - 1], c;
6712 if (!arguments.length) k = -1 / (6 * coordinates.area());
6713 while (++i < n) {
6714 a = b;
6715 b = coordinates[i];
6716 c = a[0] * b[1] - b[0] * a[1];
6717 x += (a[0] + b[0]) * c;
6718 y += (a[1] + b[1]) * c;
6719 }
6720 return [ x * k, y * k ];
6721 };
6722 coordinates.clip = function(subject) {
6723 var input, i = -1, n = coordinates.length, j, m, a = coordinates[n - 1], b, c, d;
6724 while (++i < n) {
6725 input = subject.slice();
6726 subject.length = 0;
6727 b = coordinates[i];
6728 c = input[(m = input.length) - 1];
6729 j = -1;
6730 while (++j < m) {
6731 d = input[j];
6732 if (d3_geom_polygonInside(d, a, b)) {
6733 if (!d3_geom_polygonInside(c, a, b)) {
6734 subject.push(d3_geom_polygonIntersect(c, d, a, b));
6735 }
6736 subject.push(d);
6737 } else if (d3_geom_polygonInside(c, a, b)) {
6738 subject.push(d3_geom_polygonIntersect(c, d, a, b));
6739 }
6740 c = d;
6741 }
6742 a = b;
6743 }
6744 return subject;
6745 };
6746 return coordinates;
6747 };
6748 function d3_geom_polygonInside(p, a, b) {
6749 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
6750 }
6751 function d3_geom_polygonIntersect(c, d, a, b) {
6752 var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);
6753 return [ x1 + ua * x21, y1 + ua * y21 ];
6754 }
6755 d3.geom.voronoi = function(vertices) {
6756 var polygons = vertices.map(function() {
6757 return [];
6758 }), Z = 1e6;
6759 d3_voronoi_tessellate(vertices, function(e) {
6760 var s1, s2, x1, x2, y1, y2;
6761 if (e.a === 1 && e.b >= 0) {
6762 s1 = e.ep.r;
6763 s2 = e.ep.l;
6764 } else {
6765 s1 = e.ep.l;
6766 s2 = e.ep.r;
6767 }
6768 if (e.a === 1) {
6769 y1 = s1 ? s1.y : -Z;
6770 x1 = e.c - e.b * y1;
6771 y2 = s2 ? s2.y : Z;
6772 x2 = e.c - e.b * y2;
6773 } else {
6774 x1 = s1 ? s1.x : -Z;
6775 y1 = e.c - e.a * x1;
6776 x2 = s2 ? s2.x : Z;
6777 y2 = e.c - e.a * x2;
6778 }
6779 var v1 = [ x1, y1 ], v2 = [ x2, y2 ];
6780 polygons[e.region.l.index].push(v1, v2);
6781 polygons[e.region.r.index].push(v1, v2);
6782 });
6783 polygons = polygons.map(function(polygon, i) {
6784 var cx = vertices[i][0], cy = vertices[i][1], angle = polygon.map(function(v) {
6785 return Math.atan2(v[0] - cx, v[1] - cy);
6786 }), order = d3.range(polygon.length).sort(function(a, b) {
6787 return angle[a] - angle[b];
6788 });
6789 return order.filter(function(d, i) {
6790 return !i || angle[d] - angle[order[i - 1]] > ε;
6791 }).map(function(d) {
6792 return polygon[d];
6793 });
6794 });
6795 polygons.forEach(function(polygon, i) {
6796 var n = polygon.length;
6797 if (!n) return polygon.push([ -Z, -Z ], [ -Z, Z ], [ Z, Z ], [ Z, -Z ]);
6798 if (n > 2) return;
6799 var p0 = vertices[i], p1 = polygon[0], p2 = polygon[1], x0 = p0[0], y0 = p0[1], x1 = p1[0], y1 = p1[1], x2 = p2[0], y2 = p2[1], dx = Math.abs(x2 - x1), dy = y2 - y1;
6800 if (Math.abs(dy) < ε) {
6801 var y = y0 < y1 ? -Z : Z;
6802 polygon.push([ -Z, y ], [ Z, y ]);
6803 } else if (dx < ε) {
6804 var x = x0 < x1 ? -Z : Z;
6805 polygon.push([ x, -Z ], [ x, Z ]);
6806 } else {
6807 var y = (x2 - x1) * (y1 - y0) < (x1 - x0) * (y2 - y1) ? Z : -Z, z = Math.abs(dy) - dx;
6808 if (Math.abs(z) < ε) {
6809 polygon.push([ dy < 0 ? y : -y, y ]);
6810 } else {
6811 if (z > 0) y *= -1;
6812 polygon.push([ -Z, y ], [ Z, y ]);
6813 }
6814 }
6815 });
6816 return polygons;
6817 };
6818 var d3_voronoi_opposite = {
6819 l: "r",
6820 r: "l"
6821 };
6822 function d3_voronoi_tessellate(vertices, callback) {
6823 var Sites = {
6824 list: vertices.map(function(v, i) {
6825 return {
6826 index: i,
6827 x: v[0],
6828 y: v[1]
6829 };
6830 }).sort(function(a, b) {
6831 return a.y < b.y ? -1 : a.y > b.y ? 1 : a.x < b.x ? -1 : a.x > b.x ? 1 : 0;
6832 }),
6833 bottomSite: null
6834 };
6835 var EdgeList = {
6836 list: [],
6837 leftEnd: null,
6838 rightEnd: null,
6839 init: function() {
6840 EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
6841 EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
6842 EdgeList.leftEnd.r = EdgeList.rightEnd;
6843 EdgeList.rightEnd.l = EdgeList.leftEnd;
6844 EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
6845 },
6846 createHalfEdge: function(edge, side) {
6847 return {
6848 edge: edge,
6849 side: side,
6850 vertex: null,
6851 l: null,
6852 r: null
6853 };
6854 },
6855 insert: function(lb, he) {
6856 he.l = lb;
6857 he.r = lb.r;
6858 lb.r.l = he;
6859 lb.r = he;
6860 },
6861 leftBound: function(p) {
6862 var he = EdgeList.leftEnd;
6863 do {
6864 he = he.r;
6865 } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
6866 he = he.l;
6867 return he;
6868 },
6869 del: function(he) {
6870 he.l.r = he.r;
6871 he.r.l = he.l;
6872 he.edge = null;
6873 },
6874 right: function(he) {
6875 return he.r;
6876 },
6877 left: function(he) {
6878 return he.l;
6879 },
6880 leftRegion: function(he) {
6881 return he.edge == null ? Sites.bottomSite : he.edge.region[he.side];
6882 },
6883 rightRegion: function(he) {
6884 return he.edge == null ? Sites.bottomSite : he.edge.region[d3_voronoi_opposite[he.side]];
6885 }
6886 };
6887 var Geom = {
6888 bisect: function(s1, s2) {
6889 var newEdge = {
6890 region: {
6891 l: s1,
6892 r: s2
6893 },
6894 ep: {
6895 l: null,
6896 r: null
6897 }
6898 };
6899 var dx = s2.x - s1.x, dy = s2.y - s1.y, adx = dx > 0 ? dx : -dx, ady = dy > 0 ? dy : -dy;
6900 newEdge.c = s1.x * dx + s1.y * dy + (dx * dx + dy * dy) * .5;
6901 if (adx > ady) {
6902 newEdge.a = 1;
6903 newEdge.b = dy / dx;
6904 newEdge.c /= dx;
6905 } else {
6906 newEdge.b = 1;
6907 newEdge.a = dx / dy;
6908 newEdge.c /= dy;
6909 }
6910 return newEdge;
6911 },
6912 intersect: function(el1, el2) {
6913 var e1 = el1.edge, e2 = el2.edge;
6914 if (!e1 || !e2 || e1.region.r == e2.region.r) {
6915 return null;
6916 }
6917 var d = e1.a * e2.b - e1.b * e2.a;
6918 if (Math.abs(d) < 1e-10) {
6919 return null;
6920 }
6921 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;
6922 if (e1r.y < e2r.y || e1r.y == e2r.y && e1r.x < e2r.x) {
6923 el = el1;
6924 e = e1;
6925 } else {
6926 el = el2;
6927 e = e2;
6928 }
6929 var rightOfSite = xint >= e.region.r.x;
6930 if (rightOfSite && el.side === "l" || !rightOfSite && el.side === "r") {
6931 return null;
6932 }
6933 return {
6934 x: xint,
6935 y: yint
6936 };
6937 },
6938 rightOf: function(he, p) {
6939 var e = he.edge, topsite = e.region.r, rightOfSite = p.x > topsite.x;
6940 if (rightOfSite && he.side === "l") {
6941 return 1;
6942 }
6943 if (!rightOfSite && he.side === "r") {
6944 return 0;
6945 }
6946 if (e.a === 1) {
6947 var dyp = p.y - topsite.y, dxp = p.x - topsite.x, fast = 0, above = 0;
6948 if (!rightOfSite && e.b < 0 || rightOfSite && e.b >= 0) {
6949 above = fast = dyp >= e.b * dxp;
6950 } else {
6951 above = p.x + p.y * e.b > e.c;
6952 if (e.b < 0) {
6953 above = !above;
6954 }
6955 if (!above) {
6956 fast = 1;
6957 }
6958 }
6959 if (!fast) {
6960 var dxs = topsite.x - e.region.l.x;
6961 above = e.b * (dxp * dxp - dyp * dyp) < dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b);
6962 if (e.b < 0) {
6963 above = !above;
6964 }
6965 }
6966 } else {
6967 var yl = e.c - e.a * p.x, t1 = p.y - yl, t2 = p.x - topsite.x, t3 = yl - topsite.y;
6968 above = t1 * t1 > t2 * t2 + t3 * t3;
6969 }
6970 return he.side === "l" ? above : !above;
6971 },
6972 endPoint: function(edge, side, site) {
6973 edge.ep[side] = site;
6974 if (!edge.ep[d3_voronoi_opposite[side]]) return;
6975 callback(edge);
6976 },
6977 distance: function(s, t) {
6978 var dx = s.x - t.x, dy = s.y - t.y;
6979 return Math.sqrt(dx * dx + dy * dy);
6980 }
6981 };
6982 var EventQueue = {
6983 list: [],
6984 insert: function(he, site, offset) {
6985 he.vertex = site;
6986 he.ystar = site.y + offset;
6987 for (var i = 0, list = EventQueue.list, l = list.length; i < l; i++) {
6988 var next = list[i];
6989 if (he.ystar > next.ystar || he.ystar == next.ystar && site.x > next.vertex.x) {
6990 continue;
6991 } else {
6992 break;
6993 }
6994 }
6995 list.splice(i, 0, he);
6996 },
6997 del: function(he) {
6998 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l && ls[i] != he; ++i) {}
6999 ls.splice(i, 1);
7000 },
7001 empty: function() {
7002 return EventQueue.list.length === 0;
7003 },
7004 nextEvent: function(he) {
7005 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l; ++i) {
7006 if (ls[i] == he) return ls[i + 1];
7007 }
7008 return null;
7009 },
7010 min: function() {
7011 var elem = EventQueue.list[0];
7012 return {
7013 x: elem.vertex.x,
7014 y: elem.ystar
7015 };
7016 },
7017 extractMin: function() {
7018 return EventQueue.list.shift();
7019 }
7020 };
7021 EdgeList.init();
7022 Sites.bottomSite = Sites.list.shift();
7023 var newSite = Sites.list.shift(), newIntStar;
7024 var lbnd, rbnd, llbnd, rrbnd, bisector;
7025 var bot, top, temp, p, v;
7026 var e, pm;
7027 while (true) {
7028 if (!EventQueue.empty()) {
7029 newIntStar = EventQueue.min();
7030 }
7031 if (newSite && (EventQueue.empty() || newSite.y < newIntStar.y || newSite.y == newIntStar.y && newSite.x < newIntStar.x)) {
7032 lbnd = EdgeList.leftBound(newSite);
7033 rbnd = EdgeList.right(lbnd);
7034 bot = EdgeList.rightRegion(lbnd);
7035 e = Geom.bisect(bot, newSite);
7036 bisector = EdgeList.createHalfEdge(e, "l");
7037 EdgeList.insert(lbnd, bisector);
7038 p = Geom.intersect(lbnd, bisector);
7039 if (p) {
7040 EventQueue.del(lbnd);
7041 EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
7042 }
7043 lbnd = bisector;
7044 bisector = EdgeList.createHalfEdge(e, "r");
7045 EdgeList.insert(lbnd, bisector);
7046 p = Geom.intersect(bisector, rbnd);
7047 if (p) {
7048 EventQueue.insert(bisector, p, Geom.distance(p, newSite));
7049 }
7050 newSite = Sites.list.shift();
7051 } else if (!EventQueue.empty()) {
7052 lbnd = EventQueue.extractMin();
7053 llbnd = EdgeList.left(lbnd);
7054 rbnd = EdgeList.right(lbnd);
7055 rrbnd = EdgeList.right(rbnd);
7056 bot = EdgeList.leftRegion(lbnd);
7057 top = EdgeList.rightRegion(rbnd);
7058 v = lbnd.vertex;
7059 Geom.endPoint(lbnd.edge, lbnd.side, v);
7060 Geom.endPoint(rbnd.edge, rbnd.side, v);
7061 EdgeList.del(lbnd);
7062 EventQueue.del(rbnd);
7063 EdgeList.del(rbnd);
7064 pm = "l";
7065 if (bot.y > top.y) {
7066 temp = bot;
7067 bot = top;
7068 top = temp;
7069 pm = "r";
7070 }
7071 e = Geom.bisect(bot, top);
7072 bisector = EdgeList.createHalfEdge(e, pm);
7073 EdgeList.insert(llbnd, bisector);
7074 Geom.endPoint(e, d3_voronoi_opposite[pm], v);
7075 p = Geom.intersect(llbnd, bisector);
7076 if (p) {
7077 EventQueue.del(llbnd);
7078 EventQueue.insert(llbnd, p, Geom.distance(p, bot));
7079 }
7080 p = Geom.intersect(bisector, rrbnd);
7081 if (p) {
7082 EventQueue.insert(bisector, p, Geom.distance(p, bot));
7083 }
7084 } else {
7085 break;
7086 }
7087 }
7088 for (lbnd = EdgeList.right(EdgeList.leftEnd); lbnd != EdgeList.rightEnd; lbnd = EdgeList.right(lbnd)) {
7089 callback(lbnd.edge);
7090 }
7091 }
7092 d3.geom.delaunay = function(vertices) {
7093 var edges = vertices.map(function() {
7094 return [];
7095 }), triangles = [];
7096 d3_voronoi_tessellate(vertices, function(e) {
7097 edges[e.region.l.index].push(vertices[e.region.r.index]);
7098 });
7099 edges.forEach(function(edge, i) {
7100 var v = vertices[i], cx = v[0], cy = v[1];
7101 edge.forEach(function(v) {
7102 v.angle = Math.atan2(v[0] - cx, v[1] - cy);
7103 });
7104 edge.sort(function(a, b) {
7105 return a.angle - b.angle;
7106 });
7107 for (var j = 0, m = edge.length - 1; j < m; j++) {
7108 triangles.push([ v, edge[j], edge[j + 1] ]);
7109 }
7110 });
7111 return triangles;
7112 };
7113 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
7114 var p, i = -1, n = points.length;
7115 if (arguments.length < 5) {
7116 if (arguments.length === 3) {
7117 y2 = y1;
7118 x2 = x1;
7119 y1 = x1 = 0;
7120 } else {
7121 x1 = y1 = Infinity;
7122 x2 = y2 = -Infinity;
7123 while (++i < n) {
7124 p = points[i];
7125 if (p.x < x1) x1 = p.x;
7126 if (p.y < y1) y1 = p.y;
7127 if (p.x > x2) x2 = p.x;
7128 if (p.y > y2) y2 = p.y;
7129 }
7130 }
7131 }
7132 var dx = x2 - x1, dy = y2 - y1;
7133 if (dx > dy) y2 = y1 + dx; else x2 = x1 + dy;
7134 function insert(n, p, x1, y1, x2, y2) {
7135 if (isNaN(p.x) || isNaN(p.y)) return;
7136 if (n.leaf) {
7137 var v = n.point;
7138 if (v) {
7139 if (Math.abs(v.x - p.x) + Math.abs(v.y - p.y) < .01) {
7140 insertChild(n, p, x1, y1, x2, y2);
7141 } else {
7142 n.point = null;
7143 insertChild(n, v, x1, y1, x2, y2);
7144 insertChild(n, p, x1, y1, x2, y2);
7145 }
7146 } else {
7147 n.point = p;
7148 }
7149 } else {
7150 insertChild(n, p, x1, y1, x2, y2);
7151 }
7152 }
7153 function insertChild(n, p, x1, y1, x2, y2) {
7154 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = p.x >= sx, bottom = p.y >= sy, i = (bottom << 1) + right;
7155 n.leaf = false;
7156 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
7157 if (right) x1 = sx; else x2 = sx;
7158 if (bottom) y1 = sy; else y2 = sy;
7159 insert(n, p, x1, y1, x2, y2);
7160 }
7161 var root = d3_geom_quadtreeNode();
7162 root.add = function(p) {
7163 insert(root, p, x1, y1, x2, y2);
7164 };
7165 root.visit = function(f) {
7166 d3_geom_quadtreeVisit(f, root, x1, y1, x2, y2);
7167 };
7168 points.forEach(root.add);
7169 return root;
7170 };
7171 function d3_geom_quadtreeNode() {
7172 return {
7173 leaf: true,
7174 nodes: [],
7175 point: null
7176 };
7177 }
7178 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
7179 if (!f(node, x1, y1, x2, y2)) {
7180 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
7181 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
7182 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
7183 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
7184 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
7185 }
7186 }
7187 d3.time = {};
7188 var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
7189 function d3_time_utc() {
7190 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
7191 }
7192 d3_time_utc.prototype = {
7193 getDate: function() {
7194 return this._.getUTCDate();
7195 },
7196 getDay: function() {
7197 return this._.getUTCDay();
7198 },
7199 getFullYear: function() {
7200 return this._.getUTCFullYear();
7201 },
7202 getHours: function() {
7203 return this._.getUTCHours();
7204 },
7205 getMilliseconds: function() {
7206 return this._.getUTCMilliseconds();
7207 },
7208 getMinutes: function() {
7209 return this._.getUTCMinutes();
7210 },
7211 getMonth: function() {
7212 return this._.getUTCMonth();
7213 },
7214 getSeconds: function() {
7215 return this._.getUTCSeconds();
7216 },
7217 getTime: function() {
7218 return this._.getTime();
7219 },
7220 getTimezoneOffset: function() {
7221 return 0;
7222 },
7223 valueOf: function() {
7224 return this._.valueOf();
7225 },
7226 setDate: function() {
7227 d3_time_prototype.setUTCDate.apply(this._, arguments);
7228 },
7229 setDay: function() {
7230 d3_time_prototype.setUTCDay.apply(this._, arguments);
7231 },
7232 setFullYear: function() {
7233 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
7234 },
7235 setHours: function() {
7236 d3_time_prototype.setUTCHours.apply(this._, arguments);
7237 },
7238 setMilliseconds: function() {
7239 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
7240 },
7241 setMinutes: function() {
7242 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
7243 },
7244 setMonth: function() {
7245 d3_time_prototype.setUTCMonth.apply(this._, arguments);
7246 },
7247 setSeconds: function() {
7248 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
7249 },
7250 setTime: function() {
7251 d3_time_prototype.setTime.apply(this._, arguments);
7252 }
7253 };
7254 var d3_time_prototype = Date.prototype;
7255 var d3_time_formatDateTime = "%a %b %e %X %Y", d3_time_formatDate = "%m/%d/%Y", d3_time_formatTime = "%H:%M:%S";
7256 var d3_time_days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], d3_time_dayAbbreviations = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
7257 d3.time.format = function(template) {
7258 var n = template.length;
7259 function format(date) {
7260 var string = [], i = -1, j = 0, c, p, f;
7261 while (++i < n) {
7262 if (template.charCodeAt(i) === 37) {
7263 string.push(template.substring(j, i));
7264 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
7265 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
7266 string.push(c);
7267 j = i + 1;
7268 }
7269 }
7270 string.push(template.substring(j, i));
7271 return string.join("");
7272 }
7273 format.parse = function(string) {
7274 var d = {
7275 y: 1900,
7276 m: 0,
7277 d: 1,
7278 H: 0,
7279 M: 0,
7280 S: 0,
7281 L: 0
7282 }, i = d3_time_parse(d, template, string, 0);
7283 if (i != string.length) return null;
7284 if ("p" in d) d.H = d.H % 12 + d.p * 12;
7285 var date = new d3_time();
7286 date.setFullYear(d.y, d.m, d.d);
7287 date.setHours(d.H, d.M, d.S, d.L);
7288 return date;
7289 };
7290 format.toString = function() {
7291 return template;
7292 };
7293 return format;
7294 };
7295 function d3_time_parse(date, template, string, j) {
7296 var c, p, i = 0, n = template.length, m = string.length;
7297 while (i < n) {
7298 if (j >= m) return -1;
7299 c = template.charCodeAt(i++);
7300 if (c === 37) {
7301 p = d3_time_parsers[template.charAt(i++)];
7302 if (!p || (j = p(date, string, j)) < 0) return -1;
7303 } else if (c != string.charCodeAt(j++)) {
7304 return -1;
7305 }
7306 }
7307 return j;
7308 }
7309 function d3_time_formatRe(names) {
7310 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
7311 }
7312 function d3_time_formatLookup(names) {
7313 var map = new d3_Map(), i = -1, n = names.length;
7314 while (++i < n) map.set(names[i].toLowerCase(), i);
7315 return map;
7316 }
7317 function d3_time_formatPad(value, fill, width) {
7318 value += "";
7319 var length = value.length;
7320 return length < width ? new Array(width - length + 1).join(fill) + value : value;
7321 }
7322 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);
7323 var d3_time_formatPads = {
7324 "-": "",
7325 _: " ",
7326 "0": "0"
7327 };
7328 var d3_time_formats = {
7329 a: function(d) {
7330 return d3_time_dayAbbreviations[d.getDay()];
7331 },
7332 A: function(d) {
7333 return d3_time_days[d.getDay()];
7334 },
7335 b: function(d) {
7336 return d3_time_monthAbbreviations[d.getMonth()];
7337 },
7338 B: function(d) {
7339 return d3_time_months[d.getMonth()];
7340 },
7341 c: d3.time.format(d3_time_formatDateTime),
7342 d: function(d, p) {
7343 return d3_time_formatPad(d.getDate(), p, 2);
7344 },
7345 e: function(d, p) {
7346 return d3_time_formatPad(d.getDate(), p, 2);
7347 },
7348 H: function(d, p) {
7349 return d3_time_formatPad(d.getHours(), p, 2);
7350 },
7351 I: function(d, p) {
7352 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
7353 },
7354 j: function(d, p) {
7355 return d3_time_formatPad(1 + d3.time.dayOfYear(d), p, 3);
7356 },
7357 L: function(d, p) {
7358 return d3_time_formatPad(d.getMilliseconds(), p, 3);
7359 },
7360 m: function(d, p) {
7361 return d3_time_formatPad(d.getMonth() + 1, p, 2);
7362 },
7363 M: function(d, p) {
7364 return d3_time_formatPad(d.getMinutes(), p, 2);
7365 },
7366 p: function(d) {
7367 return d.getHours() >= 12 ? "PM" : "AM";
7368 },
7369 S: function(d, p) {
7370 return d3_time_formatPad(d.getSeconds(), p, 2);
7371 },
7372 U: function(d, p) {
7373 return d3_time_formatPad(d3.time.sundayOfYear(d), p, 2);
7374 },
7375 w: function(d) {
7376 return d.getDay();
7377 },
7378 W: function(d, p) {
7379 return d3_time_formatPad(d3.time.mondayOfYear(d), p, 2);
7380 },
7381 x: d3.time.format(d3_time_formatDate),
7382 X: d3.time.format(d3_time_formatTime),
7383 y: function(d, p) {
7384 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
7385 },
7386 Y: function(d, p) {
7387 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
7388 },
7389 Z: d3_time_zone,
7390 "%": function() {
7391 return "%";
7392 }
7393 };
7394 var d3_time_parsers = {
7395 a: d3_time_parseWeekdayAbbrev,
7396 A: d3_time_parseWeekday,
7397 b: d3_time_parseMonthAbbrev,
7398 B: d3_time_parseMonth,
7399 c: d3_time_parseLocaleFull,
7400 d: d3_time_parseDay,
7401 e: d3_time_parseDay,
7402 H: d3_time_parseHour24,
7403 I: d3_time_parseHour24,
7404 L: d3_time_parseMilliseconds,
7405 m: d3_time_parseMonthNumber,
7406 M: d3_time_parseMinutes,
7407 p: d3_time_parseAmPm,
7408 S: d3_time_parseSeconds,
7409 x: d3_time_parseLocaleDate,
7410 X: d3_time_parseLocaleTime,
7411 y: d3_time_parseYear,
7412 Y: d3_time_parseFullYear
7413 };
7414 function d3_time_parseWeekdayAbbrev(date, string, i) {
7415 d3_time_dayAbbrevRe.lastIndex = 0;
7416 var n = d3_time_dayAbbrevRe.exec(string.substring(i));
7417 return n ? i += n[0].length : -1;
7418 }
7419 function d3_time_parseWeekday(date, string, i) {
7420 d3_time_dayRe.lastIndex = 0;
7421 var n = d3_time_dayRe.exec(string.substring(i));
7422 return n ? i += n[0].length : -1;
7423 }
7424 function d3_time_parseMonthAbbrev(date, string, i) {
7425 d3_time_monthAbbrevRe.lastIndex = 0;
7426 var n = d3_time_monthAbbrevRe.exec(string.substring(i));
7427 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
7428 }
7429 function d3_time_parseMonth(date, string, i) {
7430 d3_time_monthRe.lastIndex = 0;
7431 var n = d3_time_monthRe.exec(string.substring(i));
7432 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
7433 }
7434 function d3_time_parseLocaleFull(date, string, i) {
7435 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
7436 }
7437 function d3_time_parseLocaleDate(date, string, i) {
7438 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
7439 }
7440 function d3_time_parseLocaleTime(date, string, i) {
7441 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
7442 }
7443 function d3_time_parseFullYear(date, string, i) {
7444 d3_time_numberRe.lastIndex = 0;
7445 var n = d3_time_numberRe.exec(string.substring(i, i + 4));
7446 return n ? (date.y = +n[0], i += n[0].length) : -1;
7447 }
7448 function d3_time_parseYear(date, string, i) {
7449 d3_time_numberRe.lastIndex = 0;
7450 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
7451 return n ? (date.y = d3_time_expandYear(+n[0]), i += n[0].length) : -1;
7452 }
7453 function d3_time_expandYear(d) {
7454 return d + (d > 68 ? 1900 : 2e3);
7455 }
7456 function d3_time_parseMonthNumber(date, string, i) {
7457 d3_time_numberRe.lastIndex = 0;
7458 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
7459 return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
7460 }
7461 function d3_time_parseDay(date, string, i) {
7462 d3_time_numberRe.lastIndex = 0;
7463 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
7464 return n ? (date.d = +n[0], i += n[0].length) : -1;
7465 }
7466 function d3_time_parseHour24(date, string, i) {
7467 d3_time_numberRe.lastIndex = 0;
7468 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
7469 return n ? (date.H = +n[0], i += n[0].length) : -1;
7470 }
7471 function d3_time_parseMinutes(date, string, i) {
7472 d3_time_numberRe.lastIndex = 0;
7473 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
7474 return n ? (date.M = +n[0], i += n[0].length) : -1;
7475 }
7476 function d3_time_parseSeconds(date, string, i) {
7477 d3_time_numberRe.lastIndex = 0;
7478 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
7479 return n ? (date.S = +n[0], i += n[0].length) : -1;
7480 }
7481 function d3_time_parseMilliseconds(date, string, i) {
7482 d3_time_numberRe.lastIndex = 0;
7483 var n = d3_time_numberRe.exec(string.substring(i, i + 3));
7484 return n ? (date.L = +n[0], i += n[0].length) : -1;
7485 }
7486 var d3_time_numberRe = /^\s*\d+/;
7487 function d3_time_parseAmPm(date, string, i) {
7488 var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
7489 return n == null ? -1 : (date.p = n, i);
7490 }
7491 var d3_time_amPmLookup = d3.map({
7492 am: 0,
7493 pm: 1
7494 });
7495 function d3_time_zone(d) {
7496 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
7497 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
7498 }
7499 d3.time.format.utc = function(template) {
7500 var local = d3.time.format(template);
7501 function format(date) {
7502 try {
7503 d3_time = d3_time_utc;
7504 var utc = new d3_time();
7505 utc._ = date;
7506 return local(utc);
7507 } finally {
7508 d3_time = Date;
7509 }
7510 }
7511 format.parse = function(string) {
7512 try {
7513 d3_time = d3_time_utc;
7514 var date = local.parse(string);
7515 return date && date._;
7516 } finally {
7517 d3_time = Date;
7518 }
7519 };
7520 format.toString = local.toString;
7521 return format;
7522 };
7523 var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
7524 d3.time.format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
7525 function d3_time_formatIsoNative(date) {
7526 return date.toISOString();
7527 }
7528 d3_time_formatIsoNative.parse = function(string) {
7529 var date = new Date(string);
7530 return isNaN(date) ? null : date;
7531 };
7532 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
7533 function d3_time_interval(local, step, number) {
7534 function round(date) {
7535 var d0 = local(date), d1 = offset(d0, 1);
7536 return date - d0 < d1 - date ? d0 : d1;
7537 }
7538 function ceil(date) {
7539 step(date = local(new d3_time(date - 1)), 1);
7540 return date;
7541 }
7542 function offset(date, k) {
7543 step(date = new d3_time(+date), k);
7544 return date;
7545 }
7546 function range(t0, t1, dt) {
7547 var time = ceil(t0), times = [];
7548 if (dt > 1) {
7549 while (time < t1) {
7550 if (!(number(time) % dt)) times.push(new Date(+time));
7551 step(time, 1);
7552 }
7553 } else {
7554 while (time < t1) times.push(new Date(+time)), step(time, 1);
7555 }
7556 return times;
7557 }
7558 function range_utc(t0, t1, dt) {
7559 try {
7560 d3_time = d3_time_utc;
7561 var utc = new d3_time_utc();
7562 utc._ = t0;
7563 return range(utc, t1, dt);
7564 } finally {
7565 d3_time = Date;
7566 }
7567 }
7568 local.floor = local;
7569 local.round = round;
7570 local.ceil = ceil;
7571 local.offset = offset;
7572 local.range = range;
7573 var utc = local.utc = d3_time_interval_utc(local);
7574 utc.floor = utc;
7575 utc.round = d3_time_interval_utc(round);
7576 utc.ceil = d3_time_interval_utc(ceil);
7577 utc.offset = d3_time_interval_utc(offset);
7578 utc.range = range_utc;
7579 return local;
7580 }
7581 function d3_time_interval_utc(method) {
7582 return function(date, k) {
7583 try {
7584 d3_time = d3_time_utc;
7585 var utc = new d3_time_utc();
7586 utc._ = date;
7587 return method(utc, k)._;
7588 } finally {
7589 d3_time = Date;
7590 }
7591 };
7592 }
7593 d3.time.second = d3_time_interval(function(date) {
7594 return new d3_time(Math.floor(date / 1e3) * 1e3);
7595 }, function(date, offset) {
7596 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
7597 }, function(date) {
7598 return date.getSeconds();
7599 });
7600 d3.time.seconds = d3.time.second.range;
7601 d3.time.seconds.utc = d3.time.second.utc.range;
7602 d3.time.minute = d3_time_interval(function(date) {
7603 return new d3_time(Math.floor(date / 6e4) * 6e4);
7604 }, function(date, offset) {
7605 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
7606 }, function(date) {
7607 return date.getMinutes();
7608 });
7609 d3.time.minutes = d3.time.minute.range;
7610 d3.time.minutes.utc = d3.time.minute.utc.range;
7611 d3.time.hour = d3_time_interval(function(date) {
7612 var timezone = date.getTimezoneOffset() / 60;
7613 return new d3_time((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
7614 }, function(date, offset) {
7615 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
7616 }, function(date) {
7617 return date.getHours();
7618 });
7619 d3.time.hours = d3.time.hour.range;
7620 d3.time.hours.utc = d3.time.hour.utc.range;
7621 d3.time.day = d3_time_interval(function(date) {
7622 var day = new d3_time(1970, 0);
7623 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
7624 return day;
7625 }, function(date, offset) {
7626 date.setDate(date.getDate() + offset);
7627 }, function(date) {
7628 return date.getDate() - 1;
7629 });
7630 d3.time.days = d3.time.day.range;
7631 d3.time.days.utc = d3.time.day.utc.range;
7632 d3.time.dayOfYear = function(date) {
7633 var year = d3.time.year(date);
7634 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
7635 };
7636 d3_time_daySymbols.forEach(function(day, i) {
7637 day = day.toLowerCase();
7638 i = 7 - i;
7639 var interval = d3.time[day] = d3_time_interval(function(date) {
7640 (date = d3.time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
7641 return date;
7642 }, function(date, offset) {
7643 date.setDate(date.getDate() + Math.floor(offset) * 7);
7644 }, function(date) {
7645 var day = d3.time.year(date).getDay();
7646 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
7647 });
7648 d3.time[day + "s"] = interval.range;
7649 d3.time[day + "s"].utc = interval.utc.range;
7650 d3.time[day + "OfYear"] = function(date) {
7651 var day = d3.time.year(date).getDay();
7652 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7);
7653 };
7654 });
7655 d3.time.week = d3.time.sunday;
7656 d3.time.weeks = d3.time.sunday.range;
7657 d3.time.weeks.utc = d3.time.sunday.utc.range;
7658 d3.time.weekOfYear = d3.time.sundayOfYear;
7659 d3.time.month = d3_time_interval(function(date) {
7660 date = d3.time.day(date);
7661 date.setDate(1);
7662 return date;
7663 }, function(date, offset) {
7664 date.setMonth(date.getMonth() + offset);
7665 }, function(date) {
7666 return date.getMonth();
7667 });
7668 d3.time.months = d3.time.month.range;
7669 d3.time.months.utc = d3.time.month.utc.range;
7670 d3.time.year = d3_time_interval(function(date) {
7671 date = d3.time.day(date);
7672 date.setMonth(0, 1);
7673 return date;
7674 }, function(date, offset) {
7675 date.setFullYear(date.getFullYear() + offset);
7676 }, function(date) {
7677 return date.getFullYear();
7678 });
7679 d3.time.years = d3.time.year.range;
7680 d3.time.years.utc = d3.time.year.utc.range;
7681 function d3_time_scale(linear, methods, format) {
7682 function scale(x) {
7683 return linear(x);
7684 }
7685 scale.invert = function(x) {
7686 return d3_time_scaleDate(linear.invert(x));
7687 };
7688 scale.domain = function(x) {
7689 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
7690 linear.domain(x);
7691 return scale;
7692 };
7693 scale.nice = function(m) {
7694 return scale.domain(d3_scale_nice(scale.domain(), function() {
7695 return m;
7696 }));
7697 };
7698 scale.ticks = function(m, k) {
7699 var extent = d3_time_scaleExtent(scale.domain());
7700 if (typeof m !== "function") {
7701 var span = extent[1] - extent[0], target = span / m, i = d3.bisect(d3_time_scaleSteps, target);
7702 if (i == d3_time_scaleSteps.length) return methods.year(extent, m);
7703 if (!i) return linear.ticks(m).map(d3_time_scaleDate);
7704 if (Math.log(target / d3_time_scaleSteps[i - 1]) < Math.log(d3_time_scaleSteps[i] / target)) --i;
7705 m = methods[i];
7706 k = m[1];
7707 m = m[0].range;
7708 }
7709 return m(extent[0], new Date(+extent[1] + 1), k);
7710 };
7711 scale.tickFormat = function() {
7712 return format;
7713 };
7714 scale.copy = function() {
7715 return d3_time_scale(linear.copy(), methods, format);
7716 };
7717 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7718 }
7719 function d3_time_scaleExtent(domain) {
7720 var start = domain[0], stop = domain[domain.length - 1];
7721 return start < stop ? [ start, stop ] : [ stop, start ];
7722 }
7723 function d3_time_scaleDate(t) {
7724 return new Date(t);
7725 }
7726 function d3_time_scaleFormat(formats) {
7727 return function(date) {
7728 var i = formats.length - 1, f = formats[i];
7729 while (!f[1](date)) f = formats[--i];
7730 return f[0](date);
7731 };
7732 }
7733 function d3_time_scaleSetYear(y) {
7734 var d = new Date(y, 0, 1);
7735 d.setFullYear(y);
7736 return d;
7737 }
7738 function d3_time_scaleGetYear(d) {
7739 var y = d.getFullYear(), d0 = d3_time_scaleSetYear(y), d1 = d3_time_scaleSetYear(y + 1);
7740 return y + (d - d0) / (d1 - d0);
7741 }
7742 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
7743 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 ] ];
7744 var d3_time_scaleLocalFormats = [ [ d3.time.format("%Y"), d3_true ], [ d3.time.format("%B"), function(d) {
7745 return d.getMonth();
7746 } ], [ d3.time.format("%b %d"), function(d) {
7747 return d.getDate() != 1;
7748 } ], [ d3.time.format("%a %d"), function(d) {
7749 return d.getDay() && d.getDate() != 1;
7750 } ], [ d3.time.format("%I %p"), function(d) {
7751 return d.getHours();
7752 } ], [ d3.time.format("%I:%M"), function(d) {
7753 return d.getMinutes();
7754 } ], [ d3.time.format(":%S"), function(d) {
7755 return d.getSeconds();
7756 } ], [ d3.time.format(".%L"), function(d) {
7757 return d.getMilliseconds();
7758 } ] ];
7759 var d3_time_scaleLinear = d3.scale.linear(), d3_time_scaleLocalFormat = d3_time_scaleFormat(d3_time_scaleLocalFormats);
7760 d3_time_scaleLocalMethods.year = function(extent, m) {
7761 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleGetYear)).ticks(m).map(d3_time_scaleSetYear);
7762 };
7763 d3.time.scale = function() {
7764 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
7765 };
7766 var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
7767 return [ m[0].utc, m[1] ];
7768 });
7769 var d3_time_scaleUTCFormats = [ [ d3.time.format.utc("%Y"), d3_true ], [ d3.time.format.utc("%B"), function(d) {
7770 return d.getUTCMonth();
7771 } ], [ d3.time.format.utc("%b %d"), function(d) {
7772 return d.getUTCDate() != 1;
7773 } ], [ d3.time.format.utc("%a %d"), function(d) {
7774 return d.getUTCDay() && d.getUTCDate() != 1;
7775 } ], [ d3.time.format.utc("%I %p"), function(d) {
7776 return d.getUTCHours();
7777 } ], [ d3.time.format.utc("%I:%M"), function(d) {
7778 return d.getUTCMinutes();
7779 } ], [ d3.time.format.utc(":%S"), function(d) {
7780 return d.getUTCSeconds();
7781 } ], [ d3.time.format.utc(".%L"), function(d) {
7782 return d.getUTCMilliseconds();
7783 } ] ];
7784 var d3_time_scaleUTCFormat = d3_time_scaleFormat(d3_time_scaleUTCFormats);
7785 function d3_time_scaleUTCSetYear(y) {
7786 var d = new Date(Date.UTC(y, 0, 1));
7787 d.setUTCFullYear(y);
7788 return d;
7789 }
7790 function d3_time_scaleUTCGetYear(d) {
7791 var y = d.getUTCFullYear(), d0 = d3_time_scaleUTCSetYear(y), d1 = d3_time_scaleUTCSetYear(y + 1);
7792 return y + (d - d0) / (d1 - d0);
7793 }
7794 d3_time_scaleUTCMethods.year = function(extent, m) {
7795 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleUTCGetYear)).ticks(m).map(d3_time_scaleUTCSetYear);
7796 };
7797 d3.time.scale.utc = function() {
7798 return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);
7799 };
7800 return d3;
7801}();