view gtc/d3.js @ 114:d8239a080f44

cs: set domain and secure cookie parameters for unset also
author paulo
date Mon, 03 Aug 2020 02:01:05 -0600
parents
children
line source
1 !function() {
2 var d3 = {
3 version: "3.5.17"
4 };
5 var d3_arraySlice = [].slice, d3_array = function(list) {
6 return d3_arraySlice.call(list);
7 };
8 var d3_document = this.document;
9 function d3_documentElement(node) {
10 return node && (node.ownerDocument || node.document || node).documentElement;
11 }
12 function d3_window(node) {
13 return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
14 }
15 if (d3_document) {
16 try {
17 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
18 } catch (e) {
19 d3_array = function(list) {
20 var i = list.length, array = new Array(i);
21 while (i--) array[i] = list[i];
22 return array;
23 };
24 }
25 }
26 if (!Date.now) Date.now = function() {
27 return +new Date();
28 };
29 if (d3_document) {
30 try {
31 d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
32 } catch (error) {
33 var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
34 d3_element_prototype.setAttribute = function(name, value) {
35 d3_element_setAttribute.call(this, name, value + "");
36 };
37 d3_element_prototype.setAttributeNS = function(space, local, value) {
38 d3_element_setAttributeNS.call(this, space, local, value + "");
39 };
40 d3_style_prototype.setProperty = function(name, value, priority) {
41 d3_style_setProperty.call(this, name, value + "", priority);
42 };
43 }
44 }
45 d3.ascending = d3_ascending;
46 function d3_ascending(a, b) {
47 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
48 }
49 d3.descending = function(a, b) {
50 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
51 };
52 d3.min = function(array, f) {
53 var i = -1, n = array.length, a, b;
54 if (arguments.length === 1) {
55 while (++i < n) if ((b = array[i]) != null && b >= b) {
56 a = b;
57 break;
58 }
59 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
60 } else {
61 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
62 a = b;
63 break;
64 }
65 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
66 }
67 return a;
68 };
69 d3.max = function(array, f) {
70 var i = -1, n = array.length, a, b;
71 if (arguments.length === 1) {
72 while (++i < n) if ((b = array[i]) != null && b >= b) {
73 a = b;
74 break;
75 }
76 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
77 } else {
78 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
79 a = b;
80 break;
81 }
82 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
83 }
84 return a;
85 };
86 d3.extent = function(array, f) {
87 var i = -1, n = array.length, a, b, c;
88 if (arguments.length === 1) {
89 while (++i < n) if ((b = array[i]) != null && b >= b) {
90 a = c = b;
91 break;
92 }
93 while (++i < n) if ((b = array[i]) != null) {
94 if (a > b) a = b;
95 if (c < b) c = b;
96 }
97 } else {
98 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
99 a = c = b;
100 break;
101 }
102 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
103 if (a > b) a = b;
104 if (c < b) c = b;
105 }
106 }
107 return [ a, c ];
108 };
109 function d3_number(x) {
110 return x === null ? NaN : +x;
111 }
112 function d3_numeric(x) {
113 return !isNaN(x);
114 }
115 d3.sum = function(array, f) {
116 var s = 0, n = array.length, a, i = -1;
117 if (arguments.length === 1) {
118 while (++i < n) if (d3_numeric(a = +array[i])) s += a;
119 } else {
120 while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
121 }
122 return s;
123 };
124 d3.mean = function(array, f) {
125 var s = 0, n = array.length, a, i = -1, j = n;
126 if (arguments.length === 1) {
127 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
128 } else {
129 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
130 }
131 if (j) return s / j;
132 };
133 d3.quantile = function(values, p) {
134 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
135 return e ? v + e * (values[h] - v) : v;
136 };
137 d3.median = function(array, f) {
138 var numbers = [], n = array.length, a, i = -1;
139 if (arguments.length === 1) {
140 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
141 } else {
142 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
143 }
144 if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
145 };
146 d3.variance = function(array, f) {
147 var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
148 if (arguments.length === 1) {
149 while (++i < n) {
150 if (d3_numeric(a = d3_number(array[i]))) {
151 d = a - m;
152 m += d / ++j;
153 s += d * (a - m);
154 }
155 }
156 } else {
157 while (++i < n) {
158 if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
159 d = a - m;
160 m += d / ++j;
161 s += d * (a - m);
162 }
163 }
164 }
165 if (j > 1) return s / (j - 1);
166 };
167 d3.deviation = function() {
168 var v = d3.variance.apply(this, arguments);
169 return v ? Math.sqrt(v) : v;
170 };
171 function d3_bisector(compare) {
172 return {
173 left: function(a, x, lo, hi) {
174 if (arguments.length < 3) lo = 0;
175 if (arguments.length < 4) hi = a.length;
176 while (lo < hi) {
177 var mid = lo + hi >>> 1;
178 if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
179 }
180 return lo;
181 },
182 right: function(a, x, lo, hi) {
183 if (arguments.length < 3) lo = 0;
184 if (arguments.length < 4) hi = a.length;
185 while (lo < hi) {
186 var mid = lo + hi >>> 1;
187 if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
188 }
189 return lo;
190 }
191 };
192 }
193 var d3_bisect = d3_bisector(d3_ascending);
194 d3.bisectLeft = d3_bisect.left;
195 d3.bisect = d3.bisectRight = d3_bisect.right;
196 d3.bisector = function(f) {
197 return d3_bisector(f.length === 1 ? function(d, x) {
198 return d3_ascending(f(d), x);
199 } : f);
200 };
201 d3.shuffle = function(array, i0, i1) {
202 if ((m = arguments.length) < 3) {
203 i1 = array.length;
204 if (m < 2) i0 = 0;
205 }
206 var m = i1 - i0, t, i;
207 while (m) {
208 i = Math.random() * m-- | 0;
209 t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
210 }
211 return array;
212 };
213 d3.permute = function(array, indexes) {
214 var i = indexes.length, permutes = new Array(i);
215 while (i--) permutes[i] = array[indexes[i]];
216 return permutes;
217 };
218 d3.pairs = function(array) {
219 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
220 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
221 return pairs;
222 };
223 d3.transpose = function(matrix) {
224 if (!(n = matrix.length)) return [];
225 for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
226 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
227 row[j] = matrix[j][i];
228 }
229 }
230 return transpose;
231 };
232 function d3_transposeLength(d) {
233 return d.length;
234 }
235 d3.zip = function() {
236 return d3.transpose(arguments);
237 };
238 d3.keys = function(map) {
239 var keys = [];
240 for (var key in map) keys.push(key);
241 return keys;
242 };
243 d3.values = function(map) {
244 var values = [];
245 for (var key in map) values.push(map[key]);
246 return values;
247 };
248 d3.entries = function(map) {
249 var entries = [];
250 for (var key in map) entries.push({
251 key: key,
252 value: map[key]
253 });
254 return entries;
255 };
256 d3.merge = function(arrays) {
257 var n = arrays.length, m, i = -1, j = 0, merged, array;
258 while (++i < n) j += arrays[i].length;
259 merged = new Array(j);
260 while (--n >= 0) {
261 array = arrays[n];
262 m = array.length;
263 while (--m >= 0) {
264 merged[--j] = array[m];
265 }
266 }
267 return merged;
268 };
269 var abs = Math.abs;
270 d3.range = function(start, stop, step) {
271 if (arguments.length < 3) {
272 step = 1;
273 if (arguments.length < 2) {
274 stop = start;
275 start = 0;
276 }
277 }
278 if ((stop - start) / step === Infinity) throw new Error("infinite range");
279 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
280 start *= k, stop *= k, step *= k;
281 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
282 return range;
283 };
284 function d3_range_integerScale(x) {
285 var k = 1;
286 while (x * k % 1) k *= 10;
287 return k;
288 }
289 function d3_class(ctor, properties) {
290 for (var key in properties) {
291 Object.defineProperty(ctor.prototype, key, {
292 value: properties[key],
293 enumerable: false
294 });
295 }
296 }
297 d3.map = function(object, f) {
298 var map = new d3_Map();
299 if (object instanceof d3_Map) {
300 object.forEach(function(key, value) {
301 map.set(key, value);
302 });
303 } else if (Array.isArray(object)) {
304 var i = -1, n = object.length, o;
305 if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
306 } else {
307 for (var key in object) map.set(key, object[key]);
308 }
309 return map;
310 };
311 function d3_Map() {
312 this._ = Object.create(null);
313 }
314 var d3_map_proto = "__proto__", d3_map_zero = "\x00";
315 d3_class(d3_Map, {
316 has: d3_map_has,
317 get: function(key) {
318 return this._[d3_map_escape(key)];
319 },
320 set: function(key, value) {
321 return this._[d3_map_escape(key)] = value;
322 },
323 remove: d3_map_remove,
324 keys: d3_map_keys,
325 values: function() {
326 var values = [];
327 for (var key in this._) values.push(this._[key]);
328 return values;
329 },
330 entries: function() {
331 var entries = [];
332 for (var key in this._) entries.push({
333 key: d3_map_unescape(key),
334 value: this._[key]
335 });
336 return entries;
337 },
338 size: d3_map_size,
339 empty: d3_map_empty,
340 forEach: function(f) {
341 for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
342 }
343 });
344 function d3_map_escape(key) {
345 return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
346 }
347 function d3_map_unescape(key) {
348 return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
349 }
350 function d3_map_has(key) {
351 return d3_map_escape(key) in this._;
352 }
353 function d3_map_remove(key) {
354 return (key = d3_map_escape(key)) in this._ && delete this._[key];
355 }
356 function d3_map_keys() {
357 var keys = [];
358 for (var key in this._) keys.push(d3_map_unescape(key));
359 return keys;
360 }
361 function d3_map_size() {
362 var size = 0;
363 for (var key in this._) ++size;
364 return size;
365 }
366 function d3_map_empty() {
367 for (var key in this._) return false;
368 return true;
369 }
370 d3.nest = function() {
371 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
372 function map(mapType, array, depth) {
373 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
374 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
375 while (++i < n) {
376 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
377 values.push(object);
378 } else {
379 valuesByKey.set(keyValue, [ object ]);
380 }
381 }
382 if (mapType) {
383 object = mapType();
384 setter = function(keyValue, values) {
385 object.set(keyValue, map(mapType, values, depth));
386 };
387 } else {
388 object = {};
389 setter = function(keyValue, values) {
390 object[keyValue] = map(mapType, values, depth);
391 };
392 }
393 valuesByKey.forEach(setter);
394 return object;
395 }
396 function entries(map, depth) {
397 if (depth >= keys.length) return map;
398 var array = [], sortKey = sortKeys[depth++];
399 map.forEach(function(key, keyMap) {
400 array.push({
401 key: key,
402 values: entries(keyMap, depth)
403 });
404 });
405 return sortKey ? array.sort(function(a, b) {
406 return sortKey(a.key, b.key);
407 }) : array;
408 }
409 nest.map = function(array, mapType) {
410 return map(mapType, array, 0);
411 };
412 nest.entries = function(array) {
413 return entries(map(d3.map, array, 0), 0);
414 };
415 nest.key = function(d) {
416 keys.push(d);
417 return nest;
418 };
419 nest.sortKeys = function(order) {
420 sortKeys[keys.length - 1] = order;
421 return nest;
422 };
423 nest.sortValues = function(order) {
424 sortValues = order;
425 return nest;
426 };
427 nest.rollup = function(f) {
428 rollup = f;
429 return nest;
430 };
431 return nest;
432 };
433 d3.set = function(array) {
434 var set = new d3_Set();
435 if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
436 return set;
437 };
438 function d3_Set() {
439 this._ = Object.create(null);
440 }
441 d3_class(d3_Set, {
442 has: d3_map_has,
443 add: function(key) {
444 this._[d3_map_escape(key += "")] = true;
445 return key;
446 },
447 remove: d3_map_remove,
448 values: d3_map_keys,
449 size: d3_map_size,
450 empty: d3_map_empty,
451 forEach: function(f) {
452 for (var key in this._) f.call(this, d3_map_unescape(key));
453 }
454 });
455 d3.behavior = {};
456 function d3_identity(d) {
457 return d;
458 }
459 d3.rebind = function(target, source) {
460 var i = 1, n = arguments.length, method;
461 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
462 return target;
463 };
464 function d3_rebind(target, source, method) {
465 return function() {
466 var value = method.apply(source, arguments);
467 return value === source ? target : value;
468 };
469 }
470 function d3_vendorSymbol(object, name) {
471 if (name in object) return name;
472 name = name.charAt(0).toUpperCase() + name.slice(1);
473 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
474 var prefixName = d3_vendorPrefixes[i] + name;
475 if (prefixName in object) return prefixName;
476 }
477 }
478 var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
479 function d3_noop() {}
480 d3.dispatch = function() {
481 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
482 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
483 return dispatch;
484 };
485 function d3_dispatch() {}
486 d3_dispatch.prototype.on = function(type, listener) {
487 var i = type.indexOf("."), name = "";
488 if (i >= 0) {
489 name = type.slice(i + 1);
490 type = type.slice(0, i);
491 }
492 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
493 if (arguments.length === 2) {
494 if (listener == null) for (type in this) {
495 if (this.hasOwnProperty(type)) this[type].on(name, null);
496 }
497 return this;
498 }
499 };
500 function d3_dispatch_event(dispatch) {
501 var listeners = [], listenerByName = new d3_Map();
502 function event() {
503 var z = listeners, i = -1, n = z.length, l;
504 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
505 return dispatch;
506 }
507 event.on = function(name, listener) {
508 var l = listenerByName.get(name), i;
509 if (arguments.length < 2) return l && l.on;
510 if (l) {
511 l.on = null;
512 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
513 listenerByName.remove(name);
514 }
515 if (listener) listeners.push(listenerByName.set(name, {
516 on: listener
517 }));
518 return dispatch;
519 };
520 return event;
521 }
522 d3.event = null;
523 function d3_eventPreventDefault() {
524 d3.event.preventDefault();
525 }
526 function d3_eventSource() {
527 var e = d3.event, s;
528 while (s = e.sourceEvent) e = s;
529 return e;
530 }
531 function d3_eventDispatch(target) {
532 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
533 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
534 dispatch.of = function(thiz, argumentz) {
535 return function(e1) {
536 try {
537 var e0 = e1.sourceEvent = d3.event;
538 e1.target = target;
539 d3.event = e1;
540 dispatch[e1.type].apply(thiz, argumentz);
541 } finally {
542 d3.event = e0;
543 }
544 };
545 };
546 return dispatch;
547 }
548 d3.requote = function(s) {
549 return s.replace(d3_requote_re, "\\$&");
550 };
551 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
552 var d3_subclass = {}.__proto__ ? function(object, prototype) {
553 object.__proto__ = prototype;
554 } : function(object, prototype) {
555 for (var property in prototype) object[property] = prototype[property];
556 };
557 function d3_selection(groups) {
558 d3_subclass(groups, d3_selectionPrototype);
559 return groups;
560 }
561 var d3_select = function(s, n) {
562 return n.querySelector(s);
563 }, d3_selectAll = function(s, n) {
564 return n.querySelectorAll(s);
565 }, d3_selectMatches = function(n, s) {
566 var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
567 d3_selectMatches = function(n, s) {
568 return d3_selectMatcher.call(n, s);
569 };
570 return d3_selectMatches(n, s);
571 };
572 if (typeof Sizzle === "function") {
573 d3_select = function(s, n) {
574 return Sizzle(s, n)[0] || null;
575 };
576 d3_selectAll = Sizzle;
577 d3_selectMatches = Sizzle.matchesSelector;
578 }
579 d3.selection = function() {
580 return d3.select(d3_document.documentElement);
581 };
582 var d3_selectionPrototype = d3.selection.prototype = [];
583 d3_selectionPrototype.select = function(selector) {
584 var subgroups = [], subgroup, subnode, group, node;
585 selector = d3_selection_selector(selector);
586 for (var j = -1, m = this.length; ++j < m; ) {
587 subgroups.push(subgroup = []);
588 subgroup.parentNode = (group = this[j]).parentNode;
589 for (var i = -1, n = group.length; ++i < n; ) {
590 if (node = group[i]) {
591 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
592 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
593 } else {
594 subgroup.push(null);
595 }
596 }
597 }
598 return d3_selection(subgroups);
599 };
600 function d3_selection_selector(selector) {
601 return typeof selector === "function" ? selector : function() {
602 return d3_select(selector, this);
603 };
604 }
605 d3_selectionPrototype.selectAll = function(selector) {
606 var subgroups = [], subgroup, node;
607 selector = d3_selection_selectorAll(selector);
608 for (var j = -1, m = this.length; ++j < m; ) {
609 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
610 if (node = group[i]) {
611 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
612 subgroup.parentNode = node;
613 }
614 }
615 }
616 return d3_selection(subgroups);
617 };
618 function d3_selection_selectorAll(selector) {
619 return typeof selector === "function" ? selector : function() {
620 return d3_selectAll(selector, this);
621 };
622 }
623 var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
624 var d3_nsPrefix = {
625 svg: "http://www.w3.org/2000/svg",
626 xhtml: d3_nsXhtml,
627 xlink: "http://www.w3.org/1999/xlink",
628 xml: "http://www.w3.org/XML/1998/namespace",
629 xmlns: "http://www.w3.org/2000/xmlns/"
630 };
631 d3.ns = {
632 prefix: d3_nsPrefix,
633 qualify: function(name) {
634 var i = name.indexOf(":"), prefix = name;
635 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
636 return d3_nsPrefix.hasOwnProperty(prefix) ? {
637 space: d3_nsPrefix[prefix],
638 local: name
639 } : name;
640 }
641 };
642 d3_selectionPrototype.attr = function(name, value) {
643 if (arguments.length < 2) {
644 if (typeof name === "string") {
645 var node = this.node();
646 name = d3.ns.qualify(name);
647 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
648 }
649 for (value in name) this.each(d3_selection_attr(value, name[value]));
650 return this;
651 }
652 return this.each(d3_selection_attr(name, value));
653 };
654 function d3_selection_attr(name, value) {
655 name = d3.ns.qualify(name);
656 function attrNull() {
657 this.removeAttribute(name);
658 }
659 function attrNullNS() {
660 this.removeAttributeNS(name.space, name.local);
661 }
662 function attrConstant() {
663 this.setAttribute(name, value);
664 }
665 function attrConstantNS() {
666 this.setAttributeNS(name.space, name.local, value);
667 }
668 function attrFunction() {
669 var x = value.apply(this, arguments);
670 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
671 }
672 function attrFunctionNS() {
673 var x = value.apply(this, arguments);
674 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
675 }
676 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
677 }
678 function d3_collapse(s) {
679 return s.trim().replace(/\s+/g, " ");
680 }
681 d3_selectionPrototype.classed = function(name, value) {
682 if (arguments.length < 2) {
683 if (typeof name === "string") {
684 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
685 if (value = node.classList) {
686 while (++i < n) if (!value.contains(name[i])) return false;
687 } else {
688 value = node.getAttribute("class");
689 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
690 }
691 return true;
692 }
693 for (value in name) this.each(d3_selection_classed(value, name[value]));
694 return this;
695 }
696 return this.each(d3_selection_classed(name, value));
697 };
698 function d3_selection_classedRe(name) {
699 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
700 }
701 function d3_selection_classes(name) {
702 return (name + "").trim().split(/^|\s+/);
703 }
704 function d3_selection_classed(name, value) {
705 name = d3_selection_classes(name).map(d3_selection_classedName);
706 var n = name.length;
707 function classedConstant() {
708 var i = -1;
709 while (++i < n) name[i](this, value);
710 }
711 function classedFunction() {
712 var i = -1, x = value.apply(this, arguments);
713 while (++i < n) name[i](this, x);
714 }
715 return typeof value === "function" ? classedFunction : classedConstant;
716 }
717 function d3_selection_classedName(name) {
718 var re = d3_selection_classedRe(name);
719 return function(node, value) {
720 if (c = node.classList) return value ? c.add(name) : c.remove(name);
721 var c = node.getAttribute("class") || "";
722 if (value) {
723 re.lastIndex = 0;
724 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
725 } else {
726 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
727 }
728 };
729 }
730 d3_selectionPrototype.style = function(name, value, priority) {
731 var n = arguments.length;
732 if (n < 3) {
733 if (typeof name !== "string") {
734 if (n < 2) value = "";
735 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
736 return this;
737 }
738 if (n < 2) {
739 var node = this.node();
740 return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
741 }
742 priority = "";
743 }
744 return this.each(d3_selection_style(name, value, priority));
745 };
746 function d3_selection_style(name, value, priority) {
747 function styleNull() {
748 this.style.removeProperty(name);
749 }
750 function styleConstant() {
751 this.style.setProperty(name, value, priority);
752 }
753 function styleFunction() {
754 var x = value.apply(this, arguments);
755 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
756 }
757 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
758 }
759 d3_selectionPrototype.property = function(name, value) {
760 if (arguments.length < 2) {
761 if (typeof name === "string") return this.node()[name];
762 for (value in name) this.each(d3_selection_property(value, name[value]));
763 return this;
764 }
765 return this.each(d3_selection_property(name, value));
766 };
767 function d3_selection_property(name, value) {
768 function propertyNull() {
769 delete this[name];
770 }
771 function propertyConstant() {
772 this[name] = value;
773 }
774 function propertyFunction() {
775 var x = value.apply(this, arguments);
776 if (x == null) delete this[name]; else this[name] = x;
777 }
778 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
779 }
780 d3_selectionPrototype.text = function(value) {
781 return arguments.length ? this.each(typeof value === "function" ? function() {
782 var v = value.apply(this, arguments);
783 this.textContent = v == null ? "" : v;
784 } : value == null ? function() {
785 this.textContent = "";
786 } : function() {
787 this.textContent = value;
788 }) : this.node().textContent;
789 };
790 d3_selectionPrototype.html = function(value) {
791 return arguments.length ? this.each(typeof value === "function" ? function() {
792 var v = value.apply(this, arguments);
793 this.innerHTML = v == null ? "" : v;
794 } : value == null ? function() {
795 this.innerHTML = "";
796 } : function() {
797 this.innerHTML = value;
798 }) : this.node().innerHTML;
799 };
800 d3_selectionPrototype.append = function(name) {
801 name = d3_selection_creator(name);
802 return this.select(function() {
803 return this.appendChild(name.apply(this, arguments));
804 });
805 };
806 function d3_selection_creator(name) {
807 function create() {
808 var document = this.ownerDocument, namespace = this.namespaceURI;
809 return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
810 }
811 function createNS() {
812 return this.ownerDocument.createElementNS(name.space, name.local);
813 }
814 return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
815 }
816 d3_selectionPrototype.insert = function(name, before) {
817 name = d3_selection_creator(name);
818 before = d3_selection_selector(before);
819 return this.select(function() {
820 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
821 });
822 };
823 d3_selectionPrototype.remove = function() {
824 return this.each(d3_selectionRemove);
825 };
826 function d3_selectionRemove() {
827 var parent = this.parentNode;
828 if (parent) parent.removeChild(this);
829 }
830 d3_selectionPrototype.data = function(value, key) {
831 var i = -1, n = this.length, group, node;
832 if (!arguments.length) {
833 value = new Array(n = (group = this[0]).length);
834 while (++i < n) {
835 if (node = group[i]) {
836 value[i] = node.__data__;
837 }
838 }
839 return value;
840 }
841 function bind(group, groupData) {
842 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;
843 if (key) {
844 var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
845 for (i = -1; ++i < n; ) {
846 if (node = group[i]) {
847 if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
848 exitNodes[i] = node;
849 } else {
850 nodeByKeyValue.set(keyValue, node);
851 }
852 keyValues[i] = keyValue;
853 }
854 }
855 for (i = -1; ++i < m; ) {
856 if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
857 enterNodes[i] = d3_selection_dataNode(nodeData);
858 } else if (node !== true) {
859 updateNodes[i] = node;
860 node.__data__ = nodeData;
861 }
862 nodeByKeyValue.set(keyValue, true);
863 }
864 for (i = -1; ++i < n; ) {
865 if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
866 exitNodes[i] = group[i];
867 }
868 }
869 } else {
870 for (i = -1; ++i < n0; ) {
871 node = group[i];
872 nodeData = groupData[i];
873 if (node) {
874 node.__data__ = nodeData;
875 updateNodes[i] = node;
876 } else {
877 enterNodes[i] = d3_selection_dataNode(nodeData);
878 }
879 }
880 for (;i < m; ++i) {
881 enterNodes[i] = d3_selection_dataNode(groupData[i]);
882 }
883 for (;i < n; ++i) {
884 exitNodes[i] = group[i];
885 }
886 }
887 enterNodes.update = updateNodes;
888 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
889 enter.push(enterNodes);
890 update.push(updateNodes);
891 exit.push(exitNodes);
892 }
893 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
894 if (typeof value === "function") {
895 while (++i < n) {
896 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
897 }
898 } else {
899 while (++i < n) {
900 bind(group = this[i], value);
901 }
902 }
903 update.enter = function() {
904 return enter;
905 };
906 update.exit = function() {
907 return exit;
908 };
909 return update;
910 };
911 function d3_selection_dataNode(data) {
912 return {
913 __data__: data
914 };
915 }
916 d3_selectionPrototype.datum = function(value) {
917 return arguments.length ? this.property("__data__", value) : this.property("__data__");
918 };
919 d3_selectionPrototype.filter = function(filter) {
920 var subgroups = [], subgroup, group, node;
921 if (typeof filter !== "function") filter = d3_selection_filter(filter);
922 for (var j = 0, m = this.length; j < m; j++) {
923 subgroups.push(subgroup = []);
924 subgroup.parentNode = (group = this[j]).parentNode;
925 for (var i = 0, n = group.length; i < n; i++) {
926 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
927 subgroup.push(node);
928 }
929 }
930 }
931 return d3_selection(subgroups);
932 };
933 function d3_selection_filter(selector) {
934 return function() {
935 return d3_selectMatches(this, selector);
936 };
937 }
938 d3_selectionPrototype.order = function() {
939 for (var j = -1, m = this.length; ++j < m; ) {
940 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
941 if (node = group[i]) {
942 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
943 next = node;
944 }
945 }
946 }
947 return this;
948 };
949 d3_selectionPrototype.sort = function(comparator) {
950 comparator = d3_selection_sortComparator.apply(this, arguments);
951 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
952 return this.order();
953 };
954 function d3_selection_sortComparator(comparator) {
955 if (!arguments.length) comparator = d3_ascending;
956 return function(a, b) {
957 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
958 };
959 }
960 d3_selectionPrototype.each = function(callback) {
961 return d3_selection_each(this, function(node, i, j) {
962 callback.call(node, node.__data__, i, j);
963 });
964 };
965 function d3_selection_each(groups, callback) {
966 for (var j = 0, m = groups.length; j < m; j++) {
967 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
968 if (node = group[i]) callback(node, i, j);
969 }
970 }
971 return groups;
972 }
973 d3_selectionPrototype.call = function(callback) {
974 var args = d3_array(arguments);
975 callback.apply(args[0] = this, args);
976 return this;
977 };
978 d3_selectionPrototype.empty = function() {
979 return !this.node();
980 };
981 d3_selectionPrototype.node = function() {
982 for (var j = 0, m = this.length; j < m; j++) {
983 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
984 var node = group[i];
985 if (node) return node;
986 }
987 }
988 return null;
989 };
990 d3_selectionPrototype.size = function() {
991 var n = 0;
992 d3_selection_each(this, function() {
993 ++n;
994 });
995 return n;
996 };
997 function d3_selection_enter(selection) {
998 d3_subclass(selection, d3_selection_enterPrototype);
999 return selection;
1001 var d3_selection_enterPrototype = [];
1002 d3.selection.enter = d3_selection_enter;
1003 d3.selection.enter.prototype = d3_selection_enterPrototype;
1004 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
1005 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1006 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1007 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
1008 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
1009 d3_selection_enterPrototype.select = function(selector) {
1010 var subgroups = [], subgroup, subnode, upgroup, group, node;
1011 for (var j = -1, m = this.length; ++j < m; ) {
1012 upgroup = (group = this[j]).update;
1013 subgroups.push(subgroup = []);
1014 subgroup.parentNode = group.parentNode;
1015 for (var i = -1, n = group.length; ++i < n; ) {
1016 if (node = group[i]) {
1017 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
1018 subnode.__data__ = node.__data__;
1019 } else {
1020 subgroup.push(null);
1024 return d3_selection(subgroups);
1025 };
1026 d3_selection_enterPrototype.insert = function(name, before) {
1027 if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
1028 return d3_selectionPrototype.insert.call(this, name, before);
1029 };
1030 function d3_selection_enterInsertBefore(enter) {
1031 var i0, j0;
1032 return function(d, i, j) {
1033 var group = enter[j].update, n = group.length, node;
1034 if (j != j0) j0 = j, i0 = 0;
1035 if (i >= i0) i0 = i + 1;
1036 while (!(node = group[i0]) && ++i0 < n) ;
1037 return node;
1038 };
1040 d3.select = function(node) {
1041 var group;
1042 if (typeof node === "string") {
1043 group = [ d3_select(node, d3_document) ];
1044 group.parentNode = d3_document.documentElement;
1045 } else {
1046 group = [ node ];
1047 group.parentNode = d3_documentElement(node);
1049 return d3_selection([ group ]);
1050 };
1051 d3.selectAll = function(nodes) {
1052 var group;
1053 if (typeof nodes === "string") {
1054 group = d3_array(d3_selectAll(nodes, d3_document));
1055 group.parentNode = d3_document.documentElement;
1056 } else {
1057 group = d3_array(nodes);
1058 group.parentNode = null;
1060 return d3_selection([ group ]);
1061 };
1062 d3_selectionPrototype.on = function(type, listener, capture) {
1063 var n = arguments.length;
1064 if (n < 3) {
1065 if (typeof type !== "string") {
1066 if (n < 2) listener = false;
1067 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
1068 return this;
1070 if (n < 2) return (n = this.node()["__on" + type]) && n._;
1071 capture = false;
1073 return this.each(d3_selection_on(type, listener, capture));
1074 };
1075 function d3_selection_on(type, listener, capture) {
1076 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
1077 if (i > 0) type = type.slice(0, i);
1078 var filter = d3_selection_onFilters.get(type);
1079 if (filter) type = filter, wrap = d3_selection_onFilter;
1080 function onRemove() {
1081 var l = this[name];
1082 if (l) {
1083 this.removeEventListener(type, l, l.$);
1084 delete this[name];
1087 function onAdd() {
1088 var l = wrap(listener, d3_array(arguments));
1089 onRemove.call(this);
1090 this.addEventListener(type, this[name] = l, l.$ = capture);
1091 l._ = listener;
1093 function removeAll() {
1094 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
1095 for (var name in this) {
1096 if (match = name.match(re)) {
1097 var l = this[name];
1098 this.removeEventListener(match[1], l, l.$);
1099 delete this[name];
1103 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
1105 var d3_selection_onFilters = d3.map({
1106 mouseenter: "mouseover",
1107 mouseleave: "mouseout"
1108 });
1109 if (d3_document) {
1110 d3_selection_onFilters.forEach(function(k) {
1111 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
1112 });
1114 function d3_selection_onListener(listener, argumentz) {
1115 return function(e) {
1116 var o = d3.event;
1117 d3.event = e;
1118 argumentz[0] = this.__data__;
1119 try {
1120 listener.apply(this, argumentz);
1121 } finally {
1122 d3.event = o;
1124 };
1126 function d3_selection_onFilter(listener, argumentz) {
1127 var l = d3_selection_onListener(listener, argumentz);
1128 return function(e) {
1129 var target = this, related = e.relatedTarget;
1130 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
1131 l.call(target, e);
1133 };
1135 var d3_event_dragSelect, d3_event_dragId = 0;
1136 function d3_event_dragSuppress(node) {
1137 var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
1138 if (d3_event_dragSelect == null) {
1139 d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
1141 if (d3_event_dragSelect) {
1142 var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
1143 style[d3_event_dragSelect] = "none";
1145 return function(suppressClick) {
1146 w.on(name, null);
1147 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
1148 if (suppressClick) {
1149 var off = function() {
1150 w.on(click, null);
1151 };
1152 w.on(click, function() {
1153 d3_eventPreventDefault();
1154 off();
1155 }, true);
1156 setTimeout(off, 0);
1158 };
1160 d3.mouse = function(container) {
1161 return d3_mousePoint(container, d3_eventSource());
1162 };
1163 var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
1164 function d3_mousePoint(container, e) {
1165 if (e.changedTouches) e = e.changedTouches[0];
1166 var svg = container.ownerSVGElement || container;
1167 if (svg.createSVGPoint) {
1168 var point = svg.createSVGPoint();
1169 if (d3_mouse_bug44083 < 0) {
1170 var window = d3_window(container);
1171 if (window.scrollX || window.scrollY) {
1172 svg = d3.select("body").append("svg").style({
1173 position: "absolute",
1174 top: 0,
1175 left: 0,
1176 margin: 0,
1177 padding: 0,
1178 border: "none"
1179 }, "important");
1180 var ctm = svg[0][0].getScreenCTM();
1181 d3_mouse_bug44083 = !(ctm.f || ctm.e);
1182 svg.remove();
1185 if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
1186 point.y = e.clientY;
1187 point = point.matrixTransform(container.getScreenCTM().inverse());
1188 return [ point.x, point.y ];
1190 var rect = container.getBoundingClientRect();
1191 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
1193 d3.touch = function(container, touches, identifier) {
1194 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
1195 if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
1196 if ((touch = touches[i]).identifier === identifier) {
1197 return d3_mousePoint(container, touch);
1200 };
1201 d3.behavior.drag = function() {
1202 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
1203 function drag() {
1204 this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
1206 function dragstart(id, position, subject, move, end) {
1207 return function() {
1208 var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
1209 if (origin) {
1210 dragOffset = origin.apply(that, arguments);
1211 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
1212 } else {
1213 dragOffset = [ 0, 0 ];
1215 dispatch({
1216 type: "dragstart"
1217 });
1218 function moved() {
1219 var position1 = position(parent, dragId), dx, dy;
1220 if (!position1) return;
1221 dx = position1[0] - position0[0];
1222 dy = position1[1] - position0[1];
1223 dragged |= dx | dy;
1224 position0 = position1;
1225 dispatch({
1226 type: "drag",
1227 x: position1[0] + dragOffset[0],
1228 y: position1[1] + dragOffset[1],
1229 dx: dx,
1230 dy: dy
1231 });
1233 function ended() {
1234 if (!position(parent, dragId)) return;
1235 dragSubject.on(move + dragName, null).on(end + dragName, null);
1236 dragRestore(dragged);
1237 dispatch({
1238 type: "dragend"
1239 });
1241 };
1243 drag.origin = function(x) {
1244 if (!arguments.length) return origin;
1245 origin = x;
1246 return drag;
1247 };
1248 return d3.rebind(drag, event, "on");
1249 };
1250 function d3_behavior_dragTouchId() {
1251 return d3.event.changedTouches[0].identifier;
1253 d3.touches = function(container, touches) {
1254 if (arguments.length < 2) touches = d3_eventSource().touches;
1255 return touches ? d3_array(touches).map(function(touch) {
1256 var point = d3_mousePoint(container, touch);
1257 point.identifier = touch.identifier;
1258 return point;
1259 }) : [];
1260 };
1261 var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
1262 function d3_sgn(x) {
1263 return x > 0 ? 1 : x < 0 ? -1 : 0;
1265 function d3_cross2d(a, b, c) {
1266 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1268 function d3_acos(x) {
1269 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1271 function d3_asin(x) {
1272 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
1274 function d3_sinh(x) {
1275 return ((x = Math.exp(x)) - 1 / x) / 2;
1277 function d3_cosh(x) {
1278 return ((x = Math.exp(x)) + 1 / x) / 2;
1280 function d3_tanh(x) {
1281 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
1283 function d3_haversin(x) {
1284 return (x = Math.sin(x / 2)) * x;
1286 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
1287 d3.interpolateZoom = function(p0, p1) {
1288 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
1289 if (d2 < ε2) {
1290 S = Math.log(w1 / w0) / ρ;
1291 i = function(t) {
1292 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
1293 };
1294 } else {
1295 var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
1296 S = (r1 - r0) / ρ;
1297 i = function(t) {
1298 var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
1299 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
1300 };
1302 i.duration = S * 1e3;
1303 return i;
1304 };
1305 d3.behavior.zoom = function() {
1306 var view = {
1307 x: 0,
1308 y: 0,
1309 k: 1
1310 }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
1311 if (!d3_behavior_zoomWheel) {
1312 d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1313 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1314 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1315 return d3.event.wheelDelta;
1316 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
1317 return -d3.event.detail;
1318 }, "MozMousePixelScroll");
1320 function zoom(g) {
1321 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
1323 zoom.event = function(g) {
1324 g.each(function() {
1325 var dispatch = event.of(this, arguments), view1 = view;
1326 if (d3_transitionInheritId) {
1327 d3.select(this).transition().each("start.zoom", function() {
1328 view = this.__chart__ || {
1329 x: 0,
1330 y: 0,
1331 k: 1
1332 };
1333 zoomstarted(dispatch);
1334 }).tween("zoom:zoom", function() {
1335 var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
1336 return function(t) {
1337 var l = i(t), k = dx / l[2];
1338 this.__chart__ = view = {
1339 x: cx - l[0] * k,
1340 y: cy - l[1] * k,
1341 k: k
1342 };
1343 zoomed(dispatch);
1344 };
1345 }).each("interrupt.zoom", function() {
1346 zoomended(dispatch);
1347 }).each("end.zoom", function() {
1348 zoomended(dispatch);
1349 });
1350 } else {
1351 this.__chart__ = view;
1352 zoomstarted(dispatch);
1353 zoomed(dispatch);
1354 zoomended(dispatch);
1356 });
1357 };
1358 zoom.translate = function(_) {
1359 if (!arguments.length) return [ view.x, view.y ];
1360 view = {
1361 x: +_[0],
1362 y: +_[1],
1363 k: view.k
1364 };
1365 rescale();
1366 return zoom;
1367 };
1368 zoom.scale = function(_) {
1369 if (!arguments.length) return view.k;
1370 view = {
1371 x: view.x,
1372 y: view.y,
1373 k: null
1374 };
1375 scaleTo(+_);
1376 rescale();
1377 return zoom;
1378 };
1379 zoom.scaleExtent = function(_) {
1380 if (!arguments.length) return scaleExtent;
1381 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
1382 return zoom;
1383 };
1384 zoom.center = function(_) {
1385 if (!arguments.length) return center;
1386 center = _ && [ +_[0], +_[1] ];
1387 return zoom;
1388 };
1389 zoom.size = function(_) {
1390 if (!arguments.length) return size;
1391 size = _ && [ +_[0], +_[1] ];
1392 return zoom;
1393 };
1394 zoom.duration = function(_) {
1395 if (!arguments.length) return duration;
1396 duration = +_;
1397 return zoom;
1398 };
1399 zoom.x = function(z) {
1400 if (!arguments.length) return x1;
1401 x1 = z;
1402 x0 = z.copy();
1403 view = {
1404 x: 0,
1405 y: 0,
1406 k: 1
1407 };
1408 return zoom;
1409 };
1410 zoom.y = function(z) {
1411 if (!arguments.length) return y1;
1412 y1 = z;
1413 y0 = z.copy();
1414 view = {
1415 x: 0,
1416 y: 0,
1417 k: 1
1418 };
1419 return zoom;
1420 };
1421 function location(p) {
1422 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
1424 function point(l) {
1425 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
1427 function scaleTo(s) {
1428 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1430 function translateTo(p, l) {
1431 l = point(l);
1432 view.x += p[0] - l[0];
1433 view.y += p[1] - l[1];
1435 function zoomTo(that, p, l, k) {
1436 that.__chart__ = {
1437 x: view.x,
1438 y: view.y,
1439 k: view.k
1440 };
1441 scaleTo(Math.pow(2, k));
1442 translateTo(center0 = p, l);
1443 that = d3.select(that);
1444 if (duration > 0) that = that.transition().duration(duration);
1445 that.call(zoom.event);
1447 function rescale() {
1448 if (x1) x1.domain(x0.range().map(function(x) {
1449 return (x - view.x) / view.k;
1450 }).map(x0.invert));
1451 if (y1) y1.domain(y0.range().map(function(y) {
1452 return (y - view.y) / view.k;
1453 }).map(y0.invert));
1455 function zoomstarted(dispatch) {
1456 if (!zooming++) dispatch({
1457 type: "zoomstart"
1458 });
1460 function zoomed(dispatch) {
1461 rescale();
1462 dispatch({
1463 type: "zoom",
1464 scale: view.k,
1465 translate: [ view.x, view.y ]
1466 });
1468 function zoomended(dispatch) {
1469 if (!--zooming) dispatch({
1470 type: "zoomend"
1471 }), center0 = null;
1473 function mousedowned() {
1474 var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
1475 d3_selection_interrupt.call(that);
1476 zoomstarted(dispatch);
1477 function moved() {
1478 dragged = 1;
1479 translateTo(d3.mouse(that), location0);
1480 zoomed(dispatch);
1482 function ended() {
1483 subject.on(mousemove, null).on(mouseup, null);
1484 dragRestore(dragged);
1485 zoomended(dispatch);
1488 function touchstarted() {
1489 var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
1490 started();
1491 zoomstarted(dispatch);
1492 subject.on(mousedown, null).on(touchstart, started);
1493 function relocate() {
1494 var touches = d3.touches(that);
1495 scale0 = view.k;
1496 touches.forEach(function(t) {
1497 if (t.identifier in locations0) locations0[t.identifier] = location(t);
1498 });
1499 return touches;
1501 function started() {
1502 var target = d3.event.target;
1503 d3.select(target).on(touchmove, moved).on(touchend, ended);
1504 targets.push(target);
1505 var changed = d3.event.changedTouches;
1506 for (var i = 0, n = changed.length; i < n; ++i) {
1507 locations0[changed[i].identifier] = null;
1509 var touches = relocate(), now = Date.now();
1510 if (touches.length === 1) {
1511 if (now - touchtime < 500) {
1512 var p = touches[0];
1513 zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
1514 d3_eventPreventDefault();
1516 touchtime = now;
1517 } else if (touches.length > 1) {
1518 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1519 distance0 = dx * dx + dy * dy;
1522 function moved() {
1523 var touches = d3.touches(that), p0, l0, p1, l1;
1524 d3_selection_interrupt.call(that);
1525 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1526 p1 = touches[i];
1527 if (l1 = locations0[p1.identifier]) {
1528 if (l0) break;
1529 p0 = p1, l0 = l1;
1532 if (l1) {
1533 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
1534 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1535 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
1536 scaleTo(scale1 * scale0);
1538 touchtime = null;
1539 translateTo(p0, l0);
1540 zoomed(dispatch);
1542 function ended() {
1543 if (d3.event.touches.length) {
1544 var changed = d3.event.changedTouches;
1545 for (var i = 0, n = changed.length; i < n; ++i) {
1546 delete locations0[changed[i].identifier];
1548 for (var identifier in locations0) {
1549 return void relocate();
1552 d3.selectAll(targets).on(zoomName, null);
1553 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
1554 dragRestore();
1555 zoomended(dispatch);
1558 function mousewheeled() {
1559 var dispatch = event.of(this, arguments);
1560 if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
1561 translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
1562 mousewheelTimer = setTimeout(function() {
1563 mousewheelTimer = null;
1564 zoomended(dispatch);
1565 }, 50);
1566 d3_eventPreventDefault();
1567 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
1568 translateTo(center0, translate0);
1569 zoomed(dispatch);
1571 function dblclicked() {
1572 var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
1573 zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
1575 return d3.rebind(zoom, event, "on");
1576 };
1577 var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
1578 d3.color = d3_color;
1579 function d3_color() {}
1580 d3_color.prototype.toString = function() {
1581 return this.rgb() + "";
1582 };
1583 d3.hsl = d3_hsl;
1584 function d3_hsl(h, s, l) {
1585 return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
1587 var d3_hslPrototype = d3_hsl.prototype = new d3_color();
1588 d3_hslPrototype.brighter = function(k) {
1589 k = Math.pow(.7, arguments.length ? k : 1);
1590 return new d3_hsl(this.h, this.s, this.l / k);
1591 };
1592 d3_hslPrototype.darker = function(k) {
1593 k = Math.pow(.7, arguments.length ? k : 1);
1594 return new d3_hsl(this.h, this.s, k * this.l);
1595 };
1596 d3_hslPrototype.rgb = function() {
1597 return d3_hsl_rgb(this.h, this.s, this.l);
1598 };
1599 function d3_hsl_rgb(h, s, l) {
1600 var m1, m2;
1601 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
1602 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
1603 l = l < 0 ? 0 : l > 1 ? 1 : l;
1604 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1605 m1 = 2 * l - m2;
1606 function v(h) {
1607 if (h > 360) h -= 360; else if (h < 0) h += 360;
1608 if (h < 60) return m1 + (m2 - m1) * h / 60;
1609 if (h < 180) return m2;
1610 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
1611 return m1;
1613 function vv(h) {
1614 return Math.round(v(h) * 255);
1616 return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1618 d3.hcl = d3_hcl;
1619 function d3_hcl(h, c, l) {
1620 return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new 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) : new d3_hcl(h, c, l);
1622 var d3_hclPrototype = d3_hcl.prototype = new d3_color();
1623 d3_hclPrototype.brighter = function(k) {
1624 return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1625 };
1626 d3_hclPrototype.darker = function(k) {
1627 return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1628 };
1629 d3_hclPrototype.rgb = function() {
1630 return d3_hcl_lab(this.h, this.c, this.l).rgb();
1631 };
1632 function d3_hcl_lab(h, c, l) {
1633 if (isNaN(h)) h = 0;
1634 if (isNaN(c)) c = 0;
1635 return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1637 d3.lab = d3_lab;
1638 function d3_lab(l, a, b) {
1639 return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
1641 var d3_lab_K = 18;
1642 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1643 var d3_labPrototype = d3_lab.prototype = new d3_color();
1644 d3_labPrototype.brighter = function(k) {
1645 return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1646 };
1647 d3_labPrototype.darker = function(k) {
1648 return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1649 };
1650 d3_labPrototype.rgb = function() {
1651 return d3_lab_rgb(this.l, this.a, this.b);
1652 };
1653 function d3_lab_rgb(l, a, b) {
1654 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1655 x = d3_lab_xyz(x) * d3_lab_X;
1656 y = d3_lab_xyz(y) * d3_lab_Y;
1657 z = d3_lab_xyz(z) * d3_lab_Z;
1658 return new 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));
1660 function d3_lab_hcl(l, a, b) {
1661 return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
1663 function d3_lab_xyz(x) {
1664 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1666 function d3_xyz_lab(x) {
1667 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1669 function d3_xyz_rgb(r) {
1670 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1672 d3.rgb = d3_rgb;
1673 function d3_rgb(r, g, b) {
1674 return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
1676 function d3_rgbNumber(value) {
1677 return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
1679 function d3_rgbString(value) {
1680 return d3_rgbNumber(value) + "";
1682 var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
1683 d3_rgbPrototype.brighter = function(k) {
1684 k = Math.pow(.7, arguments.length ? k : 1);
1685 var r = this.r, g = this.g, b = this.b, i = 30;
1686 if (!r && !g && !b) return new d3_rgb(i, i, i);
1687 if (r && r < i) r = i;
1688 if (g && g < i) g = i;
1689 if (b && b < i) b = i;
1690 return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
1691 };
1692 d3_rgbPrototype.darker = function(k) {
1693 k = Math.pow(.7, arguments.length ? k : 1);
1694 return new d3_rgb(k * this.r, k * this.g, k * this.b);
1695 };
1696 d3_rgbPrototype.hsl = function() {
1697 return d3_rgb_hsl(this.r, this.g, this.b);
1698 };
1699 d3_rgbPrototype.toString = function() {
1700 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1701 };
1702 function d3_rgb_hex(v) {
1703 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1705 function d3_rgb_parse(format, rgb, hsl) {
1706 var r = 0, g = 0, b = 0, m1, m2, color;
1707 m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
1708 if (m1) {
1709 m2 = m1[2].split(",");
1710 switch (m1[1]) {
1711 case "hsl":
1713 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1716 case "rgb":
1718 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1722 if (color = d3_rgb_names.get(format)) {
1723 return rgb(color.r, color.g, color.b);
1725 if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
1726 if (format.length === 4) {
1727 r = (color & 3840) >> 4;
1728 r = r >> 4 | r;
1729 g = color & 240;
1730 g = g >> 4 | g;
1731 b = color & 15;
1732 b = b << 4 | b;
1733 } else if (format.length === 7) {
1734 r = (color & 16711680) >> 16;
1735 g = (color & 65280) >> 8;
1736 b = color & 255;
1739 return rgb(r, g, b);
1741 function d3_rgb_hsl(r, g, b) {
1742 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;
1743 if (d) {
1744 s = l < .5 ? d / (max + min) : d / (2 - max - min);
1745 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;
1746 h *= 60;
1747 } else {
1748 h = NaN;
1749 s = l > 0 && l < 1 ? 0 : h;
1751 return new d3_hsl(h, s, l);
1753 function d3_rgb_lab(r, g, b) {
1754 r = d3_rgb_xyz(r);
1755 g = d3_rgb_xyz(g);
1756 b = d3_rgb_xyz(b);
1757 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);
1758 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1760 function d3_rgb_xyz(r) {
1761 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1763 function d3_rgb_parseNumber(c) {
1764 var f = parseFloat(c);
1765 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1767 var d3_rgb_names = d3.map({
1768 aliceblue: 15792383,
1769 antiquewhite: 16444375,
1770 aqua: 65535,
1771 aquamarine: 8388564,
1772 azure: 15794175,
1773 beige: 16119260,
1774 bisque: 16770244,
1775 black: 0,
1776 blanchedalmond: 16772045,
1777 blue: 255,
1778 blueviolet: 9055202,
1779 brown: 10824234,
1780 burlywood: 14596231,
1781 cadetblue: 6266528,
1782 chartreuse: 8388352,
1783 chocolate: 13789470,
1784 coral: 16744272,
1785 cornflowerblue: 6591981,
1786 cornsilk: 16775388,
1787 crimson: 14423100,
1788 cyan: 65535,
1789 darkblue: 139,
1790 darkcyan: 35723,
1791 darkgoldenrod: 12092939,
1792 darkgray: 11119017,
1793 darkgreen: 25600,
1794 darkgrey: 11119017,
1795 darkkhaki: 12433259,
1796 darkmagenta: 9109643,
1797 darkolivegreen: 5597999,
1798 darkorange: 16747520,
1799 darkorchid: 10040012,
1800 darkred: 9109504,
1801 darksalmon: 15308410,
1802 darkseagreen: 9419919,
1803 darkslateblue: 4734347,
1804 darkslategray: 3100495,
1805 darkslategrey: 3100495,
1806 darkturquoise: 52945,
1807 darkviolet: 9699539,
1808 deeppink: 16716947,
1809 deepskyblue: 49151,
1810 dimgray: 6908265,
1811 dimgrey: 6908265,
1812 dodgerblue: 2003199,
1813 firebrick: 11674146,
1814 floralwhite: 16775920,
1815 forestgreen: 2263842,
1816 fuchsia: 16711935,
1817 gainsboro: 14474460,
1818 ghostwhite: 16316671,
1819 gold: 16766720,
1820 goldenrod: 14329120,
1821 gray: 8421504,
1822 green: 32768,
1823 greenyellow: 11403055,
1824 grey: 8421504,
1825 honeydew: 15794160,
1826 hotpink: 16738740,
1827 indianred: 13458524,
1828 indigo: 4915330,
1829 ivory: 16777200,
1830 khaki: 15787660,
1831 lavender: 15132410,
1832 lavenderblush: 16773365,
1833 lawngreen: 8190976,
1834 lemonchiffon: 16775885,
1835 lightblue: 11393254,
1836 lightcoral: 15761536,
1837 lightcyan: 14745599,
1838 lightgoldenrodyellow: 16448210,
1839 lightgray: 13882323,
1840 lightgreen: 9498256,
1841 lightgrey: 13882323,
1842 lightpink: 16758465,
1843 lightsalmon: 16752762,
1844 lightseagreen: 2142890,
1845 lightskyblue: 8900346,
1846 lightslategray: 7833753,
1847 lightslategrey: 7833753,
1848 lightsteelblue: 11584734,
1849 lightyellow: 16777184,
1850 lime: 65280,
1851 limegreen: 3329330,
1852 linen: 16445670,
1853 magenta: 16711935,
1854 maroon: 8388608,
1855 mediumaquamarine: 6737322,
1856 mediumblue: 205,
1857 mediumorchid: 12211667,
1858 mediumpurple: 9662683,
1859 mediumseagreen: 3978097,
1860 mediumslateblue: 8087790,
1861 mediumspringgreen: 64154,
1862 mediumturquoise: 4772300,
1863 mediumvioletred: 13047173,
1864 midnightblue: 1644912,
1865 mintcream: 16121850,
1866 mistyrose: 16770273,
1867 moccasin: 16770229,
1868 navajowhite: 16768685,
1869 navy: 128,
1870 oldlace: 16643558,
1871 olive: 8421376,
1872 olivedrab: 7048739,
1873 orange: 16753920,
1874 orangered: 16729344,
1875 orchid: 14315734,
1876 palegoldenrod: 15657130,
1877 palegreen: 10025880,
1878 paleturquoise: 11529966,
1879 palevioletred: 14381203,
1880 papayawhip: 16773077,
1881 peachpuff: 16767673,
1882 peru: 13468991,
1883 pink: 16761035,
1884 plum: 14524637,
1885 powderblue: 11591910,
1886 purple: 8388736,
1887 rebeccapurple: 6697881,
1888 red: 16711680,
1889 rosybrown: 12357519,
1890 royalblue: 4286945,
1891 saddlebrown: 9127187,
1892 salmon: 16416882,
1893 sandybrown: 16032864,
1894 seagreen: 3050327,
1895 seashell: 16774638,
1896 sienna: 10506797,
1897 silver: 12632256,
1898 skyblue: 8900331,
1899 slateblue: 6970061,
1900 slategray: 7372944,
1901 slategrey: 7372944,
1902 snow: 16775930,
1903 springgreen: 65407,
1904 steelblue: 4620980,
1905 tan: 13808780,
1906 teal: 32896,
1907 thistle: 14204888,
1908 tomato: 16737095,
1909 turquoise: 4251856,
1910 violet: 15631086,
1911 wheat: 16113331,
1912 white: 16777215,
1913 whitesmoke: 16119285,
1914 yellow: 16776960,
1915 yellowgreen: 10145074
1916 });
1917 d3_rgb_names.forEach(function(key, value) {
1918 d3_rgb_names.set(key, d3_rgbNumber(value));
1919 });
1920 function d3_functor(v) {
1921 return typeof v === "function" ? v : function() {
1922 return v;
1923 };
1925 d3.functor = d3_functor;
1926 d3.xhr = d3_xhrType(d3_identity);
1927 function d3_xhrType(response) {
1928 return function(url, mimeType, callback) {
1929 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
1930 mimeType = null;
1931 return d3_xhr(url, mimeType, response, callback);
1932 };
1934 function d3_xhr(url, mimeType, response, callback) {
1935 var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
1936 if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
1937 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1938 request.readyState > 3 && respond();
1939 };
1940 function respond() {
1941 var status = request.status, result;
1942 if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
1943 try {
1944 result = response.call(xhr, request);
1945 } catch (e) {
1946 dispatch.error.call(xhr, e);
1947 return;
1949 dispatch.load.call(xhr, result);
1950 } else {
1951 dispatch.error.call(xhr, request);
1954 request.onprogress = function(event) {
1955 var o = d3.event;
1956 d3.event = event;
1957 try {
1958 dispatch.progress.call(xhr, request);
1959 } finally {
1960 d3.event = o;
1962 };
1963 xhr.header = function(name, value) {
1964 name = (name + "").toLowerCase();
1965 if (arguments.length < 2) return headers[name];
1966 if (value == null) delete headers[name]; else headers[name] = value + "";
1967 return xhr;
1968 };
1969 xhr.mimeType = function(value) {
1970 if (!arguments.length) return mimeType;
1971 mimeType = value == null ? null : value + "";
1972 return xhr;
1973 };
1974 xhr.responseType = function(value) {
1975 if (!arguments.length) return responseType;
1976 responseType = value;
1977 return xhr;
1978 };
1979 xhr.response = function(value) {
1980 response = value;
1981 return xhr;
1982 };
1983 [ "get", "post" ].forEach(function(method) {
1984 xhr[method] = function() {
1985 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
1986 };
1987 });
1988 xhr.send = function(method, data, callback) {
1989 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
1990 request.open(method, url, true);
1991 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
1992 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
1993 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
1994 if (responseType != null) request.responseType = responseType;
1995 if (callback != null) xhr.on("error", callback).on("load", function(request) {
1996 callback(null, request);
1997 });
1998 dispatch.beforesend.call(xhr, request);
1999 request.send(data == null ? null : data);
2000 return xhr;
2001 };
2002 xhr.abort = function() {
2003 request.abort();
2004 return xhr;
2005 };
2006 d3.rebind(xhr, dispatch, "on");
2007 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
2009 function d3_xhr_fixCallback(callback) {
2010 return callback.length === 1 ? function(error, request) {
2011 callback(error == null ? request : null);
2012 } : callback;
2014 function d3_xhrHasResponse(request) {
2015 var type = request.responseType;
2016 return type && type !== "text" ? request.response : request.responseText;
2018 d3.dsv = function(delimiter, mimeType) {
2019 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
2020 function dsv(url, row, callback) {
2021 if (arguments.length < 3) callback = row, row = null;
2022 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
2023 xhr.row = function(_) {
2024 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
2025 };
2026 return xhr;
2028 function response(request) {
2029 return dsv.parse(request.responseText);
2031 function typedResponse(f) {
2032 return function(request) {
2033 return dsv.parse(request.responseText, f);
2034 };
2036 dsv.parse = function(text, f) {
2037 var o;
2038 return dsv.parseRows(text, function(row, i) {
2039 if (o) return o(row, i - 1);
2040 var a = new Function("d", "return {" + row.map(function(name, i) {
2041 return JSON.stringify(name) + ": d[" + i + "]";
2042 }).join(",") + "}");
2043 o = f ? function(row, i) {
2044 return f(a(row), i);
2045 } : a;
2046 });
2047 };
2048 dsv.parseRows = function(text, f) {
2049 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
2050 function token() {
2051 if (I >= N) return EOF;
2052 if (eol) return eol = false, EOL;
2053 var j = I;
2054 if (text.charCodeAt(j) === 34) {
2055 var i = j;
2056 while (i++ < N) {
2057 if (text.charCodeAt(i) === 34) {
2058 if (text.charCodeAt(i + 1) !== 34) break;
2059 ++i;
2062 I = i + 2;
2063 var c = text.charCodeAt(i + 1);
2064 if (c === 13) {
2065 eol = true;
2066 if (text.charCodeAt(i + 2) === 10) ++I;
2067 } else if (c === 10) {
2068 eol = true;
2070 return text.slice(j + 1, i).replace(/""/g, '"');
2072 while (I < N) {
2073 var c = text.charCodeAt(I++), k = 1;
2074 if (c === 10) eol = true; else if (c === 13) {
2075 eol = true;
2076 if (text.charCodeAt(I) === 10) ++I, ++k;
2077 } else if (c !== delimiterCode) continue;
2078 return text.slice(j, I - k);
2080 return text.slice(j);
2082 while ((t = token()) !== EOF) {
2083 var a = [];
2084 while (t !== EOL && t !== EOF) {
2085 a.push(t);
2086 t = token();
2088 if (f && (a = f(a, n++)) == null) continue;
2089 rows.push(a);
2091 return rows;
2092 };
2093 dsv.format = function(rows) {
2094 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
2095 var fieldSet = new d3_Set(), fields = [];
2096 rows.forEach(function(row) {
2097 for (var field in row) {
2098 if (!fieldSet.has(field)) {
2099 fields.push(fieldSet.add(field));
2102 });
2103 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
2104 return fields.map(function(field) {
2105 return formatValue(row[field]);
2106 }).join(delimiter);
2107 })).join("\n");
2108 };
2109 dsv.formatRows = function(rows) {
2110 return rows.map(formatRow).join("\n");
2111 };
2112 function formatRow(row) {
2113 return row.map(formatValue).join(delimiter);
2115 function formatValue(text) {
2116 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
2118 return dsv;
2119 };
2120 d3.csv = d3.dsv(",", "text/csv");
2121 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
2122 var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
2123 setTimeout(callback, 17);
2124 };
2125 d3.timer = function() {
2126 d3_timer.apply(this, arguments);
2127 };
2128 function d3_timer(callback, delay, then) {
2129 var n = arguments.length;
2130 if (n < 2) delay = 0;
2131 if (n < 3) then = Date.now();
2132 var time = then + delay, timer = {
2133 c: callback,
2134 t: time,
2135 n: null
2136 };
2137 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
2138 d3_timer_queueTail = timer;
2139 if (!d3_timer_interval) {
2140 d3_timer_timeout = clearTimeout(d3_timer_timeout);
2141 d3_timer_interval = 1;
2142 d3_timer_frame(d3_timer_step);
2144 return timer;
2146 function d3_timer_step() {
2147 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
2148 if (delay > 24) {
2149 if (isFinite(delay)) {
2150 clearTimeout(d3_timer_timeout);
2151 d3_timer_timeout = setTimeout(d3_timer_step, delay);
2153 d3_timer_interval = 0;
2154 } else {
2155 d3_timer_interval = 1;
2156 d3_timer_frame(d3_timer_step);
2159 d3.timer.flush = function() {
2160 d3_timer_mark();
2161 d3_timer_sweep();
2162 };
2163 function d3_timer_mark() {
2164 var now = Date.now(), timer = d3_timer_queueHead;
2165 while (timer) {
2166 if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
2167 timer = timer.n;
2169 return now;
2171 function d3_timer_sweep() {
2172 var t0, t1 = d3_timer_queueHead, time = Infinity;
2173 while (t1) {
2174 if (t1.c) {
2175 if (t1.t < time) time = t1.t;
2176 t1 = (t0 = t1).n;
2177 } else {
2178 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2181 d3_timer_queueTail = t0;
2182 return time;
2184 function d3_format_precision(x, p) {
2185 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
2187 d3.round = function(x, n) {
2188 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2189 };
2190 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
2191 d3.formatPrefix = function(value, precision) {
2192 var i = 0;
2193 if (value = +value) {
2194 if (value < 0) value *= -1;
2195 if (precision) value = d3.round(value, d3_format_precision(value, precision));
2196 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
2197 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
2199 return d3_formatPrefixes[8 + i / 3];
2200 };
2201 function d3_formatPrefix(d, i) {
2202 var k = Math.pow(10, abs(8 - i) * 3);
2203 return {
2204 scale: i > 8 ? function(d) {
2205 return d / k;
2206 } : function(d) {
2207 return d * k;
2208 },
2209 symbol: d
2210 };
2212 function d3_locale_numberFormat(locale) {
2213 var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
2214 var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
2215 while (i > 0 && g > 0) {
2216 if (length + g + 1 > width) g = Math.max(1, width - length);
2217 t.push(value.substring(i -= g, i + g));
2218 if ((length += g + 1) > width) break;
2219 g = locale_grouping[j = (j + 1) % locale_grouping.length];
2221 return t.reverse().join(locale_thousands);
2222 } : d3_identity;
2223 return function(specifier) {
2224 var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
2225 if (precision) precision = +precision.substring(1);
2226 if (zfill || fill === "0" && align === "=") {
2227 zfill = fill = "0";
2228 align = "=";
2230 switch (type) {
2231 case "n":
2232 comma = true;
2233 type = "g";
2234 break;
2236 case "%":
2237 scale = 100;
2238 suffix = "%";
2239 type = "f";
2240 break;
2242 case "p":
2243 scale = 100;
2244 suffix = "%";
2245 type = "r";
2246 break;
2248 case "b":
2249 case "o":
2250 case "x":
2251 case "X":
2252 if (symbol === "#") prefix = "0" + type.toLowerCase();
2254 case "c":
2255 exponent = false;
2257 case "d":
2258 integer = true;
2259 precision = 0;
2260 break;
2262 case "s":
2263 scale = -1;
2264 type = "r";
2265 break;
2267 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
2268 if (type == "r" && !precision) type = "g";
2269 if (precision != null) {
2270 if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision));
2272 type = d3_format_types.get(type) || d3_format_typeDefault;
2273 var zcomma = zfill && comma;
2274 return function(value) {
2275 var fullSuffix = suffix;
2276 if (integer && value % 1) return "";
2277 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
2278 if (scale < 0) {
2279 var unit = d3.formatPrefix(value, precision);
2280 value = unit.scale(value);
2281 fullSuffix = unit.symbol + suffix;
2282 } else {
2283 value *= scale;
2285 value = type(value, precision);
2286 var i = value.lastIndexOf("."), before, after;
2287 if (i < 0) {
2288 var j = exponent ? value.lastIndexOf("e") : -1;
2289 if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
2290 } else {
2291 before = value.substring(0, i);
2292 after = locale_decimal + value.substring(i + 1);
2294 if (!zfill && comma) before = formatGroup(before, Infinity);
2295 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
2296 if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
2297 negative += prefix;
2298 value = before + after;
2299 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)) + fullSuffix;
2300 };
2301 };
2303 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
2304 var d3_format_types = d3.map({
2305 b: function(x) {
2306 return x.toString(2);
2307 },
2308 c: function(x) {
2309 return String.fromCharCode(x);
2310 },
2311 o: function(x) {
2312 return x.toString(8);
2313 },
2314 x: function(x) {
2315 return x.toString(16);
2316 },
2317 X: function(x) {
2318 return x.toString(16).toUpperCase();
2319 },
2320 g: function(x, p) {
2321 return x.toPrecision(p);
2322 },
2323 e: function(x, p) {
2324 return x.toExponential(p);
2325 },
2326 f: function(x, p) {
2327 return x.toFixed(p);
2328 },
2329 r: function(x, p) {
2330 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))));
2332 });
2333 function d3_format_typeDefault(x) {
2334 return x + "";
2336 var d3_time = d3.time = {}, d3_date = Date;
2337 function d3_date_utc() {
2338 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2340 d3_date_utc.prototype = {
2341 getDate: function() {
2342 return this._.getUTCDate();
2343 },
2344 getDay: function() {
2345 return this._.getUTCDay();
2346 },
2347 getFullYear: function() {
2348 return this._.getUTCFullYear();
2349 },
2350 getHours: function() {
2351 return this._.getUTCHours();
2352 },
2353 getMilliseconds: function() {
2354 return this._.getUTCMilliseconds();
2355 },
2356 getMinutes: function() {
2357 return this._.getUTCMinutes();
2358 },
2359 getMonth: function() {
2360 return this._.getUTCMonth();
2361 },
2362 getSeconds: function() {
2363 return this._.getUTCSeconds();
2364 },
2365 getTime: function() {
2366 return this._.getTime();
2367 },
2368 getTimezoneOffset: function() {
2369 return 0;
2370 },
2371 valueOf: function() {
2372 return this._.valueOf();
2373 },
2374 setDate: function() {
2375 d3_time_prototype.setUTCDate.apply(this._, arguments);
2376 },
2377 setDay: function() {
2378 d3_time_prototype.setUTCDay.apply(this._, arguments);
2379 },
2380 setFullYear: function() {
2381 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
2382 },
2383 setHours: function() {
2384 d3_time_prototype.setUTCHours.apply(this._, arguments);
2385 },
2386 setMilliseconds: function() {
2387 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
2388 },
2389 setMinutes: function() {
2390 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
2391 },
2392 setMonth: function() {
2393 d3_time_prototype.setUTCMonth.apply(this._, arguments);
2394 },
2395 setSeconds: function() {
2396 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
2397 },
2398 setTime: function() {
2399 d3_time_prototype.setTime.apply(this._, arguments);
2401 };
2402 var d3_time_prototype = Date.prototype;
2403 function d3_time_interval(local, step, number) {
2404 function round(date) {
2405 var d0 = local(date), d1 = offset(d0, 1);
2406 return date - d0 < d1 - date ? d0 : d1;
2408 function ceil(date) {
2409 step(date = local(new d3_date(date - 1)), 1);
2410 return date;
2412 function offset(date, k) {
2413 step(date = new d3_date(+date), k);
2414 return date;
2416 function range(t0, t1, dt) {
2417 var time = ceil(t0), times = [];
2418 if (dt > 1) {
2419 while (time < t1) {
2420 if (!(number(time) % dt)) times.push(new Date(+time));
2421 step(time, 1);
2423 } else {
2424 while (time < t1) times.push(new Date(+time)), step(time, 1);
2426 return times;
2428 function range_utc(t0, t1, dt) {
2429 try {
2430 d3_date = d3_date_utc;
2431 var utc = new d3_date_utc();
2432 utc._ = t0;
2433 return range(utc, t1, dt);
2434 } finally {
2435 d3_date = Date;
2438 local.floor = local;
2439 local.round = round;
2440 local.ceil = ceil;
2441 local.offset = offset;
2442 local.range = range;
2443 var utc = local.utc = d3_time_interval_utc(local);
2444 utc.floor = utc;
2445 utc.round = d3_time_interval_utc(round);
2446 utc.ceil = d3_time_interval_utc(ceil);
2447 utc.offset = d3_time_interval_utc(offset);
2448 utc.range = range_utc;
2449 return local;
2451 function d3_time_interval_utc(method) {
2452 return function(date, k) {
2453 try {
2454 d3_date = d3_date_utc;
2455 var utc = new d3_date_utc();
2456 utc._ = date;
2457 return method(utc, k)._;
2458 } finally {
2459 d3_date = Date;
2461 };
2463 d3_time.year = d3_time_interval(function(date) {
2464 date = d3_time.day(date);
2465 date.setMonth(0, 1);
2466 return date;
2467 }, function(date, offset) {
2468 date.setFullYear(date.getFullYear() + offset);
2469 }, function(date) {
2470 return date.getFullYear();
2471 });
2472 d3_time.years = d3_time.year.range;
2473 d3_time.years.utc = d3_time.year.utc.range;
2474 d3_time.day = d3_time_interval(function(date) {
2475 var day = new d3_date(2e3, 0);
2476 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
2477 return day;
2478 }, function(date, offset) {
2479 date.setDate(date.getDate() + offset);
2480 }, function(date) {
2481 return date.getDate() - 1;
2482 });
2483 d3_time.days = d3_time.day.range;
2484 d3_time.days.utc = d3_time.day.utc.range;
2485 d3_time.dayOfYear = function(date) {
2486 var year = d3_time.year(date);
2487 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2488 };
2489 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
2490 i = 7 - i;
2491 var interval = d3_time[day] = d3_time_interval(function(date) {
2492 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
2493 return date;
2494 }, function(date, offset) {
2495 date.setDate(date.getDate() + Math.floor(offset) * 7);
2496 }, function(date) {
2497 var day = d3_time.year(date).getDay();
2498 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
2499 });
2500 d3_time[day + "s"] = interval.range;
2501 d3_time[day + "s"].utc = interval.utc.range;
2502 d3_time[day + "OfYear"] = function(date) {
2503 var day = d3_time.year(date).getDay();
2504 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
2505 };
2506 });
2507 d3_time.week = d3_time.sunday;
2508 d3_time.weeks = d3_time.sunday.range;
2509 d3_time.weeks.utc = d3_time.sunday.utc.range;
2510 d3_time.weekOfYear = d3_time.sundayOfYear;
2511 function d3_locale_timeFormat(locale) {
2512 var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
2513 function d3_time_format(template) {
2514 var n = template.length;
2515 function format(date) {
2516 var string = [], i = -1, j = 0, c, p, f;
2517 while (++i < n) {
2518 if (template.charCodeAt(i) === 37) {
2519 string.push(template.slice(j, i));
2520 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
2521 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
2522 string.push(c);
2523 j = i + 1;
2526 string.push(template.slice(j, i));
2527 return string.join("");
2529 format.parse = function(string) {
2530 var d = {
2531 y: 1900,
2532 m: 0,
2533 d: 1,
2534 H: 0,
2535 M: 0,
2536 S: 0,
2537 L: 0,
2538 Z: null
2539 }, i = d3_time_parse(d, template, string, 0);
2540 if (i != string.length) return null;
2541 if ("p" in d) d.H = d.H % 12 + d.p * 12;
2542 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
2543 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
2544 if (!("w" in d)) d.w = "W" in d ? 1 : 0;
2545 date.setFullYear(d.y, 0, 1);
2546 date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
2547 } else date.setFullYear(d.y, d.m, d.d);
2548 date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
2549 return localZ ? date._ : date;
2550 };
2551 format.toString = function() {
2552 return template;
2553 };
2554 return format;
2556 function d3_time_parse(date, template, string, j) {
2557 var c, p, t, i = 0, n = template.length, m = string.length;
2558 while (i < n) {
2559 if (j >= m) return -1;
2560 c = template.charCodeAt(i++);
2561 if (c === 37) {
2562 t = template.charAt(i++);
2563 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
2564 if (!p || (j = p(date, string, j)) < 0) return -1;
2565 } else if (c != string.charCodeAt(j++)) {
2566 return -1;
2569 return j;
2571 d3_time_format.utc = function(template) {
2572 var local = d3_time_format(template);
2573 function format(date) {
2574 try {
2575 d3_date = d3_date_utc;
2576 var utc = new d3_date();
2577 utc._ = date;
2578 return local(utc);
2579 } finally {
2580 d3_date = Date;
2583 format.parse = function(string) {
2584 try {
2585 d3_date = d3_date_utc;
2586 var date = local.parse(string);
2587 return date && date._;
2588 } finally {
2589 d3_date = Date;
2591 };
2592 format.toString = local.toString;
2593 return format;
2594 };
2595 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
2596 var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
2597 locale_periods.forEach(function(p, i) {
2598 d3_time_periodLookup.set(p.toLowerCase(), i);
2599 });
2600 var d3_time_formats = {
2601 a: function(d) {
2602 return locale_shortDays[d.getDay()];
2603 },
2604 A: function(d) {
2605 return locale_days[d.getDay()];
2606 },
2607 b: function(d) {
2608 return locale_shortMonths[d.getMonth()];
2609 },
2610 B: function(d) {
2611 return locale_months[d.getMonth()];
2612 },
2613 c: d3_time_format(locale_dateTime),
2614 d: function(d, p) {
2615 return d3_time_formatPad(d.getDate(), p, 2);
2616 },
2617 e: function(d, p) {
2618 return d3_time_formatPad(d.getDate(), p, 2);
2619 },
2620 H: function(d, p) {
2621 return d3_time_formatPad(d.getHours(), p, 2);
2622 },
2623 I: function(d, p) {
2624 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
2625 },
2626 j: function(d, p) {
2627 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
2628 },
2629 L: function(d, p) {
2630 return d3_time_formatPad(d.getMilliseconds(), p, 3);
2631 },
2632 m: function(d, p) {
2633 return d3_time_formatPad(d.getMonth() + 1, p, 2);
2634 },
2635 M: function(d, p) {
2636 return d3_time_formatPad(d.getMinutes(), p, 2);
2637 },
2638 p: function(d) {
2639 return locale_periods[+(d.getHours() >= 12)];
2640 },
2641 S: function(d, p) {
2642 return d3_time_formatPad(d.getSeconds(), p, 2);
2643 },
2644 U: function(d, p) {
2645 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
2646 },
2647 w: function(d) {
2648 return d.getDay();
2649 },
2650 W: function(d, p) {
2651 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
2652 },
2653 x: d3_time_format(locale_date),
2654 X: d3_time_format(locale_time),
2655 y: function(d, p) {
2656 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
2657 },
2658 Y: function(d, p) {
2659 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
2660 },
2661 Z: d3_time_zone,
2662 "%": function() {
2663 return "%";
2665 };
2666 var d3_time_parsers = {
2667 a: d3_time_parseWeekdayAbbrev,
2668 A: d3_time_parseWeekday,
2669 b: d3_time_parseMonthAbbrev,
2670 B: d3_time_parseMonth,
2671 c: d3_time_parseLocaleFull,
2672 d: d3_time_parseDay,
2673 e: d3_time_parseDay,
2674 H: d3_time_parseHour24,
2675 I: d3_time_parseHour24,
2676 j: d3_time_parseDayOfYear,
2677 L: d3_time_parseMilliseconds,
2678 m: d3_time_parseMonthNumber,
2679 M: d3_time_parseMinutes,
2680 p: d3_time_parseAmPm,
2681 S: d3_time_parseSeconds,
2682 U: d3_time_parseWeekNumberSunday,
2683 w: d3_time_parseWeekdayNumber,
2684 W: d3_time_parseWeekNumberMonday,
2685 x: d3_time_parseLocaleDate,
2686 X: d3_time_parseLocaleTime,
2687 y: d3_time_parseYear,
2688 Y: d3_time_parseFullYear,
2689 Z: d3_time_parseZone,
2690 "%": d3_time_parseLiteralPercent
2691 };
2692 function d3_time_parseWeekdayAbbrev(date, string, i) {
2693 d3_time_dayAbbrevRe.lastIndex = 0;
2694 var n = d3_time_dayAbbrevRe.exec(string.slice(i));
2695 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2697 function d3_time_parseWeekday(date, string, i) {
2698 d3_time_dayRe.lastIndex = 0;
2699 var n = d3_time_dayRe.exec(string.slice(i));
2700 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2702 function d3_time_parseMonthAbbrev(date, string, i) {
2703 d3_time_monthAbbrevRe.lastIndex = 0;
2704 var n = d3_time_monthAbbrevRe.exec(string.slice(i));
2705 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2707 function d3_time_parseMonth(date, string, i) {
2708 d3_time_monthRe.lastIndex = 0;
2709 var n = d3_time_monthRe.exec(string.slice(i));
2710 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2712 function d3_time_parseLocaleFull(date, string, i) {
2713 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2715 function d3_time_parseLocaleDate(date, string, i) {
2716 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2718 function d3_time_parseLocaleTime(date, string, i) {
2719 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2721 function d3_time_parseAmPm(date, string, i) {
2722 var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
2723 return n == null ? -1 : (date.p = n, i);
2725 return d3_time_format;
2727 var d3_time_formatPads = {
2728 "-": "",
2729 _: " ",
2730 "0": "0"
2731 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
2732 function d3_time_formatPad(value, fill, width) {
2733 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
2734 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2736 function d3_time_formatRe(names) {
2737 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2739 function d3_time_formatLookup(names) {
2740 var map = new d3_Map(), i = -1, n = names.length;
2741 while (++i < n) map.set(names[i].toLowerCase(), i);
2742 return map;
2744 function d3_time_parseWeekdayNumber(date, string, i) {
2745 d3_time_numberRe.lastIndex = 0;
2746 var n = d3_time_numberRe.exec(string.slice(i, i + 1));
2747 return n ? (date.w = +n[0], i + n[0].length) : -1;
2749 function d3_time_parseWeekNumberSunday(date, string, i) {
2750 d3_time_numberRe.lastIndex = 0;
2751 var n = d3_time_numberRe.exec(string.slice(i));
2752 return n ? (date.U = +n[0], i + n[0].length) : -1;
2754 function d3_time_parseWeekNumberMonday(date, string, i) {
2755 d3_time_numberRe.lastIndex = 0;
2756 var n = d3_time_numberRe.exec(string.slice(i));
2757 return n ? (date.W = +n[0], i + n[0].length) : -1;
2759 function d3_time_parseFullYear(date, string, i) {
2760 d3_time_numberRe.lastIndex = 0;
2761 var n = d3_time_numberRe.exec(string.slice(i, i + 4));
2762 return n ? (date.y = +n[0], i + n[0].length) : -1;
2764 function d3_time_parseYear(date, string, i) {
2765 d3_time_numberRe.lastIndex = 0;
2766 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2767 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
2769 function d3_time_parseZone(date, string, i) {
2770 return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
2771 i + 5) : -1;
2773 function d3_time_expandYear(d) {
2774 return d + (d > 68 ? 1900 : 2e3);
2776 function d3_time_parseMonthNumber(date, string, i) {
2777 d3_time_numberRe.lastIndex = 0;
2778 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2779 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
2781 function d3_time_parseDay(date, string, i) {
2782 d3_time_numberRe.lastIndex = 0;
2783 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2784 return n ? (date.d = +n[0], i + n[0].length) : -1;
2786 function d3_time_parseDayOfYear(date, string, i) {
2787 d3_time_numberRe.lastIndex = 0;
2788 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2789 return n ? (date.j = +n[0], i + n[0].length) : -1;
2791 function d3_time_parseHour24(date, string, i) {
2792 d3_time_numberRe.lastIndex = 0;
2793 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2794 return n ? (date.H = +n[0], i + n[0].length) : -1;
2796 function d3_time_parseMinutes(date, string, i) {
2797 d3_time_numberRe.lastIndex = 0;
2798 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2799 return n ? (date.M = +n[0], i + n[0].length) : -1;
2801 function d3_time_parseSeconds(date, string, i) {
2802 d3_time_numberRe.lastIndex = 0;
2803 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2804 return n ? (date.S = +n[0], i + n[0].length) : -1;
2806 function d3_time_parseMilliseconds(date, string, i) {
2807 d3_time_numberRe.lastIndex = 0;
2808 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2809 return n ? (date.L = +n[0], i + n[0].length) : -1;
2811 function d3_time_zone(d) {
2812 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
2813 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
2815 function d3_time_parseLiteralPercent(date, string, i) {
2816 d3_time_percentRe.lastIndex = 0;
2817 var n = d3_time_percentRe.exec(string.slice(i, i + 1));
2818 return n ? i + n[0].length : -1;
2820 function d3_time_formatMulti(formats) {
2821 var n = formats.length, i = -1;
2822 while (++i < n) formats[i][0] = this(formats[i][0]);
2823 return function(date) {
2824 var i = 0, f = formats[i];
2825 while (!f[1](date)) f = formats[++i];
2826 return f[0](date);
2827 };
2829 d3.locale = function(locale) {
2830 return {
2831 numberFormat: d3_locale_numberFormat(locale),
2832 timeFormat: d3_locale_timeFormat(locale)
2833 };
2834 };
2835 var d3_locale_enUS = d3.locale({
2836 decimal: ".",
2837 thousands: ",",
2838 grouping: [ 3 ],
2839 currency: [ "$", "" ],
2840 dateTime: "%a %b %e %X %Y",
2841 date: "%m/%d/%Y",
2842 time: "%H:%M:%S",
2843 periods: [ "AM", "PM" ],
2844 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
2845 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
2846 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
2847 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
2848 });
2849 d3.format = d3_locale_enUS.numberFormat;
2850 d3.geo = {};
2851 function d3_adder() {}
2852 d3_adder.prototype = {
2853 s: 0,
2854 t: 0,
2855 add: function(y) {
2856 d3_adderSum(y, this.t, d3_adderTemp);
2857 d3_adderSum(d3_adderTemp.s, this.s, this);
2858 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
2859 },
2860 reset: function() {
2861 this.s = this.t = 0;
2862 },
2863 valueOf: function() {
2864 return this.s;
2866 };
2867 var d3_adderTemp = new d3_adder();
2868 function d3_adderSum(a, b, o) {
2869 var x = o.s = a + b, bv = x - a, av = x - bv;
2870 o.t = a - av + (b - bv);
2872 d3.geo.stream = function(object, listener) {
2873 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2874 d3_geo_streamObjectType[object.type](object, listener);
2875 } else {
2876 d3_geo_streamGeometry(object, listener);
2878 };
2879 function d3_geo_streamGeometry(geometry, listener) {
2880 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2881 d3_geo_streamGeometryType[geometry.type](geometry, listener);
2884 var d3_geo_streamObjectType = {
2885 Feature: function(feature, listener) {
2886 d3_geo_streamGeometry(feature.geometry, listener);
2887 },
2888 FeatureCollection: function(object, listener) {
2889 var features = object.features, i = -1, n = features.length;
2890 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
2892 };
2893 var d3_geo_streamGeometryType = {
2894 Sphere: function(object, listener) {
2895 listener.sphere();
2896 },
2897 Point: function(object, listener) {
2898 object = object.coordinates;
2899 listener.point(object[0], object[1], object[2]);
2900 },
2901 MultiPoint: function(object, listener) {
2902 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2903 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
2904 },
2905 LineString: function(object, listener) {
2906 d3_geo_streamLine(object.coordinates, listener, 0);
2907 },
2908 MultiLineString: function(object, listener) {
2909 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2910 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
2911 },
2912 Polygon: function(object, listener) {
2913 d3_geo_streamPolygon(object.coordinates, listener);
2914 },
2915 MultiPolygon: function(object, listener) {
2916 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2917 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
2918 },
2919 GeometryCollection: function(object, listener) {
2920 var geometries = object.geometries, i = -1, n = geometries.length;
2921 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
2923 };
2924 function d3_geo_streamLine(coordinates, listener, closed) {
2925 var i = -1, n = coordinates.length - closed, coordinate;
2926 listener.lineStart();
2927 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
2928 listener.lineEnd();
2930 function d3_geo_streamPolygon(coordinates, listener) {
2931 var i = -1, n = coordinates.length;
2932 listener.polygonStart();
2933 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
2934 listener.polygonEnd();
2936 d3.geo.area = function(object) {
2937 d3_geo_areaSum = 0;
2938 d3.geo.stream(object, d3_geo_area);
2939 return d3_geo_areaSum;
2940 };
2941 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
2942 var d3_geo_area = {
2943 sphere: function() {
2944 d3_geo_areaSum += 4 * π;
2945 },
2946 point: d3_noop,
2947 lineStart: d3_noop,
2948 lineEnd: d3_noop,
2949 polygonStart: function() {
2950 d3_geo_areaRingSum.reset();
2951 d3_geo_area.lineStart = d3_geo_areaRingStart;
2952 },
2953 polygonEnd: function() {
2954 var area = 2 * d3_geo_areaRingSum;
2955 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2956 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2958 };
2959 function d3_geo_areaRingStart() {
2960 var λ00, φ00, λ0, cosφ0, sinφ0;
2961 d3_geo_area.point = function(λ, φ) {
2962 d3_geo_area.point = nextPoint;
2963 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
2964 sinφ0 = Math.sin(φ);
2965 };
2966 function nextPoint(λ, φ) {
2967 λ *= d3_radians;
2968 φ = φ * d3_radians / 2 + π / 4;
2969 var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
2970 d3_geo_areaRingSum.add(Math.atan2(v, u));
2971 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
2973 d3_geo_area.lineEnd = function() {
2974 nextPoint(λ00, φ00);
2975 };
2977 function d3_geo_cartesian(spherical) {
2978 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2979 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2981 function d3_geo_cartesianDot(a, b) {
2982 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2984 function d3_geo_cartesianCross(a, b) {
2985 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] ];
2987 function d3_geo_cartesianAdd(a, b) {
2988 a[0] += b[0];
2989 a[1] += b[1];
2990 a[2] += b[2];
2992 function d3_geo_cartesianScale(vector, k) {
2993 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2995 function d3_geo_cartesianNormalize(d) {
2996 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2997 d[0] /= l;
2998 d[1] /= l;
2999 d[2] /= l;
3001 function d3_geo_spherical(cartesian) {
3002 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
3004 function d3_geo_sphericalEqual(a, b) {
3005 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
3007 d3.geo.bounds = function() {
3008 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
3009 var bound = {
3010 point: point,
3011 lineStart: lineStart,
3012 lineEnd: lineEnd,
3013 polygonStart: function() {
3014 bound.point = ringPoint;
3015 bound.lineStart = ringStart;
3016 bound.lineEnd = ringEnd;
3017 dλSum = 0;
3018 d3_geo_area.polygonStart();
3019 },
3020 polygonEnd: function() {
3021 d3_geo_area.polygonEnd();
3022 bound.point = point;
3023 bound.lineStart = lineStart;
3024 bound.lineEnd = lineEnd;
3025 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
3026 range[0] = λ0, range[1] = λ1;
3028 };
3029 function point(λ, φ) {
3030 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
3031 if (φ < φ0) φ0 = φ;
3032 if (φ > φ1) φ1 = φ;
3034 function linePoint(λ, φ) {
3035 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
3036 if (p0) {
3037 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
3038 d3_geo_cartesianNormalize(inflection);
3039 inflection = d3_geo_spherical(inflection);
3040 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
3041 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3042 var φi = inflection[1] * d3_degrees;
3043 if (φi > φ1) φ1 = φi;
3044 } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3045 var φi = -inflection[1] * d3_degrees;
3046 if (φi < φ0) φ0 = φi;
3047 } else {
3048 if (φ < φ0) φ0 = φ;
3049 if (φ > φ1) φ1 = φ;
3051 if (antimeridian) {
3052 if (λ < λ_) {
3053 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
3054 } else {
3055 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
3057 } else {
3058 if (λ1 >= λ0) {
3059 if (λ < λ0) λ0 = λ;
3060 if (λ > λ1) λ1 = λ;
3061 } else {
3062 if (λ > λ_) {
3063 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
3064 } else {
3065 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
3069 } else {
3070 point(λ, φ);
3072 p0 = p, λ_ = λ;
3074 function lineStart() {
3075 bound.point = linePoint;
3077 function lineEnd() {
3078 range[0] = λ0, range[1] = λ1;
3079 bound.point = point;
3080 p0 = null;
3082 function ringPoint(λ, φ) {
3083 if (p0) {
3084 var dλ = λ - λ_;
3085 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
3086 } else λ__ = λ, φ__ = φ;
3087 d3_geo_area.point(λ, φ);
3088 linePoint(λ, φ);
3090 function ringStart() {
3091 d3_geo_area.lineStart();
3093 function ringEnd() {
3094 ringPoint(λ__, φ__);
3095 d3_geo_area.lineEnd();
3096 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
3097 range[0] = λ0, range[1] = λ1;
3098 p0 = null;
3100 function angle(λ0, λ1) {
3101 return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
3103 function compareRanges(a, b) {
3104 return a[0] - b[0];
3106 function withinRange(x, range) {
3107 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
3109 return function(feature) {
3110 φ1 = λ1 = -(λ0 = φ0 = Infinity);
3111 ranges = [];
3112 d3.geo.stream(feature, bound);
3113 var n = ranges.length;
3114 if (n) {
3115 ranges.sort(compareRanges);
3116 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
3117 b = ranges[i];
3118 if (withinRange(b[0], a) || withinRange(b[1], a)) {
3119 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
3120 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
3121 } else {
3122 merged.push(a = b);
3125 var best = -Infinity, dλ;
3126 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
3127 b = merged[i];
3128 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
3131 ranges = range = null;
3132 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
3133 };
3134 }();
3135 d3.geo.centroid = function(object) {
3136 d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
3137 d3.geo.stream(object, d3_geo_centroid);
3138 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
3139 if (m < ε2) {
3140 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
3141 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
3142 m = x * x + y * y + z * z;
3143 if (m < ε2) return [ NaN, NaN ];
3145 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
3146 };
3147 var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;
3148 var d3_geo_centroid = {
3149 sphere: d3_noop,
3150 point: d3_geo_centroidPoint,
3151 lineStart: d3_geo_centroidLineStart,
3152 lineEnd: d3_geo_centroidLineEnd,
3153 polygonStart: function() {
3154 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
3155 },
3156 polygonEnd: function() {
3157 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
3159 };
3160 function d3_geo_centroidPoint(λ, φ) {
3161 λ *= d3_radians;
3162 var cosφ = Math.cos(φ *= d3_radians);
3163 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
3165 function d3_geo_centroidPointXYZ(x, y, z) {
3166 ++d3_geo_centroidW0;
3167 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
3168 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
3169 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
3171 function d3_geo_centroidLineStart() {
3172 var x0, y0, z0;
3173 d3_geo_centroid.point = function(λ, φ) {
3174 λ *= d3_radians;
3175 var cosφ = Math.cos(φ *= d3_radians);
3176 x0 = cosφ * Math.cos(λ);
3177 y0 = cosφ * Math.sin(λ);
3178 z0 = Math.sin(φ);
3179 d3_geo_centroid.point = nextPoint;
3180 d3_geo_centroidPointXYZ(x0, y0, z0);
3181 };
3182 function nextPoint(λ, φ) {
3183 λ *= d3_radians;
3184 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);
3185 d3_geo_centroidW1 += w;
3186 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3187 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3188 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3189 d3_geo_centroidPointXYZ(x0, y0, z0);
3192 function d3_geo_centroidLineEnd() {
3193 d3_geo_centroid.point = d3_geo_centroidPoint;
3195 function d3_geo_centroidRingStart() {
3196 var λ00, φ00, x0, y0, z0;
3197 d3_geo_centroid.point = function(λ, φ) {
3198 λ00 = λ, φ00 = φ;
3199 d3_geo_centroid.point = nextPoint;
3200 λ *= d3_radians;
3201 var cosφ = Math.cos(φ *= d3_radians);
3202 x0 = cosφ * Math.cos(λ);
3203 y0 = cosφ * Math.sin(λ);
3204 z0 = Math.sin(φ);
3205 d3_geo_centroidPointXYZ(x0, y0, z0);
3206 };
3207 d3_geo_centroid.lineEnd = function() {
3208 nextPoint(λ00, φ00);
3209 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
3210 d3_geo_centroid.point = d3_geo_centroidPoint;
3211 };
3212 function nextPoint(λ, φ) {
3213 λ *= d3_radians;
3214 var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);
3215 d3_geo_centroidX2 += v * cx;
3216 d3_geo_centroidY2 += v * cy;
3217 d3_geo_centroidZ2 += v * cz;
3218 d3_geo_centroidW1 += w;
3219 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3220 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3221 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3222 d3_geo_centroidPointXYZ(x0, y0, z0);
3225 function d3_geo_compose(a, b) {
3226 function compose(x, y) {
3227 return x = a(x, y), b(x[0], x[1]);
3229 if (a.invert && b.invert) compose.invert = function(x, y) {
3230 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
3231 };
3232 return compose;
3234 function d3_true() {
3235 return true;
3237 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
3238 var subject = [], clip = [];
3239 segments.forEach(function(segment) {
3240 if ((n = segment.length - 1) <= 0) return;
3241 var n, p0 = segment[0], p1 = segment[n];
3242 if (d3_geo_sphericalEqual(p0, p1)) {
3243 listener.lineStart();
3244 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
3245 listener.lineEnd();
3246 return;
3248 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
3249 a.o = b;
3250 subject.push(a);
3251 clip.push(b);
3252 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
3253 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
3254 a.o = b;
3255 subject.push(a);
3256 clip.push(b);
3257 });
3258 clip.sort(compare);
3259 d3_geo_clipPolygonLinkCircular(subject);
3260 d3_geo_clipPolygonLinkCircular(clip);
3261 if (!subject.length) return;
3262 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
3263 clip[i].e = entry = !entry;
3265 var start = subject[0], points, point;
3266 while (1) {
3267 var current = start, isSubject = true;
3268 while (current.v) if ((current = current.n) === start) return;
3269 points = current.z;
3270 listener.lineStart();
3271 do {
3272 current.v = current.o.v = true;
3273 if (current.e) {
3274 if (isSubject) {
3275 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
3276 } else {
3277 interpolate(current.x, current.n.x, 1, listener);
3279 current = current.n;
3280 } else {
3281 if (isSubject) {
3282 points = current.p.z;
3283 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
3284 } else {
3285 interpolate(current.x, current.p.x, -1, listener);
3287 current = current.p;
3289 current = current.o;
3290 points = current.z;
3291 isSubject = !isSubject;
3292 } while (!current.v);
3293 listener.lineEnd();
3296 function d3_geo_clipPolygonLinkCircular(array) {
3297 if (!(n = array.length)) return;
3298 var n, i = 0, a = array[0], b;
3299 while (++i < n) {
3300 a.n = b = array[i];
3301 b.p = a;
3302 a = b;
3304 a.n = b = array[0];
3305 b.p = a;
3307 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
3308 this.x = point;
3309 this.z = points;
3310 this.o = other;
3311 this.e = entry;
3312 this.v = false;
3313 this.n = this.p = null;
3315 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
3316 return function(rotate, listener) {
3317 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
3318 var clip = {
3319 point: point,
3320 lineStart: lineStart,
3321 lineEnd: lineEnd,
3322 polygonStart: function() {
3323 clip.point = pointRing;
3324 clip.lineStart = ringStart;
3325 clip.lineEnd = ringEnd;
3326 segments = [];
3327 polygon = [];
3328 },
3329 polygonEnd: function() {
3330 clip.point = point;
3331 clip.lineStart = lineStart;
3332 clip.lineEnd = lineEnd;
3333 segments = d3.merge(segments);
3334 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
3335 if (segments.length) {
3336 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3337 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
3338 } else if (clipStartInside) {
3339 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3340 listener.lineStart();
3341 interpolate(null, null, 1, listener);
3342 listener.lineEnd();
3344 if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
3345 segments = polygon = null;
3346 },
3347 sphere: function() {
3348 listener.polygonStart();
3349 listener.lineStart();
3350 interpolate(null, null, 1, listener);
3351 listener.lineEnd();
3352 listener.polygonEnd();
3354 };
3355 function point(λ, φ) {
3356 var point = rotate(λ, φ);
3357 if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
3359 function pointLine(λ, φ) {
3360 var point = rotate(λ, φ);
3361 line.point(point[0], point[1]);
3363 function lineStart() {
3364 clip.point = pointLine;
3365 line.lineStart();
3367 function lineEnd() {
3368 clip.point = point;
3369 line.lineEnd();
3371 var segments;
3372 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
3373 function pointRing(λ, φ) {
3374 ring.push([ λ, φ ]);
3375 var point = rotate(λ, φ);
3376 ringListener.point(point[0], point[1]);
3378 function ringStart() {
3379 ringListener.lineStart();
3380 ring = [];
3382 function ringEnd() {
3383 pointRing(ring[0][0], ring[0][1]);
3384 ringListener.lineEnd();
3385 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
3386 ring.pop();
3387 polygon.push(ring);
3388 ring = null;
3389 if (!n) return;
3390 if (clean & 1) {
3391 segment = ringSegments[0];
3392 var n = segment.length - 1, i = -1, point;
3393 if (n > 0) {
3394 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3395 listener.lineStart();
3396 while (++i < n) listener.point((point = segment[i])[0], point[1]);
3397 listener.lineEnd();
3399 return;
3401 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
3402 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
3404 return clip;
3405 };
3407 function d3_geo_clipSegmentLength1(segment) {
3408 return segment.length > 1;
3410 function d3_geo_clipBufferListener() {
3411 var lines = [], line;
3412 return {
3413 lineStart: function() {
3414 lines.push(line = []);
3415 },
3416 point: function(λ, φ) {
3417 line.push([ λ, φ ]);
3418 },
3419 lineEnd: d3_noop,
3420 buffer: function() {
3421 var buffer = lines;
3422 lines = [];
3423 line = null;
3424 return buffer;
3425 },
3426 rejoin: function() {
3427 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
3429 };
3431 function d3_geo_clipSort(a, b) {
3432 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
3434 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
3435 function d3_geo_clipAntimeridianLine(listener) {
3436 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
3437 return {
3438 lineStart: function() {
3439 listener.lineStart();
3440 clean = 1;
3441 },
3442 point: function(λ1, φ1) {
3443 var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
3444 if (abs(dλ - π) < ε) {
3445 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
3446 listener.point(sλ0, φ0);
3447 listener.lineEnd();
3448 listener.lineStart();
3449 listener.point(sλ1, φ0);
3450 listener.point(λ1, φ0);
3451 clean = 0;
3452 } else if (sλ0 !== sλ1 && dλ >= π) {
3453 if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
3454 if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
3455 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
3456 listener.point(sλ0, φ0);
3457 listener.lineEnd();
3458 listener.lineStart();
3459 listener.point(sλ1, φ0);
3460 clean = 0;
3462 listener.point(λ0 = λ1, φ0 = φ1);
3463 sλ0 = sλ1;
3464 },
3465 lineEnd: function() {
3466 listener.lineEnd();
3467 λ0 = φ0 = NaN;
3468 },
3469 clean: function() {
3470 return 2 - clean;
3472 };
3474 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
3475 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
3476 return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
3478 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
3479 var φ;
3480 if (from == null) {
3481 φ = direction * halfπ;
3482 listener.point(-π, φ);
3483 listener.point(0, φ);
3484 listener.point(π, φ);
3485 listener.point(π, 0);
3486 listener.point(π, -φ);
3487 listener.point(0, -φ);
3488 listener.point(-π, -φ);
3489 listener.point(-π, 0);
3490 listener.point(-π, φ);
3491 } else if (abs(from[0] - to[0]) > ε) {
3492 var s = from[0] < to[0] ? π : -π;
3493 φ = direction * s / 2;
3494 listener.point(-s, φ);
3495 listener.point(0, φ);
3496 listener.point(s, φ);
3497 } else {
3498 listener.point(to[0], to[1]);
3501 function d3_geo_pointInPolygon(point, polygon) {
3502 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
3503 d3_geo_areaRingSum.reset();
3504 for (var i = 0, n = polygon.length; i < n; ++i) {
3505 var ring = polygon[i], m = ring.length;
3506 if (!m) continue;
3507 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
3508 while (true) {
3509 if (j === m) j = 0;
3510 point = ring[j];
3511 var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
3512 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
3513 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
3514 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
3515 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
3516 d3_geo_cartesianNormalize(arc);
3517 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
3518 d3_geo_cartesianNormalize(intersection);
3519 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
3520 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
3521 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
3524 if (!j++) break;
3525 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
3528 return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;
3530 function d3_geo_clipCircle(radius) {
3531 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
3532 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
3533 function visible(λ, φ) {
3534 return Math.cos(λ) * Math.cos(φ) > cr;
3536 function clipLine(listener) {
3537 var point0, c0, v0, v00, clean;
3538 return {
3539 lineStart: function() {
3540 v00 = v0 = false;
3541 clean = 1;
3542 },
3543 point: function(λ, φ) {
3544 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
3545 if (!point0 && (v00 = v0 = v)) listener.lineStart();
3546 if (v !== v0) {
3547 point2 = intersect(point0, point1);
3548 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
3549 point1[0] += ε;
3550 point1[1] += ε;
3551 v = visible(point1[0], point1[1]);
3554 if (v !== v0) {
3555 clean = 0;
3556 if (v) {
3557 listener.lineStart();
3558 point2 = intersect(point1, point0);
3559 listener.point(point2[0], point2[1]);
3560 } else {
3561 point2 = intersect(point0, point1);
3562 listener.point(point2[0], point2[1]);
3563 listener.lineEnd();
3565 point0 = point2;
3566 } else if (notHemisphere && point0 && smallRadius ^ v) {
3567 var t;
3568 if (!(c & c0) && (t = intersect(point1, point0, true))) {
3569 clean = 0;
3570 if (smallRadius) {
3571 listener.lineStart();
3572 listener.point(t[0][0], t[0][1]);
3573 listener.point(t[1][0], t[1][1]);
3574 listener.lineEnd();
3575 } else {
3576 listener.point(t[1][0], t[1][1]);
3577 listener.lineEnd();
3578 listener.lineStart();
3579 listener.point(t[0][0], t[0][1]);
3583 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
3584 listener.point(point1[0], point1[1]);
3586 point0 = point1, v0 = v, c0 = c;
3587 },
3588 lineEnd: function() {
3589 if (v0) listener.lineEnd();
3590 point0 = null;
3591 },
3592 clean: function() {
3593 return clean | (v00 && v0) << 1;
3595 };
3597 function intersect(a, b, two) {
3598 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
3599 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
3600 if (!determinant) return !two && a;
3601 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);
3602 d3_geo_cartesianAdd(A, B);
3603 var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);
3604 if (t2 < 0) return;
3605 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
3606 d3_geo_cartesianAdd(q, A);
3607 q = d3_geo_spherical(q);
3608 if (!two) return q;
3609 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3610 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
3611 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3612 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
3613 if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
3614 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3615 d3_geo_cartesianAdd(q1, A);
3616 return [ q, d3_geo_spherical(q1) ];
3619 function code(λ, φ) {
3620 var r = smallRadius ? radius : π - radius, code = 0;
3621 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
3622 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
3623 return code;
3626 function d3_geom_clipLine(x0, y0, x1, y1) {
3627 return function(line) {
3628 var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
3629 r = x0 - ax;
3630 if (!dx && r > 0) return;
3631 r /= dx;
3632 if (dx < 0) {
3633 if (r < t0) return;
3634 if (r < t1) t1 = r;
3635 } else if (dx > 0) {
3636 if (r > t1) return;
3637 if (r > t0) t0 = r;
3639 r = x1 - ax;
3640 if (!dx && r < 0) return;
3641 r /= dx;
3642 if (dx < 0) {
3643 if (r > t1) return;
3644 if (r > t0) t0 = r;
3645 } else if (dx > 0) {
3646 if (r < t0) return;
3647 if (r < t1) t1 = r;
3649 r = y0 - ay;
3650 if (!dy && r > 0) return;
3651 r /= dy;
3652 if (dy < 0) {
3653 if (r < t0) return;
3654 if (r < t1) t1 = r;
3655 } else if (dy > 0) {
3656 if (r > t1) return;
3657 if (r > t0) t0 = r;
3659 r = y1 - ay;
3660 if (!dy && r < 0) return;
3661 r /= dy;
3662 if (dy < 0) {
3663 if (r > t1) return;
3664 if (r > t0) t0 = r;
3665 } else if (dy > 0) {
3666 if (r < t0) return;
3667 if (r < t1) t1 = r;
3669 if (t0 > 0) line.a = {
3670 x: ax + t0 * dx,
3671 y: ay + t0 * dy
3672 };
3673 if (t1 < 1) line.b = {
3674 x: ax + t1 * dx,
3675 y: ay + t1 * dy
3676 };
3677 return line;
3678 };
3680 var d3_geo_clipExtentMAX = 1e9;
3681 d3.geo.clipExtent = function() {
3682 var x0, y0, x1, y1, stream, clip, clipExtent = {
3683 stream: function(output) {
3684 if (stream) stream.valid = false;
3685 stream = clip(output);
3686 stream.valid = true;
3687 return stream;
3688 },
3689 extent: function(_) {
3690 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3691 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
3692 if (stream) stream.valid = false, stream = null;
3693 return clipExtent;
3695 };
3696 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
3697 };
3698 function d3_geo_clipExtent(x0, y0, x1, y1) {
3699 return function(listener) {
3700 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3701 var clip = {
3702 point: point,
3703 lineStart: lineStart,
3704 lineEnd: lineEnd,
3705 polygonStart: function() {
3706 listener = bufferListener;
3707 segments = [];
3708 polygon = [];
3709 clean = true;
3710 },
3711 polygonEnd: function() {
3712 listener = listener_;
3713 segments = d3.merge(segments);
3714 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
3715 if (inside || visible) {
3716 listener.polygonStart();
3717 if (inside) {
3718 listener.lineStart();
3719 interpolate(null, null, 1, listener);
3720 listener.lineEnd();
3722 if (visible) {
3723 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
3725 listener.polygonEnd();
3727 segments = polygon = ring = null;
3729 };
3730 function insidePolygon(p) {
3731 var wn = 0, n = polygon.length, y = p[1];
3732 for (var i = 0; i < n; ++i) {
3733 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
3734 b = v[j];
3735 if (a[1] <= y) {
3736 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
3737 } else {
3738 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
3740 a = b;
3743 return wn !== 0;
3745 function interpolate(from, to, direction, listener) {
3746 var a = 0, a1 = 0;
3747 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
3748 do {
3749 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
3750 } while ((a = (a + direction + 4) % 4) !== a1);
3751 } else {
3752 listener.point(to[0], to[1]);
3755 function pointVisible(x, y) {
3756 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
3758 function point(x, y) {
3759 if (pointVisible(x, y)) listener.point(x, y);
3761 var x__, y__, v__, x_, y_, v_, first, clean;
3762 function lineStart() {
3763 clip.point = linePoint;
3764 if (polygon) polygon.push(ring = []);
3765 first = true;
3766 v_ = false;
3767 x_ = y_ = NaN;
3769 function lineEnd() {
3770 if (segments) {
3771 linePoint(x__, y__);
3772 if (v__ && v_) bufferListener.rejoin();
3773 segments.push(bufferListener.buffer());
3775 clip.point = point;
3776 if (v_) listener.lineEnd();
3778 function linePoint(x, y) {
3779 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
3780 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
3781 var v = pointVisible(x, y);
3782 if (polygon) ring.push([ x, y ]);
3783 if (first) {
3784 x__ = x, y__ = y, v__ = v;
3785 first = false;
3786 if (v) {
3787 listener.lineStart();
3788 listener.point(x, y);
3790 } else {
3791 if (v && v_) listener.point(x, y); else {
3792 var l = {
3793 a: {
3794 x: x_,
3795 y: y_
3796 },
3797 b: {
3798 x: x,
3799 y: y
3801 };
3802 if (clipLine(l)) {
3803 if (!v_) {
3804 listener.lineStart();
3805 listener.point(l.a.x, l.a.y);
3807 listener.point(l.b.x, l.b.y);
3808 if (!v) listener.lineEnd();
3809 clean = false;
3810 } else if (v) {
3811 listener.lineStart();
3812 listener.point(x, y);
3813 clean = false;
3817 x_ = x, y_ = y, v_ = v;
3819 return clip;
3820 };
3821 function corner(p, direction) {
3822 return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
3824 function compare(a, b) {
3825 return comparePoints(a.x, b.x);
3827 function comparePoints(a, b) {
3828 var ca = corner(a, 1), cb = corner(b, 1);
3829 return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
3832 function d3_geo_conic(projectAt) {
3833 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3834 p.parallels = function(_) {
3835 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3836 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3837 };
3838 return p;
3840 function d3_geo_conicEqualArea(φ0, φ1) {
3841 var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
3842 function forward(λ, φ) {
3843 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3844 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3846 forward.invert = function(x, y) {
3847 var ρ0_y = ρ0 - y;
3848 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3849 };
3850 return forward;
3852 (d3.geo.conicEqualArea = function() {
3853 return d3_geo_conic(d3_geo_conicEqualArea);
3854 }).raw = d3_geo_conicEqualArea;
3855 d3.geo.albers = function() {
3856 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3857 };
3858 d3.geo.albersUsa = function() {
3859 var lower48 = d3.geo.albers();
3860 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3861 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3862 var point, pointStream = {
3863 point: function(x, y) {
3864 point = [ x, y ];
3866 }, lower48Point, alaskaPoint, hawaiiPoint;
3867 function albersUsa(coordinates) {
3868 var x = coordinates[0], y = coordinates[1];
3869 point = null;
3870 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3871 return point;
3873 albersUsa.invert = function(coordinates) {
3874 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3875 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3876 };
3877 albersUsa.stream = function(stream) {
3878 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3879 return {
3880 point: function(x, y) {
3881 lower48Stream.point(x, y);
3882 alaskaStream.point(x, y);
3883 hawaiiStream.point(x, y);
3884 },
3885 sphere: function() {
3886 lower48Stream.sphere();
3887 alaskaStream.sphere();
3888 hawaiiStream.sphere();
3889 },
3890 lineStart: function() {
3891 lower48Stream.lineStart();
3892 alaskaStream.lineStart();
3893 hawaiiStream.lineStart();
3894 },
3895 lineEnd: function() {
3896 lower48Stream.lineEnd();
3897 alaskaStream.lineEnd();
3898 hawaiiStream.lineEnd();
3899 },
3900 polygonStart: function() {
3901 lower48Stream.polygonStart();
3902 alaskaStream.polygonStart();
3903 hawaiiStream.polygonStart();
3904 },
3905 polygonEnd: function() {
3906 lower48Stream.polygonEnd();
3907 alaskaStream.polygonEnd();
3908 hawaiiStream.polygonEnd();
3910 };
3911 };
3912 albersUsa.precision = function(_) {
3913 if (!arguments.length) return lower48.precision();
3914 lower48.precision(_);
3915 alaska.precision(_);
3916 hawaii.precision(_);
3917 return albersUsa;
3918 };
3919 albersUsa.scale = function(_) {
3920 if (!arguments.length) return lower48.scale();
3921 lower48.scale(_);
3922 alaska.scale(_ * .35);
3923 hawaii.scale(_);
3924 return albersUsa.translate(lower48.translate());
3925 };
3926 albersUsa.translate = function(_) {
3927 if (!arguments.length) return lower48.translate();
3928 var k = lower48.scale(), x = +_[0], y = +_[1];
3929 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3930 alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3931 hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3932 return albersUsa;
3933 };
3934 return albersUsa.scale(1070);
3935 };
3936 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3937 point: d3_noop,
3938 lineStart: d3_noop,
3939 lineEnd: d3_noop,
3940 polygonStart: function() {
3941 d3_geo_pathAreaPolygon = 0;
3942 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3943 },
3944 polygonEnd: function() {
3945 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3946 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3948 };
3949 function d3_geo_pathAreaRingStart() {
3950 var x00, y00, x0, y0;
3951 d3_geo_pathArea.point = function(x, y) {
3952 d3_geo_pathArea.point = nextPoint;
3953 x00 = x0 = x, y00 = y0 = y;
3954 };
3955 function nextPoint(x, y) {
3956 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3957 x0 = x, y0 = y;
3959 d3_geo_pathArea.lineEnd = function() {
3960 nextPoint(x00, y00);
3961 };
3963 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3964 var d3_geo_pathBounds = {
3965 point: d3_geo_pathBoundsPoint,
3966 lineStart: d3_noop,
3967 lineEnd: d3_noop,
3968 polygonStart: d3_noop,
3969 polygonEnd: d3_noop
3970 };
3971 function d3_geo_pathBoundsPoint(x, y) {
3972 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
3973 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
3974 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
3975 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
3977 function d3_geo_pathBuffer() {
3978 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3979 var stream = {
3980 point: point,
3981 lineStart: function() {
3982 stream.point = pointLineStart;
3983 },
3984 lineEnd: lineEnd,
3985 polygonStart: function() {
3986 stream.lineEnd = lineEndPolygon;
3987 },
3988 polygonEnd: function() {
3989 stream.lineEnd = lineEnd;
3990 stream.point = point;
3991 },
3992 pointRadius: function(_) {
3993 pointCircle = d3_geo_pathBufferCircle(_);
3994 return stream;
3995 },
3996 result: function() {
3997 if (buffer.length) {
3998 var result = buffer.join("");
3999 buffer = [];
4000 return result;
4003 };
4004 function point(x, y) {
4005 buffer.push("M", x, ",", y, pointCircle);
4007 function pointLineStart(x, y) {
4008 buffer.push("M", x, ",", y);
4009 stream.point = pointLine;
4011 function pointLine(x, y) {
4012 buffer.push("L", x, ",", y);
4014 function lineEnd() {
4015 stream.point = point;
4017 function lineEndPolygon() {
4018 buffer.push("Z");
4020 return stream;
4022 function d3_geo_pathBufferCircle(radius) {
4023 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
4025 var d3_geo_pathCentroid = {
4026 point: d3_geo_pathCentroidPoint,
4027 lineStart: d3_geo_pathCentroidLineStart,
4028 lineEnd: d3_geo_pathCentroidLineEnd,
4029 polygonStart: function() {
4030 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
4031 },
4032 polygonEnd: function() {
4033 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4034 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
4035 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
4037 };
4038 function d3_geo_pathCentroidPoint(x, y) {
4039 d3_geo_centroidX0 += x;
4040 d3_geo_centroidY0 += y;
4041 ++d3_geo_centroidZ0;
4043 function d3_geo_pathCentroidLineStart() {
4044 var x0, y0;
4045 d3_geo_pathCentroid.point = function(x, y) {
4046 d3_geo_pathCentroid.point = nextPoint;
4047 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4048 };
4049 function nextPoint(x, y) {
4050 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4051 d3_geo_centroidX1 += z * (x0 + x) / 2;
4052 d3_geo_centroidY1 += z * (y0 + y) / 2;
4053 d3_geo_centroidZ1 += z;
4054 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4057 function d3_geo_pathCentroidLineEnd() {
4058 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4060 function d3_geo_pathCentroidRingStart() {
4061 var x00, y00, x0, y0;
4062 d3_geo_pathCentroid.point = function(x, y) {
4063 d3_geo_pathCentroid.point = nextPoint;
4064 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
4065 };
4066 function nextPoint(x, y) {
4067 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4068 d3_geo_centroidX1 += z * (x0 + x) / 2;
4069 d3_geo_centroidY1 += z * (y0 + y) / 2;
4070 d3_geo_centroidZ1 += z;
4071 z = y0 * x - x0 * y;
4072 d3_geo_centroidX2 += z * (x0 + x);
4073 d3_geo_centroidY2 += z * (y0 + y);
4074 d3_geo_centroidZ2 += z * 3;
4075 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4077 d3_geo_pathCentroid.lineEnd = function() {
4078 nextPoint(x00, y00);
4079 };
4081 function d3_geo_pathContext(context) {
4082 var pointRadius = 4.5;
4083 var stream = {
4084 point: point,
4085 lineStart: function() {
4086 stream.point = pointLineStart;
4087 },
4088 lineEnd: lineEnd,
4089 polygonStart: function() {
4090 stream.lineEnd = lineEndPolygon;
4091 },
4092 polygonEnd: function() {
4093 stream.lineEnd = lineEnd;
4094 stream.point = point;
4095 },
4096 pointRadius: function(_) {
4097 pointRadius = _;
4098 return stream;
4099 },
4100 result: d3_noop
4101 };
4102 function point(x, y) {
4103 context.moveTo(x + pointRadius, y);
4104 context.arc(x, y, pointRadius, 0, τ);
4106 function pointLineStart(x, y) {
4107 context.moveTo(x, y);
4108 stream.point = pointLine;
4110 function pointLine(x, y) {
4111 context.lineTo(x, y);
4113 function lineEnd() {
4114 stream.point = point;
4116 function lineEndPolygon() {
4117 context.closePath();
4119 return stream;
4121 function d3_geo_resample(project) {
4122 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4123 function resample(stream) {
4124 return (maxDepth ? resampleRecursive : resampleNone)(stream);
4126 function resampleNone(stream) {
4127 return d3_geo_transformPoint(stream, function(x, y) {
4128 x = project(x, y);
4129 stream.point(x[0], x[1]);
4130 });
4132 function resampleRecursive(stream) {
4133 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
4134 var resample = {
4135 point: point,
4136 lineStart: lineStart,
4137 lineEnd: lineEnd,
4138 polygonStart: function() {
4139 stream.polygonStart();
4140 resample.lineStart = ringStart;
4141 },
4142 polygonEnd: function() {
4143 stream.polygonEnd();
4144 resample.lineStart = lineStart;
4146 };
4147 function point(x, y) {
4148 x = project(x, y);
4149 stream.point(x[0], x[1]);
4151 function lineStart() {
4152 x0 = NaN;
4153 resample.point = linePoint;
4154 stream.lineStart();
4156 function linePoint(λ, φ) {
4157 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4158 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);
4159 stream.point(x0, y0);
4161 function lineEnd() {
4162 resample.point = point;
4163 stream.lineEnd();
4165 function ringStart() {
4166 lineStart();
4167 resample.point = ringPoint;
4168 resample.lineEnd = ringEnd;
4170 function ringPoint(λ, φ) {
4171 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
4172 resample.point = linePoint;
4174 function ringEnd() {
4175 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4176 resample.lineEnd = lineEnd;
4177 lineEnd();
4179 return resample;
4181 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
4182 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
4183 if (d2 > 4 * δ2 && depth--) {
4184 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 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
4185 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
4186 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
4187 stream.point(x2, y2);
4188 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
4192 resample.precision = function(_) {
4193 if (!arguments.length) return Math.sqrt(δ2);
4194 maxDepth = (δ2 = _ * _) > 0 && 16;
4195 return resample;
4196 };
4197 return resample;
4199 d3.geo.path = function() {
4200 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
4201 function path(object) {
4202 if (object) {
4203 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
4204 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
4205 d3.geo.stream(object, cacheStream);
4207 return contextStream.result();
4209 path.area = function(object) {
4210 d3_geo_pathAreaSum = 0;
4211 d3.geo.stream(object, projectStream(d3_geo_pathArea));
4212 return d3_geo_pathAreaSum;
4213 };
4214 path.centroid = function(object) {
4215 d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
4216 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
4217 return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];
4218 };
4219 path.bounds = function(object) {
4220 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
4221 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
4222 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
4223 };
4224 path.projection = function(_) {
4225 if (!arguments.length) return projection;
4226 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
4227 return reset();
4228 };
4229 path.context = function(_) {
4230 if (!arguments.length) return context;
4231 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
4232 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
4233 return reset();
4234 };
4235 path.pointRadius = function(_) {
4236 if (!arguments.length) return pointRadius;
4237 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
4238 return path;
4239 };
4240 function reset() {
4241 cacheStream = null;
4242 return path;
4244 return path.projection(d3.geo.albersUsa()).context(null);
4245 };
4246 function d3_geo_pathProjectStream(project) {
4247 var resample = d3_geo_resample(function(x, y) {
4248 return project([ x * d3_degrees, y * d3_degrees ]);
4249 });
4250 return function(stream) {
4251 return d3_geo_projectionRadians(resample(stream));
4252 };
4254 d3.geo.transform = function(methods) {
4255 return {
4256 stream: function(stream) {
4257 var transform = new d3_geo_transform(stream);
4258 for (var k in methods) transform[k] = methods[k];
4259 return transform;
4261 };
4262 };
4263 function d3_geo_transform(stream) {
4264 this.stream = stream;
4266 d3_geo_transform.prototype = {
4267 point: function(x, y) {
4268 this.stream.point(x, y);
4269 },
4270 sphere: function() {
4271 this.stream.sphere();
4272 },
4273 lineStart: function() {
4274 this.stream.lineStart();
4275 },
4276 lineEnd: function() {
4277 this.stream.lineEnd();
4278 },
4279 polygonStart: function() {
4280 this.stream.polygonStart();
4281 },
4282 polygonEnd: function() {
4283 this.stream.polygonEnd();
4285 };
4286 function d3_geo_transformPoint(stream, point) {
4287 return {
4288 point: point,
4289 sphere: function() {
4290 stream.sphere();
4291 },
4292 lineStart: function() {
4293 stream.lineStart();
4294 },
4295 lineEnd: function() {
4296 stream.lineEnd();
4297 },
4298 polygonStart: function() {
4299 stream.polygonStart();
4300 },
4301 polygonEnd: function() {
4302 stream.polygonEnd();
4304 };
4306 d3.geo.projection = d3_geo_projection;
4307 d3.geo.projectionMutator = d3_geo_projectionMutator;
4308 function d3_geo_projection(project) {
4309 return d3_geo_projectionMutator(function() {
4310 return project;
4311 })();
4313 function d3_geo_projectionMutator(projectAt) {
4314 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
4315 x = project(x, y);
4316 return [ x[0] * k + δx, δy - x[1] * k ];
4317 }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;
4318 function projection(point) {
4319 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
4320 return [ point[0] * k + δx, δy - point[1] * k ];
4322 function invert(point) {
4323 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
4324 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
4326 projection.stream = function(output) {
4327 if (stream) stream.valid = false;
4328 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
4329 stream.valid = true;
4330 return stream;
4331 };
4332 projection.clipAngle = function(_) {
4333 if (!arguments.length) return clipAngle;
4334 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
4335 return invalidate();
4336 };
4337 projection.clipExtent = function(_) {
4338 if (!arguments.length) return clipExtent;
4339 clipExtent = _;
4340 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
4341 return invalidate();
4342 };
4343 projection.scale = function(_) {
4344 if (!arguments.length) return k;
4345 k = +_;
4346 return reset();
4347 };
4348 projection.translate = function(_) {
4349 if (!arguments.length) return [ x, y ];
4350 x = +_[0];
4351 y = +_[1];
4352 return reset();
4353 };
4354 projection.center = function(_) {
4355 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
4356 λ = _[0] % 360 * d3_radians;
4357 φ = _[1] % 360 * d3_radians;
4358 return reset();
4359 };
4360 projection.rotate = function(_) {
4361 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
4362 δλ = _[0] % 360 * d3_radians;
4363 δφ = _[1] % 360 * d3_radians;
4364 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
4365 return reset();
4366 };
4367 d3.rebind(projection, projectResample, "precision");
4368 function reset() {
4369 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
4370 var center = project(λ, φ);
4371 δx = x - center[0] * k;
4372 δy = y + center[1] * k;
4373 return invalidate();
4375 function invalidate() {
4376 if (stream) stream.valid = false, stream = null;
4377 return projection;
4379 return function() {
4380 project = projectAt.apply(this, arguments);
4381 projection.invert = project.invert && invert;
4382 return reset();
4383 };
4385 function d3_geo_projectionRadians(stream) {
4386 return d3_geo_transformPoint(stream, function(x, y) {
4387 stream.point(x * d3_radians, y * d3_radians);
4388 });
4390 function d3_geo_equirectangular(λ, φ) {
4391 return [ λ, φ ];
4393 (d3.geo.equirectangular = function() {
4394 return d3_geo_projection(d3_geo_equirectangular);
4395 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
4396 d3.geo.rotation = function(rotate) {
4397 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
4398 function forward(coordinates) {
4399 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4400 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4402 forward.invert = function(coordinates) {
4403 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4404 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4405 };
4406 return forward;
4407 };
4408 function d3_geo_identityRotation(λ, φ) {
4409 return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4411 d3_geo_identityRotation.invert = d3_geo_equirectangular;
4412 function d3_geo_rotation(δλ, δφ, δγ) {
4413 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
4415 function d3_geo_forwardRotationλ(δλ) {
4416 return function(λ, φ) {
4417 return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4418 };
4420 function d3_geo_rotationλ(δλ) {
4421 var rotation = d3_geo_forwardRotationλ(δλ);
4422 rotation.invert = d3_geo_forwardRotationλ(-δλ);
4423 return rotation;
4425 function d3_geo_rotationφγ(δφ, δγ) {
4426 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
4427 function rotation(λ, φ) {
4428 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
4429 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
4431 rotation.invert = function(λ, φ) {
4432 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
4433 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
4434 };
4435 return rotation;
4437 d3.geo.circle = function() {
4438 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
4439 function circle() {
4440 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 = [];
4441 interpolate(null, null, 1, {
4442 point: function(x, y) {
4443 ring.push(x = rotate(x, y));
4444 x[0] *= d3_degrees, x[1] *= d3_degrees;
4446 });
4447 return {
4448 type: "Polygon",
4449 coordinates: [ ring ]
4450 };
4452 circle.origin = function(x) {
4453 if (!arguments.length) return origin;
4454 origin = x;
4455 return circle;
4456 };
4457 circle.angle = function(x) {
4458 if (!arguments.length) return angle;
4459 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
4460 return circle;
4461 };
4462 circle.precision = function(_) {
4463 if (!arguments.length) return precision;
4464 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
4465 return circle;
4466 };
4467 return circle.angle(90);
4468 };
4469 function d3_geo_circleInterpolate(radius, precision) {
4470 var cr = Math.cos(radius), sr = Math.sin(radius);
4471 return function(from, to, direction, listener) {
4472 var step = direction * precision;
4473 if (from != null) {
4474 from = d3_geo_circleAngle(cr, from);
4475 to = d3_geo_circleAngle(cr, to);
4476 if (direction > 0 ? from < to : from > to) from += direction * τ;
4477 } else {
4478 from = radius + direction * τ;
4479 to = radius - .5 * step;
4481 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
4482 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
4484 };
4486 function d3_geo_circleAngle(cr, point) {
4487 var a = d3_geo_cartesian(point);
4488 a[0] -= cr;
4489 d3_geo_cartesianNormalize(a);
4490 var angle = d3_acos(-a[1]);
4491 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
4493 d3.geo.distance = function(a, b) {
4494 var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
4495 return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);
4496 };
4497 d3.geo.graticule = function() {
4498 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
4499 function graticule() {
4500 return {
4501 type: "MultiLineString",
4502 coordinates: lines()
4503 };
4505 function lines() {
4506 return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
4507 return abs(x % DX) > ε;
4508 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
4509 return abs(y % DY) > ε;
4510 }).map(y));
4512 graticule.lines = function() {
4513 return lines().map(function(coordinates) {
4514 return {
4515 type: "LineString",
4516 coordinates: coordinates
4517 };
4518 });
4519 };
4520 graticule.outline = function() {
4521 return {
4522 type: "Polygon",
4523 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
4524 };
4525 };
4526 graticule.extent = function(_) {
4527 if (!arguments.length) return graticule.minorExtent();
4528 return graticule.majorExtent(_).minorExtent(_);
4529 };
4530 graticule.majorExtent = function(_) {
4531 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
4532 X0 = +_[0][0], X1 = +_[1][0];
4533 Y0 = +_[0][1], Y1 = +_[1][1];
4534 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
4535 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
4536 return graticule.precision(precision);
4537 };
4538 graticule.minorExtent = function(_) {
4539 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
4540 x0 = +_[0][0], x1 = +_[1][0];
4541 y0 = +_[0][1], y1 = +_[1][1];
4542 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
4543 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
4544 return graticule.precision(precision);
4545 };
4546 graticule.step = function(_) {
4547 if (!arguments.length) return graticule.minorStep();
4548 return graticule.majorStep(_).minorStep(_);
4549 };
4550 graticule.majorStep = function(_) {
4551 if (!arguments.length) return [ DX, DY ];
4552 DX = +_[0], DY = +_[1];
4553 return graticule;
4554 };
4555 graticule.minorStep = function(_) {
4556 if (!arguments.length) return [ dx, dy ];
4557 dx = +_[0], dy = +_[1];
4558 return graticule;
4559 };
4560 graticule.precision = function(_) {
4561 if (!arguments.length) return precision;
4562 precision = +_;
4563 x = d3_geo_graticuleX(y0, y1, 90);
4564 y = d3_geo_graticuleY(x0, x1, precision);
4565 X = d3_geo_graticuleX(Y0, Y1, 90);
4566 Y = d3_geo_graticuleY(X0, X1, precision);
4567 return graticule;
4568 };
4569 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
4570 };
4571 function d3_geo_graticuleX(y0, y1, dy) {
4572 var y = d3.range(y0, y1 - ε, dy).concat(y1);
4573 return function(x) {
4574 return y.map(function(y) {
4575 return [ x, y ];
4576 });
4577 };
4579 function d3_geo_graticuleY(x0, x1, dx) {
4580 var x = d3.range(x0, x1 - ε, dx).concat(x1);
4581 return function(y) {
4582 return x.map(function(x) {
4583 return [ x, y ];
4584 });
4585 };
4587 function d3_source(d) {
4588 return d.source;
4590 function d3_target(d) {
4591 return d.target;
4593 d3.geo.greatArc = function() {
4594 var source = d3_source, source_, target = d3_target, target_;
4595 function greatArc() {
4596 return {
4597 type: "LineString",
4598 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
4599 };
4601 greatArc.distance = function() {
4602 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
4603 };
4604 greatArc.source = function(_) {
4605 if (!arguments.length) return source;
4606 source = _, source_ = typeof _ === "function" ? null : _;
4607 return greatArc;
4608 };
4609 greatArc.target = function(_) {
4610 if (!arguments.length) return target;
4611 target = _, target_ = typeof _ === "function" ? null : _;
4612 return greatArc;
4613 };
4614 greatArc.precision = function() {
4615 return arguments.length ? greatArc : 0;
4616 };
4617 return greatArc;
4618 };
4619 d3.geo.interpolate = function(source, target) {
4620 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
4621 };
4622 function d3_geo_interpolate(x0, y0, x1, y1) {
4623 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_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);
4624 var interpolate = d ? function(t) {
4625 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;
4626 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
4627 } : function() {
4628 return [ x0 * d3_degrees, y0 * d3_degrees ];
4629 };
4630 interpolate.distance = d;
4631 return interpolate;
4633 d3.geo.length = function(object) {
4634 d3_geo_lengthSum = 0;
4635 d3.geo.stream(object, d3_geo_length);
4636 return d3_geo_lengthSum;
4637 };
4638 var d3_geo_lengthSum;
4639 var d3_geo_length = {
4640 sphere: d3_noop,
4641 point: d3_noop,
4642 lineStart: d3_geo_lengthLineStart,
4643 lineEnd: d3_noop,
4644 polygonStart: d3_noop,
4645 polygonEnd: d3_noop
4646 };
4647 function d3_geo_lengthLineStart() {
4648 var λ0, sinφ0, cosφ0;
4649 d3_geo_length.point = function(λ, φ) {
4650 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
4651 d3_geo_length.point = nextPoint;
4652 };
4653 d3_geo_length.lineEnd = function() {
4654 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4655 };
4656 function nextPoint(λ, φ) {
4657 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4658 d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
4659 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
4662 function d3_geo_azimuthal(scale, angle) {
4663 function azimuthal(λ, φ) {
4664 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
4665 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
4667 azimuthal.invert = function(x, y) {
4668 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
4669 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
4670 };
4671 return azimuthal;
4673 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
4674 return Math.sqrt(2 / (1 + cosλcosφ));
4675 }, function(ρ) {
4676 return 2 * Math.asin(ρ / 2);
4677 });
4678 (d3.geo.azimuthalEqualArea = function() {
4679 return d3_geo_projection(d3_geo_azimuthalEqualArea);
4680 }).raw = d3_geo_azimuthalEqualArea;
4681 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
4682 var c = Math.acos(cosλcosφ);
4683 return c && c / Math.sin(c);
4684 }, d3_identity);
4685 (d3.geo.azimuthalEquidistant = function() {
4686 return d3_geo_projection(d3_geo_azimuthalEquidistant);
4687 }).raw = d3_geo_azimuthalEquidistant;
4688 function d3_geo_conicConformal(φ0, φ1) {
4689 var cosφ0 = Math.cos(φ0), t = function(φ) {
4690 return Math.tan(π / 4 + φ / 2);
4691 }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
4692 if (!n) return d3_geo_mercator;
4693 function forward(λ, φ) {
4694 if (F > 0) {
4695 if (φ < -halfπ + ε) φ = -halfπ + ε;
4696 } else {
4697 if (φ > halfπ - ε) φ = halfπ - ε;
4699 var ρ = F / Math.pow(t(φ), n);
4700 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4702 forward.invert = function(x, y) {
4703 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
4704 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
4705 };
4706 return forward;
4708 (d3.geo.conicConformal = function() {
4709 return d3_geo_conic(d3_geo_conicConformal);
4710 }).raw = d3_geo_conicConformal;
4711 function d3_geo_conicEquidistant(φ0, φ1) {
4712 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
4713 if (abs(n) < ε) return d3_geo_equirectangular;
4714 function forward(λ, φ) {
4715 var ρ = G - φ;
4716 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
4718 forward.invert = function(x, y) {
4719 var ρ0_y = G - y;
4720 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
4721 };
4722 return forward;
4724 (d3.geo.conicEquidistant = function() {
4725 return d3_geo_conic(d3_geo_conicEquidistant);
4726 }).raw = d3_geo_conicEquidistant;
4727 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
4728 return 1 / cosλcosφ;
4729 }, Math.atan);
4730 (d3.geo.gnomonic = function() {
4731 return d3_geo_projection(d3_geo_gnomonic);
4732 }).raw = d3_geo_gnomonic;
4733 function d3_geo_mercator(λ, φ) {
4734 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
4736 d3_geo_mercator.invert = function(x, y) {
4737 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
4738 };
4739 function d3_geo_mercatorProjection(project) {
4740 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
4741 m.scale = function() {
4742 var v = scale.apply(m, arguments);
4743 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4744 };
4745 m.translate = function() {
4746 var v = translate.apply(m, arguments);
4747 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4748 };
4749 m.clipExtent = function(_) {
4750 var v = clipExtent.apply(m, arguments);
4751 if (v === m) {
4752 if (clipAuto = _ == null) {
4753 var k = π * scale(), t = translate();
4754 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
4756 } else if (clipAuto) {
4757 v = null;
4759 return v;
4760 };
4761 return m.clipExtent(null);
4763 (d3.geo.mercator = function() {
4764 return d3_geo_mercatorProjection(d3_geo_mercator);
4765 }).raw = d3_geo_mercator;
4766 var d3_geo_orthographic = d3_geo_azimuthal(function() {
4767 return 1;
4768 }, Math.asin);
4769 (d3.geo.orthographic = function() {
4770 return d3_geo_projection(d3_geo_orthographic);
4771 }).raw = d3_geo_orthographic;
4772 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
4773 return 1 / (1 + cosλcosφ);
4774 }, function(ρ) {
4775 return 2 * Math.atan(ρ);
4776 });
4777 (d3.geo.stereographic = function() {
4778 return d3_geo_projection(d3_geo_stereographic);
4779 }).raw = d3_geo_stereographic;
4780 function d3_geo_transverseMercator(λ, φ) {
4781 return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
4783 d3_geo_transverseMercator.invert = function(x, y) {
4784 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
4785 };
4786 (d3.geo.transverseMercator = function() {
4787 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
4788 projection.center = function(_) {
4789 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
4790 };
4791 projection.rotate = function(_) {
4792 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
4793 [ _[0], _[1], _[2] - 90 ]);
4794 };
4795 return rotate([ 0, 0, 90 ]);
4796 }).raw = d3_geo_transverseMercator;
4797 d3.geom = {};
4798 function d3_geom_pointX(d) {
4799 return d[0];
4801 function d3_geom_pointY(d) {
4802 return d[1];
4804 d3.geom.hull = function(vertices) {
4805 var x = d3_geom_pointX, y = d3_geom_pointY;
4806 if (arguments.length) return hull(vertices);
4807 function hull(data) {
4808 if (data.length < 3) return [];
4809 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
4810 for (i = 0; i < n; i++) {
4811 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
4813 points.sort(d3_geom_hullOrder);
4814 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
4815 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
4816 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
4817 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
4818 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
4819 return polygon;
4821 hull.x = function(_) {
4822 return arguments.length ? (x = _, hull) : x;
4823 };
4824 hull.y = function(_) {
4825 return arguments.length ? (y = _, hull) : y;
4826 };
4827 return hull;
4828 };
4829 function d3_geom_hullUpper(points) {
4830 var n = points.length, hull = [ 0, 1 ], hs = 2;
4831 for (var i = 2; i < n; i++) {
4832 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
4833 hull[hs++] = i;
4835 return hull.slice(0, hs);
4837 function d3_geom_hullOrder(a, b) {
4838 return a[0] - b[0] || a[1] - b[1];
4840 d3.geom.polygon = function(coordinates) {
4841 d3_subclass(coordinates, d3_geom_polygonPrototype);
4842 return coordinates;
4843 };
4844 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
4845 d3_geom_polygonPrototype.area = function() {
4846 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
4847 while (++i < n) {
4848 a = b;
4849 b = this[i];
4850 area += a[1] * b[0] - a[0] * b[1];
4852 return area * .5;
4853 };
4854 d3_geom_polygonPrototype.centroid = function(k) {
4855 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
4856 if (!arguments.length) k = -1 / (6 * this.area());
4857 while (++i < n) {
4858 a = b;
4859 b = this[i];
4860 c = a[0] * b[1] - b[0] * a[1];
4861 x += (a[0] + b[0]) * c;
4862 y += (a[1] + b[1]) * c;
4864 return [ x * k, y * k ];
4865 };
4866 d3_geom_polygonPrototype.clip = function(subject) {
4867 var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
4868 while (++i < n) {
4869 input = subject.slice();
4870 subject.length = 0;
4871 b = this[i];
4872 c = input[(m = input.length - closed) - 1];
4873 j = -1;
4874 while (++j < m) {
4875 d = input[j];
4876 if (d3_geom_polygonInside(d, a, b)) {
4877 if (!d3_geom_polygonInside(c, a, b)) {
4878 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4880 subject.push(d);
4881 } else if (d3_geom_polygonInside(c, a, b)) {
4882 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4884 c = d;
4886 if (closed) subject.push(subject[0]);
4887 a = b;
4889 return subject;
4890 };
4891 function d3_geom_polygonInside(p, a, b) {
4892 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4894 function d3_geom_polygonIntersect(c, d, a, b) {
4895 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);
4896 return [ x1 + ua * x21, y1 + ua * y21 ];
4898 function d3_geom_polygonClosed(coordinates) {
4899 var a = coordinates[0], b = coordinates[coordinates.length - 1];
4900 return !(a[0] - b[0] || a[1] - b[1]);
4902 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4903 function d3_geom_voronoiBeach() {
4904 d3_geom_voronoiRedBlackNode(this);
4905 this.edge = this.site = this.circle = null;
4907 function d3_geom_voronoiCreateBeach(site) {
4908 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
4909 beach.site = site;
4910 return beach;
4912 function d3_geom_voronoiDetachBeach(beach) {
4913 d3_geom_voronoiDetachCircle(beach);
4914 d3_geom_voronoiBeaches.remove(beach);
4915 d3_geom_voronoiBeachPool.push(beach);
4916 d3_geom_voronoiRedBlackNode(beach);
4918 function d3_geom_voronoiRemoveBeach(beach) {
4919 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4920 x: x,
4921 y: y
4922 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
4923 d3_geom_voronoiDetachBeach(beach);
4924 var lArc = previous;
4925 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4926 previous = lArc.P;
4927 disappearing.unshift(lArc);
4928 d3_geom_voronoiDetachBeach(lArc);
4929 lArc = previous;
4931 disappearing.unshift(lArc);
4932 d3_geom_voronoiDetachCircle(lArc);
4933 var rArc = next;
4934 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4935 next = rArc.N;
4936 disappearing.push(rArc);
4937 d3_geom_voronoiDetachBeach(rArc);
4938 rArc = next;
4940 disappearing.push(rArc);
4941 d3_geom_voronoiDetachCircle(rArc);
4942 var nArcs = disappearing.length, iArc;
4943 for (iArc = 1; iArc < nArcs; ++iArc) {
4944 rArc = disappearing[iArc];
4945 lArc = disappearing[iArc - 1];
4946 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4948 lArc = disappearing[0];
4949 rArc = disappearing[nArcs - 1];
4950 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4951 d3_geom_voronoiAttachCircle(lArc);
4952 d3_geom_voronoiAttachCircle(rArc);
4954 function d3_geom_voronoiAddBeach(site) {
4955 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4956 while (node) {
4957 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4958 if (dxl > ε) node = node.L; else {
4959 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
4960 if (dxr > ε) {
4961 if (!node.R) {
4962 lArc = node;
4963 break;
4965 node = node.R;
4966 } else {
4967 if (dxl > -ε) {
4968 lArc = node.P;
4969 rArc = node;
4970 } else if (dxr > -ε) {
4971 lArc = node;
4972 rArc = node.N;
4973 } else {
4974 lArc = rArc = node;
4976 break;
4980 var newArc = d3_geom_voronoiCreateBeach(site);
4981 d3_geom_voronoiBeaches.insert(lArc, newArc);
4982 if (!lArc && !rArc) return;
4983 if (lArc === rArc) {
4984 d3_geom_voronoiDetachCircle(lArc);
4985 rArc = d3_geom_voronoiCreateBeach(lArc.site);
4986 d3_geom_voronoiBeaches.insert(newArc, rArc);
4987 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4988 d3_geom_voronoiAttachCircle(lArc);
4989 d3_geom_voronoiAttachCircle(rArc);
4990 return;
4992 if (!rArc) {
4993 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4994 return;
4996 d3_geom_voronoiDetachCircle(lArc);
4997 d3_geom_voronoiDetachCircle(rArc);
4998 var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
4999 x: (cy * hb - by * hc) / d + ax,
5000 y: (bx * hc - cx * hb) / d + ay
5001 };
5002 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
5003 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
5004 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
5005 d3_geom_voronoiAttachCircle(lArc);
5006 d3_geom_voronoiAttachCircle(rArc);
5008 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
5009 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
5010 if (!pby2) return rfocx;
5011 var lArc = arc.P;
5012 if (!lArc) return -Infinity;
5013 site = lArc.site;
5014 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
5015 if (!plby2) return lfocx;
5016 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
5017 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
5018 return (rfocx + lfocx) / 2;
5020 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
5021 var rArc = arc.N;
5022 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
5023 var site = arc.site;
5024 return site.y === directrix ? site.x : Infinity;
5026 function d3_geom_voronoiCell(site) {
5027 this.site = site;
5028 this.edges = [];
5030 d3_geom_voronoiCell.prototype.prepare = function() {
5031 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
5032 while (iHalfEdge--) {
5033 edge = halfEdges[iHalfEdge].edge;
5034 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
5036 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
5037 return halfEdges.length;
5038 };
5039 function d3_geom_voronoiCloseCells(extent) {
5040 var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
5041 while (iCell--) {
5042 cell = cells[iCell];
5043 if (!cell || !cell.prepare()) continue;
5044 halfEdges = cell.edges;
5045 nHalfEdges = halfEdges.length;
5046 iHalfEdge = 0;
5047 while (iHalfEdge < nHalfEdges) {
5048 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
5049 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
5050 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
5051 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
5052 x: x0,
5053 y: abs(x2 - x0) < ε ? y2 : y1
5054 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
5055 x: abs(y2 - y1) < ε ? x2 : x1,
5056 y: y1
5057 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
5058 x: x1,
5059 y: abs(x2 - x1) < ε ? y2 : y0
5060 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
5061 x: abs(y2 - y0) < ε ? x2 : x0,
5062 y: y0
5063 } : null), cell.site, null));
5064 ++nHalfEdges;
5069 function d3_geom_voronoiHalfEdgeOrder(a, b) {
5070 return b.angle - a.angle;
5072 function d3_geom_voronoiCircle() {
5073 d3_geom_voronoiRedBlackNode(this);
5074 this.x = this.y = this.arc = this.site = this.cy = null;
5076 function d3_geom_voronoiAttachCircle(arc) {
5077 var lArc = arc.P, rArc = arc.N;
5078 if (!lArc || !rArc) return;
5079 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
5080 if (lSite === rSite) return;
5081 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
5082 var d = 2 * (ax * cy - ay * cx);
5083 if (d >= -ε2) return;
5084 var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
5085 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
5086 circle.arc = arc;
5087 circle.site = cSite;
5088 circle.x = x + bx;
5089 circle.y = cy + Math.sqrt(x * x + y * y);
5090 circle.cy = cy;
5091 arc.circle = circle;
5092 var before = null, node = d3_geom_voronoiCircles._;
5093 while (node) {
5094 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
5095 if (node.L) node = node.L; else {
5096 before = node.P;
5097 break;
5099 } else {
5100 if (node.R) node = node.R; else {
5101 before = node;
5102 break;
5106 d3_geom_voronoiCircles.insert(before, circle);
5107 if (!before) d3_geom_voronoiFirstCircle = circle;
5109 function d3_geom_voronoiDetachCircle(arc) {
5110 var circle = arc.circle;
5111 if (circle) {
5112 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
5113 d3_geom_voronoiCircles.remove(circle);
5114 d3_geom_voronoiCirclePool.push(circle);
5115 d3_geom_voronoiRedBlackNode(circle);
5116 arc.circle = null;
5119 function d3_geom_voronoiClipEdges(extent) {
5120 var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
5121 while (i--) {
5122 e = edges[i];
5123 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
5124 e.a = e.b = null;
5125 edges.splice(i, 1);
5129 function d3_geom_voronoiConnectEdge(edge, extent) {
5130 var vb = edge.b;
5131 if (vb) return true;
5132 var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
5133 if (ry === ly) {
5134 if (fx < x0 || fx >= x1) return;
5135 if (lx > rx) {
5136 if (!va) va = {
5137 x: fx,
5138 y: y0
5139 }; else if (va.y >= y1) return;
5140 vb = {
5141 x: fx,
5142 y: y1
5143 };
5144 } else {
5145 if (!va) va = {
5146 x: fx,
5147 y: y1
5148 }; else if (va.y < y0) return;
5149 vb = {
5150 x: fx,
5151 y: y0
5152 };
5154 } else {
5155 fm = (lx - rx) / (ry - ly);
5156 fb = fy - fm * fx;
5157 if (fm < -1 || fm > 1) {
5158 if (lx > rx) {
5159 if (!va) va = {
5160 x: (y0 - fb) / fm,
5161 y: y0
5162 }; else if (va.y >= y1) return;
5163 vb = {
5164 x: (y1 - fb) / fm,
5165 y: y1
5166 };
5167 } else {
5168 if (!va) va = {
5169 x: (y1 - fb) / fm,
5170 y: y1
5171 }; else if (va.y < y0) return;
5172 vb = {
5173 x: (y0 - fb) / fm,
5174 y: y0
5175 };
5177 } else {
5178 if (ly < ry) {
5179 if (!va) va = {
5180 x: x0,
5181 y: fm * x0 + fb
5182 }; else if (va.x >= x1) return;
5183 vb = {
5184 x: x1,
5185 y: fm * x1 + fb
5186 };
5187 } else {
5188 if (!va) va = {
5189 x: x1,
5190 y: fm * x1 + fb
5191 }; else if (va.x < x0) return;
5192 vb = {
5193 x: x0,
5194 y: fm * x0 + fb
5195 };
5199 edge.a = va;
5200 edge.b = vb;
5201 return true;
5203 function d3_geom_voronoiEdge(lSite, rSite) {
5204 this.l = lSite;
5205 this.r = rSite;
5206 this.a = this.b = null;
5208 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
5209 var edge = new d3_geom_voronoiEdge(lSite, rSite);
5210 d3_geom_voronoiEdges.push(edge);
5211 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
5212 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
5213 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
5214 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
5215 return edge;
5217 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
5218 var edge = new d3_geom_voronoiEdge(lSite, null);
5219 edge.a = va;
5220 edge.b = vb;
5221 d3_geom_voronoiEdges.push(edge);
5222 return edge;
5224 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
5225 if (!edge.a && !edge.b) {
5226 edge.a = vertex;
5227 edge.l = lSite;
5228 edge.r = rSite;
5229 } else if (edge.l === rSite) {
5230 edge.b = vertex;
5231 } else {
5232 edge.a = vertex;
5235 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
5236 var va = edge.a, vb = edge.b;
5237 this.edge = edge;
5238 this.site = lSite;
5239 this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
5241 d3_geom_voronoiHalfEdge.prototype = {
5242 start: function() {
5243 return this.edge.l === this.site ? this.edge.a : this.edge.b;
5244 },
5245 end: function() {
5246 return this.edge.l === this.site ? this.edge.b : this.edge.a;
5248 };
5249 function d3_geom_voronoiRedBlackTree() {
5250 this._ = null;
5252 function d3_geom_voronoiRedBlackNode(node) {
5253 node.U = node.C = node.L = node.R = node.P = node.N = null;
5255 d3_geom_voronoiRedBlackTree.prototype = {
5256 insert: function(after, node) {
5257 var parent, grandpa, uncle;
5258 if (after) {
5259 node.P = after;
5260 node.N = after.N;
5261 if (after.N) after.N.P = node;
5262 after.N = node;
5263 if (after.R) {
5264 after = after.R;
5265 while (after.L) after = after.L;
5266 after.L = node;
5267 } else {
5268 after.R = node;
5270 parent = after;
5271 } else if (this._) {
5272 after = d3_geom_voronoiRedBlackFirst(this._);
5273 node.P = null;
5274 node.N = after;
5275 after.P = after.L = node;
5276 parent = after;
5277 } else {
5278 node.P = node.N = null;
5279 this._ = node;
5280 parent = null;
5282 node.L = node.R = null;
5283 node.U = parent;
5284 node.C = true;
5285 after = node;
5286 while (parent && parent.C) {
5287 grandpa = parent.U;
5288 if (parent === grandpa.L) {
5289 uncle = grandpa.R;
5290 if (uncle && uncle.C) {
5291 parent.C = uncle.C = false;
5292 grandpa.C = true;
5293 after = grandpa;
5294 } else {
5295 if (after === parent.R) {
5296 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5297 after = parent;
5298 parent = after.U;
5300 parent.C = false;
5301 grandpa.C = true;
5302 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
5304 } else {
5305 uncle = grandpa.L;
5306 if (uncle && uncle.C) {
5307 parent.C = uncle.C = false;
5308 grandpa.C = true;
5309 after = grandpa;
5310 } else {
5311 if (after === parent.L) {
5312 d3_geom_voronoiRedBlackRotateRight(this, parent);
5313 after = parent;
5314 parent = after.U;
5316 parent.C = false;
5317 grandpa.C = true;
5318 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
5321 parent = after.U;
5323 this._.C = false;
5324 },
5325 remove: function(node) {
5326 if (node.N) node.N.P = node.P;
5327 if (node.P) node.P.N = node.N;
5328 node.N = node.P = null;
5329 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
5330 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
5331 if (parent) {
5332 if (parent.L === node) parent.L = next; else parent.R = next;
5333 } else {
5334 this._ = next;
5336 if (left && right) {
5337 red = next.C;
5338 next.C = node.C;
5339 next.L = left;
5340 left.U = next;
5341 if (next !== right) {
5342 parent = next.U;
5343 next.U = node.U;
5344 node = next.R;
5345 parent.L = node;
5346 next.R = right;
5347 right.U = next;
5348 } else {
5349 next.U = parent;
5350 parent = next;
5351 node = next.R;
5353 } else {
5354 red = node.C;
5355 node = next;
5357 if (node) node.U = parent;
5358 if (red) return;
5359 if (node && node.C) {
5360 node.C = false;
5361 return;
5363 do {
5364 if (node === this._) break;
5365 if (node === parent.L) {
5366 sibling = parent.R;
5367 if (sibling.C) {
5368 sibling.C = false;
5369 parent.C = true;
5370 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5371 sibling = parent.R;
5373 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5374 if (!sibling.R || !sibling.R.C) {
5375 sibling.L.C = false;
5376 sibling.C = true;
5377 d3_geom_voronoiRedBlackRotateRight(this, sibling);
5378 sibling = parent.R;
5380 sibling.C = parent.C;
5381 parent.C = sibling.R.C = false;
5382 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5383 node = this._;
5384 break;
5386 } else {
5387 sibling = parent.L;
5388 if (sibling.C) {
5389 sibling.C = false;
5390 parent.C = true;
5391 d3_geom_voronoiRedBlackRotateRight(this, parent);
5392 sibling = parent.L;
5394 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5395 if (!sibling.L || !sibling.L.C) {
5396 sibling.R.C = false;
5397 sibling.C = true;
5398 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5399 sibling = parent.L;
5401 sibling.C = parent.C;
5402 parent.C = sibling.L.C = false;
5403 d3_geom_voronoiRedBlackRotateRight(this, parent);
5404 node = this._;
5405 break;
5408 sibling.C = true;
5409 node = parent;
5410 parent = parent.U;
5411 } while (!node.C);
5412 if (node) node.C = false;
5414 };
5415 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5416 var p = node, q = node.R, parent = p.U;
5417 if (parent) {
5418 if (parent.L === p) parent.L = q; else parent.R = q;
5419 } else {
5420 tree._ = q;
5422 q.U = parent;
5423 p.U = q;
5424 p.R = q.L;
5425 if (p.R) p.R.U = p;
5426 q.L = p;
5428 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5429 var p = node, q = node.L, parent = p.U;
5430 if (parent) {
5431 if (parent.L === p) parent.L = q; else parent.R = q;
5432 } else {
5433 tree._ = q;
5435 q.U = parent;
5436 p.U = q;
5437 p.L = q.R;
5438 if (p.L) p.L.U = p;
5439 q.R = p;
5441 function d3_geom_voronoiRedBlackFirst(node) {
5442 while (node.L) node = node.L;
5443 return node;
5445 function d3_geom_voronoi(sites, bbox) {
5446 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5447 d3_geom_voronoiEdges = [];
5448 d3_geom_voronoiCells = new Array(sites.length);
5449 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
5450 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
5451 while (true) {
5452 circle = d3_geom_voronoiFirstCircle;
5453 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5454 if (site.x !== x0 || site.y !== y0) {
5455 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
5456 d3_geom_voronoiAddBeach(site);
5457 x0 = site.x, y0 = site.y;
5459 site = sites.pop();
5460 } else if (circle) {
5461 d3_geom_voronoiRemoveBeach(circle.arc);
5462 } else {
5463 break;
5466 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
5467 var diagram = {
5468 cells: d3_geom_voronoiCells,
5469 edges: d3_geom_voronoiEdges
5470 };
5471 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5472 return diagram;
5474 function d3_geom_voronoiVertexOrder(a, b) {
5475 return b.y - a.y || b.x - a.x;
5477 d3.geom.voronoi = function(points) {
5478 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5479 if (points) return voronoi(points);
5480 function voronoi(data) {
5481 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
5482 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5483 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
5484 var s = e.start();
5485 return [ s.x, s.y ];
5486 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
5487 polygon.point = data[i];
5488 });
5489 return polygons;
5491 function sites(data) {
5492 return data.map(function(d, i) {
5493 return {
5494 x: Math.round(fx(d, i) / ε) * ε,
5495 y: Math.round(fy(d, i) / ε) * ε,
5496 i: i
5497 };
5498 });
5500 voronoi.links = function(data) {
5501 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5502 return edge.l && edge.r;
5503 }).map(function(edge) {
5504 return {
5505 source: data[edge.l.i],
5506 target: data[edge.r.i]
5507 };
5508 });
5509 };
5510 voronoi.triangles = function(data) {
5511 var triangles = [];
5512 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5513 var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
5514 while (++j < m) {
5515 e0 = e1;
5516 s0 = s1;
5517 e1 = edges[j].edge;
5518 s1 = e1.l === site ? e1.r : e1.l;
5519 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5520 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5523 });
5524 return triangles;
5525 };
5526 voronoi.x = function(_) {
5527 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
5528 };
5529 voronoi.y = function(_) {
5530 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
5531 };
5532 voronoi.clipExtent = function(_) {
5533 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
5534 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5535 return voronoi;
5536 };
5537 voronoi.size = function(_) {
5538 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
5539 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5540 };
5541 return voronoi;
5542 };
5543 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5544 function d3_geom_voronoiTriangleArea(a, b, c) {
5545 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
5547 d3.geom.delaunay = function(vertices) {
5548 return d3.geom.voronoi().triangles(vertices);
5549 };
5550 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
5551 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
5552 if (compat = arguments.length) {
5553 x = d3_geom_quadtreeCompatX;
5554 y = d3_geom_quadtreeCompatY;
5555 if (compat === 3) {
5556 y2 = y1;
5557 x2 = x1;
5558 y1 = x1 = 0;
5560 return quadtree(points);
5562 function quadtree(data) {
5563 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
5564 if (x1 != null) {
5565 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
5566 } else {
5567 x2_ = y2_ = -(x1_ = y1_ = Infinity);
5568 xs = [], ys = [];
5569 n = data.length;
5570 if (compat) for (i = 0; i < n; ++i) {
5571 d = data[i];
5572 if (d.x < x1_) x1_ = d.x;
5573 if (d.y < y1_) y1_ = d.y;
5574 if (d.x > x2_) x2_ = d.x;
5575 if (d.y > y2_) y2_ = d.y;
5576 xs.push(d.x);
5577 ys.push(d.y);
5578 } else for (i = 0; i < n; ++i) {
5579 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
5580 if (x_ < x1_) x1_ = x_;
5581 if (y_ < y1_) y1_ = y_;
5582 if (x_ > x2_) x2_ = x_;
5583 if (y_ > y2_) y2_ = y_;
5584 xs.push(x_);
5585 ys.push(y_);
5588 var dx = x2_ - x1_, dy = y2_ - y1_;
5589 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
5590 function insert(n, d, x, y, x1, y1, x2, y2) {
5591 if (isNaN(x) || isNaN(y)) return;
5592 if (n.leaf) {
5593 var nx = n.x, ny = n.y;
5594 if (nx != null) {
5595 if (abs(nx - x) + abs(ny - y) < .01) {
5596 insertChild(n, d, x, y, x1, y1, x2, y2);
5597 } else {
5598 var nPoint = n.point;
5599 n.x = n.y = n.point = null;
5600 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
5601 insertChild(n, d, x, y, x1, y1, x2, y2);
5603 } else {
5604 n.x = x, n.y = y, n.point = d;
5606 } else {
5607 insertChild(n, d, x, y, x1, y1, x2, y2);
5610 function insertChild(n, d, x, y, x1, y1, x2, y2) {
5611 var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
5612 n.leaf = false;
5613 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
5614 if (right) x1 = xm; else x2 = xm;
5615 if (below) y1 = ym; else y2 = ym;
5616 insert(n, d, x, y, x1, y1, x2, y2);
5618 var root = d3_geom_quadtreeNode();
5619 root.add = function(d) {
5620 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
5621 };
5622 root.visit = function(f) {
5623 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
5624 };
5625 root.find = function(point) {
5626 return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
5627 };
5628 i = -1;
5629 if (x1 == null) {
5630 while (++i < n) {
5631 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
5633 --i;
5634 } else data.forEach(root.add);
5635 xs = ys = data = d = null;
5636 return root;
5638 quadtree.x = function(_) {
5639 return arguments.length ? (x = _, quadtree) : x;
5640 };
5641 quadtree.y = function(_) {
5642 return arguments.length ? (y = _, quadtree) : y;
5643 };
5644 quadtree.extent = function(_) {
5645 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
5646 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
5647 y2 = +_[1][1];
5648 return quadtree;
5649 };
5650 quadtree.size = function(_) {
5651 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
5652 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
5653 return quadtree;
5654 };
5655 return quadtree;
5656 };
5657 function d3_geom_quadtreeCompatX(d) {
5658 return d.x;
5660 function d3_geom_quadtreeCompatY(d) {
5661 return d.y;
5663 function d3_geom_quadtreeNode() {
5664 return {
5665 leaf: true,
5666 nodes: [],
5667 point: null,
5668 x: null,
5669 y: null
5670 };
5672 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
5673 if (!f(node, x1, y1, x2, y2)) {
5674 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
5675 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
5676 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
5677 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
5678 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
5681 function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
5682 var minDistance2 = Infinity, closestPoint;
5683 (function find(node, x1, y1, x2, y2) {
5684 if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
5685 if (point = node.point) {
5686 var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
5687 if (distance2 < minDistance2) {
5688 var distance = Math.sqrt(minDistance2 = distance2);
5689 x0 = x - distance, y0 = y - distance;
5690 x3 = x + distance, y3 = y + distance;
5691 closestPoint = point;
5694 var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
5695 for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
5696 if (node = children[i & 3]) switch (i & 3) {
5697 case 0:
5698 find(node, x1, y1, xm, ym);
5699 break;
5701 case 1:
5702 find(node, xm, y1, x2, ym);
5703 break;
5705 case 2:
5706 find(node, x1, ym, xm, y2);
5707 break;
5709 case 3:
5710 find(node, xm, ym, x2, y2);
5711 break;
5714 })(root, x0, y0, x3, y3);
5715 return closestPoint;
5717 d3.interpolateRgb = d3_interpolateRgb;
5718 function d3_interpolateRgb(a, b) {
5719 a = d3.rgb(a);
5720 b = d3.rgb(b);
5721 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
5722 return function(t) {
5723 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));
5724 };
5726 d3.interpolateObject = d3_interpolateObject;
5727 function d3_interpolateObject(a, b) {
5728 var i = {}, c = {}, k;
5729 for (k in a) {
5730 if (k in b) {
5731 i[k] = d3_interpolate(a[k], b[k]);
5732 } else {
5733 c[k] = a[k];
5736 for (k in b) {
5737 if (!(k in a)) {
5738 c[k] = b[k];
5741 return function(t) {
5742 for (k in i) c[k] = i[k](t);
5743 return c;
5744 };
5746 d3.interpolateNumber = d3_interpolateNumber;
5747 function d3_interpolateNumber(a, b) {
5748 a = +a, b = +b;
5749 return function(t) {
5750 return a * (1 - t) + b * t;
5751 };
5753 d3.interpolateString = d3_interpolateString;
5754 function d3_interpolateString(a, b) {
5755 var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
5756 a = a + "", b = b + "";
5757 while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
5758 if ((bs = bm.index) > bi) {
5759 bs = b.slice(bi, bs);
5760 if (s[i]) s[i] += bs; else s[++i] = bs;
5762 if ((am = am[0]) === (bm = bm[0])) {
5763 if (s[i]) s[i] += bm; else s[++i] = bm;
5764 } else {
5765 s[++i] = null;
5766 q.push({
5767 i: i,
5768 x: d3_interpolateNumber(am, bm)
5769 });
5771 bi = d3_interpolate_numberB.lastIndex;
5773 if (bi < b.length) {
5774 bs = b.slice(bi);
5775 if (s[i]) s[i] += bs; else s[++i] = bs;
5777 return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
5778 return b(t) + "";
5779 }) : function() {
5780 return b;
5781 } : (b = q.length, function(t) {
5782 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
5783 return s.join("");
5784 });
5786 var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
5787 d3.interpolate = d3_interpolate;
5788 function d3_interpolate(a, b) {
5789 var i = d3.interpolators.length, f;
5790 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
5791 return f;
5793 d3.interpolators = [ function(a, b) {
5794 var t = typeof b;
5795 return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
5796 } ];
5797 d3.interpolateArray = d3_interpolateArray;
5798 function d3_interpolateArray(a, b) {
5799 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
5800 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
5801 for (;i < na; ++i) c[i] = a[i];
5802 for (;i < nb; ++i) c[i] = b[i];
5803 return function(t) {
5804 for (i = 0; i < n0; ++i) c[i] = x[i](t);
5805 return c;
5806 };
5808 var d3_ease_default = function() {
5809 return d3_identity;
5810 };
5811 var d3_ease = d3.map({
5812 linear: d3_ease_default,
5813 poly: d3_ease_poly,
5814 quad: function() {
5815 return d3_ease_quad;
5816 },
5817 cubic: function() {
5818 return d3_ease_cubic;
5819 },
5820 sin: function() {
5821 return d3_ease_sin;
5822 },
5823 exp: function() {
5824 return d3_ease_exp;
5825 },
5826 circle: function() {
5827 return d3_ease_circle;
5828 },
5829 elastic: d3_ease_elastic,
5830 back: d3_ease_back,
5831 bounce: function() {
5832 return d3_ease_bounce;
5834 });
5835 var d3_ease_mode = d3.map({
5836 "in": d3_identity,
5837 out: d3_ease_reverse,
5838 "in-out": d3_ease_reflect,
5839 "out-in": function(f) {
5840 return d3_ease_reflect(d3_ease_reverse(f));
5842 });
5843 d3.ease = function(name) {
5844 var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
5845 t = d3_ease.get(t) || d3_ease_default;
5846 m = d3_ease_mode.get(m) || d3_identity;
5847 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5848 };
5849 function d3_ease_clamp(f) {
5850 return function(t) {
5851 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
5852 };
5854 function d3_ease_reverse(f) {
5855 return function(t) {
5856 return 1 - f(1 - t);
5857 };
5859 function d3_ease_reflect(f) {
5860 return function(t) {
5861 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
5862 };
5864 function d3_ease_quad(t) {
5865 return t * t;
5867 function d3_ease_cubic(t) {
5868 return t * t * t;
5870 function d3_ease_cubicInOut(t) {
5871 if (t <= 0) return 0;
5872 if (t >= 1) return 1;
5873 var t2 = t * t, t3 = t2 * t;
5874 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
5876 function d3_ease_poly(e) {
5877 return function(t) {
5878 return Math.pow(t, e);
5879 };
5881 function d3_ease_sin(t) {
5882 return 1 - Math.cos(t * halfπ);
5884 function d3_ease_exp(t) {
5885 return Math.pow(2, 10 * (t - 1));
5887 function d3_ease_circle(t) {
5888 return 1 - Math.sqrt(1 - t * t);
5890 function d3_ease_elastic(a, p) {
5891 var s;
5892 if (arguments.length < 2) p = .45;
5893 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
5894 return function(t) {
5895 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
5896 };
5898 function d3_ease_back(s) {
5899 if (!s) s = 1.70158;
5900 return function(t) {
5901 return t * t * ((s + 1) * t - s);
5902 };
5904 function d3_ease_bounce(t) {
5905 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;
5907 d3.interpolateHcl = d3_interpolateHcl;
5908 function d3_interpolateHcl(a, b) {
5909 a = d3.hcl(a);
5910 b = d3.hcl(b);
5911 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
5912 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
5913 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5914 return function(t) {
5915 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
5916 };
5918 d3.interpolateHsl = d3_interpolateHsl;
5919 function d3_interpolateHsl(a, b) {
5920 a = d3.hsl(a);
5921 b = d3.hsl(b);
5922 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
5923 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
5924 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5925 return function(t) {
5926 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
5927 };
5929 d3.interpolateLab = d3_interpolateLab;
5930 function d3_interpolateLab(a, b) {
5931 a = d3.lab(a);
5932 b = d3.lab(b);
5933 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
5934 return function(t) {
5935 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
5936 };
5938 d3.interpolateRound = d3_interpolateRound;
5939 function d3_interpolateRound(a, b) {
5940 b -= a;
5941 return function(t) {
5942 return Math.round(a + b * t);
5943 };
5945 d3.transform = function(string) {
5946 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
5947 return (d3.transform = function(string) {
5948 if (string != null) {
5949 g.setAttribute("transform", string);
5950 var t = g.transform.baseVal.consolidate();
5952 return new d3_transform(t ? t.matrix : d3_transformIdentity);
5953 })(string);
5954 };
5955 function d3_transform(m) {
5956 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;
5957 if (r0[0] * r1[1] < r1[0] * r0[1]) {
5958 r0[0] *= -1;
5959 r0[1] *= -1;
5960 kx *= -1;
5961 kz *= -1;
5963 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
5964 this.translate = [ m.e, m.f ];
5965 this.scale = [ kx, ky ];
5966 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
5968 d3_transform.prototype.toString = function() {
5969 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
5970 };
5971 function d3_transformDot(a, b) {
5972 return a[0] * b[0] + a[1] * b[1];
5974 function d3_transformNormalize(a) {
5975 var k = Math.sqrt(d3_transformDot(a, a));
5976 if (k) {
5977 a[0] /= k;
5978 a[1] /= k;
5980 return k;
5982 function d3_transformCombine(a, b, k) {
5983 a[0] += k * b[0];
5984 a[1] += k * b[1];
5985 return a;
5987 var d3_transformIdentity = {
5988 a: 1,
5989 b: 0,
5990 c: 0,
5991 d: 1,
5992 e: 0,
5993 f: 0
5994 };
5995 d3.interpolateTransform = d3_interpolateTransform;
5996 function d3_interpolateTransformPop(s) {
5997 return s.length ? s.pop() + "," : "";
5999 function d3_interpolateTranslate(ta, tb, s, q) {
6000 if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
6001 var i = s.push("translate(", null, ",", null, ")");
6002 q.push({
6003 i: i - 4,
6004 x: d3_interpolateNumber(ta[0], tb[0])
6005 }, {
6006 i: i - 2,
6007 x: d3_interpolateNumber(ta[1], tb[1])
6008 });
6009 } else if (tb[0] || tb[1]) {
6010 s.push("translate(" + tb + ")");
6013 function d3_interpolateRotate(ra, rb, s, q) {
6014 if (ra !== rb) {
6015 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
6016 q.push({
6017 i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
6018 x: d3_interpolateNumber(ra, rb)
6019 });
6020 } else if (rb) {
6021 s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
6024 function d3_interpolateSkew(wa, wb, s, q) {
6025 if (wa !== wb) {
6026 q.push({
6027 i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
6028 x: d3_interpolateNumber(wa, wb)
6029 });
6030 } else if (wb) {
6031 s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
6034 function d3_interpolateScale(ka, kb, s, q) {
6035 if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
6036 var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
6037 q.push({
6038 i: i - 4,
6039 x: d3_interpolateNumber(ka[0], kb[0])
6040 }, {
6041 i: i - 2,
6042 x: d3_interpolateNumber(ka[1], kb[1])
6043 });
6044 } else if (kb[0] !== 1 || kb[1] !== 1) {
6045 s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
6048 function d3_interpolateTransform(a, b) {
6049 var s = [], q = [];
6050 a = d3.transform(a), b = d3.transform(b);
6051 d3_interpolateTranslate(a.translate, b.translate, s, q);
6052 d3_interpolateRotate(a.rotate, b.rotate, s, q);
6053 d3_interpolateSkew(a.skew, b.skew, s, q);
6054 d3_interpolateScale(a.scale, b.scale, s, q);
6055 a = b = null;
6056 return function(t) {
6057 var i = -1, n = q.length, o;
6058 while (++i < n) s[(o = q[i]).i] = o.x(t);
6059 return s.join("");
6060 };
6062 function d3_uninterpolateNumber(a, b) {
6063 b = (b -= a = +a) || 1 / b;
6064 return function(x) {
6065 return (x - a) / b;
6066 };
6068 function d3_uninterpolateClamp(a, b) {
6069 b = (b -= a = +a) || 1 / b;
6070 return function(x) {
6071 return Math.max(0, Math.min(1, (x - a) / b));
6072 };
6074 d3.layout = {};
6075 d3.layout.bundle = function() {
6076 return function(links) {
6077 var paths = [], i = -1, n = links.length;
6078 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
6079 return paths;
6080 };
6081 };
6082 function d3_layout_bundlePath(link) {
6083 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
6084 while (start !== lca) {
6085 start = start.parent;
6086 points.push(start);
6088 var k = points.length;
6089 while (end !== lca) {
6090 points.splice(k, 0, end);
6091 end = end.parent;
6093 return points;
6095 function d3_layout_bundleAncestors(node) {
6096 var ancestors = [], parent = node.parent;
6097 while (parent != null) {
6098 ancestors.push(node);
6099 node = parent;
6100 parent = parent.parent;
6102 ancestors.push(node);
6103 return ancestors;
6105 function d3_layout_bundleLeastCommonAncestor(a, b) {
6106 if (a === b) return a;
6107 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
6108 while (aNode === bNode) {
6109 sharedNode = aNode;
6110 aNode = aNodes.pop();
6111 bNode = bNodes.pop();
6113 return sharedNode;
6115 d3.layout.chord = function() {
6116 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
6117 function relayout() {
6118 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
6119 chords = [];
6120 groups = [];
6121 k = 0, i = -1;
6122 while (++i < n) {
6123 x = 0, j = -1;
6124 while (++j < n) {
6125 x += matrix[i][j];
6127 groupSums.push(x);
6128 subgroupIndex.push(d3.range(n));
6129 k += x;
6131 if (sortGroups) {
6132 groupIndex.sort(function(a, b) {
6133 return sortGroups(groupSums[a], groupSums[b]);
6134 });
6136 if (sortSubgroups) {
6137 subgroupIndex.forEach(function(d, i) {
6138 d.sort(function(a, b) {
6139 return sortSubgroups(matrix[i][a], matrix[i][b]);
6140 });
6141 });
6143 k = (τ - padding * n) / k;
6144 x = 0, i = -1;
6145 while (++i < n) {
6146 x0 = x, j = -1;
6147 while (++j < n) {
6148 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
6149 subgroups[di + "-" + dj] = {
6150 index: di,
6151 subindex: dj,
6152 startAngle: a0,
6153 endAngle: a1,
6154 value: v
6155 };
6157 groups[di] = {
6158 index: di,
6159 startAngle: x0,
6160 endAngle: x,
6161 value: groupSums[di]
6162 };
6163 x += padding;
6165 i = -1;
6166 while (++i < n) {
6167 j = i - 1;
6168 while (++j < n) {
6169 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
6170 if (source.value || target.value) {
6171 chords.push(source.value < target.value ? {
6172 source: target,
6173 target: source
6174 } : {
6175 source: source,
6176 target: target
6177 });
6181 if (sortChords) resort();
6183 function resort() {
6184 chords.sort(function(a, b) {
6185 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
6186 });
6188 chord.matrix = function(x) {
6189 if (!arguments.length) return matrix;
6190 n = (matrix = x) && matrix.length;
6191 chords = groups = null;
6192 return chord;
6193 };
6194 chord.padding = function(x) {
6195 if (!arguments.length) return padding;
6196 padding = x;
6197 chords = groups = null;
6198 return chord;
6199 };
6200 chord.sortGroups = function(x) {
6201 if (!arguments.length) return sortGroups;
6202 sortGroups = x;
6203 chords = groups = null;
6204 return chord;
6205 };
6206 chord.sortSubgroups = function(x) {
6207 if (!arguments.length) return sortSubgroups;
6208 sortSubgroups = x;
6209 chords = null;
6210 return chord;
6211 };
6212 chord.sortChords = function(x) {
6213 if (!arguments.length) return sortChords;
6214 sortChords = x;
6215 if (chords) resort();
6216 return chord;
6217 };
6218 chord.chords = function() {
6219 if (!chords) relayout();
6220 return chords;
6221 };
6222 chord.groups = function() {
6223 if (!groups) relayout();
6224 return groups;
6225 };
6226 return chord;
6227 };
6228 d3.layout.force = function() {
6229 var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
6230 function repulse(node) {
6231 return function(quad, x1, _, x2) {
6232 if (quad.point !== node) {
6233 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
6234 if (dw * dw / theta2 < dn) {
6235 if (dn < chargeDistance2) {
6236 var k = quad.charge / dn;
6237 node.px -= dx * k;
6238 node.py -= dy * k;
6240 return true;
6242 if (quad.point && dn && dn < chargeDistance2) {
6243 var k = quad.pointCharge / dn;
6244 node.px -= dx * k;
6245 node.py -= dy * k;
6248 return !quad.charge;
6249 };
6251 force.tick = function() {
6252 if ((alpha *= .99) < .005) {
6253 timer = null;
6254 event.end({
6255 type: "end",
6256 alpha: alpha = 0
6257 });
6258 return true;
6260 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
6261 for (i = 0; i < m; ++i) {
6262 o = links[i];
6263 s = o.source;
6264 t = o.target;
6265 x = t.x - s.x;
6266 y = t.y - s.y;
6267 if (l = x * x + y * y) {
6268 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
6269 x *= l;
6270 y *= l;
6271 t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
6272 t.y -= y * k;
6273 s.x += x * (k = 1 - k);
6274 s.y += y * k;
6277 if (k = alpha * gravity) {
6278 x = size[0] / 2;
6279 y = size[1] / 2;
6280 i = -1;
6281 if (k) while (++i < n) {
6282 o = nodes[i];
6283 o.x += (x - o.x) * k;
6284 o.y += (y - o.y) * k;
6287 if (charge) {
6288 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
6289 i = -1;
6290 while (++i < n) {
6291 if (!(o = nodes[i]).fixed) {
6292 q.visit(repulse(o));
6296 i = -1;
6297 while (++i < n) {
6298 o = nodes[i];
6299 if (o.fixed) {
6300 o.x = o.px;
6301 o.y = o.py;
6302 } else {
6303 o.x -= (o.px - (o.px = o.x)) * friction;
6304 o.y -= (o.py - (o.py = o.y)) * friction;
6307 event.tick({
6308 type: "tick",
6309 alpha: alpha
6310 });
6311 };
6312 force.nodes = function(x) {
6313 if (!arguments.length) return nodes;
6314 nodes = x;
6315 return force;
6316 };
6317 force.links = function(x) {
6318 if (!arguments.length) return links;
6319 links = x;
6320 return force;
6321 };
6322 force.size = function(x) {
6323 if (!arguments.length) return size;
6324 size = x;
6325 return force;
6326 };
6327 force.linkDistance = function(x) {
6328 if (!arguments.length) return linkDistance;
6329 linkDistance = typeof x === "function" ? x : +x;
6330 return force;
6331 };
6332 force.distance = force.linkDistance;
6333 force.linkStrength = function(x) {
6334 if (!arguments.length) return linkStrength;
6335 linkStrength = typeof x === "function" ? x : +x;
6336 return force;
6337 };
6338 force.friction = function(x) {
6339 if (!arguments.length) return friction;
6340 friction = +x;
6341 return force;
6342 };
6343 force.charge = function(x) {
6344 if (!arguments.length) return charge;
6345 charge = typeof x === "function" ? x : +x;
6346 return force;
6347 };
6348 force.chargeDistance = function(x) {
6349 if (!arguments.length) return Math.sqrt(chargeDistance2);
6350 chargeDistance2 = x * x;
6351 return force;
6352 };
6353 force.gravity = function(x) {
6354 if (!arguments.length) return gravity;
6355 gravity = +x;
6356 return force;
6357 };
6358 force.theta = function(x) {
6359 if (!arguments.length) return Math.sqrt(theta2);
6360 theta2 = x * x;
6361 return force;
6362 };
6363 force.alpha = function(x) {
6364 if (!arguments.length) return alpha;
6365 x = +x;
6366 if (alpha) {
6367 if (x > 0) {
6368 alpha = x;
6369 } else {
6370 timer.c = null, timer.t = NaN, timer = null;
6371 event.end({
6372 type: "end",
6373 alpha: alpha = 0
6374 });
6376 } else if (x > 0) {
6377 event.start({
6378 type: "start",
6379 alpha: alpha = x
6380 });
6381 timer = d3_timer(force.tick);
6383 return force;
6384 };
6385 force.start = function() {
6386 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6387 for (i = 0; i < n; ++i) {
6388 (o = nodes[i]).index = i;
6389 o.weight = 0;
6391 for (i = 0; i < m; ++i) {
6392 o = links[i];
6393 if (typeof o.source == "number") o.source = nodes[o.source];
6394 if (typeof o.target == "number") o.target = nodes[o.target];
6395 ++o.source.weight;
6396 ++o.target.weight;
6398 for (i = 0; i < n; ++i) {
6399 o = nodes[i];
6400 if (isNaN(o.x)) o.x = position("x", w);
6401 if (isNaN(o.y)) o.y = position("y", h);
6402 if (isNaN(o.px)) o.px = o.x;
6403 if (isNaN(o.py)) o.py = o.y;
6405 distances = [];
6406 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;
6407 strengths = [];
6408 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;
6409 charges = [];
6410 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;
6411 function position(dimension, size) {
6412 if (!neighbors) {
6413 neighbors = new Array(n);
6414 for (j = 0; j < n; ++j) {
6415 neighbors[j] = [];
6417 for (j = 0; j < m; ++j) {
6418 var o = links[j];
6419 neighbors[o.source.index].push(o.target);
6420 neighbors[o.target.index].push(o.source);
6423 var candidates = neighbors[i], j = -1, l = candidates.length, x;
6424 while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
6425 return Math.random() * size;
6427 return force.resume();
6428 };
6429 force.resume = function() {
6430 return force.alpha(.1);
6431 };
6432 force.stop = function() {
6433 return force.alpha(0);
6434 };
6435 force.drag = function() {
6436 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);
6437 if (!arguments.length) return drag;
6438 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
6439 };
6440 function dragmove(d) {
6441 d.px = d3.event.x, d.py = d3.event.y;
6442 force.resume();
6444 return d3.rebind(force, event, "on");
6445 };
6446 function d3_layout_forceDragstart(d) {
6447 d.fixed |= 2;
6449 function d3_layout_forceDragend(d) {
6450 d.fixed &= ~6;
6452 function d3_layout_forceMouseover(d) {
6453 d.fixed |= 4;
6454 d.px = d.x, d.py = d.y;
6456 function d3_layout_forceMouseout(d) {
6457 d.fixed &= ~4;
6459 function d3_layout_forceAccumulate(quad, alpha, charges) {
6460 var cx = 0, cy = 0;
6461 quad.charge = 0;
6462 if (!quad.leaf) {
6463 var nodes = quad.nodes, n = nodes.length, i = -1, c;
6464 while (++i < n) {
6465 c = nodes[i];
6466 if (c == null) continue;
6467 d3_layout_forceAccumulate(c, alpha, charges);
6468 quad.charge += c.charge;
6469 cx += c.charge * c.cx;
6470 cy += c.charge * c.cy;
6473 if (quad.point) {
6474 if (!quad.leaf) {
6475 quad.point.x += Math.random() - .5;
6476 quad.point.y += Math.random() - .5;
6478 var k = alpha * charges[quad.point.index];
6479 quad.charge += quad.pointCharge = k;
6480 cx += k * quad.point.x;
6481 cy += k * quad.point.y;
6483 quad.cx = cx / quad.charge;
6484 quad.cy = cy / quad.charge;
6486 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
6487 d3.layout.hierarchy = function() {
6488 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
6489 function hierarchy(root) {
6490 var stack = [ root ], nodes = [], node;
6491 root.depth = 0;
6492 while ((node = stack.pop()) != null) {
6493 nodes.push(node);
6494 if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
6495 var n, childs, child;
6496 while (--n >= 0) {
6497 stack.push(child = childs[n]);
6498 child.parent = node;
6499 child.depth = node.depth + 1;
6501 if (value) node.value = 0;
6502 node.children = childs;
6503 } else {
6504 if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
6505 delete node.children;
6508 d3_layout_hierarchyVisitAfter(root, function(node) {
6509 var childs, parent;
6510 if (sort && (childs = node.children)) childs.sort(sort);
6511 if (value && (parent = node.parent)) parent.value += node.value;
6512 });
6513 return nodes;
6515 hierarchy.sort = function(x) {
6516 if (!arguments.length) return sort;
6517 sort = x;
6518 return hierarchy;
6519 };
6520 hierarchy.children = function(x) {
6521 if (!arguments.length) return children;
6522 children = x;
6523 return hierarchy;
6524 };
6525 hierarchy.value = function(x) {
6526 if (!arguments.length) return value;
6527 value = x;
6528 return hierarchy;
6529 };
6530 hierarchy.revalue = function(root) {
6531 if (value) {
6532 d3_layout_hierarchyVisitBefore(root, function(node) {
6533 if (node.children) node.value = 0;
6534 });
6535 d3_layout_hierarchyVisitAfter(root, function(node) {
6536 var parent;
6537 if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
6538 if (parent = node.parent) parent.value += node.value;
6539 });
6541 return root;
6542 };
6543 return hierarchy;
6544 };
6545 function d3_layout_hierarchyRebind(object, hierarchy) {
6546 d3.rebind(object, hierarchy, "sort", "children", "value");
6547 object.nodes = object;
6548 object.links = d3_layout_hierarchyLinks;
6549 return object;
6551 function d3_layout_hierarchyVisitBefore(node, callback) {
6552 var nodes = [ node ];
6553 while ((node = nodes.pop()) != null) {
6554 callback(node);
6555 if ((children = node.children) && (n = children.length)) {
6556 var n, children;
6557 while (--n >= 0) nodes.push(children[n]);
6561 function d3_layout_hierarchyVisitAfter(node, callback) {
6562 var nodes = [ node ], nodes2 = [];
6563 while ((node = nodes.pop()) != null) {
6564 nodes2.push(node);
6565 if ((children = node.children) && (n = children.length)) {
6566 var i = -1, n, children;
6567 while (++i < n) nodes.push(children[i]);
6570 while ((node = nodes2.pop()) != null) {
6571 callback(node);
6574 function d3_layout_hierarchyChildren(d) {
6575 return d.children;
6577 function d3_layout_hierarchyValue(d) {
6578 return d.value;
6580 function d3_layout_hierarchySort(a, b) {
6581 return b.value - a.value;
6583 function d3_layout_hierarchyLinks(nodes) {
6584 return d3.merge(nodes.map(function(parent) {
6585 return (parent.children || []).map(function(child) {
6586 return {
6587 source: parent,
6588 target: child
6589 };
6590 });
6591 }));
6593 d3.layout.partition = function() {
6594 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
6595 function position(node, x, dx, dy) {
6596 var children = node.children;
6597 node.x = x;
6598 node.y = node.depth * dy;
6599 node.dx = dx;
6600 node.dy = dy;
6601 if (children && (n = children.length)) {
6602 var i = -1, n, c, d;
6603 dx = node.value ? dx / node.value : 0;
6604 while (++i < n) {
6605 position(c = children[i], x, d = c.value * dx, dy);
6606 x += d;
6610 function depth(node) {
6611 var children = node.children, d = 0;
6612 if (children && (n = children.length)) {
6613 var i = -1, n;
6614 while (++i < n) d = Math.max(d, depth(children[i]));
6616 return 1 + d;
6618 function partition(d, i) {
6619 var nodes = hierarchy.call(this, d, i);
6620 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
6621 return nodes;
6623 partition.size = function(x) {
6624 if (!arguments.length) return size;
6625 size = x;
6626 return partition;
6627 };
6628 return d3_layout_hierarchyRebind(partition, hierarchy);
6629 };
6630 d3.layout.pie = function() {
6631 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
6632 function pie(data) {
6633 var n = data.length, values = data.map(function(d, i) {
6634 return +value.call(pie, d, i);
6635 }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
6636 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
6637 return values[j] - values[i];
6638 } : function(i, j) {
6639 return sort(data[i], data[j]);
6640 });
6641 index.forEach(function(i) {
6642 arcs[i] = {
6643 data: data[i],
6644 value: v = values[i],
6645 startAngle: a,
6646 endAngle: a += v * k + pa,
6647 padAngle: p
6648 };
6649 });
6650 return arcs;
6652 pie.value = function(_) {
6653 if (!arguments.length) return value;
6654 value = _;
6655 return pie;
6656 };
6657 pie.sort = function(_) {
6658 if (!arguments.length) return sort;
6659 sort = _;
6660 return pie;
6661 };
6662 pie.startAngle = function(_) {
6663 if (!arguments.length) return startAngle;
6664 startAngle = _;
6665 return pie;
6666 };
6667 pie.endAngle = function(_) {
6668 if (!arguments.length) return endAngle;
6669 endAngle = _;
6670 return pie;
6671 };
6672 pie.padAngle = function(_) {
6673 if (!arguments.length) return padAngle;
6674 padAngle = _;
6675 return pie;
6676 };
6677 return pie;
6678 };
6679 var d3_layout_pieSortByValue = {};
6680 d3.layout.stack = function() {
6681 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
6682 function stack(data, index) {
6683 if (!(n = data.length)) return data;
6684 var series = data.map(function(d, i) {
6685 return values.call(stack, d, i);
6686 });
6687 var points = series.map(function(d) {
6688 return d.map(function(v, i) {
6689 return [ x.call(stack, v, i), y.call(stack, v, i) ];
6690 });
6691 });
6692 var orders = order.call(stack, points, index);
6693 series = d3.permute(series, orders);
6694 points = d3.permute(points, orders);
6695 var offsets = offset.call(stack, points, index);
6696 var m = series[0].length, n, i, j, o;
6697 for (j = 0; j < m; ++j) {
6698 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
6699 for (i = 1; i < n; ++i) {
6700 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
6703 return data;
6705 stack.values = function(x) {
6706 if (!arguments.length) return values;
6707 values = x;
6708 return stack;
6709 };
6710 stack.order = function(x) {
6711 if (!arguments.length) return order;
6712 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
6713 return stack;
6714 };
6715 stack.offset = function(x) {
6716 if (!arguments.length) return offset;
6717 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
6718 return stack;
6719 };
6720 stack.x = function(z) {
6721 if (!arguments.length) return x;
6722 x = z;
6723 return stack;
6724 };
6725 stack.y = function(z) {
6726 if (!arguments.length) return y;
6727 y = z;
6728 return stack;
6729 };
6730 stack.out = function(z) {
6731 if (!arguments.length) return out;
6732 out = z;
6733 return stack;
6734 };
6735 return stack;
6736 };
6737 function d3_layout_stackX(d) {
6738 return d.x;
6740 function d3_layout_stackY(d) {
6741 return d.y;
6743 function d3_layout_stackOut(d, y0, y) {
6744 d.y0 = y0;
6745 d.y = y;
6747 var d3_layout_stackOrders = d3.map({
6748 "inside-out": function(data) {
6749 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) {
6750 return max[a] - max[b];
6751 }), top = 0, bottom = 0, tops = [], bottoms = [];
6752 for (i = 0; i < n; ++i) {
6753 j = index[i];
6754 if (top < bottom) {
6755 top += sums[j];
6756 tops.push(j);
6757 } else {
6758 bottom += sums[j];
6759 bottoms.push(j);
6762 return bottoms.reverse().concat(tops);
6763 },
6764 reverse: function(data) {
6765 return d3.range(data.length).reverse();
6766 },
6767 "default": d3_layout_stackOrderDefault
6768 });
6769 var d3_layout_stackOffsets = d3.map({
6770 silhouette: function(data) {
6771 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
6772 for (j = 0; j < m; ++j) {
6773 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6774 if (o > max) max = o;
6775 sums.push(o);
6777 for (j = 0; j < m; ++j) {
6778 y0[j] = (max - sums[j]) / 2;
6780 return y0;
6781 },
6782 wiggle: function(data) {
6783 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
6784 y0[0] = o = o0 = 0;
6785 for (j = 1; j < m; ++j) {
6786 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
6787 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
6788 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
6789 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
6791 s2 += s3 * data[i][j][1];
6793 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
6794 if (o < o0) o0 = o;
6796 for (j = 0; j < m; ++j) y0[j] -= o0;
6797 return y0;
6798 },
6799 expand: function(data) {
6800 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
6801 for (j = 0; j < m; ++j) {
6802 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6803 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;
6805 for (j = 0; j < m; ++j) y0[j] = 0;
6806 return y0;
6807 },
6808 zero: d3_layout_stackOffsetZero
6809 });
6810 function d3_layout_stackOrderDefault(data) {
6811 return d3.range(data.length);
6813 function d3_layout_stackOffsetZero(data) {
6814 var j = -1, m = data[0].length, y0 = [];
6815 while (++j < m) y0[j] = 0;
6816 return y0;
6818 function d3_layout_stackMaxIndex(array) {
6819 var i = 1, j = 0, v = array[0][1], k, n = array.length;
6820 for (;i < n; ++i) {
6821 if ((k = array[i][1]) > v) {
6822 j = i;
6823 v = k;
6826 return j;
6828 function d3_layout_stackReduceSum(d) {
6829 return d.reduce(d3_layout_stackSum, 0);
6831 function d3_layout_stackSum(p, d) {
6832 return p + d[1];
6834 d3.layout.histogram = function() {
6835 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
6836 function histogram(data, i) {
6837 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;
6838 while (++i < m) {
6839 bin = bins[i] = [];
6840 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
6841 bin.y = 0;
6843 if (m > 0) {
6844 i = -1;
6845 while (++i < n) {
6846 x = values[i];
6847 if (x >= range[0] && x <= range[1]) {
6848 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
6849 bin.y += k;
6850 bin.push(data[i]);
6854 return bins;
6856 histogram.value = function(x) {
6857 if (!arguments.length) return valuer;
6858 valuer = x;
6859 return histogram;
6860 };
6861 histogram.range = function(x) {
6862 if (!arguments.length) return ranger;
6863 ranger = d3_functor(x);
6864 return histogram;
6865 };
6866 histogram.bins = function(x) {
6867 if (!arguments.length) return binner;
6868 binner = typeof x === "number" ? function(range) {
6869 return d3_layout_histogramBinFixed(range, x);
6870 } : d3_functor(x);
6871 return histogram;
6872 };
6873 histogram.frequency = function(x) {
6874 if (!arguments.length) return frequency;
6875 frequency = !!x;
6876 return histogram;
6877 };
6878 return histogram;
6879 };
6880 function d3_layout_histogramBinSturges(range, values) {
6881 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
6883 function d3_layout_histogramBinFixed(range, n) {
6884 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
6885 while (++x <= n) f[x] = m * x + b;
6886 return f;
6888 function d3_layout_histogramRange(values) {
6889 return [ d3.min(values), d3.max(values) ];
6891 d3.layout.pack = function() {
6892 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6893 function pack(d, i) {
6894 var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
6895 return radius;
6896 };
6897 root.x = root.y = 0;
6898 d3_layout_hierarchyVisitAfter(root, function(d) {
6899 d.r = +r(d.value);
6900 });
6901 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6902 if (padding) {
6903 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6904 d3_layout_hierarchyVisitAfter(root, function(d) {
6905 d.r += dr;
6906 });
6907 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6908 d3_layout_hierarchyVisitAfter(root, function(d) {
6909 d.r -= dr;
6910 });
6912 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6913 return nodes;
6915 pack.size = function(_) {
6916 if (!arguments.length) return size;
6917 size = _;
6918 return pack;
6919 };
6920 pack.radius = function(_) {
6921 if (!arguments.length) return radius;
6922 radius = _ == null || typeof _ === "function" ? _ : +_;
6923 return pack;
6924 };
6925 pack.padding = function(_) {
6926 if (!arguments.length) return padding;
6927 padding = +_;
6928 return pack;
6929 };
6930 return d3_layout_hierarchyRebind(pack, hierarchy);
6931 };
6932 function d3_layout_packSort(a, b) {
6933 return a.value - b.value;
6935 function d3_layout_packInsert(a, b) {
6936 var c = a._pack_next;
6937 a._pack_next = b;
6938 b._pack_prev = a;
6939 b._pack_next = c;
6940 c._pack_prev = b;
6942 function d3_layout_packSplice(a, b) {
6943 a._pack_next = b;
6944 b._pack_prev = a;
6946 function d3_layout_packIntersects(a, b) {
6947 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6948 return .999 * dr * dr > dx * dx + dy * dy;
6950 function d3_layout_packSiblings(node) {
6951 if (!(nodes = node.children) || !(n = nodes.length)) return;
6952 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6953 function bound(node) {
6954 xMin = Math.min(node.x - node.r, xMin);
6955 xMax = Math.max(node.x + node.r, xMax);
6956 yMin = Math.min(node.y - node.r, yMin);
6957 yMax = Math.max(node.y + node.r, yMax);
6959 nodes.forEach(d3_layout_packLink);
6960 a = nodes[0];
6961 a.x = -a.r;
6962 a.y = 0;
6963 bound(a);
6964 if (n > 1) {
6965 b = nodes[1];
6966 b.x = b.r;
6967 b.y = 0;
6968 bound(b);
6969 if (n > 2) {
6970 c = nodes[2];
6971 d3_layout_packPlace(a, b, c);
6972 bound(c);
6973 d3_layout_packInsert(a, c);
6974 a._pack_prev = c;
6975 d3_layout_packInsert(c, b);
6976 b = a._pack_next;
6977 for (i = 3; i < n; i++) {
6978 d3_layout_packPlace(a, b, c = nodes[i]);
6979 var isect = 0, s1 = 1, s2 = 1;
6980 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
6981 if (d3_layout_packIntersects(j, c)) {
6982 isect = 1;
6983 break;
6986 if (isect == 1) {
6987 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
6988 if (d3_layout_packIntersects(k, c)) {
6989 break;
6993 if (isect) {
6994 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
6995 i--;
6996 } else {
6997 d3_layout_packInsert(a, c);
6998 b = c;
6999 bound(c);
7004 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
7005 for (i = 0; i < n; i++) {
7006 c = nodes[i];
7007 c.x -= cx;
7008 c.y -= cy;
7009 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
7011 node.r = cr;
7012 nodes.forEach(d3_layout_packUnlink);
7014 function d3_layout_packLink(node) {
7015 node._pack_next = node._pack_prev = node;
7017 function d3_layout_packUnlink(node) {
7018 delete node._pack_next;
7019 delete node._pack_prev;
7021 function d3_layout_packTransform(node, x, y, k) {
7022 var children = node.children;
7023 node.x = x += k * node.x;
7024 node.y = y += k * node.y;
7025 node.r *= k;
7026 if (children) {
7027 var i = -1, n = children.length;
7028 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
7031 function d3_layout_packPlace(a, b, c) {
7032 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
7033 if (db && (dx || dy)) {
7034 var da = b.r + c.r, dc = dx * dx + dy * dy;
7035 da *= da;
7036 db *= db;
7037 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
7038 c.x = a.x + x * dx + y * dy;
7039 c.y = a.y + x * dy - y * dx;
7040 } else {
7041 c.x = a.x + db;
7042 c.y = a.y;
7045 d3.layout.tree = function() {
7046 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
7047 function tree(d, i) {
7048 var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
7049 d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
7050 d3_layout_hierarchyVisitBefore(root1, secondWalk);
7051 if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
7052 var left = root0, right = root0, bottom = root0;
7053 d3_layout_hierarchyVisitBefore(root0, function(node) {
7054 if (node.x < left.x) left = node;
7055 if (node.x > right.x) right = node;
7056 if (node.depth > bottom.depth) bottom = node;
7057 });
7058 var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
7059 d3_layout_hierarchyVisitBefore(root0, function(node) {
7060 node.x = (node.x + tx) * kx;
7061 node.y = node.depth * ky;
7062 });
7064 return nodes;
7066 function wrapTree(root0) {
7067 var root1 = {
7068 A: null,
7069 children: [ root0 ]
7070 }, queue = [ root1 ], node1;
7071 while ((node1 = queue.pop()) != null) {
7072 for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
7073 queue.push((children[i] = child = {
7074 _: children[i],
7075 parent: node1,
7076 children: (child = children[i].children) && child.slice() || [],
7077 A: null,
7078 a: null,
7079 z: 0,
7080 m: 0,
7081 c: 0,
7082 s: 0,
7083 t: null,
7084 i: i
7085 }).a = child);
7088 return root1.children[0];
7090 function firstWalk(v) {
7091 var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
7092 if (children.length) {
7093 d3_layout_treeShift(v);
7094 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
7095 if (w) {
7096 v.z = w.z + separation(v._, w._);
7097 v.m = v.z - midpoint;
7098 } else {
7099 v.z = midpoint;
7101 } else if (w) {
7102 v.z = w.z + separation(v._, w._);
7104 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
7106 function secondWalk(v) {
7107 v._.x = v.z + v.parent.m;
7108 v.m += v.parent.m;
7110 function apportion(v, w, ancestor) {
7111 if (w) {
7112 var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
7113 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
7114 vom = d3_layout_treeLeft(vom);
7115 vop = d3_layout_treeRight(vop);
7116 vop.a = v;
7117 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
7118 if (shift > 0) {
7119 d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
7120 sip += shift;
7121 sop += shift;
7123 sim += vim.m;
7124 sip += vip.m;
7125 som += vom.m;
7126 sop += vop.m;
7128 if (vim && !d3_layout_treeRight(vop)) {
7129 vop.t = vim;
7130 vop.m += sim - sop;
7132 if (vip && !d3_layout_treeLeft(vom)) {
7133 vom.t = vip;
7134 vom.m += sip - som;
7135 ancestor = v;
7138 return ancestor;
7140 function sizeNode(node) {
7141 node.x *= size[0];
7142 node.y = node.depth * size[1];
7144 tree.separation = function(x) {
7145 if (!arguments.length) return separation;
7146 separation = x;
7147 return tree;
7148 };
7149 tree.size = function(x) {
7150 if (!arguments.length) return nodeSize ? null : size;
7151 nodeSize = (size = x) == null ? sizeNode : null;
7152 return tree;
7153 };
7154 tree.nodeSize = function(x) {
7155 if (!arguments.length) return nodeSize ? size : null;
7156 nodeSize = (size = x) == null ? null : sizeNode;
7157 return tree;
7158 };
7159 return d3_layout_hierarchyRebind(tree, hierarchy);
7160 };
7161 function d3_layout_treeSeparation(a, b) {
7162 return a.parent == b.parent ? 1 : 2;
7164 function d3_layout_treeLeft(v) {
7165 var children = v.children;
7166 return children.length ? children[0] : v.t;
7168 function d3_layout_treeRight(v) {
7169 var children = v.children, n;
7170 return (n = children.length) ? children[n - 1] : v.t;
7172 function d3_layout_treeMove(wm, wp, shift) {
7173 var change = shift / (wp.i - wm.i);
7174 wp.c -= change;
7175 wp.s += shift;
7176 wm.c += change;
7177 wp.z += shift;
7178 wp.m += shift;
7180 function d3_layout_treeShift(v) {
7181 var shift = 0, change = 0, children = v.children, i = children.length, w;
7182 while (--i >= 0) {
7183 w = children[i];
7184 w.z += shift;
7185 w.m += shift;
7186 shift += w.s + (change += w.c);
7189 function d3_layout_treeAncestor(vim, v, ancestor) {
7190 return vim.a.parent === v.parent ? vim.a : ancestor;
7192 d3.layout.cluster = function() {
7193 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
7194 function cluster(d, i) {
7195 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
7196 d3_layout_hierarchyVisitAfter(root, function(node) {
7197 var children = node.children;
7198 if (children && children.length) {
7199 node.x = d3_layout_clusterX(children);
7200 node.y = d3_layout_clusterY(children);
7201 } else {
7202 node.x = previousNode ? x += separation(node, previousNode) : 0;
7203 node.y = 0;
7204 previousNode = node;
7206 });
7207 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;
7208 d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
7209 node.x = (node.x - root.x) * size[0];
7210 node.y = (root.y - node.y) * size[1];
7211 } : function(node) {
7212 node.x = (node.x - x0) / (x1 - x0) * size[0];
7213 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
7214 });
7215 return nodes;
7217 cluster.separation = function(x) {
7218 if (!arguments.length) return separation;
7219 separation = x;
7220 return cluster;
7221 };
7222 cluster.size = function(x) {
7223 if (!arguments.length) return nodeSize ? null : size;
7224 nodeSize = (size = x) == null;
7225 return cluster;
7226 };
7227 cluster.nodeSize = function(x) {
7228 if (!arguments.length) return nodeSize ? size : null;
7229 nodeSize = (size = x) != null;
7230 return cluster;
7231 };
7232 return d3_layout_hierarchyRebind(cluster, hierarchy);
7233 };
7234 function d3_layout_clusterY(children) {
7235 return 1 + d3.max(children, function(child) {
7236 return child.y;
7237 });
7239 function d3_layout_clusterX(children) {
7240 return children.reduce(function(x, child) {
7241 return x + child.x;
7242 }, 0) / children.length;
7244 function d3_layout_clusterLeft(node) {
7245 var children = node.children;
7246 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
7248 function d3_layout_clusterRight(node) {
7249 var children = node.children, n;
7250 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
7252 d3.layout.treemap = function() {
7253 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));
7254 function scale(children, k) {
7255 var i = -1, n = children.length, child, area;
7256 while (++i < n) {
7257 area = (child = children[i]).value * (k < 0 ? 0 : k);
7258 child.area = isNaN(area) || area <= 0 ? 0 : area;
7261 function squarify(node) {
7262 var children = node.children;
7263 if (children && children.length) {
7264 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;
7265 scale(remaining, rect.dx * rect.dy / node.value);
7266 row.area = 0;
7267 while ((n = remaining.length) > 0) {
7268 row.push(child = remaining[n - 1]);
7269 row.area += child.area;
7270 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
7271 remaining.pop();
7272 best = score;
7273 } else {
7274 row.area -= row.pop().area;
7275 position(row, u, rect, false);
7276 u = Math.min(rect.dx, rect.dy);
7277 row.length = row.area = 0;
7278 best = Infinity;
7281 if (row.length) {
7282 position(row, u, rect, true);
7283 row.length = row.area = 0;
7285 children.forEach(squarify);
7288 function stickify(node) {
7289 var children = node.children;
7290 if (children && children.length) {
7291 var rect = pad(node), remaining = children.slice(), child, row = [];
7292 scale(remaining, rect.dx * rect.dy / node.value);
7293 row.area = 0;
7294 while (child = remaining.pop()) {
7295 row.push(child);
7296 row.area += child.area;
7297 if (child.z != null) {
7298 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
7299 row.length = row.area = 0;
7302 children.forEach(stickify);
7305 function worst(row, u) {
7306 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
7307 while (++i < n) {
7308 if (!(r = row[i].area)) continue;
7309 if (r < rmin) rmin = r;
7310 if (r > rmax) rmax = r;
7312 s *= s;
7313 u *= u;
7314 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
7316 function position(row, u, rect, flush) {
7317 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
7318 if (u == rect.dx) {
7319 if (flush || v > rect.dy) v = rect.dy;
7320 while (++i < n) {
7321 o = row[i];
7322 o.x = x;
7323 o.y = y;
7324 o.dy = v;
7325 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
7327 o.z = true;
7328 o.dx += rect.x + rect.dx - x;
7329 rect.y += v;
7330 rect.dy -= v;
7331 } else {
7332 if (flush || v > rect.dx) v = rect.dx;
7333 while (++i < n) {
7334 o = row[i];
7335 o.x = x;
7336 o.y = y;
7337 o.dx = v;
7338 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
7340 o.z = false;
7341 o.dy += rect.y + rect.dy - y;
7342 rect.x += v;
7343 rect.dx -= v;
7346 function treemap(d) {
7347 var nodes = stickies || hierarchy(d), root = nodes[0];
7348 root.x = root.y = 0;
7349 if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
7350 if (stickies) hierarchy.revalue(root);
7351 scale([ root ], root.dx * root.dy / root.value);
7352 (stickies ? stickify : squarify)(root);
7353 if (sticky) stickies = nodes;
7354 return nodes;
7356 treemap.size = function(x) {
7357 if (!arguments.length) return size;
7358 size = x;
7359 return treemap;
7360 };
7361 treemap.padding = function(x) {
7362 if (!arguments.length) return padding;
7363 function padFunction(node) {
7364 var p = x.call(treemap, node, node.depth);
7365 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
7367 function padConstant(node) {
7368 return d3_layout_treemapPad(node, x);
7370 var type;
7371 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
7372 padConstant) : padConstant;
7373 return treemap;
7374 };
7375 treemap.round = function(x) {
7376 if (!arguments.length) return round != Number;
7377 round = x ? Math.round : Number;
7378 return treemap;
7379 };
7380 treemap.sticky = function(x) {
7381 if (!arguments.length) return sticky;
7382 sticky = x;
7383 stickies = null;
7384 return treemap;
7385 };
7386 treemap.ratio = function(x) {
7387 if (!arguments.length) return ratio;
7388 ratio = x;
7389 return treemap;
7390 };
7391 treemap.mode = function(x) {
7392 if (!arguments.length) return mode;
7393 mode = x + "";
7394 return treemap;
7395 };
7396 return d3_layout_hierarchyRebind(treemap, hierarchy);
7397 };
7398 function d3_layout_treemapPadNull(node) {
7399 return {
7400 x: node.x,
7401 y: node.y,
7402 dx: node.dx,
7403 dy: node.dy
7404 };
7406 function d3_layout_treemapPad(node, padding) {
7407 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];
7408 if (dx < 0) {
7409 x += dx / 2;
7410 dx = 0;
7412 if (dy < 0) {
7413 y += dy / 2;
7414 dy = 0;
7416 return {
7417 x: x,
7418 y: y,
7419 dx: dx,
7420 dy: dy
7421 };
7423 d3.random = {
7424 normal: function(µ, σ) {
7425 var n = arguments.length;
7426 if (n < 2) σ = 1;
7427 if (n < 1) µ = 0;
7428 return function() {
7429 var x, y, r;
7430 do {
7431 x = Math.random() * 2 - 1;
7432 y = Math.random() * 2 - 1;
7433 r = x * x + y * y;
7434 } while (!r || r > 1);
7435 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
7436 };
7437 },
7438 logNormal: function() {
7439 var random = d3.random.normal.apply(d3, arguments);
7440 return function() {
7441 return Math.exp(random());
7442 };
7443 },
7444 bates: function(m) {
7445 var random = d3.random.irwinHall(m);
7446 return function() {
7447 return random() / m;
7448 };
7449 },
7450 irwinHall: function(m) {
7451 return function() {
7452 for (var s = 0, j = 0; j < m; j++) s += Math.random();
7453 return s;
7454 };
7456 };
7457 d3.scale = {};
7458 function d3_scaleExtent(domain) {
7459 var start = domain[0], stop = domain[domain.length - 1];
7460 return start < stop ? [ start, stop ] : [ stop, start ];
7462 function d3_scaleRange(scale) {
7463 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
7465 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
7466 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
7467 return function(x) {
7468 return i(u(x));
7469 };
7471 function d3_scale_nice(domain, nice) {
7472 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
7473 if (x1 < x0) {
7474 dx = i0, i0 = i1, i1 = dx;
7475 dx = x0, x0 = x1, x1 = dx;
7477 domain[i0] = nice.floor(x0);
7478 domain[i1] = nice.ceil(x1);
7479 return domain;
7481 function d3_scale_niceStep(step) {
7482 return step ? {
7483 floor: function(x) {
7484 return Math.floor(x / step) * step;
7485 },
7486 ceil: function(x) {
7487 return Math.ceil(x / step) * step;
7489 } : d3_scale_niceIdentity;
7491 var d3_scale_niceIdentity = {
7492 floor: d3_identity,
7493 ceil: d3_identity
7494 };
7495 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
7496 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
7497 if (domain[k] < domain[0]) {
7498 domain = domain.slice().reverse();
7499 range = range.slice().reverse();
7501 while (++j <= k) {
7502 u.push(uninterpolate(domain[j - 1], domain[j]));
7503 i.push(interpolate(range[j - 1], range[j]));
7505 return function(x) {
7506 var j = d3.bisect(domain, x, 1, k) - 1;
7507 return i[j](u[j](x));
7508 };
7510 d3.scale.linear = function() {
7511 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
7512 };
7513 function d3_scale_linear(domain, range, interpolate, clamp) {
7514 var output, input;
7515 function rescale() {
7516 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
7517 output = linear(domain, range, uninterpolate, interpolate);
7518 input = linear(range, domain, uninterpolate, d3_interpolate);
7519 return scale;
7521 function scale(x) {
7522 return output(x);
7524 scale.invert = function(y) {
7525 return input(y);
7526 };
7527 scale.domain = function(x) {
7528 if (!arguments.length) return domain;
7529 domain = x.map(Number);
7530 return rescale();
7531 };
7532 scale.range = function(x) {
7533 if (!arguments.length) return range;
7534 range = x;
7535 return rescale();
7536 };
7537 scale.rangeRound = function(x) {
7538 return scale.range(x).interpolate(d3_interpolateRound);
7539 };
7540 scale.clamp = function(x) {
7541 if (!arguments.length) return clamp;
7542 clamp = x;
7543 return rescale();
7544 };
7545 scale.interpolate = function(x) {
7546 if (!arguments.length) return interpolate;
7547 interpolate = x;
7548 return rescale();
7549 };
7550 scale.ticks = function(m) {
7551 return d3_scale_linearTicks(domain, m);
7552 };
7553 scale.tickFormat = function(m, format) {
7554 return d3_scale_linearTickFormat(domain, m, format);
7555 };
7556 scale.nice = function(m) {
7557 d3_scale_linearNice(domain, m);
7558 return rescale();
7559 };
7560 scale.copy = function() {
7561 return d3_scale_linear(domain, range, interpolate, clamp);
7562 };
7563 return rescale();
7565 function d3_scale_linearRebind(scale, linear) {
7566 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7568 function d3_scale_linearNice(domain, m) {
7569 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7570 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7571 return domain;
7573 function d3_scale_linearTickRange(domain, m) {
7574 if (m == null) m = 10;
7575 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;
7576 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
7577 extent[0] = Math.ceil(extent[0] / step) * step;
7578 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
7579 extent[2] = step;
7580 return extent;
7582 function d3_scale_linearTicks(domain, m) {
7583 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
7585 function d3_scale_linearTickFormat(domain, m, format) {
7586 var range = d3_scale_linearTickRange(domain, m);
7587 if (format) {
7588 var match = d3_format_re.exec(format);
7589 match.shift();
7590 if (match[8] === "s") {
7591 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
7592 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
7593 match[8] = "f";
7594 format = d3.format(match.join(""));
7595 return function(d) {
7596 return format(prefix.scale(d)) + prefix.symbol;
7597 };
7599 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
7600 format = match.join("");
7601 } else {
7602 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
7604 return d3.format(format);
7606 var d3_scale_linearFormatSignificant = {
7607 s: 1,
7608 g: 1,
7609 p: 1,
7610 r: 1,
7611 e: 1
7612 };
7613 function d3_scale_linearPrecision(value) {
7614 return -Math.floor(Math.log(value) / Math.LN10 + .01);
7616 function d3_scale_linearFormatPrecision(type, range) {
7617 var p = d3_scale_linearPrecision(range[2]);
7618 return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
7620 d3.scale.log = function() {
7621 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
7622 };
7623 function d3_scale_log(linear, base, positive, domain) {
7624 function log(x) {
7625 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
7627 function pow(x) {
7628 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
7630 function scale(x) {
7631 return linear(log(x));
7633 scale.invert = function(x) {
7634 return pow(linear.invert(x));
7635 };
7636 scale.domain = function(x) {
7637 if (!arguments.length) return domain;
7638 positive = x[0] >= 0;
7639 linear.domain((domain = x.map(Number)).map(log));
7640 return scale;
7641 };
7642 scale.base = function(_) {
7643 if (!arguments.length) return base;
7644 base = +_;
7645 linear.domain(domain.map(log));
7646 return scale;
7647 };
7648 scale.nice = function() {
7649 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
7650 linear.domain(niced);
7651 domain = niced.map(pow);
7652 return scale;
7653 };
7654 scale.ticks = function() {
7655 var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
7656 if (isFinite(j - i)) {
7657 if (positive) {
7658 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
7659 ticks.push(pow(i));
7660 } else {
7661 ticks.push(pow(i));
7662 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
7664 for (i = 0; ticks[i] < u; i++) {}
7665 for (j = ticks.length; ticks[j - 1] > v; j--) {}
7666 ticks = ticks.slice(i, j);
7668 return ticks;
7669 };
7670 scale.tickFormat = function(n, format) {
7671 if (!arguments.length) return d3_scale_logFormat;
7672 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
7673 var k = Math.max(1, base * n / scale.ticks().length);
7674 return function(d) {
7675 var i = d / pow(Math.round(log(d)));
7676 if (i * base < base - .5) i *= base;
7677 return i <= k ? format(d) : "";
7678 };
7679 };
7680 scale.copy = function() {
7681 return d3_scale_log(linear.copy(), base, positive, domain);
7682 };
7683 return d3_scale_linearRebind(scale, linear);
7685 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
7686 floor: function(x) {
7687 return -Math.ceil(-x);
7688 },
7689 ceil: function(x) {
7690 return -Math.floor(-x);
7692 };
7693 d3.scale.pow = function() {
7694 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
7695 };
7696 function d3_scale_pow(linear, exponent, domain) {
7697 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
7698 function scale(x) {
7699 return linear(powp(x));
7701 scale.invert = function(x) {
7702 return powb(linear.invert(x));
7703 };
7704 scale.domain = function(x) {
7705 if (!arguments.length) return domain;
7706 linear.domain((domain = x.map(Number)).map(powp));
7707 return scale;
7708 };
7709 scale.ticks = function(m) {
7710 return d3_scale_linearTicks(domain, m);
7711 };
7712 scale.tickFormat = function(m, format) {
7713 return d3_scale_linearTickFormat(domain, m, format);
7714 };
7715 scale.nice = function(m) {
7716 return scale.domain(d3_scale_linearNice(domain, m));
7717 };
7718 scale.exponent = function(x) {
7719 if (!arguments.length) return exponent;
7720 powp = d3_scale_powPow(exponent = x);
7721 powb = d3_scale_powPow(1 / exponent);
7722 linear.domain(domain.map(powp));
7723 return scale;
7724 };
7725 scale.copy = function() {
7726 return d3_scale_pow(linear.copy(), exponent, domain);
7727 };
7728 return d3_scale_linearRebind(scale, linear);
7730 function d3_scale_powPow(e) {
7731 return function(x) {
7732 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
7733 };
7735 d3.scale.sqrt = function() {
7736 return d3.scale.pow().exponent(.5);
7737 };
7738 d3.scale.ordinal = function() {
7739 return d3_scale_ordinal([], {
7740 t: "range",
7741 a: [ [] ]
7742 });
7743 };
7744 function d3_scale_ordinal(domain, ranger) {
7745 var index, range, rangeBand;
7746 function scale(x) {
7747 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
7749 function steps(start, step) {
7750 return d3.range(domain.length).map(function(i) {
7751 return start + step * i;
7752 });
7754 scale.domain = function(x) {
7755 if (!arguments.length) return domain;
7756 domain = [];
7757 index = new d3_Map();
7758 var i = -1, n = x.length, xi;
7759 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
7760 return scale[ranger.t].apply(scale, ranger.a);
7761 };
7762 scale.range = function(x) {
7763 if (!arguments.length) return range;
7764 range = x;
7765 rangeBand = 0;
7766 ranger = {
7767 t: "range",
7768 a: arguments
7769 };
7770 return scale;
7771 };
7772 scale.rangePoints = function(x, padding) {
7773 if (arguments.length < 2) padding = 0;
7774 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
7775 0) : (stop - start) / (domain.length - 1 + padding);
7776 range = steps(start + step * padding / 2, step);
7777 rangeBand = 0;
7778 ranger = {
7779 t: "rangePoints",
7780 a: arguments
7781 };
7782 return scale;
7783 };
7784 scale.rangeRoundPoints = function(x, padding) {
7785 if (arguments.length < 2) padding = 0;
7786 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
7787 0) : (stop - start) / (domain.length - 1 + padding) | 0;
7788 range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
7789 rangeBand = 0;
7790 ranger = {
7791 t: "rangeRoundPoints",
7792 a: arguments
7793 };
7794 return scale;
7795 };
7796 scale.rangeBands = function(x, padding, outerPadding) {
7797 if (arguments.length < 2) padding = 0;
7798 if (arguments.length < 3) outerPadding = padding;
7799 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
7800 range = steps(start + step * outerPadding, step);
7801 if (reverse) range.reverse();
7802 rangeBand = step * (1 - padding);
7803 ranger = {
7804 t: "rangeBands",
7805 a: arguments
7806 };
7807 return scale;
7808 };
7809 scale.rangeRoundBands = function(x, padding, outerPadding) {
7810 if (arguments.length < 2) padding = 0;
7811 if (arguments.length < 3) outerPadding = padding;
7812 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
7813 range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
7814 if (reverse) range.reverse();
7815 rangeBand = Math.round(step * (1 - padding));
7816 ranger = {
7817 t: "rangeRoundBands",
7818 a: arguments
7819 };
7820 return scale;
7821 };
7822 scale.rangeBand = function() {
7823 return rangeBand;
7824 };
7825 scale.rangeExtent = function() {
7826 return d3_scaleExtent(ranger.a[0]);
7827 };
7828 scale.copy = function() {
7829 return d3_scale_ordinal(domain, ranger);
7830 };
7831 return scale.domain(domain);
7833 d3.scale.category10 = function() {
7834 return d3.scale.ordinal().range(d3_category10);
7835 };
7836 d3.scale.category20 = function() {
7837 return d3.scale.ordinal().range(d3_category20);
7838 };
7839 d3.scale.category20b = function() {
7840 return d3.scale.ordinal().range(d3_category20b);
7841 };
7842 d3.scale.category20c = function() {
7843 return d3.scale.ordinal().range(d3_category20c);
7844 };
7845 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
7846 var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
7847 var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
7848 var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
7849 d3.scale.quantile = function() {
7850 return d3_scale_quantile([], []);
7851 };
7852 function d3_scale_quantile(domain, range) {
7853 var thresholds;
7854 function rescale() {
7855 var k = 0, q = range.length;
7856 thresholds = [];
7857 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
7858 return scale;
7860 function scale(x) {
7861 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
7863 scale.domain = function(x) {
7864 if (!arguments.length) return domain;
7865 domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
7866 return rescale();
7867 };
7868 scale.range = function(x) {
7869 if (!arguments.length) return range;
7870 range = x;
7871 return rescale();
7872 };
7873 scale.quantiles = function() {
7874 return thresholds;
7875 };
7876 scale.invertExtent = function(y) {
7877 y = range.indexOf(y);
7878 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
7879 };
7880 scale.copy = function() {
7881 return d3_scale_quantile(domain, range);
7882 };
7883 return rescale();
7885 d3.scale.quantize = function() {
7886 return d3_scale_quantize(0, 1, [ 0, 1 ]);
7887 };
7888 function d3_scale_quantize(x0, x1, range) {
7889 var kx, i;
7890 function scale(x) {
7891 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7893 function rescale() {
7894 kx = range.length / (x1 - x0);
7895 i = range.length - 1;
7896 return scale;
7898 scale.domain = function(x) {
7899 if (!arguments.length) return [ x0, x1 ];
7900 x0 = +x[0];
7901 x1 = +x[x.length - 1];
7902 return rescale();
7903 };
7904 scale.range = function(x) {
7905 if (!arguments.length) return range;
7906 range = x;
7907 return rescale();
7908 };
7909 scale.invertExtent = function(y) {
7910 y = range.indexOf(y);
7911 y = y < 0 ? NaN : y / kx + x0;
7912 return [ y, y + 1 / kx ];
7913 };
7914 scale.copy = function() {
7915 return d3_scale_quantize(x0, x1, range);
7916 };
7917 return rescale();
7919 d3.scale.threshold = function() {
7920 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7921 };
7922 function d3_scale_threshold(domain, range) {
7923 function scale(x) {
7924 if (x <= x) return range[d3.bisect(domain, x)];
7926 scale.domain = function(_) {
7927 if (!arguments.length) return domain;
7928 domain = _;
7929 return scale;
7930 };
7931 scale.range = function(_) {
7932 if (!arguments.length) return range;
7933 range = _;
7934 return scale;
7935 };
7936 scale.invertExtent = function(y) {
7937 y = range.indexOf(y);
7938 return [ domain[y - 1], domain[y] ];
7939 };
7940 scale.copy = function() {
7941 return d3_scale_threshold(domain, range);
7942 };
7943 return scale;
7945 d3.scale.identity = function() {
7946 return d3_scale_identity([ 0, 1 ]);
7947 };
7948 function d3_scale_identity(domain) {
7949 function identity(x) {
7950 return +x;
7952 identity.invert = identity;
7953 identity.domain = identity.range = function(x) {
7954 if (!arguments.length) return domain;
7955 domain = x.map(identity);
7956 return identity;
7957 };
7958 identity.ticks = function(m) {
7959 return d3_scale_linearTicks(domain, m);
7960 };
7961 identity.tickFormat = function(m, format) {
7962 return d3_scale_linearTickFormat(domain, m, format);
7963 };
7964 identity.copy = function() {
7965 return d3_scale_identity(domain);
7966 };
7967 return identity;
7969 d3.svg = {};
7970 function d3_zero() {
7971 return 0;
7973 d3.svg.arc = function() {
7974 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
7975 function arc() {
7976 var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
7977 if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
7978 if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
7979 var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
7980 if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
7981 rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
7982 if (!cw) p1 *= -1;
7983 if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
7984 if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
7986 if (r1) {
7987 x0 = r1 * Math.cos(a0 + p1);
7988 y0 = r1 * Math.sin(a0 + p1);
7989 x1 = r1 * Math.cos(a1 - p1);
7990 y1 = r1 * Math.sin(a1 - p1);
7991 var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
7992 if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
7993 var h1 = (a0 + a1) / 2;
7994 x0 = r1 * Math.cos(h1);
7995 y0 = r1 * Math.sin(h1);
7996 x1 = y1 = null;
7998 } else {
7999 x0 = y0 = 0;
8001 if (r0) {
8002 x2 = r0 * Math.cos(a1 - p0);
8003 y2 = r0 * Math.sin(a1 - p0);
8004 x3 = r0 * Math.cos(a0 + p0);
8005 y3 = r0 * Math.sin(a0 + p0);
8006 var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
8007 if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
8008 var h0 = (a0 + a1) / 2;
8009 x2 = r0 * Math.cos(h0);
8010 y2 = r0 * Math.sin(h0);
8011 x3 = y3 = null;
8013 } else {
8014 x2 = y2 = 0;
8016 if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
8017 cr = r0 < r1 ^ cw ? 0 : 1;
8018 var rc1 = rc, rc0 = rc;
8019 if (da < π) {
8020 var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
8021 rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
8022 rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
8024 if (x1 != null) {
8025 var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
8026 if (rc === rc1) {
8027 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
8028 } else {
8029 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
8031 } else {
8032 path.push("M", x0, ",", y0);
8034 if (x3 != null) {
8035 var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
8036 if (rc === rc0) {
8037 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8038 } else {
8039 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8041 } else {
8042 path.push("L", x2, ",", y2);
8044 } else {
8045 path.push("M", x0, ",", y0);
8046 if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
8047 path.push("L", x2, ",", y2);
8048 if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
8050 path.push("Z");
8051 return path.join("");
8053 function circleSegment(r1, cw) {
8054 return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
8056 arc.innerRadius = function(v) {
8057 if (!arguments.length) return innerRadius;
8058 innerRadius = d3_functor(v);
8059 return arc;
8060 };
8061 arc.outerRadius = function(v) {
8062 if (!arguments.length) return outerRadius;
8063 outerRadius = d3_functor(v);
8064 return arc;
8065 };
8066 arc.cornerRadius = function(v) {
8067 if (!arguments.length) return cornerRadius;
8068 cornerRadius = d3_functor(v);
8069 return arc;
8070 };
8071 arc.padRadius = function(v) {
8072 if (!arguments.length) return padRadius;
8073 padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
8074 return arc;
8075 };
8076 arc.startAngle = function(v) {
8077 if (!arguments.length) return startAngle;
8078 startAngle = d3_functor(v);
8079 return arc;
8080 };
8081 arc.endAngle = function(v) {
8082 if (!arguments.length) return endAngle;
8083 endAngle = d3_functor(v);
8084 return arc;
8085 };
8086 arc.padAngle = function(v) {
8087 if (!arguments.length) return padAngle;
8088 padAngle = d3_functor(v);
8089 return arc;
8090 };
8091 arc.centroid = function() {
8092 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
8093 return [ Math.cos(a) * r, Math.sin(a) * r ];
8094 };
8095 return arc;
8096 };
8097 var d3_svg_arcAuto = "auto";
8098 function d3_svg_arcInnerRadius(d) {
8099 return d.innerRadius;
8101 function d3_svg_arcOuterRadius(d) {
8102 return d.outerRadius;
8104 function d3_svg_arcStartAngle(d) {
8105 return d.startAngle;
8107 function d3_svg_arcEndAngle(d) {
8108 return d.endAngle;
8110 function d3_svg_arcPadAngle(d) {
8111 return d && d.padAngle;
8113 function d3_svg_arcSweep(x0, y0, x1, y1) {
8114 return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
8116 function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
8117 var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
8118 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
8119 return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
8121 function d3_svg_line(projection) {
8122 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
8123 function line(data) {
8124 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
8125 function segment() {
8126 segments.push("M", interpolate(projection(points), tension));
8128 while (++i < n) {
8129 if (defined.call(this, d = data[i], i)) {
8130 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
8131 } else if (points.length) {
8132 segment();
8133 points = [];
8136 if (points.length) segment();
8137 return segments.length ? segments.join("") : null;
8139 line.x = function(_) {
8140 if (!arguments.length) return x;
8141 x = _;
8142 return line;
8143 };
8144 line.y = function(_) {
8145 if (!arguments.length) return y;
8146 y = _;
8147 return line;
8148 };
8149 line.defined = function(_) {
8150 if (!arguments.length) return defined;
8151 defined = _;
8152 return line;
8153 };
8154 line.interpolate = function(_) {
8155 if (!arguments.length) return interpolateKey;
8156 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8157 return line;
8158 };
8159 line.tension = function(_) {
8160 if (!arguments.length) return tension;
8161 tension = _;
8162 return line;
8163 };
8164 return line;
8166 d3.svg.line = function() {
8167 return d3_svg_line(d3_identity);
8168 };
8169 var d3_svg_lineInterpolators = d3.map({
8170 linear: d3_svg_lineLinear,
8171 "linear-closed": d3_svg_lineLinearClosed,
8172 step: d3_svg_lineStep,
8173 "step-before": d3_svg_lineStepBefore,
8174 "step-after": d3_svg_lineStepAfter,
8175 basis: d3_svg_lineBasis,
8176 "basis-open": d3_svg_lineBasisOpen,
8177 "basis-closed": d3_svg_lineBasisClosed,
8178 bundle: d3_svg_lineBundle,
8179 cardinal: d3_svg_lineCardinal,
8180 "cardinal-open": d3_svg_lineCardinalOpen,
8181 "cardinal-closed": d3_svg_lineCardinalClosed,
8182 monotone: d3_svg_lineMonotone
8183 });
8184 d3_svg_lineInterpolators.forEach(function(key, value) {
8185 value.key = key;
8186 value.closed = /-closed$/.test(key);
8187 });
8188 function d3_svg_lineLinear(points) {
8189 return points.length > 1 ? points.join("L") : points + "Z";
8191 function d3_svg_lineLinearClosed(points) {
8192 return points.join("L") + "Z";
8194 function d3_svg_lineStep(points) {
8195 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8196 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
8197 if (n > 1) path.push("H", p[0]);
8198 return path.join("");
8200 function d3_svg_lineStepBefore(points) {
8201 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8202 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
8203 return path.join("");
8205 function d3_svg_lineStepAfter(points) {
8206 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8207 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
8208 return path.join("");
8210 function d3_svg_lineCardinalOpen(points, tension) {
8211 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
8213 function d3_svg_lineCardinalClosed(points, tension) {
8214 return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
8215 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
8217 function d3_svg_lineCardinal(points, tension) {
8218 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
8220 function d3_svg_lineHermite(points, tangents) {
8221 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
8222 return d3_svg_lineLinear(points);
8224 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
8225 if (quad) {
8226 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
8227 p0 = points[1];
8228 pi = 2;
8230 if (tangents.length > 1) {
8231 t = tangents[1];
8232 p = points[pi];
8233 pi++;
8234 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8235 for (var i = 2; i < tangents.length; i++, pi++) {
8236 p = points[pi];
8237 t = tangents[i];
8238 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8241 if (quad) {
8242 var lp = points[pi];
8243 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
8245 return path;
8247 function d3_svg_lineCardinalTangents(points, tension) {
8248 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
8249 while (++i < n) {
8250 p0 = p1;
8251 p1 = p2;
8252 p2 = points[i];
8253 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
8255 return tangents;
8257 function d3_svg_lineBasis(points) {
8258 if (points.length < 3) return d3_svg_lineLinear(points);
8259 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, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8260 points.push(points[n - 1]);
8261 while (++i <= n) {
8262 pi = points[i];
8263 px.shift();
8264 px.push(pi[0]);
8265 py.shift();
8266 py.push(pi[1]);
8267 d3_svg_lineBasisBezier(path, px, py);
8269 points.pop();
8270 path.push("L", pi);
8271 return path.join("");
8273 function d3_svg_lineBasisOpen(points) {
8274 if (points.length < 4) return d3_svg_lineLinear(points);
8275 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
8276 while (++i < 3) {
8277 pi = points[i];
8278 px.push(pi[0]);
8279 py.push(pi[1]);
8281 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
8282 --i;
8283 while (++i < n) {
8284 pi = points[i];
8285 px.shift();
8286 px.push(pi[0]);
8287 py.shift();
8288 py.push(pi[1]);
8289 d3_svg_lineBasisBezier(path, px, py);
8291 return path.join("");
8293 function d3_svg_lineBasisClosed(points) {
8294 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
8295 while (++i < 4) {
8296 pi = points[i % n];
8297 px.push(pi[0]);
8298 py.push(pi[1]);
8300 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8301 --i;
8302 while (++i < m) {
8303 pi = points[i % n];
8304 px.shift();
8305 px.push(pi[0]);
8306 py.shift();
8307 py.push(pi[1]);
8308 d3_svg_lineBasisBezier(path, px, py);
8310 return path.join("");
8312 function d3_svg_lineBundle(points, tension) {
8313 var n = points.length - 1;
8314 if (n) {
8315 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
8316 while (++i <= n) {
8317 p = points[i];
8318 t = i / n;
8319 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
8320 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
8323 return d3_svg_lineBasis(points);
8325 function d3_svg_lineDot4(a, b) {
8326 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
8328 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 ];
8329 function d3_svg_lineBasisBezier(path, x, y) {
8330 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));
8332 function d3_svg_lineSlope(p0, p1) {
8333 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
8335 function d3_svg_lineFiniteDifferences(points) {
8336 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
8337 while (++i < j) {
8338 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
8340 m[i] = d;
8341 return m;
8343 function d3_svg_lineMonotoneTangents(points) {
8344 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
8345 while (++i < j) {
8346 d = d3_svg_lineSlope(points[i], points[i + 1]);
8347 if (abs(d) < ε) {
8348 m[i] = m[i + 1] = 0;
8349 } else {
8350 a = m[i] / d;
8351 b = m[i + 1] / d;
8352 s = a * a + b * b;
8353 if (s > 9) {
8354 s = d * 3 / Math.sqrt(s);
8355 m[i] = s * a;
8356 m[i + 1] = s * b;
8360 i = -1;
8361 while (++i <= j) {
8362 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
8363 tangents.push([ s || 0, m[i] * s || 0 ]);
8365 return tangents;
8367 function d3_svg_lineMonotone(points) {
8368 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
8370 d3.svg.line.radial = function() {
8371 var line = d3_svg_line(d3_svg_lineRadial);
8372 line.radius = line.x, delete line.x;
8373 line.angle = line.y, delete line.y;
8374 return line;
8375 };
8376 function d3_svg_lineRadial(points) {
8377 var point, i = -1, n = points.length, r, a;
8378 while (++i < n) {
8379 point = points[i];
8380 r = point[0];
8381 a = point[1] - halfπ;
8382 point[0] = r * Math.cos(a);
8383 point[1] = r * Math.sin(a);
8385 return points;
8387 function d3_svg_area(projection) {
8388 var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
8389 function area(data) {
8390 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
8391 return x;
8392 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
8393 return y;
8394 } : d3_functor(y1), x, y;
8395 function segment() {
8396 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
8398 while (++i < n) {
8399 if (defined.call(this, d = data[i], i)) {
8400 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
8401 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
8402 } else if (points0.length) {
8403 segment();
8404 points0 = [];
8405 points1 = [];
8408 if (points0.length) segment();
8409 return segments.length ? segments.join("") : null;
8411 area.x = function(_) {
8412 if (!arguments.length) return x1;
8413 x0 = x1 = _;
8414 return area;
8415 };
8416 area.x0 = function(_) {
8417 if (!arguments.length) return x0;
8418 x0 = _;
8419 return area;
8420 };
8421 area.x1 = function(_) {
8422 if (!arguments.length) return x1;
8423 x1 = _;
8424 return area;
8425 };
8426 area.y = function(_) {
8427 if (!arguments.length) return y1;
8428 y0 = y1 = _;
8429 return area;
8430 };
8431 area.y0 = function(_) {
8432 if (!arguments.length) return y0;
8433 y0 = _;
8434 return area;
8435 };
8436 area.y1 = function(_) {
8437 if (!arguments.length) return y1;
8438 y1 = _;
8439 return area;
8440 };
8441 area.defined = function(_) {
8442 if (!arguments.length) return defined;
8443 defined = _;
8444 return area;
8445 };
8446 area.interpolate = function(_) {
8447 if (!arguments.length) return interpolateKey;
8448 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8449 interpolateReverse = interpolate.reverse || interpolate;
8450 L = interpolate.closed ? "M" : "L";
8451 return area;
8452 };
8453 area.tension = function(_) {
8454 if (!arguments.length) return tension;
8455 tension = _;
8456 return area;
8457 };
8458 return area;
8460 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
8461 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
8462 d3.svg.area = function() {
8463 return d3_svg_area(d3_identity);
8464 };
8465 d3.svg.area.radial = function() {
8466 var area = d3_svg_area(d3_svg_lineRadial);
8467 area.radius = area.x, delete area.x;
8468 area.innerRadius = area.x0, delete area.x0;
8469 area.outerRadius = area.x1, delete area.x1;
8470 area.angle = area.y, delete area.y;
8471 area.startAngle = area.y0, delete area.y0;
8472 area.endAngle = area.y1, delete area.y1;
8473 return area;
8474 };
8475 d3.svg.chord = function() {
8476 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
8477 function chord(d, i) {
8478 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
8479 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";
8481 function subgroup(self, f, d, i) {
8482 var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
8483 return {
8484 r: r,
8485 a0: a0,
8486 a1: a1,
8487 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
8488 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
8489 };
8491 function equals(a, b) {
8492 return a.a0 == b.a0 && a.a1 == b.a1;
8494 function arc(r, p, a) {
8495 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
8497 function curve(r0, p0, r1, p1) {
8498 return "Q 0,0 " + p1;
8500 chord.radius = function(v) {
8501 if (!arguments.length) return radius;
8502 radius = d3_functor(v);
8503 return chord;
8504 };
8505 chord.source = function(v) {
8506 if (!arguments.length) return source;
8507 source = d3_functor(v);
8508 return chord;
8509 };
8510 chord.target = function(v) {
8511 if (!arguments.length) return target;
8512 target = d3_functor(v);
8513 return chord;
8514 };
8515 chord.startAngle = function(v) {
8516 if (!arguments.length) return startAngle;
8517 startAngle = d3_functor(v);
8518 return chord;
8519 };
8520 chord.endAngle = function(v) {
8521 if (!arguments.length) return endAngle;
8522 endAngle = d3_functor(v);
8523 return chord;
8524 };
8525 return chord;
8526 };
8527 function d3_svg_chordRadius(d) {
8528 return d.radius;
8530 d3.svg.diagonal = function() {
8531 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
8532 function diagonal(d, i) {
8533 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
8534 x: p0.x,
8535 y: m
8536 }, {
8537 x: p3.x,
8538 y: m
8539 }, p3 ];
8540 p = p.map(projection);
8541 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
8543 diagonal.source = function(x) {
8544 if (!arguments.length) return source;
8545 source = d3_functor(x);
8546 return diagonal;
8547 };
8548 diagonal.target = function(x) {
8549 if (!arguments.length) return target;
8550 target = d3_functor(x);
8551 return diagonal;
8552 };
8553 diagonal.projection = function(x) {
8554 if (!arguments.length) return projection;
8555 projection = x;
8556 return diagonal;
8557 };
8558 return diagonal;
8559 };
8560 function d3_svg_diagonalProjection(d) {
8561 return [ d.x, d.y ];
8563 d3.svg.diagonal.radial = function() {
8564 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
8565 diagonal.projection = function(x) {
8566 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
8567 };
8568 return diagonal;
8569 };
8570 function d3_svg_diagonalRadialProjection(projection) {
8571 return function() {
8572 var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
8573 return [ r * Math.cos(a), r * Math.sin(a) ];
8574 };
8576 d3.svg.symbol = function() {
8577 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
8578 function symbol(d, i) {
8579 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
8581 symbol.type = function(x) {
8582 if (!arguments.length) return type;
8583 type = d3_functor(x);
8584 return symbol;
8585 };
8586 symbol.size = function(x) {
8587 if (!arguments.length) return size;
8588 size = d3_functor(x);
8589 return symbol;
8590 };
8591 return symbol;
8592 };
8593 function d3_svg_symbolSize() {
8594 return 64;
8596 function d3_svg_symbolType() {
8597 return "circle";
8599 function d3_svg_symbolCircle(size) {
8600 var r = Math.sqrt(size / π);
8601 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
8603 var d3_svg_symbols = d3.map({
8604 circle: d3_svg_symbolCircle,
8605 cross: function(size) {
8606 var r = Math.sqrt(size / 5) / 2;
8607 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";
8608 },
8609 diamond: function(size) {
8610 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
8611 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
8612 },
8613 square: function(size) {
8614 var r = Math.sqrt(size) / 2;
8615 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
8616 },
8617 "triangle-down": function(size) {
8618 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8619 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
8620 },
8621 "triangle-up": function(size) {
8622 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8623 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
8625 });
8626 d3.svg.symbolTypes = d3_svg_symbols.keys();
8627 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
8628 d3_selectionPrototype.transition = function(name) {
8629 var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
8630 time: Date.now(),
8631 ease: d3_ease_cubicInOut,
8632 delay: 0,
8633 duration: 250
8634 };
8635 for (var j = -1, m = this.length; ++j < m; ) {
8636 subgroups.push(subgroup = []);
8637 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8638 if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
8639 subgroup.push(node);
8642 return d3_transition(subgroups, ns, id);
8643 };
8644 d3_selectionPrototype.interrupt = function(name) {
8645 return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
8646 };
8647 var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
8648 function d3_selection_interruptNS(ns) {
8649 return function() {
8650 var lock, activeId, active;
8651 if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
8652 active.timer.c = null;
8653 active.timer.t = NaN;
8654 if (--lock.count) delete lock[activeId]; else delete this[ns];
8655 lock.active += .5;
8656 active.event && active.event.interrupt.call(this, this.__data__, active.index);
8658 };
8660 function d3_transition(groups, ns, id) {
8661 d3_subclass(groups, d3_transitionPrototype);
8662 groups.namespace = ns;
8663 groups.id = id;
8664 return groups;
8666 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
8667 d3_transitionPrototype.call = d3_selectionPrototype.call;
8668 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
8669 d3_transitionPrototype.node = d3_selectionPrototype.node;
8670 d3_transitionPrototype.size = d3_selectionPrototype.size;
8671 d3.transition = function(selection, name) {
8672 return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
8673 };
8674 d3.transition.prototype = d3_transitionPrototype;
8675 d3_transitionPrototype.select = function(selector) {
8676 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
8677 selector = d3_selection_selector(selector);
8678 for (var j = -1, m = this.length; ++j < m; ) {
8679 subgroups.push(subgroup = []);
8680 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8681 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
8682 if ("__data__" in node) subnode.__data__ = node.__data__;
8683 d3_transitionNode(subnode, i, ns, id, node[ns][id]);
8684 subgroup.push(subnode);
8685 } else {
8686 subgroup.push(null);
8690 return d3_transition(subgroups, ns, id);
8691 };
8692 d3_transitionPrototype.selectAll = function(selector) {
8693 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
8694 selector = d3_selection_selectorAll(selector);
8695 for (var j = -1, m = this.length; ++j < m; ) {
8696 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8697 if (node = group[i]) {
8698 transition = node[ns][id];
8699 subnodes = selector.call(node, node.__data__, i, j);
8700 subgroups.push(subgroup = []);
8701 for (var k = -1, o = subnodes.length; ++k < o; ) {
8702 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
8703 subgroup.push(subnode);
8708 return d3_transition(subgroups, ns, id);
8709 };
8710 d3_transitionPrototype.filter = function(filter) {
8711 var subgroups = [], subgroup, group, node;
8712 if (typeof filter !== "function") filter = d3_selection_filter(filter);
8713 for (var j = 0, m = this.length; j < m; j++) {
8714 subgroups.push(subgroup = []);
8715 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8716 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
8717 subgroup.push(node);
8721 return d3_transition(subgroups, this.namespace, this.id);
8722 };
8723 d3_transitionPrototype.tween = function(name, tween) {
8724 var id = this.id, ns = this.namespace;
8725 if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
8726 return d3_selection_each(this, tween == null ? function(node) {
8727 node[ns][id].tween.remove(name);
8728 } : function(node) {
8729 node[ns][id].tween.set(name, tween);
8730 });
8731 };
8732 function d3_transition_tween(groups, name, value, tween) {
8733 var id = groups.id, ns = groups.namespace;
8734 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
8735 node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
8736 } : (value = tween(value), function(node) {
8737 node[ns][id].tween.set(name, value);
8738 }));
8740 d3_transitionPrototype.attr = function(nameNS, value) {
8741 if (arguments.length < 2) {
8742 for (value in nameNS) this.attr(value, nameNS[value]);
8743 return this;
8745 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
8746 function attrNull() {
8747 this.removeAttribute(name);
8749 function attrNullNS() {
8750 this.removeAttributeNS(name.space, name.local);
8752 function attrTween(b) {
8753 return b == null ? attrNull : (b += "", function() {
8754 var a = this.getAttribute(name), i;
8755 return a !== b && (i = interpolate(a, b), function(t) {
8756 this.setAttribute(name, i(t));
8757 });
8758 });
8760 function attrTweenNS(b) {
8761 return b == null ? attrNullNS : (b += "", function() {
8762 var a = this.getAttributeNS(name.space, name.local), i;
8763 return a !== b && (i = interpolate(a, b), function(t) {
8764 this.setAttributeNS(name.space, name.local, i(t));
8765 });
8766 });
8768 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
8769 };
8770 d3_transitionPrototype.attrTween = function(nameNS, tween) {
8771 var name = d3.ns.qualify(nameNS);
8772 function attrTween(d, i) {
8773 var f = tween.call(this, d, i, this.getAttribute(name));
8774 return f && function(t) {
8775 this.setAttribute(name, f(t));
8776 };
8778 function attrTweenNS(d, i) {
8779 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
8780 return f && function(t) {
8781 this.setAttributeNS(name.space, name.local, f(t));
8782 };
8784 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
8785 };
8786 d3_transitionPrototype.style = function(name, value, priority) {
8787 var n = arguments.length;
8788 if (n < 3) {
8789 if (typeof name !== "string") {
8790 if (n < 2) value = "";
8791 for (priority in name) this.style(priority, name[priority], value);
8792 return this;
8794 priority = "";
8796 function styleNull() {
8797 this.style.removeProperty(name);
8799 function styleString(b) {
8800 return b == null ? styleNull : (b += "", function() {
8801 var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
8802 return a !== b && (i = d3_interpolate(a, b), function(t) {
8803 this.style.setProperty(name, i(t), priority);
8804 });
8805 });
8807 return d3_transition_tween(this, "style." + name, value, styleString);
8808 };
8809 d3_transitionPrototype.styleTween = function(name, tween, priority) {
8810 if (arguments.length < 3) priority = "";
8811 function styleTween(d, i) {
8812 var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
8813 return f && function(t) {
8814 this.style.setProperty(name, f(t), priority);
8815 };
8817 return this.tween("style." + name, styleTween);
8818 };
8819 d3_transitionPrototype.text = function(value) {
8820 return d3_transition_tween(this, "text", value, d3_transition_text);
8821 };
8822 function d3_transition_text(b) {
8823 if (b == null) b = "";
8824 return function() {
8825 this.textContent = b;
8826 };
8828 d3_transitionPrototype.remove = function() {
8829 var ns = this.namespace;
8830 return this.each("end.transition", function() {
8831 var p;
8832 if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
8833 });
8834 };
8835 d3_transitionPrototype.ease = function(value) {
8836 var id = this.id, ns = this.namespace;
8837 if (arguments.length < 1) return this.node()[ns][id].ease;
8838 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
8839 return d3_selection_each(this, function(node) {
8840 node[ns][id].ease = value;
8841 });
8842 };
8843 d3_transitionPrototype.delay = function(value) {
8844 var id = this.id, ns = this.namespace;
8845 if (arguments.length < 1) return this.node()[ns][id].delay;
8846 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8847 node[ns][id].delay = +value.call(node, node.__data__, i, j);
8848 } : (value = +value, function(node) {
8849 node[ns][id].delay = value;
8850 }));
8851 };
8852 d3_transitionPrototype.duration = function(value) {
8853 var id = this.id, ns = this.namespace;
8854 if (arguments.length < 1) return this.node()[ns][id].duration;
8855 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8856 node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
8857 } : (value = Math.max(1, value), function(node) {
8858 node[ns][id].duration = value;
8859 }));
8860 };
8861 d3_transitionPrototype.each = function(type, listener) {
8862 var id = this.id, ns = this.namespace;
8863 if (arguments.length < 2) {
8864 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
8865 try {
8866 d3_transitionInheritId = id;
8867 d3_selection_each(this, function(node, i, j) {
8868 d3_transitionInherit = node[ns][id];
8869 type.call(node, node.__data__, i, j);
8870 });
8871 } finally {
8872 d3_transitionInherit = inherit;
8873 d3_transitionInheritId = inheritId;
8875 } else {
8876 d3_selection_each(this, function(node) {
8877 var transition = node[ns][id];
8878 (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
8879 });
8881 return this;
8882 };
8883 d3_transitionPrototype.transition = function() {
8884 var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
8885 for (var j = 0, m = this.length; j < m; j++) {
8886 subgroups.push(subgroup = []);
8887 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8888 if (node = group[i]) {
8889 transition = node[ns][id0];
8890 d3_transitionNode(node, i, ns, id1, {
8891 time: transition.time,
8892 ease: transition.ease,
8893 delay: transition.delay + transition.duration,
8894 duration: transition.duration
8895 });
8897 subgroup.push(node);
8900 return d3_transition(subgroups, ns, id1);
8901 };
8902 function d3_transitionNamespace(name) {
8903 return name == null ? "__transition__" : "__transition_" + name + "__";
8905 function d3_transitionNode(node, i, ns, id, inherit) {
8906 var lock = node[ns] || (node[ns] = {
8907 active: 0,
8908 count: 0
8909 }), transition = lock[id], time, timer, duration, ease, tweens;
8910 function schedule(elapsed) {
8911 var delay = transition.delay;
8912 timer.t = delay + time;
8913 if (delay <= elapsed) return start(elapsed - delay);
8914 timer.c = start;
8916 function start(elapsed) {
8917 var activeId = lock.active, active = lock[activeId];
8918 if (active) {
8919 active.timer.c = null;
8920 active.timer.t = NaN;
8921 --lock.count;
8922 delete lock[activeId];
8923 active.event && active.event.interrupt.call(node, node.__data__, active.index);
8925 for (var cancelId in lock) {
8926 if (+cancelId < id) {
8927 var cancel = lock[cancelId];
8928 cancel.timer.c = null;
8929 cancel.timer.t = NaN;
8930 --lock.count;
8931 delete lock[cancelId];
8934 timer.c = tick;
8935 d3_timer(function() {
8936 if (timer.c && tick(elapsed || 1)) {
8937 timer.c = null;
8938 timer.t = NaN;
8940 return 1;
8941 }, 0, time);
8942 lock.active = id;
8943 transition.event && transition.event.start.call(node, node.__data__, i);
8944 tweens = [];
8945 transition.tween.forEach(function(key, value) {
8946 if (value = value.call(node, node.__data__, i)) {
8947 tweens.push(value);
8949 });
8950 ease = transition.ease;
8951 duration = transition.duration;
8953 function tick(elapsed) {
8954 var t = elapsed / duration, e = ease(t), n = tweens.length;
8955 while (n > 0) {
8956 tweens[--n].call(node, e);
8958 if (t >= 1) {
8959 transition.event && transition.event.end.call(node, node.__data__, i);
8960 if (--lock.count) delete lock[id]; else delete node[ns];
8961 return 1;
8964 if (!transition) {
8965 time = inherit.time;
8966 timer = d3_timer(schedule, 0, time);
8967 transition = lock[id] = {
8968 tween: new d3_Map(),
8969 time: time,
8970 timer: timer,
8971 delay: inherit.delay,
8972 duration: inherit.duration,
8973 ease: inherit.ease,
8974 index: i
8975 };
8976 inherit = null;
8977 ++lock.count;
8980 d3.svg.axis = function() {
8981 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
8982 function axis(g) {
8983 g.each(function() {
8984 var g = d3.select(this);
8985 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
8986 var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
8987 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
8988 d3.transition(path));
8989 tickEnter.append("line");
8990 tickEnter.append("text");
8991 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
8992 if (orient === "bottom" || orient === "top") {
8993 tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
8994 text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
8995 pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
8996 } else {
8997 tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
8998 text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
8999 pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
9001 lineEnter.attr(y2, sign * innerTickSize);
9002 textEnter.attr(y1, sign * tickSpacing);
9003 lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
9004 textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
9005 if (scale1.rangeBand) {
9006 var x = scale1, dx = x.rangeBand() / 2;
9007 scale0 = scale1 = function(d) {
9008 return x(d) + dx;
9009 };
9010 } else if (scale0.rangeBand) {
9011 scale0 = scale1;
9012 } else {
9013 tickExit.call(tickTransform, scale1, scale0);
9015 tickEnter.call(tickTransform, scale0, scale1);
9016 tickUpdate.call(tickTransform, scale1, scale1);
9017 });
9019 axis.scale = function(x) {
9020 if (!arguments.length) return scale;
9021 scale = x;
9022 return axis;
9023 };
9024 axis.orient = function(x) {
9025 if (!arguments.length) return orient;
9026 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
9027 return axis;
9028 };
9029 axis.ticks = function() {
9030 if (!arguments.length) return tickArguments_;
9031 tickArguments_ = d3_array(arguments);
9032 return axis;
9033 };
9034 axis.tickValues = function(x) {
9035 if (!arguments.length) return tickValues;
9036 tickValues = x;
9037 return axis;
9038 };
9039 axis.tickFormat = function(x) {
9040 if (!arguments.length) return tickFormat_;
9041 tickFormat_ = x;
9042 return axis;
9043 };
9044 axis.tickSize = function(x) {
9045 var n = arguments.length;
9046 if (!n) return innerTickSize;
9047 innerTickSize = +x;
9048 outerTickSize = +arguments[n - 1];
9049 return axis;
9050 };
9051 axis.innerTickSize = function(x) {
9052 if (!arguments.length) return innerTickSize;
9053 innerTickSize = +x;
9054 return axis;
9055 };
9056 axis.outerTickSize = function(x) {
9057 if (!arguments.length) return outerTickSize;
9058 outerTickSize = +x;
9059 return axis;
9060 };
9061 axis.tickPadding = function(x) {
9062 if (!arguments.length) return tickPadding;
9063 tickPadding = +x;
9064 return axis;
9065 };
9066 axis.tickSubdivide = function() {
9067 return arguments.length && axis;
9068 };
9069 return axis;
9070 };
9071 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
9072 top: 1,
9073 right: 1,
9074 bottom: 1,
9075 left: 1
9076 };
9077 function d3_svg_axisX(selection, x0, x1) {
9078 selection.attr("transform", function(d) {
9079 var v0 = x0(d);
9080 return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
9081 });
9083 function d3_svg_axisY(selection, y0, y1) {
9084 selection.attr("transform", function(d) {
9085 var v0 = y0(d);
9086 return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
9087 });
9089 d3.svg.brush = function() {
9090 var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
9091 function brush(g) {
9092 g.each(function() {
9093 var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
9094 var background = g.selectAll(".background").data([ 0 ]);
9095 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
9096 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
9097 var resize = g.selectAll(".resize").data(resizes, d3_identity);
9098 resize.exit().remove();
9099 resize.enter().append("g").attr("class", function(d) {
9100 return "resize " + d;
9101 }).style("cursor", function(d) {
9102 return d3_svg_brushCursor[d];
9103 }).append("rect").attr("x", function(d) {
9104 return /[ew]$/.test(d) ? -3 : null;
9105 }).attr("y", function(d) {
9106 return /^[ns]/.test(d) ? -3 : null;
9107 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
9108 resize.style("display", brush.empty() ? "none" : null);
9109 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
9110 if (x) {
9111 range = d3_scaleRange(x);
9112 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
9113 redrawX(gUpdate);
9115 if (y) {
9116 range = d3_scaleRange(y);
9117 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
9118 redrawY(gUpdate);
9120 redraw(gUpdate);
9121 });
9123 brush.event = function(g) {
9124 g.each(function() {
9125 var event_ = event.of(this, arguments), extent1 = {
9126 x: xExtent,
9127 y: yExtent,
9128 i: xExtentDomain,
9129 j: yExtentDomain
9130 }, extent0 = this.__chart__ || extent1;
9131 this.__chart__ = extent1;
9132 if (d3_transitionInheritId) {
9133 d3.select(this).transition().each("start.brush", function() {
9134 xExtentDomain = extent0.i;
9135 yExtentDomain = extent0.j;
9136 xExtent = extent0.x;
9137 yExtent = extent0.y;
9138 event_({
9139 type: "brushstart"
9140 });
9141 }).tween("brush:brush", function() {
9142 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
9143 xExtentDomain = yExtentDomain = null;
9144 return function(t) {
9145 xExtent = extent1.x = xi(t);
9146 yExtent = extent1.y = yi(t);
9147 event_({
9148 type: "brush",
9149 mode: "resize"
9150 });
9151 };
9152 }).each("end.brush", function() {
9153 xExtentDomain = extent1.i;
9154 yExtentDomain = extent1.j;
9155 event_({
9156 type: "brush",
9157 mode: "resize"
9158 });
9159 event_({
9160 type: "brushend"
9161 });
9162 });
9163 } else {
9164 event_({
9165 type: "brushstart"
9166 });
9167 event_({
9168 type: "brush",
9169 mode: "resize"
9170 });
9171 event_({
9172 type: "brushend"
9173 });
9175 });
9176 };
9177 function redraw(g) {
9178 g.selectAll(".resize").attr("transform", function(d) {
9179 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
9180 });
9182 function redrawX(g) {
9183 g.select(".extent").attr("x", xExtent[0]);
9184 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
9186 function redrawY(g) {
9187 g.select(".extent").attr("y", yExtent[0]);
9188 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
9190 function brushstart() {
9191 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"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
9192 var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
9193 if (d3.event.changedTouches) {
9194 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
9195 } else {
9196 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
9198 g.interrupt().selectAll("*").interrupt();
9199 if (dragging) {
9200 origin[0] = xExtent[0] - origin[0];
9201 origin[1] = yExtent[0] - origin[1];
9202 } else if (resizing) {
9203 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
9204 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
9205 origin[0] = xExtent[ex];
9206 origin[1] = yExtent[ey];
9207 } else if (d3.event.altKey) center = origin.slice();
9208 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
9209 d3.select("body").style("cursor", eventTarget.style("cursor"));
9210 event_({
9211 type: "brushstart"
9212 });
9213 brushmove();
9214 function keydown() {
9215 if (d3.event.keyCode == 32) {
9216 if (!dragging) {
9217 center = null;
9218 origin[0] -= xExtent[1];
9219 origin[1] -= yExtent[1];
9220 dragging = 2;
9222 d3_eventPreventDefault();
9225 function keyup() {
9226 if (d3.event.keyCode == 32 && dragging == 2) {
9227 origin[0] += xExtent[1];
9228 origin[1] += yExtent[1];
9229 dragging = 0;
9230 d3_eventPreventDefault();
9233 function brushmove() {
9234 var point = d3.mouse(target), moved = false;
9235 if (offset) {
9236 point[0] += offset[0];
9237 point[1] += offset[1];
9239 if (!dragging) {
9240 if (d3.event.altKey) {
9241 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
9242 origin[0] = xExtent[+(point[0] < center[0])];
9243 origin[1] = yExtent[+(point[1] < center[1])];
9244 } else center = null;
9246 if (resizingX && move1(point, x, 0)) {
9247 redrawX(g);
9248 moved = true;
9250 if (resizingY && move1(point, y, 1)) {
9251 redrawY(g);
9252 moved = true;
9254 if (moved) {
9255 redraw(g);
9256 event_({
9257 type: "brush",
9258 mode: dragging ? "move" : "resize"
9259 });
9262 function move1(point, scale, i) {
9263 var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
9264 if (dragging) {
9265 r0 -= position;
9266 r1 -= size + position;
9268 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
9269 if (dragging) {
9270 max = (min += position) + size;
9271 } else {
9272 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
9273 if (position < min) {
9274 max = min;
9275 min = position;
9276 } else {
9277 max = position;
9280 if (extent[0] != min || extent[1] != max) {
9281 if (i) yExtentDomain = null; else xExtentDomain = null;
9282 extent[0] = min;
9283 extent[1] = max;
9284 return true;
9287 function brushend() {
9288 brushmove();
9289 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
9290 d3.select("body").style("cursor", null);
9291 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);
9292 dragRestore();
9293 event_({
9294 type: "brushend"
9295 });
9298 brush.x = function(z) {
9299 if (!arguments.length) return x;
9300 x = z;
9301 resizes = d3_svg_brushResizes[!x << 1 | !y];
9302 return brush;
9303 };
9304 brush.y = function(z) {
9305 if (!arguments.length) return y;
9306 y = z;
9307 resizes = d3_svg_brushResizes[!x << 1 | !y];
9308 return brush;
9309 };
9310 brush.clamp = function(z) {
9311 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
9312 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
9313 return brush;
9314 };
9315 brush.extent = function(z) {
9316 var x0, x1, y0, y1, t;
9317 if (!arguments.length) {
9318 if (x) {
9319 if (xExtentDomain) {
9320 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
9321 } else {
9322 x0 = xExtent[0], x1 = xExtent[1];
9323 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
9324 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9327 if (y) {
9328 if (yExtentDomain) {
9329 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
9330 } else {
9331 y0 = yExtent[0], y1 = yExtent[1];
9332 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
9333 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9336 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
9338 if (x) {
9339 x0 = z[0], x1 = z[1];
9340 if (y) x0 = x0[0], x1 = x1[0];
9341 xExtentDomain = [ x0, x1 ];
9342 if (x.invert) x0 = x(x0), x1 = x(x1);
9343 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9344 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
9346 if (y) {
9347 y0 = z[0], y1 = z[1];
9348 if (x) y0 = y0[1], y1 = y1[1];
9349 yExtentDomain = [ y0, y1 ];
9350 if (y.invert) y0 = y(y0), y1 = y(y1);
9351 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9352 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
9354 return brush;
9355 };
9356 brush.clear = function() {
9357 if (!brush.empty()) {
9358 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
9359 xExtentDomain = yExtentDomain = null;
9361 return brush;
9362 };
9363 brush.empty = function() {
9364 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
9365 };
9366 return d3.rebind(brush, event, "on");
9367 };
9368 var d3_svg_brushCursor = {
9369 n: "ns-resize",
9370 e: "ew-resize",
9371 s: "ns-resize",
9372 w: "ew-resize",
9373 nw: "nwse-resize",
9374 ne: "nesw-resize",
9375 se: "nwse-resize",
9376 sw: "nesw-resize"
9377 };
9378 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
9379 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
9380 var d3_time_formatUtc = d3_time_format.utc;
9381 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
9382 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
9383 function d3_time_formatIsoNative(date) {
9384 return date.toISOString();
9386 d3_time_formatIsoNative.parse = function(string) {
9387 var date = new Date(string);
9388 return isNaN(date) ? null : date;
9389 };
9390 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
9391 d3_time.second = d3_time_interval(function(date) {
9392 return new d3_date(Math.floor(date / 1e3) * 1e3);
9393 }, function(date, offset) {
9394 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
9395 }, function(date) {
9396 return date.getSeconds();
9397 });
9398 d3_time.seconds = d3_time.second.range;
9399 d3_time.seconds.utc = d3_time.second.utc.range;
9400 d3_time.minute = d3_time_interval(function(date) {
9401 return new d3_date(Math.floor(date / 6e4) * 6e4);
9402 }, function(date, offset) {
9403 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
9404 }, function(date) {
9405 return date.getMinutes();
9406 });
9407 d3_time.minutes = d3_time.minute.range;
9408 d3_time.minutes.utc = d3_time.minute.utc.range;
9409 d3_time.hour = d3_time_interval(function(date) {
9410 var timezone = date.getTimezoneOffset() / 60;
9411 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
9412 }, function(date, offset) {
9413 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
9414 }, function(date) {
9415 return date.getHours();
9416 });
9417 d3_time.hours = d3_time.hour.range;
9418 d3_time.hours.utc = d3_time.hour.utc.range;
9419 d3_time.month = d3_time_interval(function(date) {
9420 date = d3_time.day(date);
9421 date.setDate(1);
9422 return date;
9423 }, function(date, offset) {
9424 date.setMonth(date.getMonth() + offset);
9425 }, function(date) {
9426 return date.getMonth();
9427 });
9428 d3_time.months = d3_time.month.range;
9429 d3_time.months.utc = d3_time.month.utc.range;
9430 function d3_time_scale(linear, methods, format) {
9431 function scale(x) {
9432 return linear(x);
9434 scale.invert = function(x) {
9435 return d3_time_scaleDate(linear.invert(x));
9436 };
9437 scale.domain = function(x) {
9438 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
9439 linear.domain(x);
9440 return scale;
9441 };
9442 function tickMethod(extent, count) {
9443 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
9444 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
9445 return d / 31536e6;
9446 }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];
9448 scale.nice = function(interval, skip) {
9449 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
9450 if (method) interval = method[0], skip = method[1];
9451 function skipped(date) {
9452 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
9454 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
9455 floor: function(date) {
9456 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
9457 return date;
9458 },
9459 ceil: function(date) {
9460 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
9461 return date;
9463 } : interval));
9464 };
9465 scale.ticks = function(interval, skip) {
9466 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
9467 range: interval
9468 }, skip ];
9469 if (method) interval = method[0], skip = method[1];
9470 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
9471 };
9472 scale.tickFormat = function() {
9473 return format;
9474 };
9475 scale.copy = function() {
9476 return d3_time_scale(linear.copy(), methods, format);
9477 };
9478 return d3_scale_linearRebind(scale, linear);
9480 function d3_time_scaleDate(t) {
9481 return new Date(t);
9483 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
9484 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 ] ];
9485 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
9486 return d.getMilliseconds();
9487 } ], [ ":%S", function(d) {
9488 return d.getSeconds();
9489 } ], [ "%I:%M", function(d) {
9490 return d.getMinutes();
9491 } ], [ "%I %p", function(d) {
9492 return d.getHours();
9493 } ], [ "%a %d", function(d) {
9494 return d.getDay() && d.getDate() != 1;
9495 } ], [ "%b %d", function(d) {
9496 return d.getDate() != 1;
9497 } ], [ "%B", function(d) {
9498 return d.getMonth();
9499 } ], [ "%Y", d3_true ] ]);
9500 var d3_time_scaleMilliseconds = {
9501 range: function(start, stop, step) {
9502 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
9503 },
9504 floor: d3_identity,
9505 ceil: d3_identity
9506 };
9507 d3_time_scaleLocalMethods.year = d3_time.year;
9508 d3_time.scale = function() {
9509 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
9510 };
9511 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
9512 return [ m[0].utc, m[1] ];
9513 });
9514 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
9515 return d.getUTCMilliseconds();
9516 } ], [ ":%S", function(d) {
9517 return d.getUTCSeconds();
9518 } ], [ "%I:%M", function(d) {
9519 return d.getUTCMinutes();
9520 } ], [ "%I %p", function(d) {
9521 return d.getUTCHours();
9522 } ], [ "%a %d", function(d) {
9523 return d.getUTCDay() && d.getUTCDate() != 1;
9524 } ], [ "%b %d", function(d) {
9525 return d.getUTCDate() != 1;
9526 } ], [ "%B", function(d) {
9527 return d.getUTCMonth();
9528 } ], [ "%Y", d3_true ] ]);
9529 d3_time_scaleUtcMethods.year = d3_time.year.utc;
9530 d3_time.scale.utc = function() {
9531 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
9532 };
9533 d3.text = d3_xhrType(function(request) {
9534 return request.responseText;
9535 });
9536 d3.json = function(url, callback) {
9537 return d3_xhr(url, "application/json", d3_json, callback);
9538 };
9539 function d3_json(request) {
9540 return JSON.parse(request.responseText);
9542 d3.html = function(url, callback) {
9543 return d3_xhr(url, "text/html", d3_html, callback);
9544 };
9545 function d3_html(request) {
9546 var range = d3_document.createRange();
9547 range.selectNode(d3_document.body);
9548 return range.createContextualFragment(request.responseText);
9550 d3.xml = d3_xhrType(function(request) {
9551 return request.responseXML;
9552 });
9553 if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
9554 }();