1 | !function() {
|
2 | var d3 = {
|
3 | version: "3.4.11"
|
4 | };
|
5 | if (!Date.now) Date.now = function() {
|
6 | return +new Date();
|
7 | };
|
8 | var d3_arraySlice = [].slice, d3_array = function(list) {
|
9 | return d3_arraySlice.call(list);
|
10 | };
|
11 | var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window;
|
12 | try {
|
13 | d3_array(d3_documentElement.childNodes)[0].nodeType;
|
14 | } catch (e) {
|
15 | d3_array = function(list) {
|
16 | var i = list.length, array = new Array(i);
|
17 | while (i--) array[i] = list[i];
|
18 | return array;
|
19 | };
|
20 | }
|
21 | try {
|
22 | d3_document.createElement("div").style.setProperty("opacity", 0, "");
|
23 | } catch (error) {
|
24 | var d3_element_prototype = d3_window.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
|
25 | d3_element_prototype.setAttribute = function(name, value) {
|
26 | d3_element_setAttribute.call(this, name, value + "");
|
27 | };
|
28 | d3_element_prototype.setAttributeNS = function(space, local, value) {
|
29 | d3_element_setAttributeNS.call(this, space, local, value + "");
|
30 | };
|
31 | d3_style_prototype.setProperty = function(name, value, priority) {
|
32 | d3_style_setProperty.call(this, name, value + "", priority);
|
33 | };
|
34 | }
|
35 | d3.ascending = d3_ascending;
|
36 | function d3_ascending(a, b) {
|
37 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
38 | }
|
39 | d3.descending = function(a, b) {
|
40 | return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
41 | };
|
42 | d3.min = function(array, f) {
|
43 | var i = -1, n = array.length, a, b;
|
44 | if (arguments.length === 1) {
|
45 | while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
|
46 | while (++i < n) if ((b = array[i]) != null && a > b) a = b;
|
47 | } else {
|
48 | while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
|
49 | while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
|
50 | }
|
51 | return a;
|
52 | };
|
53 | d3.max = function(array, f) {
|
54 | var i = -1, n = array.length, a, b;
|
55 | if (arguments.length === 1) {
|
56 | while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
|
57 | while (++i < n) if ((b = array[i]) != null && b > a) a = b;
|
58 | } else {
|
59 | while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
|
60 | while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
|
61 | }
|
62 | return a;
|
63 | };
|
64 | d3.extent = function(array, f) {
|
65 | var i = -1, n = array.length, a, b, c;
|
66 | if (arguments.length === 1) {
|
67 | while (++i < n && !((a = c = array[i]) != null && a <= a)) a = c = undefined;
|
68 | while (++i < n) if ((b = array[i]) != null) {
|
69 | if (a > b) a = b;
|
70 | if (c < b) c = b;
|
71 | }
|
72 | } else {
|
73 | while (++i < n && !((a = c = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
|
74 | while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
|
75 | if (a > b) a = b;
|
76 | if (c < b) c = b;
|
77 | }
|
78 | }
|
79 | return [ a, c ];
|
80 | };
|
81 | d3.sum = function(array, f) {
|
82 | var s = 0, n = array.length, a, i = -1;
|
83 | if (arguments.length === 1) {
|
84 | while (++i < n) if (!isNaN(a = +array[i])) s += a;
|
85 | } else {
|
86 | while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
|
87 | }
|
88 | return s;
|
89 | };
|
90 | function d3_number(x) {
|
91 | return x != null && !isNaN(x);
|
92 | }
|
93 | d3.mean = function(array, f) {
|
94 | var s = 0, n = array.length, a, i = -1, j = n;
|
95 | if (arguments.length === 1) {
|
96 | while (++i < n) if (d3_number(a = array[i])) s += a; else --j;
|
97 | } else {
|
98 | while (++i < n) if (d3_number(a = f.call(array, array[i], i))) s += a; else --j;
|
99 | }
|
100 | return j ? s / j : undefined;
|
101 | };
|
102 | d3.quantile = function(values, p) {
|
103 | var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
|
104 | return e ? v + e * (values[h] - v) : v;
|
105 | };
|
106 | d3.median = function(array, f) {
|
107 | if (arguments.length > 1) array = array.map(f);
|
108 | array = array.filter(d3_number);
|
109 | return array.length ? d3.quantile(array.sort(d3_ascending), .5) : undefined;
|
110 | };
|
111 | function d3_bisector(compare) {
|
112 | return {
|
113 | left: function(a, x, lo, hi) {
|
114 | if (arguments.length < 3) lo = 0;
|
115 | if (arguments.length < 4) hi = a.length;
|
116 | while (lo < hi) {
|
117 | var mid = lo + hi >>> 1;
|
118 | if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
|
119 | }
|
120 | return lo;
|
121 | },
|
122 | right: function(a, x, lo, hi) {
|
123 | if (arguments.length < 3) lo = 0;
|
124 | if (arguments.length < 4) hi = a.length;
|
125 | while (lo < hi) {
|
126 | var mid = lo + hi >>> 1;
|
127 | if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
|
128 | }
|
129 | return lo;
|
130 | }
|
131 | };
|
132 | }
|
133 | var d3_bisect = d3_bisector(d3_ascending);
|
134 | d3.bisectLeft = d3_bisect.left;
|
135 | d3.bisect = d3.bisectRight = d3_bisect.right;
|
136 | d3.bisector = function(f) {
|
137 | return d3_bisector(f.length === 1 ? function(d, x) {
|
138 | return d3_ascending(f(d), x);
|
139 | } : f);
|
140 | };
|
141 | d3.shuffle = function(array) {
|
142 | var m = array.length, t, i;
|
143 | while (m) {
|
144 | i = Math.random() * m-- | 0;
|
145 | t = array[m], array[m] = array[i], array[i] = t;
|
146 | }
|
147 | return array;
|
148 | };
|
149 | d3.permute = function(array, indexes) {
|
150 | var i = indexes.length, permutes = new Array(i);
|
151 | while (i--) permutes[i] = array[indexes[i]];
|
152 | return permutes;
|
153 | };
|
154 | d3.pairs = function(array) {
|
155 | var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
|
156 | while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
|
157 | return pairs;
|
158 | };
|
159 | d3.zip = function() {
|
160 | if (!(n = arguments.length)) return [];
|
161 | for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
|
162 | for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
|
163 | zip[j] = arguments[j][i];
|
164 | }
|
165 | }
|
166 | return zips;
|
167 | };
|
168 | function d3_zipLength(d) {
|
169 | return d.length;
|
170 | }
|
171 | d3.transpose = function(matrix) {
|
172 | return d3.zip.apply(d3, matrix);
|
173 | };
|
174 | d3.keys = function(map) {
|
175 | var keys = [];
|
176 | for (var key in map) keys.push(key);
|
177 | return keys;
|
178 | };
|
179 | d3.values = function(map) {
|
180 | var values = [];
|
181 | for (var key in map) values.push(map[key]);
|
182 | return values;
|
183 | };
|
184 | d3.entries = function(map) {
|
185 | var entries = [];
|
186 | for (var key in map) entries.push({
|
187 | key: key,
|
188 | value: map[key]
|
189 | });
|
190 | return entries;
|
191 | };
|
192 | d3.merge = function(arrays) {
|
193 | var n = arrays.length, m, i = -1, j = 0, merged, array;
|
194 | while (++i < n) j += arrays[i].length;
|
195 | merged = new Array(j);
|
196 | while (--n >= 0) {
|
197 | array = arrays[n];
|
198 | m = array.length;
|
199 | while (--m >= 0) {
|
200 | merged[--j] = array[m];
|
201 | }
|
202 | }
|
203 | return merged;
|
204 | };
|
205 | var abs = Math.abs;
|
206 | d3.range = function(start, stop, step) {
|
207 | if (arguments.length < 3) {
|
208 | step = 1;
|
209 | if (arguments.length < 2) {
|
210 | stop = start;
|
211 | start = 0;
|
212 | }
|
213 | }
|
214 | if ((stop - start) / step === Infinity) throw new Error("infinite range");
|
215 | var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
|
216 | start *= k, stop *= k, step *= k;
|
217 | if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
|
218 | return range;
|
219 | };
|
220 | function d3_range_integerScale(x) {
|
221 | var k = 1;
|
222 | while (x * k % 1) k *= 10;
|
223 | return k;
|
224 | }
|
225 | function d3_class(ctor, properties) {
|
226 | try {
|
227 | for (var key in properties) {
|
228 | Object.defineProperty(ctor.prototype, key, {
|
229 | value: properties[key],
|
230 | enumerable: false
|
231 | });
|
232 | }
|
233 | } catch (e) {
|
234 | ctor.prototype = properties;
|
235 | }
|
236 | }
|
237 | d3.map = function(object) {
|
238 | var map = new d3_Map();
|
239 | if (object instanceof d3_Map) object.forEach(function(key, value) {
|
240 | map.set(key, value);
|
241 | }); else for (var key in object) map.set(key, object[key]);
|
242 | return map;
|
243 | };
|
244 | function d3_Map() {}
|
245 | d3_class(d3_Map, {
|
246 | has: d3_map_has,
|
247 | get: function(key) {
|
248 | return this[d3_map_prefix + key];
|
249 | },
|
250 | set: function(key, value) {
|
251 | return this[d3_map_prefix + key] = value;
|
252 | },
|
253 | remove: d3_map_remove,
|
254 | keys: d3_map_keys,
|
255 | values: function() {
|
256 | var values = [];
|
257 | this.forEach(function(key, value) {
|
258 | values.push(value);
|
259 | });
|
260 | return values;
|
261 | },
|
262 | entries: function() {
|
263 | var entries = [];
|
264 | this.forEach(function(key, value) {
|
265 | entries.push({
|
266 | key: key,
|
267 | value: value
|
268 | });
|
269 | });
|
270 | return entries;
|
271 | },
|
272 | size: d3_map_size,
|
273 | empty: d3_map_empty,
|
274 | forEach: function(f) {
|
275 | for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) f.call(this, key.substring(1), this[key]);
|
276 | }
|
277 | });
|
278 | var d3_map_prefix = "\x00", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
|
279 | function d3_map_has(key) {
|
280 | return d3_map_prefix + key in this;
|
281 | }
|
282 | function d3_map_remove(key) {
|
283 | key = d3_map_prefix + key;
|
284 | return key in this && delete this[key];
|
285 | }
|
286 | function d3_map_keys() {
|
287 | var keys = [];
|
288 | this.forEach(function(key) {
|
289 | keys.push(key);
|
290 | });
|
291 | return keys;
|
292 | }
|
293 | function d3_map_size() {
|
294 | var size = 0;
|
295 | for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) ++size;
|
296 | return size;
|
297 | }
|
298 | function d3_map_empty() {
|
299 | for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) return false;
|
300 | return true;
|
301 | }
|
302 | d3.nest = function() {
|
303 | var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
|
304 | function map(mapType, array, depth) {
|
305 | if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
|
306 | var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
|
307 | while (++i < n) {
|
308 | if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
|
309 | values.push(object);
|
310 | } else {
|
311 | valuesByKey.set(keyValue, [ object ]);
|
312 | }
|
313 | }
|
314 | if (mapType) {
|
315 | object = mapType();
|
316 | setter = function(keyValue, values) {
|
317 | object.set(keyValue, map(mapType, values, depth));
|
318 | };
|
319 | } else {
|
320 | object = {};
|
321 | setter = function(keyValue, values) {
|
322 | object[keyValue] = map(mapType, values, depth);
|
323 | };
|
324 | }
|
325 | valuesByKey.forEach(setter);
|
326 | return object;
|
327 | }
|
328 | function entries(map, depth) {
|
329 | if (depth >= keys.length) return map;
|
330 | var array = [], sortKey = sortKeys[depth++];
|
331 | map.forEach(function(key, keyMap) {
|
332 | array.push({
|
333 | key: key,
|
334 | values: entries(keyMap, depth)
|
335 | });
|
336 | });
|
337 | return sortKey ? array.sort(function(a, b) {
|
338 | return sortKey(a.key, b.key);
|
339 | }) : array;
|
340 | }
|
341 | nest.map = function(array, mapType) {
|
342 | return map(mapType, array, 0);
|
343 | };
|
344 | nest.entries = function(array) {
|
345 | return entries(map(d3.map, array, 0), 0);
|
346 | };
|
347 | nest.key = function(d) {
|
348 | keys.push(d);
|
349 | return nest;
|
350 | };
|
351 | nest.sortKeys = function(order) {
|
352 | sortKeys[keys.length - 1] = order;
|
353 | return nest;
|
354 | };
|
355 | nest.sortValues = function(order) {
|
356 | sortValues = order;
|
357 | return nest;
|
358 | };
|
359 | nest.rollup = function(f) {
|
360 | rollup = f;
|
361 | return nest;
|
362 | };
|
363 | return nest;
|
364 | };
|
365 | d3.set = function(array) {
|
366 | var set = new d3_Set();
|
367 | if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
|
368 | return set;
|
369 | };
|
370 | function d3_Set() {}
|
371 | d3_class(d3_Set, {
|
372 | has: d3_map_has,
|
373 | add: function(value) {
|
374 | this[d3_map_prefix + value] = true;
|
375 | return value;
|
376 | },
|
377 | remove: function(value) {
|
378 | value = d3_map_prefix + value;
|
379 | return value in this && delete this[value];
|
380 | },
|
381 | values: d3_map_keys,
|
382 | size: d3_map_size,
|
383 | empty: d3_map_empty,
|
384 | forEach: function(f) {
|
385 | for (var value in this) if (value.charCodeAt(0) === d3_map_prefixCode) f.call(this, value.substring(1));
|
386 | }
|
387 | });
|
388 | d3.behavior = {};
|
389 | d3.rebind = function(target, source) {
|
390 | var i = 1, n = arguments.length, method;
|
391 | while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
|
392 | return target;
|
393 | };
|
394 | function d3_rebind(target, source, method) {
|
395 | return function() {
|
396 | var value = method.apply(source, arguments);
|
397 | return value === source ? target : value;
|
398 | };
|
399 | }
|
400 | function d3_vendorSymbol(object, name) {
|
401 | if (name in object) return name;
|
402 | name = name.charAt(0).toUpperCase() + name.substring(1);
|
403 | for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
|
404 | var prefixName = d3_vendorPrefixes[i] + name;
|
405 | if (prefixName in object) return prefixName;
|
406 | }
|
407 | }
|
408 | var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
|
409 | function d3_noop() {}
|
410 | d3.dispatch = function() {
|
411 | var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
|
412 | while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
|
413 | return dispatch;
|
414 | };
|
415 | function d3_dispatch() {}
|
416 | d3_dispatch.prototype.on = function(type, listener) {
|
417 | var i = type.indexOf("."), name = "";
|
418 | if (i >= 0) {
|
419 | name = type.substring(i + 1);
|
420 | type = type.substring(0, i);
|
421 | }
|
422 | if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
|
423 | if (arguments.length === 2) {
|
424 | if (listener == null) for (type in this) {
|
425 | if (this.hasOwnProperty(type)) this[type].on(name, null);
|
426 | }
|
427 | return this;
|
428 | }
|
429 | };
|
430 | function d3_dispatch_event(dispatch) {
|
431 | var listeners = [], listenerByName = new d3_Map();
|
432 | function event() {
|
433 | var z = listeners, i = -1, n = z.length, l;
|
434 | while (++i < n) if (l = z[i].on) l.apply(this, arguments);
|
435 | return dispatch;
|
436 | }
|
437 | event.on = function(name, listener) {
|
438 | var l = listenerByName.get(name), i;
|
439 | if (arguments.length < 2) return l && l.on;
|
440 | if (l) {
|
441 | l.on = null;
|
442 | listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
|
443 | listenerByName.remove(name);
|
444 | }
|
445 | if (listener) listeners.push(listenerByName.set(name, {
|
446 | on: listener
|
447 | }));
|
448 | return dispatch;
|
449 | };
|
450 | return event;
|
451 | }
|
452 | d3.event = null;
|
453 | function d3_eventPreventDefault() {
|
454 | d3.event.preventDefault();
|
455 | }
|
456 | function d3_eventSource() {
|
457 | var e = d3.event, s;
|
458 | while (s = e.sourceEvent) e = s;
|
459 | return e;
|
460 | }
|
461 | function d3_eventDispatch(target) {
|
462 | var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
|
463 | while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
|
464 | dispatch.of = function(thiz, argumentz) {
|
465 | return function(e1) {
|
466 | try {
|
467 | var e0 = e1.sourceEvent = d3.event;
|
468 | e1.target = target;
|
469 | d3.event = e1;
|
470 | dispatch[e1.type].apply(thiz, argumentz);
|
471 | } finally {
|
472 | d3.event = e0;
|
473 | }
|
474 | };
|
475 | };
|
476 | return dispatch;
|
477 | }
|
478 | d3.requote = function(s) {
|
479 | return s.replace(d3_requote_re, "\\$&");
|
480 | };
|
481 | var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
|
482 | var d3_subclass = {}.__proto__ ? function(object, prototype) {
|
483 | object.__proto__ = prototype;
|
484 | } : function(object, prototype) {
|
485 | for (var property in prototype) object[property] = prototype[property];
|
486 | };
|
487 | function d3_selection(groups) {
|
488 | d3_subclass(groups, d3_selectionPrototype);
|
489 | return groups;
|
490 | }
|
491 | var d3_select = function(s, n) {
|
492 | return n.querySelector(s);
|
493 | }, d3_selectAll = function(s, n) {
|
494 | return n.querySelectorAll(s);
|
495 | }, d3_selectMatcher = d3_documentElement.matches || d3_documentElement[d3_vendorSymbol(d3_documentElement, "matchesSelector")], d3_selectMatches = function(n, s) {
|
496 | return d3_selectMatcher.call(n, s);
|
497 | };
|
498 | if (typeof Sizzle === "function") {
|
499 | d3_select = function(s, n) {
|
500 | return Sizzle(s, n)[0] || null;
|
501 | };
|
502 | d3_selectAll = Sizzle;
|
503 | d3_selectMatches = Sizzle.matchesSelector;
|
504 | }
|
505 | d3.selection = function() {
|
506 | return d3_selectionRoot;
|
507 | };
|
508 | var d3_selectionPrototype = d3.selection.prototype = [];
|
509 | d3_selectionPrototype.select = function(selector) {
|
510 | var subgroups = [], subgroup, subnode, group, node;
|
511 | selector = d3_selection_selector(selector);
|
512 | for (var j = -1, m = this.length; ++j < m; ) {
|
513 | subgroups.push(subgroup = []);
|
514 | subgroup.parentNode = (group = this[j]).parentNode;
|
515 | for (var i = -1, n = group.length; ++i < n; ) {
|
516 | if (node = group[i]) {
|
517 | subgroup.push(subnode = selector.call(node, node.__data__, i, j));
|
518 | if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
|
519 | } else {
|
520 | subgroup.push(null);
|
521 | }
|
522 | }
|
523 | }
|
524 | return d3_selection(subgroups);
|
525 | };
|
526 | function d3_selection_selector(selector) {
|
527 | return typeof selector === "function" ? selector : function() {
|
528 | return d3_select(selector, this);
|
529 | };
|
530 | }
|
531 | d3_selectionPrototype.selectAll = function(selector) {
|
532 | var subgroups = [], subgroup, node;
|
533 | selector = d3_selection_selectorAll(selector);
|
534 | for (var j = -1, m = this.length; ++j < m; ) {
|
535 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
|
536 | if (node = group[i]) {
|
537 | subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
|
538 | subgroup.parentNode = node;
|
539 | }
|
540 | }
|
541 | }
|
542 | return d3_selection(subgroups);
|
543 | };
|
544 | function d3_selection_selectorAll(selector) {
|
545 | return typeof selector === "function" ? selector : function() {
|
546 | return d3_selectAll(selector, this);
|
547 | };
|
548 | }
|
549 | var d3_nsPrefix = {
|
550 | svg: "http://www.w3.org/2000/svg",
|
551 | xhtml: "http://www.w3.org/1999/xhtml",
|
552 | xlink: "http://www.w3.org/1999/xlink",
|
553 | xml: "http://www.w3.org/XML/1998/namespace",
|
554 | xmlns: "http://www.w3.org/2000/xmlns/"
|
555 | };
|
556 | d3.ns = {
|
557 | prefix: d3_nsPrefix,
|
558 | qualify: function(name) {
|
559 | var i = name.indexOf(":"), prefix = name;
|
560 | if (i >= 0) {
|
561 | prefix = name.substring(0, i);
|
562 | name = name.substring(i + 1);
|
563 | }
|
564 | return d3_nsPrefix.hasOwnProperty(prefix) ? {
|
565 | space: d3_nsPrefix[prefix],
|
566 | local: name
|
567 | } : name;
|
568 | }
|
569 | };
|
570 | d3_selectionPrototype.attr = function(name, value) {
|
571 | if (arguments.length < 2) {
|
572 | if (typeof name === "string") {
|
573 | var node = this.node();
|
574 | name = d3.ns.qualify(name);
|
575 | return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
|
576 | }
|
577 | for (value in name) this.each(d3_selection_attr(value, name[value]));
|
578 | return this;
|
579 | }
|
580 | return this.each(d3_selection_attr(name, value));
|
581 | };
|
582 | function d3_selection_attr(name, value) {
|
583 | name = d3.ns.qualify(name);
|
584 | function attrNull() {
|
585 | this.removeAttribute(name);
|
586 | }
|
587 | function attrNullNS() {
|
588 | this.removeAttributeNS(name.space, name.local);
|
589 | }
|
590 | function attrConstant() {
|
591 | this.setAttribute(name, value);
|
592 | }
|
593 | function attrConstantNS() {
|
594 | this.setAttributeNS(name.space, name.local, value);
|
595 | }
|
596 | function attrFunction() {
|
597 | var x = value.apply(this, arguments);
|
598 | if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
|
599 | }
|
600 | function attrFunctionNS() {
|
601 | var x = value.apply(this, arguments);
|
602 | if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
|
603 | }
|
604 | return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
|
605 | }
|
606 | function d3_collapse(s) {
|
607 | return s.trim().replace(/\s+/g, " ");
|
608 | }
|
609 | d3_selectionPrototype.classed = function(name, value) {
|
610 | if (arguments.length < 2) {
|
611 | if (typeof name === "string") {
|
612 | var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
|
613 | if (value = node.classList) {
|
614 | while (++i < n) if (!value.contains(name[i])) return false;
|
615 | } else {
|
616 | value = node.getAttribute("class");
|
617 | while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
|
618 | }
|
619 | return true;
|
620 | }
|
621 | for (value in name) this.each(d3_selection_classed(value, name[value]));
|
622 | return this;
|
623 | }
|
624 | return this.each(d3_selection_classed(name, value));
|
625 | };
|
626 | function d3_selection_classedRe(name) {
|
627 | return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
|
628 | }
|
629 | function d3_selection_classes(name) {
|
630 | return (name + "").trim().split(/^|\s+/);
|
631 | }
|
632 | function d3_selection_classed(name, value) {
|
633 | name = d3_selection_classes(name).map(d3_selection_classedName);
|
634 | var n = name.length;
|
635 | function classedConstant() {
|
636 | var i = -1;
|
637 | while (++i < n) name[i](this, value);
|
638 | }
|
639 | function classedFunction() {
|
640 | var i = -1, x = value.apply(this, arguments);
|
641 | while (++i < n) name[i](this, x);
|
642 | }
|
643 | return typeof value === "function" ? classedFunction : classedConstant;
|
644 | }
|
645 | function d3_selection_classedName(name) {
|
646 | var re = d3_selection_classedRe(name);
|
647 | return function(node, value) {
|
648 | if (c = node.classList) return value ? c.add(name) : c.remove(name);
|
649 | var c = node.getAttribute("class") || "";
|
650 | if (value) {
|
651 | re.lastIndex = 0;
|
652 | if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
|
653 | } else {
|
654 | node.setAttribute("class", d3_collapse(c.replace(re, " ")));
|
655 | }
|
656 | };
|
657 | }
|
658 | d3_selectionPrototype.style = function(name, value, priority) {
|
659 | var n = arguments.length;
|
660 | if (n < 3) {
|
661 | if (typeof name !== "string") {
|
662 | if (n < 2) value = "";
|
663 | for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
|
664 | return this;
|
665 | }
|
666 | if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
|
667 | priority = "";
|
668 | }
|
669 | return this.each(d3_selection_style(name, value, priority));
|
670 | };
|
671 | function d3_selection_style(name, value, priority) {
|
672 | function styleNull() {
|
673 | this.style.removeProperty(name);
|
674 | }
|
675 | function styleConstant() {
|
676 | this.style.setProperty(name, value, priority);
|
677 | }
|
678 | function styleFunction() {
|
679 | var x = value.apply(this, arguments);
|
680 | if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
|
681 | }
|
682 | return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
|
683 | }
|
684 | d3_selectionPrototype.property = function(name, value) {
|
685 | if (arguments.length < 2) {
|
686 | if (typeof name === "string") return this.node()[name];
|
687 | for (value in name) this.each(d3_selection_property(value, name[value]));
|
688 | return this;
|
689 | }
|
690 | return this.each(d3_selection_property(name, value));
|
691 | };
|
692 | function d3_selection_property(name, value) {
|
693 | function propertyNull() {
|
694 | delete this[name];
|
695 | }
|
696 | function propertyConstant() {
|
697 | this[name] = value;
|
698 | }
|
699 | function propertyFunction() {
|
700 | var x = value.apply(this, arguments);
|
701 | if (x == null) delete this[name]; else this[name] = x;
|
702 | }
|
703 | return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
|
704 | }
|
705 | d3_selectionPrototype.text = function(value) {
|
706 | return arguments.length ? this.each(typeof value === "function" ? function() {
|
707 | var v = value.apply(this, arguments);
|
708 | this.textContent = v == null ? "" : v;
|
709 | } : value == null ? function() {
|
710 | this.textContent = "";
|
711 | } : function() {
|
712 | this.textContent = value;
|
713 | }) : this.node().textContent;
|
714 | };
|
715 | d3_selectionPrototype.html = function(value) {
|
716 | return arguments.length ? this.each(typeof value === "function" ? function() {
|
717 | var v = value.apply(this, arguments);
|
718 | this.innerHTML = v == null ? "" : v;
|
719 | } : value == null ? function() {
|
720 | this.innerHTML = "";
|
721 | } : function() {
|
722 | this.innerHTML = value;
|
723 | }) : this.node().innerHTML;
|
724 | };
|
725 | d3_selectionPrototype.append = function(name) {
|
726 | name = d3_selection_creator(name);
|
727 | return this.select(function() {
|
728 | return this.appendChild(name.apply(this, arguments));
|
729 | });
|
730 | };
|
731 | function d3_selection_creator(name) {
|
732 | return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? function() {
|
733 | return this.ownerDocument.createElementNS(name.space, name.local);
|
734 | } : function() {
|
735 | return this.ownerDocument.createElementNS(this.namespaceURI, name);
|
736 | };
|
737 | }
|
738 | d3_selectionPrototype.insert = function(name, before) {
|
739 | name = d3_selection_creator(name);
|
740 | before = d3_selection_selector(before);
|
741 | return this.select(function() {
|
742 | return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
|
743 | });
|
744 | };
|
745 | d3_selectionPrototype.remove = function() {
|
746 | return this.each(function() {
|
747 | var parent = this.parentNode;
|
748 | if (parent) parent.removeChild(this);
|
749 | });
|
750 | };
|
751 | d3_selectionPrototype.data = function(value, key) {
|
752 | var i = -1, n = this.length, group, node;
|
753 | if (!arguments.length) {
|
754 | value = new Array(n = (group = this[0]).length);
|
755 | while (++i < n) {
|
756 | if (node = group[i]) {
|
757 | value[i] = node.__data__;
|
758 | }
|
759 | }
|
760 | return value;
|
761 | }
|
762 | function bind(group, groupData) {
|
763 | 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;
|
764 | if (key) {
|
765 | var nodeByKeyValue = new d3_Map(), dataByKeyValue = new d3_Map(), keyValues = [], keyValue;
|
766 | for (i = -1; ++i < n; ) {
|
767 | keyValue = key.call(node = group[i], node.__data__, i);
|
768 | if (nodeByKeyValue.has(keyValue)) {
|
769 | exitNodes[i] = node;
|
770 | } else {
|
771 | nodeByKeyValue.set(keyValue, node);
|
772 | }
|
773 | keyValues.push(keyValue);
|
774 | }
|
775 | for (i = -1; ++i < m; ) {
|
776 | keyValue = key.call(groupData, nodeData = groupData[i], i);
|
777 | if (node = nodeByKeyValue.get(keyValue)) {
|
778 | updateNodes[i] = node;
|
779 | node.__data__ = nodeData;
|
780 | } else if (!dataByKeyValue.has(keyValue)) {
|
781 | enterNodes[i] = d3_selection_dataNode(nodeData);
|
782 | }
|
783 | dataByKeyValue.set(keyValue, nodeData);
|
784 | nodeByKeyValue.remove(keyValue);
|
785 | }
|
786 | for (i = -1; ++i < n; ) {
|
787 | if (nodeByKeyValue.has(keyValues[i])) {
|
788 | exitNodes[i] = group[i];
|
789 | }
|
790 | }
|
791 | } else {
|
792 | for (i = -1; ++i < n0; ) {
|
793 | node = group[i];
|
794 | nodeData = groupData[i];
|
795 | if (node) {
|
796 | node.__data__ = nodeData;
|
797 | updateNodes[i] = node;
|
798 | } else {
|
799 | enterNodes[i] = d3_selection_dataNode(nodeData);
|
800 | }
|
801 | }
|
802 | for (;i < m; ++i) {
|
803 | enterNodes[i] = d3_selection_dataNode(groupData[i]);
|
804 | }
|
805 | for (;i < n; ++i) {
|
806 | exitNodes[i] = group[i];
|
807 | }
|
808 | }
|
809 | enterNodes.update = updateNodes;
|
810 | enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
|
811 | enter.push(enterNodes);
|
812 | update.push(updateNodes);
|
813 | exit.push(exitNodes);
|
814 | }
|
815 | var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
|
816 | if (typeof value === "function") {
|
817 | while (++i < n) {
|
818 | bind(group = this[i], value.call(group, group.parentNode.__data__, i));
|
819 | }
|
820 | } else {
|
821 | while (++i < n) {
|
822 | bind(group = this[i], value);
|
823 | }
|
824 | }
|
825 | update.enter = function() {
|
826 | return enter;
|
827 | };
|
828 | update.exit = function() {
|
829 | return exit;
|
830 | };
|
831 | return update;
|
832 | };
|
833 | function d3_selection_dataNode(data) {
|
834 | return {
|
835 | __data__: data
|
836 | };
|
837 | }
|
838 | d3_selectionPrototype.datum = function(value) {
|
839 | return arguments.length ? this.property("__data__", value) : this.property("__data__");
|
840 | };
|
841 | d3_selectionPrototype.filter = function(filter) {
|
842 | var subgroups = [], subgroup, group, node;
|
843 | if (typeof filter !== "function") filter = d3_selection_filter(filter);
|
844 | for (var j = 0, m = this.length; j < m; j++) {
|
845 | subgroups.push(subgroup = []);
|
846 | subgroup.parentNode = (group = this[j]).parentNode;
|
847 | for (var i = 0, n = group.length; i < n; i++) {
|
848 | if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
|
849 | subgroup.push(node);
|
850 | }
|
851 | }
|
852 | }
|
853 | return d3_selection(subgroups);
|
854 | };
|
855 | function d3_selection_filter(selector) {
|
856 | return function() {
|
857 | return d3_selectMatches(this, selector);
|
858 | };
|
859 | }
|
860 | d3_selectionPrototype.order = function() {
|
861 | for (var j = -1, m = this.length; ++j < m; ) {
|
862 | for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
|
863 | if (node = group[i]) {
|
864 | if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
|
865 | next = node;
|
866 | }
|
867 | }
|
868 | }
|
869 | return this;
|
870 | };
|
871 | d3_selectionPrototype.sort = function(comparator) {
|
872 | comparator = d3_selection_sortComparator.apply(this, arguments);
|
873 | for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
|
874 | return this.order();
|
875 | };
|
876 | function d3_selection_sortComparator(comparator) {
|
877 | if (!arguments.length) comparator = d3_ascending;
|
878 | return function(a, b) {
|
879 | return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
|
880 | };
|
881 | }
|
882 | d3_selectionPrototype.each = function(callback) {
|
883 | return d3_selection_each(this, function(node, i, j) {
|
884 | callback.call(node, node.__data__, i, j);
|
885 | });
|
886 | };
|
887 | function d3_selection_each(groups, callback) {
|
888 | for (var j = 0, m = groups.length; j < m; j++) {
|
889 | for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
|
890 | if (node = group[i]) callback(node, i, j);
|
891 | }
|
892 | }
|
893 | return groups;
|
894 | }
|
895 | d3_selectionPrototype.call = function(callback) {
|
896 | var args = d3_array(arguments);
|
897 | callback.apply(args[0] = this, args);
|
898 | return this;
|
899 | };
|
900 | d3_selectionPrototype.empty = function() {
|
901 | return !this.node();
|
902 | };
|
903 | d3_selectionPrototype.node = function() {
|
904 | for (var j = 0, m = this.length; j < m; j++) {
|
905 | for (var group = this[j], i = 0, n = group.length; i < n; i++) {
|
906 | var node = group[i];
|
907 | if (node) return node;
|
908 | }
|
909 | }
|
910 | return null;
|
911 | };
|
912 | d3_selectionPrototype.size = function() {
|
913 | var n = 0;
|
914 | this.each(function() {
|
915 | ++n;
|
916 | });
|
917 | return n;
|
918 | };
|
919 | function d3_selection_enter(selection) {
|
920 | d3_subclass(selection, d3_selection_enterPrototype);
|
921 | return selection;
|
922 | }
|
923 | var d3_selection_enterPrototype = [];
|
924 | d3.selection.enter = d3_selection_enter;
|
925 | d3.selection.enter.prototype = d3_selection_enterPrototype;
|
926 | d3_selection_enterPrototype.append = d3_selectionPrototype.append;
|
927 | d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
|
928 | d3_selection_enterPrototype.node = d3_selectionPrototype.node;
|
929 | d3_selection_enterPrototype.call = d3_selectionPrototype.call;
|
930 | d3_selection_enterPrototype.size = d3_selectionPrototype.size;
|
931 | d3_selection_enterPrototype.select = function(selector) {
|
932 | var subgroups = [], subgroup, subnode, upgroup, group, node;
|
933 | for (var j = -1, m = this.length; ++j < m; ) {
|
934 | upgroup = (group = this[j]).update;
|
935 | subgroups.push(subgroup = []);
|
936 | subgroup.parentNode = group.parentNode;
|
937 | for (var i = -1, n = group.length; ++i < n; ) {
|
938 | if (node = group[i]) {
|
939 | subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
|
940 | subnode.__data__ = node.__data__;
|
941 | } else {
|
942 | subgroup.push(null);
|
943 | }
|
944 | }
|
945 | }
|
946 | return d3_selection(subgroups);
|
947 | };
|
948 | d3_selection_enterPrototype.insert = function(name, before) {
|
949 | if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
|
950 | return d3_selectionPrototype.insert.call(this, name, before);
|
951 | };
|
952 | function d3_selection_enterInsertBefore(enter) {
|
953 | var i0, j0;
|
954 | return function(d, i, j) {
|
955 | var group = enter[j].update, n = group.length, node;
|
956 | if (j != j0) j0 = j, i0 = 0;
|
957 | if (i >= i0) i0 = i + 1;
|
958 | while (!(node = group[i0]) && ++i0 < n) ;
|
959 | return node;
|
960 | };
|
961 | }
|
962 | d3_selectionPrototype.transition = function() {
|
963 | var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = d3_transitionInherit || {
|
964 | time: Date.now(),
|
965 | ease: d3_ease_cubicInOut,
|
966 | delay: 0,
|
967 | duration: 250
|
968 | };
|
969 | for (var j = -1, m = this.length; ++j < m; ) {
|
970 | subgroups.push(subgroup = []);
|
971 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
|
972 | if (node = group[i]) d3_transitionNode(node, i, id, transition);
|
973 | subgroup.push(node);
|
974 | }
|
975 | }
|
976 | return d3_transition(subgroups, id);
|
977 | };
|
978 | d3_selectionPrototype.interrupt = function() {
|
979 | return this.each(d3_selection_interrupt);
|
980 | };
|
981 | function d3_selection_interrupt() {
|
982 | var lock = this.__transition__;
|
983 | if (lock) ++lock.active;
|
984 | }
|
985 | d3.select = function(node) {
|
986 | var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
|
987 | group.parentNode = d3_documentElement;
|
988 | return d3_selection([ group ]);
|
989 | };
|
990 | d3.selectAll = function(nodes) {
|
991 | var group = d3_array(typeof nodes === "string" ? d3_selectAll(nodes, d3_document) : nodes);
|
992 | group.parentNode = d3_documentElement;
|
993 | return d3_selection([ group ]);
|
994 | };
|
995 | var d3_selectionRoot = d3.select(d3_documentElement);
|
996 | d3_selectionPrototype.on = function(type, listener, capture) {
|
997 | var n = arguments.length;
|
998 | if (n < 3) {
|
999 | if (typeof type !== "string") {
|
1000 | if (n < 2) listener = false;
|
1001 | for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
|
1002 | return this;
|
1003 | }
|
1004 | if (n < 2) return (n = this.node()["__on" + type]) && n._;
|
1005 | capture = false;
|
1006 | }
|
1007 | return this.each(d3_selection_on(type, listener, capture));
|
1008 | };
|
1009 | function d3_selection_on(type, listener, capture) {
|
1010 | var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
|
1011 | if (i > 0) type = type.substring(0, i);
|
1012 | var filter = d3_selection_onFilters.get(type);
|
1013 | if (filter) type = filter, wrap = d3_selection_onFilter;
|
1014 | function onRemove() {
|
1015 | var l = this[name];
|
1016 | if (l) {
|
1017 | this.removeEventListener(type, l, l.$);
|
1018 | delete this[name];
|
1019 | }
|
1020 | }
|
1021 | function onAdd() {
|
1022 | var l = wrap(listener, d3_array(arguments));
|
1023 | onRemove.call(this);
|
1024 | this.addEventListener(type, this[name] = l, l.$ = capture);
|
1025 | l._ = listener;
|
1026 | }
|
1027 | function removeAll() {
|
1028 | var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
|
1029 | for (var name in this) {
|
1030 | if (match = name.match(re)) {
|
1031 | var l = this[name];
|
1032 | this.removeEventListener(match[1], l, l.$);
|
1033 | delete this[name];
|
1034 | }
|
1035 | }
|
1036 | }
|
1037 | return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
|
1038 | }
|
1039 | var d3_selection_onFilters = d3.map({
|
1040 | mouseenter: "mouseover",
|
1041 | mouseleave: "mouseout"
|
1042 | });
|
1043 | d3_selection_onFilters.forEach(function(k) {
|
1044 | if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
|
1045 | });
|
1046 | function d3_selection_onListener(listener, argumentz) {
|
1047 | return function(e) {
|
1048 | var o = d3.event;
|
1049 | d3.event = e;
|
1050 | argumentz[0] = this.__data__;
|
1051 | try {
|
1052 | listener.apply(this, argumentz);
|
1053 | } finally {
|
1054 | d3.event = o;
|
1055 | }
|
1056 | };
|
1057 | }
|
1058 | function d3_selection_onFilter(listener, argumentz) {
|
1059 | var l = d3_selection_onListener(listener, argumentz);
|
1060 | return function(e) {
|
1061 | var target = this, related = e.relatedTarget;
|
1062 | if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
|
1063 | l.call(target, e);
|
1064 | }
|
1065 | };
|
1066 | }
|
1067 | var d3_event_dragSelect = "onselectstart" in d3_document ? null : d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0;
|
1068 | function d3_event_dragSuppress() {
|
1069 | var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
|
1070 | if (d3_event_dragSelect) {
|
1071 | var style = d3_documentElement.style, select = style[d3_event_dragSelect];
|
1072 | style[d3_event_dragSelect] = "none";
|
1073 | }
|
1074 | return function(suppressClick) {
|
1075 | w.on(name, null);
|
1076 | if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
|
1077 | if (suppressClick) {
|
1078 | function off() {
|
1079 | w.on(click, null);
|
1080 | }
|
1081 | w.on(click, function() {
|
1082 | d3_eventPreventDefault();
|
1083 | off();
|
1084 | }, true);
|
1085 | setTimeout(off, 0);
|
1086 | }
|
1087 | };
|
1088 | }
|
1089 | d3.mouse = function(container) {
|
1090 | return d3_mousePoint(container, d3_eventSource());
|
1091 | };
|
1092 | var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
|
1093 | function d3_mousePoint(container, e) {
|
1094 | if (e.changedTouches) e = e.changedTouches[0];
|
1095 | var svg = container.ownerSVGElement || container;
|
1096 | if (svg.createSVGPoint) {
|
1097 | var point = svg.createSVGPoint();
|
1098 | if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
|
1099 | svg = d3.select("body").append("svg").style({
|
1100 | position: "absolute",
|
1101 | top: 0,
|
1102 | left: 0,
|
1103 | margin: 0,
|
1104 | padding: 0,
|
1105 | border: "none"
|
1106 | }, "important");
|
1107 | var ctm = svg[0][0].getScreenCTM();
|
1108 | d3_mouse_bug44083 = !(ctm.f || ctm.e);
|
1109 | svg.remove();
|
1110 | }
|
1111 | if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
|
1112 | point.y = e.clientY;
|
1113 | point = point.matrixTransform(container.getScreenCTM().inverse());
|
1114 | return [ point.x, point.y ];
|
1115 | }
|
1116 | var rect = container.getBoundingClientRect();
|
1117 | return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
|
1118 | }
|
1119 | d3.touches = function(container, touches) {
|
1120 | if (arguments.length < 2) touches = d3_eventSource().touches;
|
1121 | return touches ? d3_array(touches).map(function(touch) {
|
1122 | var point = d3_mousePoint(container, touch);
|
1123 | point.identifier = touch.identifier;
|
1124 | return point;
|
1125 | }) : [];
|
1126 | };
|
1127 | d3.behavior.drag = function() {
|
1128 | var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_behavior_dragMouseSubject, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_behavior_dragTouchSubject, "touchmove", "touchend");
|
1129 | function drag() {
|
1130 | this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
|
1131 | }
|
1132 | function dragstart(id, position, subject, move, end) {
|
1133 | return function() {
|
1134 | var that = this, target = 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()).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(), position0 = position(parent, dragId);
|
1135 | if (origin) {
|
1136 | dragOffset = origin.apply(that, arguments);
|
1137 | dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
|
1138 | } else {
|
1139 | dragOffset = [ 0, 0 ];
|
1140 | }
|
1141 | dispatch({
|
1142 | type: "dragstart"
|
1143 | });
|
1144 | function moved() {
|
1145 | var position1 = position(parent, dragId), dx, dy;
|
1146 | if (!position1) return;
|
1147 | dx = position1[0] - position0[0];
|
1148 | dy = position1[1] - position0[1];
|
1149 | dragged |= dx | dy;
|
1150 | position0 = position1;
|
1151 | dispatch({
|
1152 | type: "drag",
|
1153 | x: position1[0] + dragOffset[0],
|
1154 | y: position1[1] + dragOffset[1],
|
1155 | dx: dx,
|
1156 | dy: dy
|
1157 | });
|
1158 | }
|
1159 | function ended() {
|
1160 | if (!position(parent, dragId)) return;
|
1161 | dragSubject.on(move + dragName, null).on(end + dragName, null);
|
1162 | dragRestore(dragged && d3.event.target === target);
|
1163 | dispatch({
|
1164 | type: "dragend"
|
1165 | });
|
1166 | }
|
1167 | };
|
1168 | }
|
1169 | drag.origin = function(x) {
|
1170 | if (!arguments.length) return origin;
|
1171 | origin = x;
|
1172 | return drag;
|
1173 | };
|
1174 | return d3.rebind(drag, event, "on");
|
1175 | };
|
1176 | function d3_behavior_dragTouchId() {
|
1177 | return d3.event.changedTouches[0].identifier;
|
1178 | }
|
1179 | function d3_behavior_dragTouchSubject() {
|
1180 | return d3.event.target;
|
1181 | }
|
1182 | function d3_behavior_dragMouseSubject() {
|
1183 | return d3_window;
|
1184 | }
|
1185 | var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
|
1186 | function d3_sgn(x) {
|
1187 | return x > 0 ? 1 : x < 0 ? -1 : 0;
|
1188 | }
|
1189 | function d3_cross2d(a, b, c) {
|
1190 | return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
1191 | }
|
1192 | function d3_acos(x) {
|
1193 | return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
|
1194 | }
|
1195 | function d3_asin(x) {
|
1196 | return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
|
1197 | }
|
1198 | function d3_sinh(x) {
|
1199 | return ((x = Math.exp(x)) - 1 / x) / 2;
|
1200 | }
|
1201 | function d3_cosh(x) {
|
1202 | return ((x = Math.exp(x)) + 1 / x) / 2;
|
1203 | }
|
1204 | function d3_tanh(x) {
|
1205 | return ((x = Math.exp(2 * x)) - 1) / (x + 1);
|
1206 | }
|
1207 | function d3_haversin(x) {
|
1208 | return (x = Math.sin(x / 2)) * x;
|
1209 | }
|
1210 | var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
|
1211 | d3.interpolateZoom = function(p0, p1) {
|
1212 | var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
|
1213 | var dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, 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), dr = r1 - r0, S = (dr || Math.log(w1 / w0)) / ρ;
|
1214 | function interpolate(t) {
|
1215 | var s = t * S;
|
1216 | if (dr) {
|
1217 | var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
|
1218 | return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
|
1219 | }
|
1220 | return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
|
1221 | }
|
1222 | interpolate.duration = S * 1e3;
|
1223 | return interpolate;
|
1224 | };
|
1225 | d3.behavior.zoom = function() {
|
1226 | var view = {
|
1227 | x: 0,
|
1228 | y: 0,
|
1229 | k: 1
|
1230 | }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, 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;
|
1231 | function zoom(g) {
|
1232 | g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
|
1233 | }
|
1234 | zoom.event = function(g) {
|
1235 | g.each(function() {
|
1236 | var dispatch = event.of(this, arguments), view1 = view;
|
1237 | if (d3_transitionInheritId) {
|
1238 | d3.select(this).transition().each("start.zoom", function() {
|
1239 | view = this.__chart__ || {
|
1240 | x: 0,
|
1241 | y: 0,
|
1242 | k: 1
|
1243 | };
|
1244 | zoomstarted(dispatch);
|
1245 | }).tween("zoom:zoom", function() {
|
1246 | var dx = size[0], dy = size[1], cx = dx / 2, cy = 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 ]);
|
1247 | return function(t) {
|
1248 | var l = i(t), k = dx / l[2];
|
1249 | this.__chart__ = view = {
|
1250 | x: cx - l[0] * k,
|
1251 | y: cy - l[1] * k,
|
1252 | k: k
|
1253 | };
|
1254 | zoomed(dispatch);
|
1255 | };
|
1256 | }).each("end.zoom", function() {
|
1257 | zoomended(dispatch);
|
1258 | });
|
1259 | } else {
|
1260 | this.__chart__ = view;
|
1261 | zoomstarted(dispatch);
|
1262 | zoomed(dispatch);
|
1263 | zoomended(dispatch);
|
1264 | }
|
1265 | });
|
1266 | };
|
1267 | zoom.translate = function(_) {
|
1268 | if (!arguments.length) return [ view.x, view.y ];
|
1269 | view = {
|
1270 | x: +_[0],
|
1271 | y: +_[1],
|
1272 | k: view.k
|
1273 | };
|
1274 | rescale();
|
1275 | return zoom;
|
1276 | };
|
1277 | zoom.scale = function(_) {
|
1278 | if (!arguments.length) return view.k;
|
1279 | view = {
|
1280 | x: view.x,
|
1281 | y: view.y,
|
1282 | k: +_
|
1283 | };
|
1284 | rescale();
|
1285 | return zoom;
|
1286 | };
|
1287 | zoom.scaleExtent = function(_) {
|
1288 | if (!arguments.length) return scaleExtent;
|
1289 | scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
|
1290 | return zoom;
|
1291 | };
|
1292 | zoom.center = function(_) {
|
1293 | if (!arguments.length) return center;
|
1294 | center = _ && [ +_[0], +_[1] ];
|
1295 | return zoom;
|
1296 | };
|
1297 | zoom.size = function(_) {
|
1298 | if (!arguments.length) return size;
|
1299 | size = _ && [ +_[0], +_[1] ];
|
1300 | return zoom;
|
1301 | };
|
1302 | zoom.x = function(z) {
|
1303 | if (!arguments.length) return x1;
|
1304 | x1 = z;
|
1305 | x0 = z.copy();
|
1306 | view = {
|
1307 | x: 0,
|
1308 | y: 0,
|
1309 | k: 1
|
1310 | };
|
1311 | return zoom;
|
1312 | };
|
1313 | zoom.y = function(z) {
|
1314 | if (!arguments.length) return y1;
|
1315 | y1 = z;
|
1316 | y0 = z.copy();
|
1317 | view = {
|
1318 | x: 0,
|
1319 | y: 0,
|
1320 | k: 1
|
1321 | };
|
1322 | return zoom;
|
1323 | };
|
1324 | function location(p) {
|
1325 | return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
|
1326 | }
|
1327 | function point(l) {
|
1328 | return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
|
1329 | }
|
1330 | function scaleTo(s) {
|
1331 | view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
|
1332 | }
|
1333 | function translateTo(p, l) {
|
1334 | l = point(l);
|
1335 | view.x += p[0] - l[0];
|
1336 | view.y += p[1] - l[1];
|
1337 | }
|
1338 | function rescale() {
|
1339 | if (x1) x1.domain(x0.range().map(function(x) {
|
1340 | return (x - view.x) / view.k;
|
1341 | }).map(x0.invert));
|
1342 | if (y1) y1.domain(y0.range().map(function(y) {
|
1343 | return (y - view.y) / view.k;
|
1344 | }).map(y0.invert));
|
1345 | }
|
1346 | function zoomstarted(dispatch) {
|
1347 | dispatch({
|
1348 | type: "zoomstart"
|
1349 | });
|
1350 | }
|
1351 | function zoomed(dispatch) {
|
1352 | rescale();
|
1353 | dispatch({
|
1354 | type: "zoom",
|
1355 | scale: view.k,
|
1356 | translate: [ view.x, view.y ]
|
1357 | });
|
1358 | }
|
1359 | function zoomended(dispatch) {
|
1360 | dispatch({
|
1361 | type: "zoomend"
|
1362 | });
|
1363 | }
|
1364 | function mousedowned() {
|
1365 | var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress();
|
1366 | d3_selection_interrupt.call(that);
|
1367 | zoomstarted(dispatch);
|
1368 | function moved() {
|
1369 | dragged = 1;
|
1370 | translateTo(d3.mouse(that), location0);
|
1371 | zoomed(dispatch);
|
1372 | }
|
1373 | function ended() {
|
1374 | subject.on(mousemove, null).on(mouseup, null);
|
1375 | dragRestore(dragged && d3.event.target === target);
|
1376 | zoomended(dispatch);
|
1377 | }
|
1378 | }
|
1379 | function touchstarted() {
|
1380 | 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).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
|
1381 | d3_selection_interrupt.call(that);
|
1382 | started();
|
1383 | zoomstarted(dispatch);
|
1384 | function relocate() {
|
1385 | var touches = d3.touches(that);
|
1386 | scale0 = view.k;
|
1387 | touches.forEach(function(t) {
|
1388 | if (t.identifier in locations0) locations0[t.identifier] = location(t);
|
1389 | });
|
1390 | return touches;
|
1391 | }
|
1392 | function started() {
|
1393 | var target = d3.event.target;
|
1394 | d3.select(target).on(touchmove, moved).on(touchend, ended);
|
1395 | targets.push(target);
|
1396 | var changed = d3.event.changedTouches;
|
1397 | for (var i = 0, n = changed.length; i < n; ++i) {
|
1398 | locations0[changed[i].identifier] = null;
|
1399 | }
|
1400 | var touches = relocate(), now = Date.now();
|
1401 | if (touches.length === 1) {
|
1402 | if (now - touchtime < 500) {
|
1403 | var p = touches[0], l = locations0[p.identifier];
|
1404 | scaleTo(view.k * 2);
|
1405 | translateTo(p, l);
|
1406 | d3_eventPreventDefault();
|
1407 | zoomed(dispatch);
|
1408 | }
|
1409 | touchtime = now;
|
1410 | } else if (touches.length > 1) {
|
1411 | var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
|
1412 | distance0 = dx * dx + dy * dy;
|
1413 | }
|
1414 | }
|
1415 | function moved() {
|
1416 | var touches = d3.touches(that), p0, l0, p1, l1;
|
1417 | for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
|
1418 | p1 = touches[i];
|
1419 | if (l1 = locations0[p1.identifier]) {
|
1420 | if (l0) break;
|
1421 | p0 = p1, l0 = l1;
|
1422 | }
|
1423 | }
|
1424 | if (l1) {
|
1425 | var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
|
1426 | p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
|
1427 | l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
|
1428 | scaleTo(scale1 * scale0);
|
1429 | }
|
1430 | touchtime = null;
|
1431 | translateTo(p0, l0);
|
1432 | zoomed(dispatch);
|
1433 | }
|
1434 | function ended() {
|
1435 | if (d3.event.touches.length) {
|
1436 | var changed = d3.event.changedTouches;
|
1437 | for (var i = 0, n = changed.length; i < n; ++i) {
|
1438 | delete locations0[changed[i].identifier];
|
1439 | }
|
1440 | for (var identifier in locations0) {
|
1441 | return void relocate();
|
1442 | }
|
1443 | }
|
1444 | d3.selectAll(targets).on(zoomName, null);
|
1445 | subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
|
1446 | dragRestore();
|
1447 | zoomended(dispatch);
|
1448 | }
|
1449 | }
|
1450 | function mousewheeled() {
|
1451 | var dispatch = event.of(this, arguments);
|
1452 | if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)),
|
1453 | d3_selection_interrupt.call(this), zoomstarted(dispatch);
|
1454 | mousewheelTimer = setTimeout(function() {
|
1455 | mousewheelTimer = null;
|
1456 | zoomended(dispatch);
|
1457 | }, 50);
|
1458 | d3_eventPreventDefault();
|
1459 | scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
|
1460 | translateTo(center0, translate0);
|
1461 | zoomed(dispatch);
|
1462 | }
|
1463 | function dblclicked() {
|
1464 | var dispatch = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2;
|
1465 | zoomstarted(dispatch);
|
1466 | scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
|
1467 | translateTo(p, l);
|
1468 | zoomed(dispatch);
|
1469 | zoomended(dispatch);
|
1470 | }
|
1471 | return d3.rebind(zoom, event, "on");
|
1472 | };
|
1473 | var d3_behavior_zoomInfinity = [ 0, Infinity ];
|
1474 | var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
|
1475 | return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
|
1476 | }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
|
1477 | return d3.event.wheelDelta;
|
1478 | }, "mousewheel") : (d3_behavior_zoomDelta = function() {
|
1479 | return -d3.event.detail;
|
1480 | }, "MozMousePixelScroll");
|
1481 | d3.color = d3_color;
|
1482 | function d3_color() {}
|
1483 | d3_color.prototype.toString = function() {
|
1484 | return this.rgb() + "";
|
1485 | };
|
1486 | d3.hsl = d3_hsl;
|
1487 | function d3_hsl(h, s, l) {
|
1488 | 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);
|
1489 | }
|
1490 | var d3_hslPrototype = d3_hsl.prototype = new d3_color();
|
1491 | d3_hslPrototype.brighter = function(k) {
|
1492 | k = Math.pow(.7, arguments.length ? k : 1);
|
1493 | return new d3_hsl(this.h, this.s, this.l / k);
|
1494 | };
|
1495 | d3_hslPrototype.darker = function(k) {
|
1496 | k = Math.pow(.7, arguments.length ? k : 1);
|
1497 | return new d3_hsl(this.h, this.s, k * this.l);
|
1498 | };
|
1499 | d3_hslPrototype.rgb = function() {
|
1500 | return d3_hsl_rgb(this.h, this.s, this.l);
|
1501 | };
|
1502 | function d3_hsl_rgb(h, s, l) {
|
1503 | var m1, m2;
|
1504 | h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
|
1505 | s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
|
1506 | l = l < 0 ? 0 : l > 1 ? 1 : l;
|
1507 | m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
|
1508 | m1 = 2 * l - m2;
|
1509 | function v(h) {
|
1510 | if (h > 360) h -= 360; else if (h < 0) h += 360;
|
1511 | if (h < 60) return m1 + (m2 - m1) * h / 60;
|
1512 | if (h < 180) return m2;
|
1513 | if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
|
1514 | return m1;
|
1515 | }
|
1516 | function vv(h) {
|
1517 | return Math.round(v(h) * 255);
|
1518 | }
|
1519 | return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
|
1520 | }
|
1521 | d3.hcl = d3_hcl;
|
1522 | function d3_hcl(h, c, l) {
|
1523 | 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);
|
1524 | }
|
1525 | var d3_hclPrototype = d3_hcl.prototype = new d3_color();
|
1526 | d3_hclPrototype.brighter = function(k) {
|
1527 | return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
|
1528 | };
|
1529 | d3_hclPrototype.darker = function(k) {
|
1530 | return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
|
1531 | };
|
1532 | d3_hclPrototype.rgb = function() {
|
1533 | return d3_hcl_lab(this.h, this.c, this.l).rgb();
|
1534 | };
|
1535 | function d3_hcl_lab(h, c, l) {
|
1536 | if (isNaN(h)) h = 0;
|
1537 | if (isNaN(c)) c = 0;
|
1538 | return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
|
1539 | }
|
1540 | d3.lab = d3_lab;
|
1541 | function d3_lab(l, a, b) {
|
1542 | 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.l, l.c, l.h) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
|
1543 | }
|
1544 | var d3_lab_K = 18;
|
1545 | var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
|
1546 | var d3_labPrototype = d3_lab.prototype = new d3_color();
|
1547 | d3_labPrototype.brighter = function(k) {
|
1548 | return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
|
1549 | };
|
1550 | d3_labPrototype.darker = function(k) {
|
1551 | return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
|
1552 | };
|
1553 | d3_labPrototype.rgb = function() {
|
1554 | return d3_lab_rgb(this.l, this.a, this.b);
|
1555 | };
|
1556 | function d3_lab_rgb(l, a, b) {
|
1557 | var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
|
1558 | x = d3_lab_xyz(x) * d3_lab_X;
|
1559 | y = d3_lab_xyz(y) * d3_lab_Y;
|
1560 | z = d3_lab_xyz(z) * d3_lab_Z;
|
1561 | 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));
|
1562 | }
|
1563 | function d3_lab_hcl(l, a, b) {
|
1564 | 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);
|
1565 | }
|
1566 | function d3_lab_xyz(x) {
|
1567 | return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
|
1568 | }
|
1569 | function d3_xyz_lab(x) {
|
1570 | return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
|
1571 | }
|
1572 | function d3_xyz_rgb(r) {
|
1573 | return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
|
1574 | }
|
1575 | d3.rgb = d3_rgb;
|
1576 | function d3_rgb(r, g, b) {
|
1577 | 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);
|
1578 | }
|
1579 | function d3_rgbNumber(value) {
|
1580 | return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
|
1581 | }
|
1582 | function d3_rgbString(value) {
|
1583 | return d3_rgbNumber(value) + "";
|
1584 | }
|
1585 | var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
|
1586 | d3_rgbPrototype.brighter = function(k) {
|
1587 | k = Math.pow(.7, arguments.length ? k : 1);
|
1588 | var r = this.r, g = this.g, b = this.b, i = 30;
|
1589 | if (!r && !g && !b) return new d3_rgb(i, i, i);
|
1590 | if (r && r < i) r = i;
|
1591 | if (g && g < i) g = i;
|
1592 | if (b && b < i) b = i;
|
1593 | return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
|
1594 | };
|
1595 | d3_rgbPrototype.darker = function(k) {
|
1596 | k = Math.pow(.7, arguments.length ? k : 1);
|
1597 | return new d3_rgb(k * this.r, k * this.g, k * this.b);
|
1598 | };
|
1599 | d3_rgbPrototype.hsl = function() {
|
1600 | return d3_rgb_hsl(this.r, this.g, this.b);
|
1601 | };
|
1602 | d3_rgbPrototype.toString = function() {
|
1603 | return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
|
1604 | };
|
1605 | function d3_rgb_hex(v) {
|
1606 | return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
|
1607 | }
|
1608 | function d3_rgb_parse(format, rgb, hsl) {
|
1609 | var r = 0, g = 0, b = 0, m1, m2, color;
|
1610 | m1 = /([a-z]+)\((.*)\)/i.exec(format);
|
1611 | if (m1) {
|
1612 | m2 = m1[2].split(",");
|
1613 | switch (m1[1]) {
|
1614 | case "hsl":
|
1615 | {
|
1616 | return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
|
1617 | }
|
1618 |
|
1619 | case "rgb":
|
1620 | {
|
1621 | return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
|
1622 | }
|
1623 | }
|
1624 | }
|
1625 | if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b);
|
1626 | if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.substring(1), 16))) {
|
1627 | if (format.length === 4) {
|
1628 | r = (color & 3840) >> 4;
|
1629 | r = r >> 4 | r;
|
1630 | g = color & 240;
|
1631 | g = g >> 4 | g;
|
1632 | b = color & 15;
|
1633 | b = b << 4 | b;
|
1634 | } else if (format.length === 7) {
|
1635 | r = (color & 16711680) >> 16;
|
1636 | g = (color & 65280) >> 8;
|
1637 | b = color & 255;
|
1638 | }
|
1639 | }
|
1640 | return rgb(r, g, b);
|
1641 | }
|
1642 | function d3_rgb_hsl(r, g, b) {
|
1643 | 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;
|
1644 | if (d) {
|
1645 | s = l < .5 ? d / (max + min) : d / (2 - max - min);
|
1646 | 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;
|
1647 | h *= 60;
|
1648 | } else {
|
1649 | h = NaN;
|
1650 | s = l > 0 && l < 1 ? 0 : h;
|
1651 | }
|
1652 | return new d3_hsl(h, s, l);
|
1653 | }
|
1654 | function d3_rgb_lab(r, g, b) {
|
1655 | r = d3_rgb_xyz(r);
|
1656 | g = d3_rgb_xyz(g);
|
1657 | b = d3_rgb_xyz(b);
|
1658 | 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);
|
1659 | return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
|
1660 | }
|
1661 | function d3_rgb_xyz(r) {
|
1662 | return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
|
1663 | }
|
1664 | function d3_rgb_parseNumber(c) {
|
1665 | var f = parseFloat(c);
|
1666 | return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
|
1667 | }
|
1668 | var d3_rgb_names = d3.map({
|
1669 | aliceblue: 15792383,
|
1670 | antiquewhite: 16444375,
|
1671 | aqua: 65535,
|
1672 | aquamarine: 8388564,
|
1673 | azure: 15794175,
|
1674 | beige: 16119260,
|
1675 | bisque: 16770244,
|
1676 | black: 0,
|
1677 | blanchedalmond: 16772045,
|
1678 | blue: 255,
|
1679 | blueviolet: 9055202,
|
1680 | brown: 10824234,
|
1681 | burlywood: 14596231,
|
1682 | cadetblue: 6266528,
|
1683 | chartreuse: 8388352,
|
1684 | chocolate: 13789470,
|
1685 | coral: 16744272,
|
1686 | cornflowerblue: 6591981,
|
1687 | cornsilk: 16775388,
|
1688 | crimson: 14423100,
|
1689 | cyan: 65535,
|
1690 | darkblue: 139,
|
1691 | darkcyan: 35723,
|
1692 | darkgoldenrod: 12092939,
|
1693 | darkgray: 11119017,
|
1694 | darkgreen: 25600,
|
1695 | darkgrey: 11119017,
|
1696 | darkkhaki: 12433259,
|
1697 | darkmagenta: 9109643,
|
1698 | darkolivegreen: 5597999,
|
1699 | darkorange: 16747520,
|
1700 | darkorchid: 10040012,
|
1701 | darkred: 9109504,
|
1702 | darksalmon: 15308410,
|
1703 | darkseagreen: 9419919,
|
1704 | darkslateblue: 4734347,
|
1705 | darkslategray: 3100495,
|
1706 | darkslategrey: 3100495,
|
1707 | darkturquoise: 52945,
|
1708 | darkviolet: 9699539,
|
1709 | deeppink: 16716947,
|
1710 | deepskyblue: 49151,
|
1711 | dimgray: 6908265,
|
1712 | dimgrey: 6908265,
|
1713 | dodgerblue: 2003199,
|
1714 | firebrick: 11674146,
|
1715 | floralwhite: 16775920,
|
1716 | forestgreen: 2263842,
|
1717 | fuchsia: 16711935,
|
1718 | gainsboro: 14474460,
|
1719 | ghostwhite: 16316671,
|
1720 | gold: 16766720,
|
1721 | goldenrod: 14329120,
|
1722 | gray: 8421504,
|
1723 | green: 32768,
|
1724 | greenyellow: 11403055,
|
1725 | grey: 8421504,
|
1726 | honeydew: 15794160,
|
1727 | hotpink: 16738740,
|
1728 | indianred: 13458524,
|
1729 | indigo: 4915330,
|
1730 | ivory: 16777200,
|
1731 | khaki: 15787660,
|
1732 | lavender: 15132410,
|
1733 | lavenderblush: 16773365,
|
1734 | lawngreen: 8190976,
|
1735 | lemonchiffon: 16775885,
|
1736 | lightblue: 11393254,
|
1737 | lightcoral: 15761536,
|
1738 | lightcyan: 14745599,
|
1739 | lightgoldenrodyellow: 16448210,
|
1740 | lightgray: 13882323,
|
1741 | lightgreen: 9498256,
|
1742 | lightgrey: 13882323,
|
1743 | lightpink: 16758465,
|
1744 | lightsalmon: 16752762,
|
1745 | lightseagreen: 2142890,
|
1746 | lightskyblue: 8900346,
|
1747 | lightslategray: 7833753,
|
1748 | lightslategrey: 7833753,
|
1749 | lightsteelblue: 11584734,
|
1750 | lightyellow: 16777184,
|
1751 | lime: 65280,
|
1752 | limegreen: 3329330,
|
1753 | linen: 16445670,
|
1754 | magenta: 16711935,
|
1755 | maroon: 8388608,
|
1756 | mediumaquamarine: 6737322,
|
1757 | mediumblue: 205,
|
1758 | mediumorchid: 12211667,
|
1759 | mediumpurple: 9662683,
|
1760 | mediumseagreen: 3978097,
|
1761 | mediumslateblue: 8087790,
|
1762 | mediumspringgreen: 64154,
|
1763 | mediumturquoise: 4772300,
|
1764 | mediumvioletred: 13047173,
|
1765 | midnightblue: 1644912,
|
1766 | mintcream: 16121850,
|
1767 | mistyrose: 16770273,
|
1768 | moccasin: 16770229,
|
1769 | navajowhite: 16768685,
|
1770 | navy: 128,
|
1771 | oldlace: 16643558,
|
1772 | olive: 8421376,
|
1773 | olivedrab: 7048739,
|
1774 | orange: 16753920,
|
1775 | orangered: 16729344,
|
1776 | orchid: 14315734,
|
1777 | palegoldenrod: 15657130,
|
1778 | palegreen: 10025880,
|
1779 | paleturquoise: 11529966,
|
1780 | palevioletred: 14381203,
|
1781 | papayawhip: 16773077,
|
1782 | peachpuff: 16767673,
|
1783 | peru: 13468991,
|
1784 | pink: 16761035,
|
1785 | plum: 14524637,
|
1786 | powderblue: 11591910,
|
1787 | purple: 8388736,
|
1788 | red: 16711680,
|
1789 | rosybrown: 12357519,
|
1790 | royalblue: 4286945,
|
1791 | saddlebrown: 9127187,
|
1792 | salmon: 16416882,
|
1793 | sandybrown: 16032864,
|
1794 | seagreen: 3050327,
|
1795 | seashell: 16774638,
|
1796 | sienna: 10506797,
|
1797 | silver: 12632256,
|
1798 | skyblue: 8900331,
|
1799 | slateblue: 6970061,
|
1800 | slategray: 7372944,
|
1801 | slategrey: 7372944,
|
1802 | snow: 16775930,
|
1803 | springgreen: 65407,
|
1804 | steelblue: 4620980,
|
1805 | tan: 13808780,
|
1806 | teal: 32896,
|
1807 | thistle: 14204888,
|
1808 | tomato: 16737095,
|
1809 | turquoise: 4251856,
|
1810 | violet: 15631086,
|
1811 | wheat: 16113331,
|
1812 | white: 16777215,
|
1813 | whitesmoke: 16119285,
|
1814 | yellow: 16776960,
|
1815 | yellowgreen: 10145074
|
1816 | });
|
1817 | d3_rgb_names.forEach(function(key, value) {
|
1818 | d3_rgb_names.set(key, d3_rgbNumber(value));
|
1819 | });
|
1820 | function d3_functor(v) {
|
1821 | return typeof v === "function" ? v : function() {
|
1822 | return v;
|
1823 | };
|
1824 | }
|
1825 | d3.functor = d3_functor;
|
1826 | function d3_identity(d) {
|
1827 | return d;
|
1828 | }
|
1829 | d3.xhr = d3_xhrType(d3_identity);
|
1830 | function d3_xhrType(response) {
|
1831 | return function(url, mimeType, callback) {
|
1832 | if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
|
1833 | mimeType = null;
|
1834 | return d3_xhr(url, mimeType, response, callback);
|
1835 | };
|
1836 | }
|
1837 | function d3_xhr(url, mimeType, response, callback) {
|
1838 | var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
|
1839 | if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
|
1840 | "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
|
1841 | request.readyState > 3 && respond();
|
1842 | };
|
1843 | function respond() {
|
1844 | var status = request.status, result;
|
1845 | if (!status && request.responseText || status >= 200 && status < 300 || status === 304) {
|
1846 | try {
|
1847 | result = response.call(xhr, request);
|
1848 | } catch (e) {
|
1849 | dispatch.error.call(xhr, e);
|
1850 | return;
|
1851 | }
|
1852 | dispatch.load.call(xhr, result);
|
1853 | } else {
|
1854 | dispatch.error.call(xhr, request);
|
1855 | }
|
1856 | }
|
1857 | request.onprogress = function(event) {
|
1858 | var o = d3.event;
|
1859 | d3.event = event;
|
1860 | try {
|
1861 | dispatch.progress.call(xhr, request);
|
1862 | } finally {
|
1863 | d3.event = o;
|
1864 | }
|
1865 | };
|
1866 | xhr.header = function(name, value) {
|
1867 | name = (name + "").toLowerCase();
|
1868 | if (arguments.length < 2) return headers[name];
|
1869 | if (value == null) delete headers[name]; else headers[name] = value + "";
|
1870 | return xhr;
|
1871 | };
|
1872 | xhr.mimeType = function(value) {
|
1873 | if (!arguments.length) return mimeType;
|
1874 | mimeType = value == null ? null : value + "";
|
1875 | return xhr;
|
1876 | };
|
1877 | xhr.responseType = function(value) {
|
1878 | if (!arguments.length) return responseType;
|
1879 | responseType = value;
|
1880 | return xhr;
|
1881 | };
|
1882 | xhr.response = function(value) {
|
1883 | response = value;
|
1884 | return xhr;
|
1885 | };
|
1886 | [ "get", "post" ].forEach(function(method) {
|
1887 | xhr[method] = function() {
|
1888 | return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
|
1889 | };
|
1890 | });
|
1891 | xhr.send = function(method, data, callback) {
|
1892 | if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
|
1893 | request.open(method, url, true);
|
1894 | if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
|
1895 | if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
|
1896 | if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
|
1897 | if (responseType != null) request.responseType = responseType;
|
1898 | if (callback != null) xhr.on("error", callback).on("load", function(request) {
|
1899 | callback(null, request);
|
1900 | });
|
1901 | dispatch.beforesend.call(xhr, request);
|
1902 | request.send(data == null ? null : data);
|
1903 | return xhr;
|
1904 | };
|
1905 | xhr.abort = function() {
|
1906 | request.abort();
|
1907 | return xhr;
|
1908 | };
|
1909 | d3.rebind(xhr, dispatch, "on");
|
1910 | return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
|
1911 | }
|
1912 | function d3_xhr_fixCallback(callback) {
|
1913 | return callback.length === 1 ? function(error, request) {
|
1914 | callback(error == null ? request : null);
|
1915 | } : callback;
|
1916 | }
|
1917 | d3.dsv = function(delimiter, mimeType) {
|
1918 | var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
|
1919 | function dsv(url, row, callback) {
|
1920 | if (arguments.length < 3) callback = row, row = null;
|
1921 | var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
|
1922 | xhr.row = function(_) {
|
1923 | return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
|
1924 | };
|
1925 | return xhr;
|
1926 | }
|
1927 | function response(request) {
|
1928 | return dsv.parse(request.responseText);
|
1929 | }
|
1930 | function typedResponse(f) {
|
1931 | return function(request) {
|
1932 | return dsv.parse(request.responseText, f);
|
1933 | };
|
1934 | }
|
1935 | dsv.parse = function(text, f) {
|
1936 | var o;
|
1937 | return dsv.parseRows(text, function(row, i) {
|
1938 | if (o) return o(row, i - 1);
|
1939 | var a = new Function("d", "return {" + row.map(function(name, i) {
|
1940 | return JSON.stringify(name) + ": d[" + i + "]";
|
1941 | }).join(",") + "}");
|
1942 | o = f ? function(row, i) {
|
1943 | return f(a(row), i);
|
1944 | } : a;
|
1945 | });
|
1946 | };
|
1947 | dsv.parseRows = function(text, f) {
|
1948 | var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
|
1949 | function token() {
|
1950 | if (I >= N) return EOF;
|
1951 | if (eol) return eol = false, EOL;
|
1952 | var j = I;
|
1953 | if (text.charCodeAt(j) === 34) {
|
1954 | var i = j;
|
1955 | while (i++ < N) {
|
1956 | if (text.charCodeAt(i) === 34) {
|
1957 | if (text.charCodeAt(i + 1) !== 34) break;
|
1958 | ++i;
|
1959 | }
|
1960 | }
|
1961 | I = i + 2;
|
1962 | var c = text.charCodeAt(i + 1);
|
1963 | if (c === 13) {
|
1964 | eol = true;
|
1965 | if (text.charCodeAt(i + 2) === 10) ++I;
|
1966 | } else if (c === 10) {
|
1967 | eol = true;
|
1968 | }
|
1969 | return text.substring(j + 1, i).replace(/""/g, '"');
|
1970 | }
|
1971 | while (I < N) {
|
1972 | var c = text.charCodeAt(I++), k = 1;
|
1973 | if (c === 10) eol = true; else if (c === 13) {
|
1974 | eol = true;
|
1975 | if (text.charCodeAt(I) === 10) ++I, ++k;
|
1976 | } else if (c !== delimiterCode) continue;
|
1977 | return text.substring(j, I - k);
|
1978 | }
|
1979 | return text.substring(j);
|
1980 | }
|
1981 | while ((t = token()) !== EOF) {
|
1982 | var a = [];
|
1983 | while (t !== EOL && t !== EOF) {
|
1984 | a.push(t);
|
1985 | t = token();
|
1986 | }
|
1987 | if (f && !(a = f(a, n++))) continue;
|
1988 | rows.push(a);
|
1989 | }
|
1990 | return rows;
|
1991 | };
|
1992 | dsv.format = function(rows) {
|
1993 | if (Array.isArray(rows[0])) return dsv.formatRows(rows);
|
1994 | var fieldSet = new d3_Set(), fields = [];
|
1995 | rows.forEach(function(row) {
|
1996 | for (var field in row) {
|
1997 | if (!fieldSet.has(field)) {
|
1998 | fields.push(fieldSet.add(field));
|
1999 | }
|
2000 | }
|
2001 | });
|
2002 | return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
|
2003 | return fields.map(function(field) {
|
2004 | return formatValue(row[field]);
|
2005 | }).join(delimiter);
|
2006 | })).join("\n");
|
2007 | };
|
2008 | dsv.formatRows = function(rows) {
|
2009 | return rows.map(formatRow).join("\n");
|
2010 | };
|
2011 | function formatRow(row) {
|
2012 | return row.map(formatValue).join(delimiter);
|
2013 | }
|
2014 | function formatValue(text) {
|
2015 | return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
|
2016 | }
|
2017 | return dsv;
|
2018 | };
|
2019 | d3.csv = d3.dsv(",", "text/csv");
|
2020 | d3.tsv = d3.dsv(" ", "text/tab-separated-values");
|
2021 | d3.touch = function(container, touches, identifier) {
|
2022 | if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
|
2023 | if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
|
2024 | if ((touch = touches[i]).identifier === identifier) {
|
2025 | return d3_mousePoint(container, touch);
|
2026 | }
|
2027 | }
|
2028 | };
|
2029 | var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = d3_window[d3_vendorSymbol(d3_window, "requestAnimationFrame")] || function(callback) {
|
2030 | setTimeout(callback, 17);
|
2031 | };
|
2032 | d3.timer = function(callback, delay, then) {
|
2033 | var n = arguments.length;
|
2034 | if (n < 2) delay = 0;
|
2035 | if (n < 3) then = Date.now();
|
2036 | var time = then + delay, timer = {
|
2037 | c: callback,
|
2038 | t: time,
|
2039 | f: false,
|
2040 | n: null
|
2041 | };
|
2042 | if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
|
2043 | d3_timer_queueTail = timer;
|
2044 | if (!d3_timer_interval) {
|
2045 | d3_timer_timeout = clearTimeout(d3_timer_timeout);
|
2046 | d3_timer_interval = 1;
|
2047 | d3_timer_frame(d3_timer_step);
|
2048 | }
|
2049 | };
|
2050 | function d3_timer_step() {
|
2051 | var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
|
2052 | if (delay > 24) {
|
2053 | if (isFinite(delay)) {
|
2054 | clearTimeout(d3_timer_timeout);
|
2055 | d3_timer_timeout = setTimeout(d3_timer_step, delay);
|
2056 | }
|
2057 | d3_timer_interval = 0;
|
2058 | } else {
|
2059 | d3_timer_interval = 1;
|
2060 | d3_timer_frame(d3_timer_step);
|
2061 | }
|
2062 | }
|
2063 | d3.timer.flush = function() {
|
2064 | d3_timer_mark();
|
2065 | d3_timer_sweep();
|
2066 | };
|
2067 | function d3_timer_mark() {
|
2068 | var now = Date.now();
|
2069 | d3_timer_active = d3_timer_queueHead;
|
2070 | while (d3_timer_active) {
|
2071 | if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
|
2072 | d3_timer_active = d3_timer_active.n;
|
2073 | }
|
2074 | return now;
|
2075 | }
|
2076 | function d3_timer_sweep() {
|
2077 | var t0, t1 = d3_timer_queueHead, time = Infinity;
|
2078 | while (t1) {
|
2079 | if (t1.f) {
|
2080 | t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
|
2081 | } else {
|
2082 | if (t1.t < time) time = t1.t;
|
2083 | t1 = (t0 = t1).n;
|
2084 | }
|
2085 | }
|
2086 | d3_timer_queueTail = t0;
|
2087 | return time;
|
2088 | }
|
2089 | function d3_format_precision(x, p) {
|
2090 | return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
|
2091 | }
|
2092 | d3.round = function(x, n) {
|
2093 | return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
|
2094 | };
|
2095 | var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
|
2096 | d3.formatPrefix = function(value, precision) {
|
2097 | var i = 0;
|
2098 | if (value) {
|
2099 | if (value < 0) value *= -1;
|
2100 | if (precision) value = d3.round(value, d3_format_precision(value, precision));
|
2101 | i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
|
2102 | i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
|
2103 | }
|
2104 | return d3_formatPrefixes[8 + i / 3];
|
2105 | };
|
2106 | function d3_formatPrefix(d, i) {
|
2107 | var k = Math.pow(10, abs(8 - i) * 3);
|
2108 | return {
|
2109 | scale: i > 8 ? function(d) {
|
2110 | return d / k;
|
2111 | } : function(d) {
|
2112 | return d * k;
|
2113 | },
|
2114 | symbol: d
|
2115 | };
|
2116 | }
|
2117 | function d3_locale_numberFormat(locale) {
|
2118 | var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping ? function(value) {
|
2119 | var i = value.length, t = [], j = 0, g = locale_grouping[0];
|
2120 | while (i > 0 && g > 0) {
|
2121 | t.push(value.substring(i -= g, i + g));
|
2122 | g = locale_grouping[j = (j + 1) % locale_grouping.length];
|
2123 | }
|
2124 | return t.reverse().join(locale_thousands);
|
2125 | } : d3_identity;
|
2126 | return function(specifier) {
|
2127 | 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;
|
2128 | if (precision) precision = +precision.substring(1);
|
2129 | if (zfill || fill === "0" && align === "=") {
|
2130 | zfill = fill = "0";
|
2131 | align = "=";
|
2132 | if (comma) width -= Math.floor((width - 1) / 4);
|
2133 | }
|
2134 | switch (type) {
|
2135 | case "n":
|
2136 | comma = true;
|
2137 | type = "g";
|
2138 | break;
|
2139 |
|
2140 | case "%":
|
2141 | scale = 100;
|
2142 | suffix = "%";
|
2143 | type = "f";
|
2144 | break;
|
2145 |
|
2146 | case "p":
|
2147 | scale = 100;
|
2148 | suffix = "%";
|
2149 | type = "r";
|
2150 | break;
|
2151 |
|
2152 | case "b":
|
2153 | case "o":
|
2154 | case "x":
|
2155 | case "X":
|
2156 | if (symbol === "#") prefix = "0" + type.toLowerCase();
|
2157 |
|
2158 | case "c":
|
2159 | case "d":
|
2160 | integer = true;
|
2161 | precision = 0;
|
2162 | break;
|
2163 |
|
2164 | case "s":
|
2165 | scale = -1;
|
2166 | type = "r";
|
2167 | break;
|
2168 | }
|
2169 | if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
|
2170 | if (type == "r" && !precision) type = "g";
|
2171 | if (precision != null) {
|
2172 | 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));
|
2173 | }
|
2174 | type = d3_format_types.get(type) || d3_format_typeDefault;
|
2175 | var zcomma = zfill && comma;
|
2176 | return function(value) {
|
2177 | var fullSuffix = suffix;
|
2178 | if (integer && value % 1) return "";
|
2179 | var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
|
2180 | if (scale < 0) {
|
2181 | var unit = d3.formatPrefix(value, precision);
|
2182 | value = unit.scale(value);
|
2183 | fullSuffix = unit.symbol + suffix;
|
2184 | } else {
|
2185 | value *= scale;
|
2186 | }
|
2187 | value = type(value, precision);
|
2188 | var i = value.lastIndexOf("."), before = i < 0 ? value : value.substring(0, i), after = i < 0 ? "" : locale_decimal + value.substring(i + 1);
|
2189 | if (!zfill && comma) before = formatGroup(before);
|
2190 | var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
|
2191 | if (zcomma) before = formatGroup(padding + before);
|
2192 | negative += prefix;
|
2193 | value = before + after;
|
2194 | 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;
|
2195 | };
|
2196 | };
|
2197 | }
|
2198 | var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
|
2199 | var d3_format_types = d3.map({
|
2200 | b: function(x) {
|
2201 | return x.toString(2);
|
2202 | },
|
2203 | c: function(x) {
|
2204 | return String.fromCharCode(x);
|
2205 | },
|
2206 | o: function(x) {
|
2207 | return x.toString(8);
|
2208 | },
|
2209 | x: function(x) {
|
2210 | return x.toString(16);
|
2211 | },
|
2212 | X: function(x) {
|
2213 | return x.toString(16).toUpperCase();
|
2214 | },
|
2215 | g: function(x, p) {
|
2216 | return x.toPrecision(p);
|
2217 | },
|
2218 | e: function(x, p) {
|
2219 | return x.toExponential(p);
|
2220 | },
|
2221 | f: function(x, p) {
|
2222 | return x.toFixed(p);
|
2223 | },
|
2224 | r: function(x, p) {
|
2225 | 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))));
|
2226 | }
|
2227 | });
|
2228 | function d3_format_typeDefault(x) {
|
2229 | return x + "";
|
2230 | }
|
2231 | var d3_time = d3.time = {}, d3_date = Date;
|
2232 | function d3_date_utc() {
|
2233 | this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
|
2234 | }
|
2235 | d3_date_utc.prototype = {
|
2236 | getDate: function() {
|
2237 | return this._.getUTCDate();
|
2238 | },
|
2239 | getDay: function() {
|
2240 | return this._.getUTCDay();
|
2241 | },
|
2242 | getFullYear: function() {
|
2243 | return this._.getUTCFullYear();
|
2244 | },
|
2245 | getHours: function() {
|
2246 | return this._.getUTCHours();
|
2247 | },
|
2248 | getMilliseconds: function() {
|
2249 | return this._.getUTCMilliseconds();
|
2250 | },
|
2251 | getMinutes: function() {
|
2252 | return this._.getUTCMinutes();
|
2253 | },
|
2254 | getMonth: function() {
|
2255 | return this._.getUTCMonth();
|
2256 | },
|
2257 | getSeconds: function() {
|
2258 | return this._.getUTCSeconds();
|
2259 | },
|
2260 | getTime: function() {
|
2261 | return this._.getTime();
|
2262 | },
|
2263 | getTimezoneOffset: function() {
|
2264 | return 0;
|
2265 | },
|
2266 | valueOf: function() {
|
2267 | return this._.valueOf();
|
2268 | },
|
2269 | setDate: function() {
|
2270 | d3_time_prototype.setUTCDate.apply(this._, arguments);
|
2271 | },
|
2272 | setDay: function() {
|
2273 | d3_time_prototype.setUTCDay.apply(this._, arguments);
|
2274 | },
|
2275 | setFullYear: function() {
|
2276 | d3_time_prototype.setUTCFullYear.apply(this._, arguments);
|
2277 | },
|
2278 | setHours: function() {
|
2279 | d3_time_prototype.setUTCHours.apply(this._, arguments);
|
2280 | },
|
2281 | setMilliseconds: function() {
|
2282 | d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
|
2283 | },
|
2284 | setMinutes: function() {
|
2285 | d3_time_prototype.setUTCMinutes.apply(this._, arguments);
|
2286 | },
|
2287 | setMonth: function() {
|
2288 | d3_time_prototype.setUTCMonth.apply(this._, arguments);
|
2289 | },
|
2290 | setSeconds: function() {
|
2291 | d3_time_prototype.setUTCSeconds.apply(this._, arguments);
|
2292 | },
|
2293 | setTime: function() {
|
2294 | d3_time_prototype.setTime.apply(this._, arguments);
|
2295 | }
|
2296 | };
|
2297 | var d3_time_prototype = Date.prototype;
|
2298 | function d3_time_interval(local, step, number) {
|
2299 | function round(date) {
|
2300 | var d0 = local(date), d1 = offset(d0, 1);
|
2301 | return date - d0 < d1 - date ? d0 : d1;
|
2302 | }
|
2303 | function ceil(date) {
|
2304 | step(date = local(new d3_date(date - 1)), 1);
|
2305 | return date;
|
2306 | }
|
2307 | function offset(date, k) {
|
2308 | step(date = new d3_date(+date), k);
|
2309 | return date;
|
2310 | }
|
2311 | function range(t0, t1, dt) {
|
2312 | var time = ceil(t0), times = [];
|
2313 | if (dt > 1) {
|
2314 | while (time < t1) {
|
2315 | if (!(number(time) % dt)) times.push(new Date(+time));
|
2316 | step(time, 1);
|
2317 | }
|
2318 | } else {
|
2319 | while (time < t1) times.push(new Date(+time)), step(time, 1);
|
2320 | }
|
2321 | return times;
|
2322 | }
|
2323 | function range_utc(t0, t1, dt) {
|
2324 | try {
|
2325 | d3_date = d3_date_utc;
|
2326 | var utc = new d3_date_utc();
|
2327 | utc._ = t0;
|
2328 | return range(utc, t1, dt);
|
2329 | } finally {
|
2330 | d3_date = Date;
|
2331 | }
|
2332 | }
|
2333 | local.floor = local;
|
2334 | local.round = round;
|
2335 | local.ceil = ceil;
|
2336 | local.offset = offset;
|
2337 | local.range = range;
|
2338 | var utc = local.utc = d3_time_interval_utc(local);
|
2339 | utc.floor = utc;
|
2340 | utc.round = d3_time_interval_utc(round);
|
2341 | utc.ceil = d3_time_interval_utc(ceil);
|
2342 | utc.offset = d3_time_interval_utc(offset);
|
2343 | utc.range = range_utc;
|
2344 | return local;
|
2345 | }
|
2346 | function d3_time_interval_utc(method) {
|
2347 | return function(date, k) {
|
2348 | try {
|
2349 | d3_date = d3_date_utc;
|
2350 | var utc = new d3_date_utc();
|
2351 | utc._ = date;
|
2352 | return method(utc, k)._;
|
2353 | } finally {
|
2354 | d3_date = Date;
|
2355 | }
|
2356 | };
|
2357 | }
|
2358 | d3_time.year = d3_time_interval(function(date) {
|
2359 | date = d3_time.day(date);
|
2360 | date.setMonth(0, 1);
|
2361 | return date;
|
2362 | }, function(date, offset) {
|
2363 | date.setFullYear(date.getFullYear() + offset);
|
2364 | }, function(date) {
|
2365 | return date.getFullYear();
|
2366 | });
|
2367 | d3_time.years = d3_time.year.range;
|
2368 | d3_time.years.utc = d3_time.year.utc.range;
|
2369 | d3_time.day = d3_time_interval(function(date) {
|
2370 | var day = new d3_date(2e3, 0);
|
2371 | day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
|
2372 | return day;
|
2373 | }, function(date, offset) {
|
2374 | date.setDate(date.getDate() + offset);
|
2375 | }, function(date) {
|
2376 | return date.getDate() - 1;
|
2377 | });
|
2378 | d3_time.days = d3_time.day.range;
|
2379 | d3_time.days.utc = d3_time.day.utc.range;
|
2380 | d3_time.dayOfYear = function(date) {
|
2381 | var year = d3_time.year(date);
|
2382 | return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
|
2383 | };
|
2384 | [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
|
2385 | i = 7 - i;
|
2386 | var interval = d3_time[day] = d3_time_interval(function(date) {
|
2387 | (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
|
2388 | return date;
|
2389 | }, function(date, offset) {
|
2390 | date.setDate(date.getDate() + Math.floor(offset) * 7);
|
2391 | }, function(date) {
|
2392 | var day = d3_time.year(date).getDay();
|
2393 | return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
|
2394 | });
|
2395 | d3_time[day + "s"] = interval.range;
|
2396 | d3_time[day + "s"].utc = interval.utc.range;
|
2397 | d3_time[day + "OfYear"] = function(date) {
|
2398 | var day = d3_time.year(date).getDay();
|
2399 | return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
|
2400 | };
|
2401 | });
|
2402 | d3_time.week = d3_time.sunday;
|
2403 | d3_time.weeks = d3_time.sunday.range;
|
2404 | d3_time.weeks.utc = d3_time.sunday.utc.range;
|
2405 | d3_time.weekOfYear = d3_time.sundayOfYear;
|
2406 | function d3_locale_timeFormat(locale) {
|
2407 | 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;
|
2408 | function d3_time_format(template) {
|
2409 | var n = template.length;
|
2410 | function format(date) {
|
2411 | var string = [], i = -1, j = 0, c, p, f;
|
2412 | while (++i < n) {
|
2413 | if (template.charCodeAt(i) === 37) {
|
2414 | string.push(template.substring(j, i));
|
2415 | if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
|
2416 | if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
|
2417 | string.push(c);
|
2418 | j = i + 1;
|
2419 | }
|
2420 | }
|
2421 | string.push(template.substring(j, i));
|
2422 | return string.join("");
|
2423 | }
|
2424 | format.parse = function(string) {
|
2425 | var d = {
|
2426 | y: 1900,
|
2427 | m: 0,
|
2428 | d: 1,
|
2429 | H: 0,
|
2430 | M: 0,
|
2431 | S: 0,
|
2432 | L: 0,
|
2433 | Z: null
|
2434 | }, i = d3_time_parse(d, template, string, 0);
|
2435 | if (i != string.length) return null;
|
2436 | if ("p" in d) d.H = d.H % 12 + d.p * 12;
|
2437 | var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
|
2438 | if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
|
2439 | date.setFullYear(d.y, 0, 1);
|
2440 | 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);
|
2441 | } else date.setFullYear(d.y, d.m, d.d);
|
2442 | date.setHours(d.H + Math.floor(d.Z / 100), d.M + d.Z % 100, d.S, d.L);
|
2443 | return localZ ? date._ : date;
|
2444 | };
|
2445 | format.toString = function() {
|
2446 | return template;
|
2447 | };
|
2448 | return format;
|
2449 | }
|
2450 | function d3_time_parse(date, template, string, j) {
|
2451 | var c, p, t, i = 0, n = template.length, m = string.length;
|
2452 | while (i < n) {
|
2453 | if (j >= m) return -1;
|
2454 | c = template.charCodeAt(i++);
|
2455 | if (c === 37) {
|
2456 | t = template.charAt(i++);
|
2457 | p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
|
2458 | if (!p || (j = p(date, string, j)) < 0) return -1;
|
2459 | } else if (c != string.charCodeAt(j++)) {
|
2460 | return -1;
|
2461 | }
|
2462 | }
|
2463 | return j;
|
2464 | }
|
2465 | d3_time_format.utc = function(template) {
|
2466 | var local = d3_time_format(template);
|
2467 | function format(date) {
|
2468 | try {
|
2469 | d3_date = d3_date_utc;
|
2470 | var utc = new d3_date();
|
2471 | utc._ = date;
|
2472 | return local(utc);
|
2473 | } finally {
|
2474 | d3_date = Date;
|
2475 | }
|
2476 | }
|
2477 | format.parse = function(string) {
|
2478 | try {
|
2479 | d3_date = d3_date_utc;
|
2480 | var date = local.parse(string);
|
2481 | return date && date._;
|
2482 | } finally {
|
2483 | d3_date = Date;
|
2484 | }
|
2485 | };
|
2486 | format.toString = local.toString;
|
2487 | return format;
|
2488 | };
|
2489 | d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
|
2490 | 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);
|
2491 | locale_periods.forEach(function(p, i) {
|
2492 | d3_time_periodLookup.set(p.toLowerCase(), i);
|
2493 | });
|
2494 | var d3_time_formats = {
|
2495 | a: function(d) {
|
2496 | return locale_shortDays[d.getDay()];
|
2497 | },
|
2498 | A: function(d) {
|
2499 | return locale_days[d.getDay()];
|
2500 | },
|
2501 | b: function(d) {
|
2502 | return locale_shortMonths[d.getMonth()];
|
2503 | },
|
2504 | B: function(d) {
|
2505 | return locale_months[d.getMonth()];
|
2506 | },
|
2507 | c: d3_time_format(locale_dateTime),
|
2508 | d: function(d, p) {
|
2509 | return d3_time_formatPad(d.getDate(), p, 2);
|
2510 | },
|
2511 | e: function(d, p) {
|
2512 | return d3_time_formatPad(d.getDate(), p, 2);
|
2513 | },
|
2514 | H: function(d, p) {
|
2515 | return d3_time_formatPad(d.getHours(), p, 2);
|
2516 | },
|
2517 | I: function(d, p) {
|
2518 | return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
|
2519 | },
|
2520 | j: function(d, p) {
|
2521 | return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
|
2522 | },
|
2523 | L: function(d, p) {
|
2524 | return d3_time_formatPad(d.getMilliseconds(), p, 3);
|
2525 | },
|
2526 | m: function(d, p) {
|
2527 | return d3_time_formatPad(d.getMonth() + 1, p, 2);
|
2528 | },
|
2529 | M: function(d, p) {
|
2530 | return d3_time_formatPad(d.getMinutes(), p, 2);
|
2531 | },
|
2532 | p: function(d) {
|
2533 | return locale_periods[+(d.getHours() >= 12)];
|
2534 | },
|
2535 | S: function(d, p) {
|
2536 | return d3_time_formatPad(d.getSeconds(), p, 2);
|
2537 | },
|
2538 | U: function(d, p) {
|
2539 | return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
|
2540 | },
|
2541 | w: function(d) {
|
2542 | return d.getDay();
|
2543 | },
|
2544 | W: function(d, p) {
|
2545 | return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
|
2546 | },
|
2547 | x: d3_time_format(locale_date),
|
2548 | X: d3_time_format(locale_time),
|
2549 | y: function(d, p) {
|
2550 | return d3_time_formatPad(d.getFullYear() % 100, p, 2);
|
2551 | },
|
2552 | Y: function(d, p) {
|
2553 | return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
|
2554 | },
|
2555 | Z: d3_time_zone,
|
2556 | "%": function() {
|
2557 | return "%";
|
2558 | }
|
2559 | };
|
2560 | var d3_time_parsers = {
|
2561 | a: d3_time_parseWeekdayAbbrev,
|
2562 | A: d3_time_parseWeekday,
|
2563 | b: d3_time_parseMonthAbbrev,
|
2564 | B: d3_time_parseMonth,
|
2565 | c: d3_time_parseLocaleFull,
|
2566 | d: d3_time_parseDay,
|
2567 | e: d3_time_parseDay,
|
2568 | H: d3_time_parseHour24,
|
2569 | I: d3_time_parseHour24,
|
2570 | j: d3_time_parseDayOfYear,
|
2571 | L: d3_time_parseMilliseconds,
|
2572 | m: d3_time_parseMonthNumber,
|
2573 | M: d3_time_parseMinutes,
|
2574 | p: d3_time_parseAmPm,
|
2575 | S: d3_time_parseSeconds,
|
2576 | U: d3_time_parseWeekNumberSunday,
|
2577 | w: d3_time_parseWeekdayNumber,
|
2578 | W: d3_time_parseWeekNumberMonday,
|
2579 | x: d3_time_parseLocaleDate,
|
2580 | X: d3_time_parseLocaleTime,
|
2581 | y: d3_time_parseYear,
|
2582 | Y: d3_time_parseFullYear,
|
2583 | Z: d3_time_parseZone,
|
2584 | "%": d3_time_parseLiteralPercent
|
2585 | };
|
2586 | function d3_time_parseWeekdayAbbrev(date, string, i) {
|
2587 | d3_time_dayAbbrevRe.lastIndex = 0;
|
2588 | var n = d3_time_dayAbbrevRe.exec(string.substring(i));
|
2589 | return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
2590 | }
|
2591 | function d3_time_parseWeekday(date, string, i) {
|
2592 | d3_time_dayRe.lastIndex = 0;
|
2593 | var n = d3_time_dayRe.exec(string.substring(i));
|
2594 | return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
2595 | }
|
2596 | function d3_time_parseMonthAbbrev(date, string, i) {
|
2597 | d3_time_monthAbbrevRe.lastIndex = 0;
|
2598 | var n = d3_time_monthAbbrevRe.exec(string.substring(i));
|
2599 | return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
2600 | }
|
2601 | function d3_time_parseMonth(date, string, i) {
|
2602 | d3_time_monthRe.lastIndex = 0;
|
2603 | var n = d3_time_monthRe.exec(string.substring(i));
|
2604 | return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
2605 | }
|
2606 | function d3_time_parseLocaleFull(date, string, i) {
|
2607 | return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
|
2608 | }
|
2609 | function d3_time_parseLocaleDate(date, string, i) {
|
2610 | return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
|
2611 | }
|
2612 | function d3_time_parseLocaleTime(date, string, i) {
|
2613 | return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
|
2614 | }
|
2615 | function d3_time_parseAmPm(date, string, i) {
|
2616 | var n = d3_time_periodLookup.get(string.substring(i, i += 2).toLowerCase());
|
2617 | return n == null ? -1 : (date.p = n, i);
|
2618 | }
|
2619 | return d3_time_format;
|
2620 | }
|
2621 | var d3_time_formatPads = {
|
2622 | "-": "",
|
2623 | _: " ",
|
2624 | "0": "0"
|
2625 | }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
|
2626 | function d3_time_formatPad(value, fill, width) {
|
2627 | var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
|
2628 | return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
|
2629 | }
|
2630 | function d3_time_formatRe(names) {
|
2631 | return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
|
2632 | }
|
2633 | function d3_time_formatLookup(names) {
|
2634 | var map = new d3_Map(), i = -1, n = names.length;
|
2635 | while (++i < n) map.set(names[i].toLowerCase(), i);
|
2636 | return map;
|
2637 | }
|
2638 | function d3_time_parseWeekdayNumber(date, string, i) {
|
2639 | d3_time_numberRe.lastIndex = 0;
|
2640 | var n = d3_time_numberRe.exec(string.substring(i, i + 1));
|
2641 | return n ? (date.w = +n[0], i + n[0].length) : -1;
|
2642 | }
|
2643 | function d3_time_parseWeekNumberSunday(date, string, i) {
|
2644 | d3_time_numberRe.lastIndex = 0;
|
2645 | var n = d3_time_numberRe.exec(string.substring(i));
|
2646 | return n ? (date.U = +n[0], i + n[0].length) : -1;
|
2647 | }
|
2648 | function d3_time_parseWeekNumberMonday(date, string, i) {
|
2649 | d3_time_numberRe.lastIndex = 0;
|
2650 | var n = d3_time_numberRe.exec(string.substring(i));
|
2651 | return n ? (date.W = +n[0], i + n[0].length) : -1;
|
2652 | }
|
2653 | function d3_time_parseFullYear(date, string, i) {
|
2654 | d3_time_numberRe.lastIndex = 0;
|
2655 | var n = d3_time_numberRe.exec(string.substring(i, i + 4));
|
2656 | return n ? (date.y = +n[0], i + n[0].length) : -1;
|
2657 | }
|
2658 | function d3_time_parseYear(date, string, i) {
|
2659 | d3_time_numberRe.lastIndex = 0;
|
2660 | var n = d3_time_numberRe.exec(string.substring(i, i + 2));
|
2661 | return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
|
2662 | }
|
2663 | function d3_time_parseZone(date, string, i) {
|
2664 | return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = -string,
|
2665 | i + 5) : -1;
|
2666 | }
|
2667 | function d3_time_expandYear(d) {
|
2668 | return d + (d > 68 ? 1900 : 2e3);
|
2669 | }
|
2670 | function d3_time_parseMonthNumber(date, string, i) {
|
2671 | d3_time_numberRe.lastIndex = 0;
|
2672 | var n = d3_time_numberRe.exec(string.substring(i, i + 2));
|
2673 | return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
|
2674 | }
|
2675 | function d3_time_parseDay(date, string, i) {
|
2676 | d3_time_numberRe.lastIndex = 0;
|
2677 | var n = d3_time_numberRe.exec(string.substring(i, i + 2));
|
2678 | return n ? (date.d = +n[0], i + n[0].length) : -1;
|
2679 | }
|
2680 | function d3_time_parseDayOfYear(date, string, i) {
|
2681 | d3_time_numberRe.lastIndex = 0;
|
2682 | var n = d3_time_numberRe.exec(string.substring(i, i + 3));
|
2683 | return n ? (date.j = +n[0], i + n[0].length) : -1;
|
2684 | }
|
2685 | function d3_time_parseHour24(date, string, i) {
|
2686 | d3_time_numberRe.lastIndex = 0;
|
2687 | var n = d3_time_numberRe.exec(string.substring(i, i + 2));
|
2688 | return n ? (date.H = +n[0], i + n[0].length) : -1;
|
2689 | }
|
2690 | function d3_time_parseMinutes(date, string, i) {
|
2691 | d3_time_numberRe.lastIndex = 0;
|
2692 | var n = d3_time_numberRe.exec(string.substring(i, i + 2));
|
2693 | return n ? (date.M = +n[0], i + n[0].length) : -1;
|
2694 | }
|
2695 | function d3_time_parseSeconds(date, string, i) {
|
2696 | d3_time_numberRe.lastIndex = 0;
|
2697 | var n = d3_time_numberRe.exec(string.substring(i, i + 2));
|
2698 | return n ? (date.S = +n[0], i + n[0].length) : -1;
|
2699 | }
|
2700 | function d3_time_parseMilliseconds(date, string, i) {
|
2701 | d3_time_numberRe.lastIndex = 0;
|
2702 | var n = d3_time_numberRe.exec(string.substring(i, i + 3));
|
2703 | return n ? (date.L = +n[0], i + n[0].length) : -1;
|
2704 | }
|
2705 | function d3_time_zone(d) {
|
2706 | var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(abs(z) / 60), zm = abs(z) % 60;
|
2707 | return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
|
2708 | }
|
2709 | function d3_time_parseLiteralPercent(date, string, i) {
|
2710 | d3_time_percentRe.lastIndex = 0;
|
2711 | var n = d3_time_percentRe.exec(string.substring(i, i + 1));
|
2712 | return n ? i + n[0].length : -1;
|
2713 | }
|
2714 | function d3_time_formatMulti(formats) {
|
2715 | var n = formats.length, i = -1;
|
2716 | while (++i < n) formats[i][0] = this(formats[i][0]);
|
2717 | return function(date) {
|
2718 | var i = 0, f = formats[i];
|
2719 | while (!f[1](date)) f = formats[++i];
|
2720 | return f[0](date);
|
2721 | };
|
2722 | }
|
2723 | d3.locale = function(locale) {
|
2724 | return {
|
2725 | numberFormat: d3_locale_numberFormat(locale),
|
2726 | timeFormat: d3_locale_timeFormat(locale)
|
2727 | };
|
2728 | };
|
2729 | var d3_locale_enUS = d3.locale({
|
2730 | decimal: ".",
|
2731 | thousands: ",",
|
2732 | grouping: [ 3 ],
|
2733 | currency: [ "$", "" ],
|
2734 | dateTime: "%a %b %e %X %Y",
|
2735 | date: "%m/%d/%Y",
|
2736 | time: "%H:%M:%S",
|
2737 | periods: [ "AM", "PM" ],
|
2738 | days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
|
2739 | shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
|
2740 | months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
|
2741 | shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
|
2742 | });
|
2743 | d3.format = d3_locale_enUS.numberFormat;
|
2744 | d3.geo = {};
|
2745 | function d3_adder() {}
|
2746 | d3_adder.prototype = {
|
2747 | s: 0,
|
2748 | t: 0,
|
2749 | add: function(y) {
|
2750 | d3_adderSum(y, this.t, d3_adderTemp);
|
2751 | d3_adderSum(d3_adderTemp.s, this.s, this);
|
2752 | if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
|
2753 | },
|
2754 | reset: function() {
|
2755 | this.s = this.t = 0;
|
2756 | },
|
2757 | valueOf: function() {
|
2758 | return this.s;
|
2759 | }
|
2760 | };
|
2761 | var d3_adderTemp = new d3_adder();
|
2762 | function d3_adderSum(a, b, o) {
|
2763 | var x = o.s = a + b, bv = x - a, av = x - bv;
|
2764 | o.t = a - av + (b - bv);
|
2765 | }
|
2766 | d3.geo.stream = function(object, listener) {
|
2767 | if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
|
2768 | d3_geo_streamObjectType[object.type](object, listener);
|
2769 | } else {
|
2770 | d3_geo_streamGeometry(object, listener);
|
2771 | }
|
2772 | };
|
2773 | function d3_geo_streamGeometry(geometry, listener) {
|
2774 | if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
|
2775 | d3_geo_streamGeometryType[geometry.type](geometry, listener);
|
2776 | }
|
2777 | }
|
2778 | var d3_geo_streamObjectType = {
|
2779 | Feature: function(feature, listener) {
|
2780 | d3_geo_streamGeometry(feature.geometry, listener);
|
2781 | },
|
2782 | FeatureCollection: function(object, listener) {
|
2783 | var features = object.features, i = -1, n = features.length;
|
2784 | while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
|
2785 | }
|
2786 | };
|
2787 | var d3_geo_streamGeometryType = {
|
2788 | Sphere: function(object, listener) {
|
2789 | listener.sphere();
|
2790 | },
|
2791 | Point: function(object, listener) {
|
2792 | object = object.coordinates;
|
2793 | listener.point(object[0], object[1], object[2]);
|
2794 | },
|
2795 | MultiPoint: function(object, listener) {
|
2796 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
2797 | while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
|
2798 | },
|
2799 | LineString: function(object, listener) {
|
2800 | d3_geo_streamLine(object.coordinates, listener, 0);
|
2801 | },
|
2802 | MultiLineString: function(object, listener) {
|
2803 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
2804 | while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
|
2805 | },
|
2806 | Polygon: function(object, listener) {
|
2807 | d3_geo_streamPolygon(object.coordinates, listener);
|
2808 | },
|
2809 | MultiPolygon: function(object, listener) {
|
2810 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
2811 | while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
|
2812 | },
|
2813 | GeometryCollection: function(object, listener) {
|
2814 | var geometries = object.geometries, i = -1, n = geometries.length;
|
2815 | while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
|
2816 | }
|
2817 | };
|
2818 | function d3_geo_streamLine(coordinates, listener, closed) {
|
2819 | var i = -1, n = coordinates.length - closed, coordinate;
|
2820 | listener.lineStart();
|
2821 | while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
|
2822 | listener.lineEnd();
|
2823 | }
|
2824 | function d3_geo_streamPolygon(coordinates, listener) {
|
2825 | var i = -1, n = coordinates.length;
|
2826 | listener.polygonStart();
|
2827 | while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
|
2828 | listener.polygonEnd();
|
2829 | }
|
2830 | d3.geo.area = function(object) {
|
2831 | d3_geo_areaSum = 0;
|
2832 | d3.geo.stream(object, d3_geo_area);
|
2833 | return d3_geo_areaSum;
|
2834 | };
|
2835 | var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
|
2836 | var d3_geo_area = {
|
2837 | sphere: function() {
|
2838 | d3_geo_areaSum += 4 * π;
|
2839 | },
|
2840 | point: d3_noop,
|
2841 | lineStart: d3_noop,
|
2842 | lineEnd: d3_noop,
|
2843 | polygonStart: function() {
|
2844 | d3_geo_areaRingSum.reset();
|
2845 | d3_geo_area.lineStart = d3_geo_areaRingStart;
|
2846 | },
|
2847 | polygonEnd: function() {
|
2848 | var area = 2 * d3_geo_areaRingSum;
|
2849 | d3_geo_areaSum += area < 0 ? 4 * π + area : area;
|
2850 | d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
|
2851 | }
|
2852 | };
|
2853 | function d3_geo_areaRingStart() {
|
2854 | var λ00, φ00, λ0, cosφ0, sinφ0;
|
2855 | d3_geo_area.point = function(λ, φ) {
|
2856 | d3_geo_area.point = nextPoint;
|
2857 | λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
|
2858 | sinφ0 = Math.sin(φ);
|
2859 | };
|
2860 | function nextPoint(λ, φ) {
|
2861 | λ *= d3_radians;
|
2862 | φ = φ * d3_radians / 2 + π / 4;
|
2863 | 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λ);
|
2864 | d3_geo_areaRingSum.add(Math.atan2(v, u));
|
2865 | λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
|
2866 | }
|
2867 | d3_geo_area.lineEnd = function() {
|
2868 | nextPoint(λ00, φ00);
|
2869 | };
|
2870 | }
|
2871 | function d3_geo_cartesian(spherical) {
|
2872 | var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
|
2873 | return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
|
2874 | }
|
2875 | function d3_geo_cartesianDot(a, b) {
|
2876 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
2877 | }
|
2878 | function d3_geo_cartesianCross(a, b) {
|
2879 | 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] ];
|
2880 | }
|
2881 | function d3_geo_cartesianAdd(a, b) {
|
2882 | a[0] += b[0];
|
2883 | a[1] += b[1];
|
2884 | a[2] += b[2];
|
2885 | }
|
2886 | function d3_geo_cartesianScale(vector, k) {
|
2887 | return [ vector[0] * k, vector[1] * k, vector[2] * k ];
|
2888 | }
|
2889 | function d3_geo_cartesianNormalize(d) {
|
2890 | var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
2891 | d[0] /= l;
|
2892 | d[1] /= l;
|
2893 | d[2] /= l;
|
2894 | }
|
2895 | function d3_geo_spherical(cartesian) {
|
2896 | return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
|
2897 | }
|
2898 | function d3_geo_sphericalEqual(a, b) {
|
2899 | return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
|
2900 | }
|
2901 | d3.geo.bounds = function() {
|
2902 | var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
|
2903 | var bound = {
|
2904 | point: point,
|
2905 | lineStart: lineStart,
|
2906 | lineEnd: lineEnd,
|
2907 | polygonStart: function() {
|
2908 | bound.point = ringPoint;
|
2909 | bound.lineStart = ringStart;
|
2910 | bound.lineEnd = ringEnd;
|
2911 | dλSum = 0;
|
2912 | d3_geo_area.polygonStart();
|
2913 | },
|
2914 | polygonEnd: function() {
|
2915 | d3_geo_area.polygonEnd();
|
2916 | bound.point = point;
|
2917 | bound.lineStart = lineStart;
|
2918 | bound.lineEnd = lineEnd;
|
2919 | if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
|
2920 | range[0] = λ0, range[1] = λ1;
|
2921 | }
|
2922 | };
|
2923 | function point(λ, φ) {
|
2924 | ranges.push(range = [ λ0 = λ, λ1 = λ ]);
|
2925 | if (φ < φ0) φ0 = φ;
|
2926 | if (φ > φ1) φ1 = φ;
|
2927 | }
|
2928 | function linePoint(λ, φ) {
|
2929 | var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
|
2930 | if (p0) {
|
2931 | var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
|
2932 | d3_geo_cartesianNormalize(inflection);
|
2933 | inflection = d3_geo_spherical(inflection);
|
2934 | var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
|
2935 | if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
|
2936 | var φi = inflection[1] * d3_degrees;
|
2937 | if (φi > φ1) φ1 = φi;
|
2938 | } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
|
2939 | var φi = -inflection[1] * d3_degrees;
|
2940 | if (φi < φ0) φ0 = φi;
|
2941 | } else {
|
2942 | if (φ < φ0) φ0 = φ;
|
2943 | if (φ > φ1) φ1 = φ;
|
2944 | }
|
2945 | if (antimeridian) {
|
2946 | if (λ < λ_) {
|
2947 | if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
|
2948 | } else {
|
2949 | if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
|
2950 | }
|
2951 | } else {
|
2952 | if (λ1 >= λ0) {
|
2953 | if (λ < λ0) λ0 = λ;
|
2954 | if (λ > λ1) λ1 = λ;
|
2955 | } else {
|
2956 | if (λ > λ_) {
|
2957 | if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
|
2958 | } else {
|
2959 | if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
|
2960 | }
|
2961 | }
|
2962 | }
|
2963 | } else {
|
2964 | point(λ, φ);
|
2965 | }
|
2966 | p0 = p, λ_ = λ;
|
2967 | }
|
2968 | function lineStart() {
|
2969 | bound.point = linePoint;
|
2970 | }
|
2971 | function lineEnd() {
|
2972 | range[0] = λ0, range[1] = λ1;
|
2973 | bound.point = point;
|
2974 | p0 = null;
|
2975 | }
|
2976 | function ringPoint(λ, φ) {
|
2977 | if (p0) {
|
2978 | var dλ = λ - λ_;
|
2979 | dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
|
2980 | } else λ__ = λ, φ__ = φ;
|
2981 | d3_geo_area.point(λ, φ);
|
2982 | linePoint(λ, φ);
|
2983 | }
|
2984 | function ringStart() {
|
2985 | d3_geo_area.lineStart();
|
2986 | }
|
2987 | function ringEnd() {
|
2988 | ringPoint(λ__, φ__);
|
2989 | d3_geo_area.lineEnd();
|
2990 | if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
|
2991 | range[0] = λ0, range[1] = λ1;
|
2992 | p0 = null;
|
2993 | }
|
2994 | function angle(λ0, λ1) {
|
2995 | return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
|
2996 | }
|
2997 | function compareRanges(a, b) {
|
2998 | return a[0] - b[0];
|
2999 | }
|
3000 | function withinRange(x, range) {
|
3001 | return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
|
3002 | }
|
3003 | return function(feature) {
|
3004 | φ1 = λ1 = -(λ0 = φ0 = Infinity);
|
3005 | ranges = [];
|
3006 | d3.geo.stream(feature, bound);
|
3007 | var n = ranges.length;
|
3008 | if (n) {
|
3009 | ranges.sort(compareRanges);
|
3010 | for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
|
3011 | b = ranges[i];
|
3012 | if (withinRange(b[0], a) || withinRange(b[1], a)) {
|
3013 | if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
|
3014 | if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
|
3015 | } else {
|
3016 | merged.push(a = b);
|
3017 | }
|
3018 | }
|
3019 | var best = -Infinity, dλ;
|
3020 | for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
|
3021 | b = merged[i];
|
3022 | if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
|
3023 | }
|
3024 | }
|
3025 | ranges = range = null;
|
3026 | return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
|
3027 | };
|
3028 | }();
|
3029 | d3.geo.centroid = function(object) {
|
3030 | 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;
|
3031 | d3.geo.stream(object, d3_geo_centroid);
|
3032 | var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
|
3033 | if (m < ε2) {
|
3034 | x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
|
3035 | if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
|
3036 | m = x * x + y * y + z * z;
|
3037 | if (m < ε2) return [ NaN, NaN ];
|
3038 | }
|
3039 | return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
|
3040 | };
|
3041 | 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;
|
3042 | var d3_geo_centroid = {
|
3043 | sphere: d3_noop,
|
3044 | point: d3_geo_centroidPoint,
|
3045 | lineStart: d3_geo_centroidLineStart,
|
3046 | lineEnd: d3_geo_centroidLineEnd,
|
3047 | polygonStart: function() {
|
3048 | d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
|
3049 | },
|
3050 | polygonEnd: function() {
|
3051 | d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
|
3052 | }
|
3053 | };
|
3054 | function d3_geo_centroidPoint(λ, φ) {
|
3055 | λ *= d3_radians;
|
3056 | var cosφ = Math.cos(φ *= d3_radians);
|
3057 | d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
|
3058 | }
|
3059 | function d3_geo_centroidPointXYZ(x, y, z) {
|
3060 | ++d3_geo_centroidW0;
|
3061 | d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
|
3062 | d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
|
3063 | d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
|
3064 | }
|
3065 | function d3_geo_centroidLineStart() {
|
3066 | var x0, y0, z0;
|
3067 | d3_geo_centroid.point = function(λ, φ) {
|
3068 | λ *= d3_radians;
|
3069 | var cosφ = Math.cos(φ *= d3_radians);
|
3070 | x0 = cosφ * Math.cos(λ);
|
3071 | y0 = cosφ * Math.sin(λ);
|
3072 | z0 = Math.sin(φ);
|
3073 | d3_geo_centroid.point = nextPoint;
|
3074 | d3_geo_centroidPointXYZ(x0, y0, z0);
|
3075 | };
|
3076 | function nextPoint(λ, φ) {
|
3077 | λ *= d3_radians;
|
3078 | 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);
|
3079 | d3_geo_centroidW1 += w;
|
3080 | d3_geo_centroidX1 += w * (x0 + (x0 = x));
|
3081 | d3_geo_centroidY1 += w * (y0 + (y0 = y));
|
3082 | d3_geo_centroidZ1 += w * (z0 + (z0 = z));
|
3083 | d3_geo_centroidPointXYZ(x0, y0, z0);
|
3084 | }
|
3085 | }
|
3086 | function d3_geo_centroidLineEnd() {
|
3087 | d3_geo_centroid.point = d3_geo_centroidPoint;
|
3088 | }
|
3089 | function d3_geo_centroidRingStart() {
|
3090 | var λ00, φ00, x0, y0, z0;
|
3091 | d3_geo_centroid.point = function(λ, φ) {
|
3092 | λ00 = λ, φ00 = φ;
|
3093 | d3_geo_centroid.point = nextPoint;
|
3094 | λ *= d3_radians;
|
3095 | var cosφ = Math.cos(φ *= d3_radians);
|
3096 | x0 = cosφ * Math.cos(λ);
|
3097 | y0 = cosφ * Math.sin(λ);
|
3098 | z0 = Math.sin(φ);
|
3099 | d3_geo_centroidPointXYZ(x0, y0, z0);
|
3100 | };
|
3101 | d3_geo_centroid.lineEnd = function() {
|
3102 | nextPoint(λ00, φ00);
|
3103 | d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
|
3104 | d3_geo_centroid.point = d3_geo_centroidPoint;
|
3105 | };
|
3106 | function nextPoint(λ, φ) {
|
3107 | λ *= d3_radians;
|
3108 | 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);
|
3109 | d3_geo_centroidX2 += v * cx;
|
3110 | d3_geo_centroidY2 += v * cy;
|
3111 | d3_geo_centroidZ2 += v * cz;
|
3112 | d3_geo_centroidW1 += w;
|
3113 | d3_geo_centroidX1 += w * (x0 + (x0 = x));
|
3114 | d3_geo_centroidY1 += w * (y0 + (y0 = y));
|
3115 | d3_geo_centroidZ1 += w * (z0 + (z0 = z));
|
3116 | d3_geo_centroidPointXYZ(x0, y0, z0);
|
3117 | }
|
3118 | }
|
3119 | function d3_true() {
|
3120 | return true;
|
3121 | }
|
3122 | function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
|
3123 | var subject = [], clip = [];
|
3124 | segments.forEach(function(segment) {
|
3125 | if ((n = segment.length - 1) <= 0) return;
|
3126 | var n, p0 = segment[0], p1 = segment[n];
|
3127 | if (d3_geo_sphericalEqual(p0, p1)) {
|
3128 | listener.lineStart();
|
3129 | for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
|
3130 | listener.lineEnd();
|
3131 | return;
|
3132 | }
|
3133 | var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
|
3134 | a.o = b;
|
3135 | subject.push(a);
|
3136 | clip.push(b);
|
3137 | a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
|
3138 | b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
|
3139 | a.o = b;
|
3140 | subject.push(a);
|
3141 | clip.push(b);
|
3142 | });
|
3143 | clip.sort(compare);
|
3144 | d3_geo_clipPolygonLinkCircular(subject);
|
3145 | d3_geo_clipPolygonLinkCircular(clip);
|
3146 | if (!subject.length) return;
|
3147 | for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
|
3148 | clip[i].e = entry = !entry;
|
3149 | }
|
3150 | var start = subject[0], points, point;
|
3151 | while (1) {
|
3152 | var current = start, isSubject = true;
|
3153 | while (current.v) if ((current = current.n) === start) return;
|
3154 | points = current.z;
|
3155 | listener.lineStart();
|
3156 | do {
|
3157 | current.v = current.o.v = true;
|
3158 | if (current.e) {
|
3159 | if (isSubject) {
|
3160 | for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
|
3161 | } else {
|
3162 | interpolate(current.x, current.n.x, 1, listener);
|
3163 | }
|
3164 | current = current.n;
|
3165 | } else {
|
3166 | if (isSubject) {
|
3167 | points = current.p.z;
|
3168 | for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
|
3169 | } else {
|
3170 | interpolate(current.x, current.p.x, -1, listener);
|
3171 | }
|
3172 | current = current.p;
|
3173 | }
|
3174 | current = current.o;
|
3175 | points = current.z;
|
3176 | isSubject = !isSubject;
|
3177 | } while (!current.v);
|
3178 | listener.lineEnd();
|
3179 | }
|
3180 | }
|
3181 | function d3_geo_clipPolygonLinkCircular(array) {
|
3182 | if (!(n = array.length)) return;
|
3183 | var n, i = 0, a = array[0], b;
|
3184 | while (++i < n) {
|
3185 | a.n = b = array[i];
|
3186 | b.p = a;
|
3187 | a = b;
|
3188 | }
|
3189 | a.n = b = array[0];
|
3190 | b.p = a;
|
3191 | }
|
3192 | function d3_geo_clipPolygonIntersection(point, points, other, entry) {
|
3193 | this.x = point;
|
3194 | this.z = points;
|
3195 | this.o = other;
|
3196 | this.e = entry;
|
3197 | this.v = false;
|
3198 | this.n = this.p = null;
|
3199 | }
|
3200 | function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
|
3201 | return function(rotate, listener) {
|
3202 | var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
|
3203 | var clip = {
|
3204 | point: point,
|
3205 | lineStart: lineStart,
|
3206 | lineEnd: lineEnd,
|
3207 | polygonStart: function() {
|
3208 | clip.point = pointRing;
|
3209 | clip.lineStart = ringStart;
|
3210 | clip.lineEnd = ringEnd;
|
3211 | segments = [];
|
3212 | polygon = [];
|
3213 | },
|
3214 | polygonEnd: function() {
|
3215 | clip.point = point;
|
3216 | clip.lineStart = lineStart;
|
3217 | clip.lineEnd = lineEnd;
|
3218 | segments = d3.merge(segments);
|
3219 | var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
|
3220 | if (segments.length) {
|
3221 | if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
|
3222 | d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
|
3223 | } else if (clipStartInside) {
|
3224 | if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
|
3225 | listener.lineStart();
|
3226 | interpolate(null, null, 1, listener);
|
3227 | listener.lineEnd();
|
3228 | }
|
3229 | if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
|
3230 | segments = polygon = null;
|
3231 | },
|
3232 | sphere: function() {
|
3233 | listener.polygonStart();
|
3234 | listener.lineStart();
|
3235 | interpolate(null, null, 1, listener);
|
3236 | listener.lineEnd();
|
3237 | listener.polygonEnd();
|
3238 | }
|
3239 | };
|
3240 | function point(λ, φ) {
|
3241 | var point = rotate(λ, φ);
|
3242 | if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
|
3243 | }
|
3244 | function pointLine(λ, φ) {
|
3245 | var point = rotate(λ, φ);
|
3246 | line.point(point[0], point[1]);
|
3247 | }
|
3248 | function lineStart() {
|
3249 | clip.point = pointLine;
|
3250 | line.lineStart();
|
3251 | }
|
3252 | function lineEnd() {
|
3253 | clip.point = point;
|
3254 | line.lineEnd();
|
3255 | }
|
3256 | var segments;
|
3257 | var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
|
3258 | function pointRing(λ, φ) {
|
3259 | ring.push([ λ, φ ]);
|
3260 | var point = rotate(λ, φ);
|
3261 | ringListener.point(point[0], point[1]);
|
3262 | }
|
3263 | function ringStart() {
|
3264 | ringListener.lineStart();
|
3265 | ring = [];
|
3266 | }
|
3267 | function ringEnd() {
|
3268 | pointRing(ring[0][0], ring[0][1]);
|
3269 | ringListener.lineEnd();
|
3270 | var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
|
3271 | ring.pop();
|
3272 | polygon.push(ring);
|
3273 | ring = null;
|
3274 | if (!n) return;
|
3275 | if (clean & 1) {
|
3276 | segment = ringSegments[0];
|
3277 | var n = segment.length - 1, i = -1, point;
|
3278 | if (n > 0) {
|
3279 | if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
|
3280 | listener.lineStart();
|
3281 | while (++i < n) listener.point((point = segment[i])[0], point[1]);
|
3282 | listener.lineEnd();
|
3283 | }
|
3284 | return;
|
3285 | }
|
3286 | if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
|
3287 | segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
|
3288 | }
|
3289 | return clip;
|
3290 | };
|
3291 | }
|
3292 | function d3_geo_clipSegmentLength1(segment) {
|
3293 | return segment.length > 1;
|
3294 | }
|
3295 | function d3_geo_clipBufferListener() {
|
3296 | var lines = [], line;
|
3297 | return {
|
3298 | lineStart: function() {
|
3299 | lines.push(line = []);
|
3300 | },
|
3301 | point: function(λ, φ) {
|
3302 | line.push([ λ, φ ]);
|
3303 | },
|
3304 | lineEnd: d3_noop,
|
3305 | buffer: function() {
|
3306 | var buffer = lines;
|
3307 | lines = [];
|
3308 | line = null;
|
3309 | return buffer;
|
3310 | },
|
3311 | rejoin: function() {
|
3312 | if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
|
3313 | }
|
3314 | };
|
3315 | }
|
3316 | function d3_geo_clipSort(a, b) {
|
3317 | return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
|
3318 | }
|
3319 | function d3_geo_pointInPolygon(point, polygon) {
|
3320 | var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
|
3321 | d3_geo_areaRingSum.reset();
|
3322 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
3323 | var ring = polygon[i], m = ring.length;
|
3324 | if (!m) continue;
|
3325 | var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
|
3326 | while (true) {
|
3327 | if (j === m) j = 0;
|
3328 | point = ring[j];
|
3329 | 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φ;
|
3330 | d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
|
3331 | polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
|
3332 | if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
|
3333 | var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
|
3334 | d3_geo_cartesianNormalize(arc);
|
3335 | var intersection = d3_geo_cartesianCross(meridianNormal, arc);
|
3336 | d3_geo_cartesianNormalize(intersection);
|
3337 | var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
|
3338 | if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
|
3339 | winding += antimeridian ^ dλ >= 0 ? 1 : -1;
|
3340 | }
|
3341 | }
|
3342 | if (!j++) break;
|
3343 | λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
|
3344 | }
|
3345 | }
|
3346 | return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
|
3347 | }
|
3348 | var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
|
3349 | function d3_geo_clipAntimeridianLine(listener) {
|
3350 | var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
|
3351 | return {
|
3352 | lineStart: function() {
|
3353 | listener.lineStart();
|
3354 | clean = 1;
|
3355 | },
|
3356 | point: function(λ1, φ1) {
|
3357 | var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
|
3358 | if (abs(dλ - π) < ε) {
|
3359 | listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
|
3360 | listener.point(sλ0, φ0);
|
3361 | listener.lineEnd();
|
3362 | listener.lineStart();
|
3363 | listener.point(sλ1, φ0);
|
3364 | listener.point(λ1, φ0);
|
3365 | clean = 0;
|
3366 | } else if (sλ0 !== sλ1 && dλ >= π) {
|
3367 | if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
|
3368 | if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
|
3369 | φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
|
3370 | listener.point(sλ0, φ0);
|
3371 | listener.lineEnd();
|
3372 | listener.lineStart();
|
3373 | listener.point(sλ1, φ0);
|
3374 | clean = 0;
|
3375 | }
|
3376 | listener.point(λ0 = λ1, φ0 = φ1);
|
3377 | sλ0 = sλ1;
|
3378 | },
|
3379 | lineEnd: function() {
|
3380 | listener.lineEnd();
|
3381 | λ0 = φ0 = NaN;
|
3382 | },
|
3383 | clean: function() {
|
3384 | return 2 - clean;
|
3385 | }
|
3386 | };
|
3387 | }
|
3388 | function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
|
3389 | var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
|
3390 | 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;
|
3391 | }
|
3392 | function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
|
3393 | var φ;
|
3394 | if (from == null) {
|
3395 | φ = direction * halfπ;
|
3396 | listener.point(-π, φ);
|
3397 | listener.point(0, φ);
|
3398 | listener.point(π, φ);
|
3399 | listener.point(π, 0);
|
3400 | listener.point(π, -φ);
|
3401 | listener.point(0, -φ);
|
3402 | listener.point(-π, -φ);
|
3403 | listener.point(-π, 0);
|
3404 | listener.point(-π, φ);
|
3405 | } else if (abs(from[0] - to[0]) > ε) {
|
3406 | var s = from[0] < to[0] ? π : -π;
|
3407 | φ = direction * s / 2;
|
3408 | listener.point(-s, φ);
|
3409 | listener.point(0, φ);
|
3410 | listener.point(s, φ);
|
3411 | } else {
|
3412 | listener.point(to[0], to[1]);
|
3413 | }
|
3414 | }
|
3415 | function d3_geo_clipCircle(radius) {
|
3416 | var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
|
3417 | return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
|
3418 | function visible(λ, φ) {
|
3419 | return Math.cos(λ) * Math.cos(φ) > cr;
|
3420 | }
|
3421 | function clipLine(listener) {
|
3422 | var point0, c0, v0, v00, clean;
|
3423 | return {
|
3424 | lineStart: function() {
|
3425 | v00 = v0 = false;
|
3426 | clean = 1;
|
3427 | },
|
3428 | point: function(λ, φ) {
|
3429 | var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
|
3430 | if (!point0 && (v00 = v0 = v)) listener.lineStart();
|
3431 | if (v !== v0) {
|
3432 | point2 = intersect(point0, point1);
|
3433 | if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
|
3434 | point1[0] += ε;
|
3435 | point1[1] += ε;
|
3436 | v = visible(point1[0], point1[1]);
|
3437 | }
|
3438 | }
|
3439 | if (v !== v0) {
|
3440 | clean = 0;
|
3441 | if (v) {
|
3442 | listener.lineStart();
|
3443 | point2 = intersect(point1, point0);
|
3444 | listener.point(point2[0], point2[1]);
|
3445 | } else {
|
3446 | point2 = intersect(point0, point1);
|
3447 | listener.point(point2[0], point2[1]);
|
3448 | listener.lineEnd();
|
3449 | }
|
3450 | point0 = point2;
|
3451 | } else if (notHemisphere && point0 && smallRadius ^ v) {
|
3452 | var t;
|
3453 | if (!(c & c0) && (t = intersect(point1, point0, true))) {
|
3454 | clean = 0;
|
3455 | if (smallRadius) {
|
3456 | listener.lineStart();
|
3457 | listener.point(t[0][0], t[0][1]);
|
3458 | listener.point(t[1][0], t[1][1]);
|
3459 | listener.lineEnd();
|
3460 | } else {
|
3461 | listener.point(t[1][0], t[1][1]);
|
3462 | listener.lineEnd();
|
3463 | listener.lineStart();
|
3464 | listener.point(t[0][0], t[0][1]);
|
3465 | }
|
3466 | }
|
3467 | }
|
3468 | if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
|
3469 | listener.point(point1[0], point1[1]);
|
3470 | }
|
3471 | point0 = point1, v0 = v, c0 = c;
|
3472 | },
|
3473 | lineEnd: function() {
|
3474 | if (v0) listener.lineEnd();
|
3475 | point0 = null;
|
3476 | },
|
3477 | clean: function() {
|
3478 | return clean | (v00 && v0) << 1;
|
3479 | }
|
3480 | };
|
3481 | }
|
3482 | function intersect(a, b, two) {
|
3483 | var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
|
3484 | var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
|
3485 | if (!determinant) return !two && a;
|
3486 | 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);
|
3487 | d3_geo_cartesianAdd(A, B);
|
3488 | 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);
|
3489 | if (t2 < 0) return;
|
3490 | var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
|
3491 | d3_geo_cartesianAdd(q, A);
|
3492 | q = d3_geo_spherical(q);
|
3493 | if (!two) return q;
|
3494 | var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
|
3495 | if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
|
3496 | var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
|
3497 | if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
|
3498 | 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)) {
|
3499 | var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
|
3500 | d3_geo_cartesianAdd(q1, A);
|
3501 | return [ q, d3_geo_spherical(q1) ];
|
3502 | }
|
3503 | }
|
3504 | function code(λ, φ) {
|
3505 | var r = smallRadius ? radius : π - radius, code = 0;
|
3506 | if (λ < -r) code |= 1; else if (λ > r) code |= 2;
|
3507 | if (φ < -r) code |= 4; else if (φ > r) code |= 8;
|
3508 | return code;
|
3509 | }
|
3510 | }
|
3511 | function d3_geom_clipLine(x0, y0, x1, y1) {
|
3512 | return function(line) {
|
3513 | 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;
|
3514 | r = x0 - ax;
|
3515 | if (!dx && r > 0) return;
|
3516 | r /= dx;
|
3517 | if (dx < 0) {
|
3518 | if (r < t0) return;
|
3519 | if (r < t1) t1 = r;
|
3520 | } else if (dx > 0) {
|
3521 | if (r > t1) return;
|
3522 | if (r > t0) t0 = r;
|
3523 | }
|
3524 | r = x1 - ax;
|
3525 | if (!dx && r < 0) return;
|
3526 | r /= dx;
|
3527 | if (dx < 0) {
|
3528 | if (r > t1) return;
|
3529 | if (r > t0) t0 = r;
|
3530 | } else if (dx > 0) {
|
3531 | if (r < t0) return;
|
3532 | if (r < t1) t1 = r;
|
3533 | }
|
3534 | r = y0 - ay;
|
3535 | if (!dy && r > 0) return;
|
3536 | r /= dy;
|
3537 | if (dy < 0) {
|
3538 | if (r < t0) return;
|
3539 | if (r < t1) t1 = r;
|
3540 | } else if (dy > 0) {
|
3541 | if (r > t1) return;
|
3542 | if (r > t0) t0 = r;
|
3543 | }
|
3544 | r = y1 - ay;
|
3545 | if (!dy && r < 0) return;
|
3546 | r /= dy;
|
3547 | if (dy < 0) {
|
3548 | if (r > t1) return;
|
3549 | if (r > t0) t0 = r;
|
3550 | } else if (dy > 0) {
|
3551 | if (r < t0) return;
|
3552 | if (r < t1) t1 = r;
|
3553 | }
|
3554 | if (t0 > 0) line.a = {
|
3555 | x: ax + t0 * dx,
|
3556 | y: ay + t0 * dy
|
3557 | };
|
3558 | if (t1 < 1) line.b = {
|
3559 | x: ax + t1 * dx,
|
3560 | y: ay + t1 * dy
|
3561 | };
|
3562 | return line;
|
3563 | };
|
3564 | }
|
3565 | var d3_geo_clipExtentMAX = 1e9;
|
3566 | d3.geo.clipExtent = function() {
|
3567 | var x0, y0, x1, y1, stream, clip, clipExtent = {
|
3568 | stream: function(output) {
|
3569 | if (stream) stream.valid = false;
|
3570 | stream = clip(output);
|
3571 | stream.valid = true;
|
3572 | return stream;
|
3573 | },
|
3574 | extent: function(_) {
|
3575 | if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
|
3576 | clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
|
3577 | if (stream) stream.valid = false, stream = null;
|
3578 | return clipExtent;
|
3579 | }
|
3580 | };
|
3581 | return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
|
3582 | };
|
3583 | function d3_geo_clipExtent(x0, y0, x1, y1) {
|
3584 | return function(listener) {
|
3585 | var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
|
3586 | var clip = {
|
3587 | point: point,
|
3588 | lineStart: lineStart,
|
3589 | lineEnd: lineEnd,
|
3590 | polygonStart: function() {
|
3591 | listener = bufferListener;
|
3592 | segments = [];
|
3593 | polygon = [];
|
3594 | clean = true;
|
3595 | },
|
3596 | polygonEnd: function() {
|
3597 | listener = listener_;
|
3598 | segments = d3.merge(segments);
|
3599 | var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
|
3600 | if (inside || visible) {
|
3601 | listener.polygonStart();
|
3602 | if (inside) {
|
3603 | listener.lineStart();
|
3604 | interpolate(null, null, 1, listener);
|
3605 | listener.lineEnd();
|
3606 | }
|
3607 | if (visible) {
|
3608 | d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
|
3609 | }
|
3610 | listener.polygonEnd();
|
3611 | }
|
3612 | segments = polygon = ring = null;
|
3613 | }
|
3614 | };
|
3615 | function insidePolygon(p) {
|
3616 | var wn = 0, n = polygon.length, y = p[1];
|
3617 | for (var i = 0; i < n; ++i) {
|
3618 | for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
|
3619 | b = v[j];
|
3620 | if (a[1] <= y) {
|
3621 | if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
|
3622 | } else {
|
3623 | if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
|
3624 | }
|
3625 | a = b;
|
3626 | }
|
3627 | }
|
3628 | return wn !== 0;
|
3629 | }
|
3630 | function interpolate(from, to, direction, listener) {
|
3631 | var a = 0, a1 = 0;
|
3632 | if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
|
3633 | do {
|
3634 | listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
|
3635 | } while ((a = (a + direction + 4) % 4) !== a1);
|
3636 | } else {
|
3637 | listener.point(to[0], to[1]);
|
3638 | }
|
3639 | }
|
3640 | function pointVisible(x, y) {
|
3641 | return x0 <= x && x <= x1 && y0 <= y && y <= y1;
|
3642 | }
|
3643 | function point(x, y) {
|
3644 | if (pointVisible(x, y)) listener.point(x, y);
|
3645 | }
|
3646 | var x__, y__, v__, x_, y_, v_, first, clean;
|
3647 | function lineStart() {
|
3648 | clip.point = linePoint;
|
3649 | if (polygon) polygon.push(ring = []);
|
3650 | first = true;
|
3651 | v_ = false;
|
3652 | x_ = y_ = NaN;
|
3653 | }
|
3654 | function lineEnd() {
|
3655 | if (segments) {
|
3656 | linePoint(x__, y__);
|
3657 | if (v__ && v_) bufferListener.rejoin();
|
3658 | segments.push(bufferListener.buffer());
|
3659 | }
|
3660 | clip.point = point;
|
3661 | if (v_) listener.lineEnd();
|
3662 | }
|
3663 | function linePoint(x, y) {
|
3664 | x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
|
3665 | y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
|
3666 | var v = pointVisible(x, y);
|
3667 | if (polygon) ring.push([ x, y ]);
|
3668 | if (first) {
|
3669 | x__ = x, y__ = y, v__ = v;
|
3670 | first = false;
|
3671 | if (v) {
|
3672 | listener.lineStart();
|
3673 | listener.point(x, y);
|
3674 | }
|
3675 | } else {
|
3676 | if (v && v_) listener.point(x, y); else {
|
3677 | var l = {
|
3678 | a: {
|
3679 | x: x_,
|
3680 | y: y_
|
3681 | },
|
3682 | b: {
|
3683 | x: x,
|
3684 | y: y
|
3685 | }
|
3686 | };
|
3687 | if (clipLine(l)) {
|
3688 | if (!v_) {
|
3689 | listener.lineStart();
|
3690 | listener.point(l.a.x, l.a.y);
|
3691 | }
|
3692 | listener.point(l.b.x, l.b.y);
|
3693 | if (!v) listener.lineEnd();
|
3694 | clean = false;
|
3695 | } else if (v) {
|
3696 | listener.lineStart();
|
3697 | listener.point(x, y);
|
3698 | clean = false;
|
3699 | }
|
3700 | }
|
3701 | }
|
3702 | x_ = x, y_ = y, v_ = v;
|
3703 | }
|
3704 | return clip;
|
3705 | };
|
3706 | function corner(p, direction) {
|
3707 | 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;
|
3708 | }
|
3709 | function compare(a, b) {
|
3710 | return comparePoints(a.x, b.x);
|
3711 | }
|
3712 | function comparePoints(a, b) {
|
3713 | var ca = corner(a, 1), cb = corner(b, 1);
|
3714 | 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];
|
3715 | }
|
3716 | }
|
3717 | function d3_geo_compose(a, b) {
|
3718 | function compose(x, y) {
|
3719 | return x = a(x, y), b(x[0], x[1]);
|
3720 | }
|
3721 | if (a.invert && b.invert) compose.invert = function(x, y) {
|
3722 | return x = b.invert(x, y), x && a.invert(x[0], x[1]);
|
3723 | };
|
3724 | return compose;
|
3725 | }
|
3726 | function d3_geo_conic(projectAt) {
|
3727 | var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
|
3728 | p.parallels = function(_) {
|
3729 | if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
|
3730 | return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
|
3731 | };
|
3732 | return p;
|
3733 | }
|
3734 | function d3_geo_conicEqualArea(φ0, φ1) {
|
3735 | 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;
|
3736 | function forward(λ, φ) {
|
3737 | var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
|
3738 | return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
|
3739 | }
|
3740 | forward.invert = function(x, y) {
|
3741 | var ρ0_y = ρ0 - y;
|
3742 | return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
|
3743 | };
|
3744 | return forward;
|
3745 | }
|
3746 | (d3.geo.conicEqualArea = function() {
|
3747 | return d3_geo_conic(d3_geo_conicEqualArea);
|
3748 | }).raw = d3_geo_conicEqualArea;
|
3749 | d3.geo.albers = function() {
|
3750 | return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
|
3751 | };
|
3752 | d3.geo.albersUsa = function() {
|
3753 | var lower48 = d3.geo.albers();
|
3754 | var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
|
3755 | var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
|
3756 | var point, pointStream = {
|
3757 | point: function(x, y) {
|
3758 | point = [ x, y ];
|
3759 | }
|
3760 | }, lower48Point, alaskaPoint, hawaiiPoint;
|
3761 | function albersUsa(coordinates) {
|
3762 | var x = coordinates[0], y = coordinates[1];
|
3763 | point = null;
|
3764 | (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
|
3765 | return point;
|
3766 | }
|
3767 | albersUsa.invert = function(coordinates) {
|
3768 | var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
|
3769 | return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
|
3770 | };
|
3771 | albersUsa.stream = function(stream) {
|
3772 | var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
|
3773 | return {
|
3774 | point: function(x, y) {
|
3775 | lower48Stream.point(x, y);
|
3776 | alaskaStream.point(x, y);
|
3777 | hawaiiStream.point(x, y);
|
3778 | },
|
3779 | sphere: function() {
|
3780 | lower48Stream.sphere();
|
3781 | alaskaStream.sphere();
|
3782 | hawaiiStream.sphere();
|
3783 | },
|
3784 | lineStart: function() {
|
3785 | lower48Stream.lineStart();
|
3786 | alaskaStream.lineStart();
|
3787 | hawaiiStream.lineStart();
|
3788 | },
|
3789 | lineEnd: function() {
|
3790 | lower48Stream.lineEnd();
|
3791 | alaskaStream.lineEnd();
|
3792 | hawaiiStream.lineEnd();
|
3793 | },
|
3794 | polygonStart: function() {
|
3795 | lower48Stream.polygonStart();
|
3796 | alaskaStream.polygonStart();
|
3797 | hawaiiStream.polygonStart();
|
3798 | },
|
3799 | polygonEnd: function() {
|
3800 | lower48Stream.polygonEnd();
|
3801 | alaskaStream.polygonEnd();
|
3802 | hawaiiStream.polygonEnd();
|
3803 | }
|
3804 | };
|
3805 | };
|
3806 | albersUsa.precision = function(_) {
|
3807 | if (!arguments.length) return lower48.precision();
|
3808 | lower48.precision(_);
|
3809 | alaska.precision(_);
|
3810 | hawaii.precision(_);
|
3811 | return albersUsa;
|
3812 | };
|
3813 | albersUsa.scale = function(_) {
|
3814 | if (!arguments.length) return lower48.scale();
|
3815 | lower48.scale(_);
|
3816 | alaska.scale(_ * .35);
|
3817 | hawaii.scale(_);
|
3818 | return albersUsa.translate(lower48.translate());
|
3819 | };
|
3820 | albersUsa.translate = function(_) {
|
3821 | if (!arguments.length) return lower48.translate();
|
3822 | var k = lower48.scale(), x = +_[0], y = +_[1];
|
3823 | lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
|
3824 | 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;
|
3825 | 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;
|
3826 | return albersUsa;
|
3827 | };
|
3828 | return albersUsa.scale(1070);
|
3829 | };
|
3830 | var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
|
3831 | point: d3_noop,
|
3832 | lineStart: d3_noop,
|
3833 | lineEnd: d3_noop,
|
3834 | polygonStart: function() {
|
3835 | d3_geo_pathAreaPolygon = 0;
|
3836 | d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
|
3837 | },
|
3838 | polygonEnd: function() {
|
3839 | d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
|
3840 | d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
|
3841 | }
|
3842 | };
|
3843 | function d3_geo_pathAreaRingStart() {
|
3844 | var x00, y00, x0, y0;
|
3845 | d3_geo_pathArea.point = function(x, y) {
|
3846 | d3_geo_pathArea.point = nextPoint;
|
3847 | x00 = x0 = x, y00 = y0 = y;
|
3848 | };
|
3849 | function nextPoint(x, y) {
|
3850 | d3_geo_pathAreaPolygon += y0 * x - x0 * y;
|
3851 | x0 = x, y0 = y;
|
3852 | }
|
3853 | d3_geo_pathArea.lineEnd = function() {
|
3854 | nextPoint(x00, y00);
|
3855 | };
|
3856 | }
|
3857 | var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
|
3858 | var d3_geo_pathBounds = {
|
3859 | point: d3_geo_pathBoundsPoint,
|
3860 | lineStart: d3_noop,
|
3861 | lineEnd: d3_noop,
|
3862 | polygonStart: d3_noop,
|
3863 | polygonEnd: d3_noop
|
3864 | };
|
3865 | function d3_geo_pathBoundsPoint(x, y) {
|
3866 | if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
|
3867 | if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
|
3868 | if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
|
3869 | if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
|
3870 | }
|
3871 | function d3_geo_pathBuffer() {
|
3872 | var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
|
3873 | var stream = {
|
3874 | point: point,
|
3875 | lineStart: function() {
|
3876 | stream.point = pointLineStart;
|
3877 | },
|
3878 | lineEnd: lineEnd,
|
3879 | polygonStart: function() {
|
3880 | stream.lineEnd = lineEndPolygon;
|
3881 | },
|
3882 | polygonEnd: function() {
|
3883 | stream.lineEnd = lineEnd;
|
3884 | stream.point = point;
|
3885 | },
|
3886 | pointRadius: function(_) {
|
3887 | pointCircle = d3_geo_pathBufferCircle(_);
|
3888 | return stream;
|
3889 | },
|
3890 | result: function() {
|
3891 | if (buffer.length) {
|
3892 | var result = buffer.join("");
|
3893 | buffer = [];
|
3894 | return result;
|
3895 | }
|
3896 | }
|
3897 | };
|
3898 | function point(x, y) {
|
3899 | buffer.push("M", x, ",", y, pointCircle);
|
3900 | }
|
3901 | function pointLineStart(x, y) {
|
3902 | buffer.push("M", x, ",", y);
|
3903 | stream.point = pointLine;
|
3904 | }
|
3905 | function pointLine(x, y) {
|
3906 | buffer.push("L", x, ",", y);
|
3907 | }
|
3908 | function lineEnd() {
|
3909 | stream.point = point;
|
3910 | }
|
3911 | function lineEndPolygon() {
|
3912 | buffer.push("Z");
|
3913 | }
|
3914 | return stream;
|
3915 | }
|
3916 | function d3_geo_pathBufferCircle(radius) {
|
3917 | return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
|
3918 | }
|
3919 | var d3_geo_pathCentroid = {
|
3920 | point: d3_geo_pathCentroidPoint,
|
3921 | lineStart: d3_geo_pathCentroidLineStart,
|
3922 | lineEnd: d3_geo_pathCentroidLineEnd,
|
3923 | polygonStart: function() {
|
3924 | d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
|
3925 | },
|
3926 | polygonEnd: function() {
|
3927 | d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
|
3928 | d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
|
3929 | d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
|
3930 | }
|
3931 | };
|
3932 | function d3_geo_pathCentroidPoint(x, y) {
|
3933 | d3_geo_centroidX0 += x;
|
3934 | d3_geo_centroidY0 += y;
|
3935 | ++d3_geo_centroidZ0;
|
3936 | }
|
3937 | function d3_geo_pathCentroidLineStart() {
|
3938 | var x0, y0;
|
3939 | d3_geo_pathCentroid.point = function(x, y) {
|
3940 | d3_geo_pathCentroid.point = nextPoint;
|
3941 | d3_geo_pathCentroidPoint(x0 = x, y0 = y);
|
3942 | };
|
3943 | function nextPoint(x, y) {
|
3944 | var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
|
3945 | d3_geo_centroidX1 += z * (x0 + x) / 2;
|
3946 | d3_geo_centroidY1 += z * (y0 + y) / 2;
|
3947 | d3_geo_centroidZ1 += z;
|
3948 | d3_geo_pathCentroidPoint(x0 = x, y0 = y);
|
3949 | }
|
3950 | }
|
3951 | function d3_geo_pathCentroidLineEnd() {
|
3952 | d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
|
3953 | }
|
3954 | function d3_geo_pathCentroidRingStart() {
|
3955 | var x00, y00, x0, y0;
|
3956 | d3_geo_pathCentroid.point = function(x, y) {
|
3957 | d3_geo_pathCentroid.point = nextPoint;
|
3958 | d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
|
3959 | };
|
3960 | function nextPoint(x, y) {
|
3961 | var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
|
3962 | d3_geo_centroidX1 += z * (x0 + x) / 2;
|
3963 | d3_geo_centroidY1 += z * (y0 + y) / 2;
|
3964 | d3_geo_centroidZ1 += z;
|
3965 | z = y0 * x - x0 * y;
|
3966 | d3_geo_centroidX2 += z * (x0 + x);
|
3967 | d3_geo_centroidY2 += z * (y0 + y);
|
3968 | d3_geo_centroidZ2 += z * 3;
|
3969 | d3_geo_pathCentroidPoint(x0 = x, y0 = y);
|
3970 | }
|
3971 | d3_geo_pathCentroid.lineEnd = function() {
|
3972 | nextPoint(x00, y00);
|
3973 | };
|
3974 | }
|
3975 | function d3_geo_pathContext(context) {
|
3976 | var pointRadius = 4.5;
|
3977 | var stream = {
|
3978 | point: point,
|
3979 | lineStart: function() {
|
3980 | stream.point = pointLineStart;
|
3981 | },
|
3982 | lineEnd: lineEnd,
|
3983 | polygonStart: function() {
|
3984 | stream.lineEnd = lineEndPolygon;
|
3985 | },
|
3986 | polygonEnd: function() {
|
3987 | stream.lineEnd = lineEnd;
|
3988 | stream.point = point;
|
3989 | },
|
3990 | pointRadius: function(_) {
|
3991 | pointRadius = _;
|
3992 | return stream;
|
3993 | },
|
3994 | result: d3_noop
|
3995 | };
|
3996 | function point(x, y) {
|
3997 | context.moveTo(x, y);
|
3998 | context.arc(x, y, pointRadius, 0, τ);
|
3999 | }
|
4000 | function pointLineStart(x, y) {
|
4001 | context.moveTo(x, y);
|
4002 | stream.point = pointLine;
|
4003 | }
|
4004 | function pointLine(x, y) {
|
4005 | context.lineTo(x, y);
|
4006 | }
|
4007 | function lineEnd() {
|
4008 | stream.point = point;
|
4009 | }
|
4010 | function lineEndPolygon() {
|
4011 | context.closePath();
|
4012 | }
|
4013 | return stream;
|
4014 | }
|
4015 | function d3_geo_resample(project) {
|
4016 | var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
|
4017 | function resample(stream) {
|
4018 | return (maxDepth ? resampleRecursive : resampleNone)(stream);
|
4019 | }
|
4020 | function resampleNone(stream) {
|
4021 | return d3_geo_transformPoint(stream, function(x, y) {
|
4022 | x = project(x, y);
|
4023 | stream.point(x[0], x[1]);
|
4024 | });
|
4025 | }
|
4026 | function resampleRecursive(stream) {
|
4027 | var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
|
4028 | var resample = {
|
4029 | point: point,
|
4030 | lineStart: lineStart,
|
4031 | lineEnd: lineEnd,
|
4032 | polygonStart: function() {
|
4033 | stream.polygonStart();
|
4034 | resample.lineStart = ringStart;
|
4035 | },
|
4036 | polygonEnd: function() {
|
4037 | stream.polygonEnd();
|
4038 | resample.lineStart = lineStart;
|
4039 | }
|
4040 | };
|
4041 | function point(x, y) {
|
4042 | x = project(x, y);
|
4043 | stream.point(x[0], x[1]);
|
4044 | }
|
4045 | function lineStart() {
|
4046 | x0 = NaN;
|
4047 | resample.point = linePoint;
|
4048 | stream.lineStart();
|
4049 | }
|
4050 | function linePoint(λ, φ) {
|
4051 | var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
|
4052 | 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);
|
4053 | stream.point(x0, y0);
|
4054 | }
|
4055 | function lineEnd() {
|
4056 | resample.point = point;
|
4057 | stream.lineEnd();
|
4058 | }
|
4059 | function ringStart() {
|
4060 | lineStart();
|
4061 | resample.point = ringPoint;
|
4062 | resample.lineEnd = ringEnd;
|
4063 | }
|
4064 | function ringPoint(λ, φ) {
|
4065 | linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
|
4066 | resample.point = linePoint;
|
4067 | }
|
4068 | function ringEnd() {
|
4069 | resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
|
4070 | resample.lineEnd = lineEnd;
|
4071 | lineEnd();
|
4072 | }
|
4073 | return resample;
|
4074 | }
|
4075 | function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
|
4076 | var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
|
4077 | if (d2 > 4 * δ2 && depth--) {
|
4078 | 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;
|
4079 | if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
|
4080 | resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
|
4081 | stream.point(x2, y2);
|
4082 | resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
|
4083 | }
|
4084 | }
|
4085 | }
|
4086 | resample.precision = function(_) {
|
4087 | if (!arguments.length) return Math.sqrt(δ2);
|
4088 | maxDepth = (δ2 = _ * _) > 0 && 16;
|
4089 | return resample;
|
4090 | };
|
4091 | return resample;
|
4092 | }
|
4093 | d3.geo.path = function() {
|
4094 | var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
|
4095 | function path(object) {
|
4096 | if (object) {
|
4097 | if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
|
4098 | if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
|
4099 | d3.geo.stream(object, cacheStream);
|
4100 | }
|
4101 | return contextStream.result();
|
4102 | }
|
4103 | path.area = function(object) {
|
4104 | d3_geo_pathAreaSum = 0;
|
4105 | d3.geo.stream(object, projectStream(d3_geo_pathArea));
|
4106 | return d3_geo_pathAreaSum;
|
4107 | };
|
4108 | path.centroid = function(object) {
|
4109 | 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;
|
4110 | d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
|
4111 | 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 ];
|
4112 | };
|
4113 | path.bounds = function(object) {
|
4114 | d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
|
4115 | d3.geo.stream(object, projectStream(d3_geo_pathBounds));
|
4116 | return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
|
4117 | };
|
4118 | path.projection = function(_) {
|
4119 | if (!arguments.length) return projection;
|
4120 | projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
|
4121 | return reset();
|
4122 | };
|
4123 | path.context = function(_) {
|
4124 | if (!arguments.length) return context;
|
4125 | contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
|
4126 | if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
|
4127 | return reset();
|
4128 | };
|
4129 | path.pointRadius = function(_) {
|
4130 | if (!arguments.length) return pointRadius;
|
4131 | pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
|
4132 | return path;
|
4133 | };
|
4134 | function reset() {
|
4135 | cacheStream = null;
|
4136 | return path;
|
4137 | }
|
4138 | return path.projection(d3.geo.albersUsa()).context(null);
|
4139 | };
|
4140 | function d3_geo_pathProjectStream(project) {
|
4141 | var resample = d3_geo_resample(function(x, y) {
|
4142 | return project([ x * d3_degrees, y * d3_degrees ]);
|
4143 | });
|
4144 | return function(stream) {
|
4145 | return d3_geo_projectionRadians(resample(stream));
|
4146 | };
|
4147 | }
|
4148 | d3.geo.transform = function(methods) {
|
4149 | return {
|
4150 | stream: function(stream) {
|
4151 | var transform = new d3_geo_transform(stream);
|
4152 | for (var k in methods) transform[k] = methods[k];
|
4153 | return transform;
|
4154 | }
|
4155 | };
|
4156 | };
|
4157 | function d3_geo_transform(stream) {
|
4158 | this.stream = stream;
|
4159 | }
|
4160 | d3_geo_transform.prototype = {
|
4161 | point: function(x, y) {
|
4162 | this.stream.point(x, y);
|
4163 | },
|
4164 | sphere: function() {
|
4165 | this.stream.sphere();
|
4166 | },
|
4167 | lineStart: function() {
|
4168 | this.stream.lineStart();
|
4169 | },
|
4170 | lineEnd: function() {
|
4171 | this.stream.lineEnd();
|
4172 | },
|
4173 | polygonStart: function() {
|
4174 | this.stream.polygonStart();
|
4175 | },
|
4176 | polygonEnd: function() {
|
4177 | this.stream.polygonEnd();
|
4178 | }
|
4179 | };
|
4180 | function d3_geo_transformPoint(stream, point) {
|
4181 | return {
|
4182 | point: point,
|
4183 | sphere: function() {
|
4184 | stream.sphere();
|
4185 | },
|
4186 | lineStart: function() {
|
4187 | stream.lineStart();
|
4188 | },
|
4189 | lineEnd: function() {
|
4190 | stream.lineEnd();
|
4191 | },
|
4192 | polygonStart: function() {
|
4193 | stream.polygonStart();
|
4194 | },
|
4195 | polygonEnd: function() {
|
4196 | stream.polygonEnd();
|
4197 | }
|
4198 | };
|
4199 | }
|
4200 | d3.geo.projection = d3_geo_projection;
|
4201 | d3.geo.projectionMutator = d3_geo_projectionMutator;
|
4202 | function d3_geo_projection(project) {
|
4203 | return d3_geo_projectionMutator(function() {
|
4204 | return project;
|
4205 | })();
|
4206 | }
|
4207 | function d3_geo_projectionMutator(projectAt) {
|
4208 | var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
|
4209 | x = project(x, y);
|
4210 | return [ x[0] * k + δx, δy - x[1] * k ];
|
4211 | }), 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;
|
4212 | function projection(point) {
|
4213 | point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
|
4214 | return [ point[0] * k + δx, δy - point[1] * k ];
|
4215 | }
|
4216 | function invert(point) {
|
4217 | point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
|
4218 | return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
|
4219 | }
|
4220 | projection.stream = function(output) {
|
4221 | if (stream) stream.valid = false;
|
4222 | stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
|
4223 | stream.valid = true;
|
4224 | return stream;
|
4225 | };
|
4226 | projection.clipAngle = function(_) {
|
4227 | if (!arguments.length) return clipAngle;
|
4228 | preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
|
4229 | return invalidate();
|
4230 | };
|
4231 | projection.clipExtent = function(_) {
|
4232 | if (!arguments.length) return clipExtent;
|
4233 | clipExtent = _;
|
4234 | postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
|
4235 | return invalidate();
|
4236 | };
|
4237 | projection.scale = function(_) {
|
4238 | if (!arguments.length) return k;
|
4239 | k = +_;
|
4240 | return reset();
|
4241 | };
|
4242 | projection.translate = function(_) {
|
4243 | if (!arguments.length) return [ x, y ];
|
4244 | x = +_[0];
|
4245 | y = +_[1];
|
4246 | return reset();
|
4247 | };
|
4248 | projection.center = function(_) {
|
4249 | if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
|
4250 | λ = _[0] % 360 * d3_radians;
|
4251 | φ = _[1] % 360 * d3_radians;
|
4252 | return reset();
|
4253 | };
|
4254 | projection.rotate = function(_) {
|
4255 | if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
|
4256 | δλ = _[0] % 360 * d3_radians;
|
4257 | δφ = _[1] % 360 * d3_radians;
|
4258 | δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
|
4259 | return reset();
|
4260 | };
|
4261 | d3.rebind(projection, projectResample, "precision");
|
4262 | function reset() {
|
4263 | projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
|
4264 | var center = project(λ, φ);
|
4265 | δx = x - center[0] * k;
|
4266 | δy = y + center[1] * k;
|
4267 | return invalidate();
|
4268 | }
|
4269 | function invalidate() {
|
4270 | if (stream) stream.valid = false, stream = null;
|
4271 | return projection;
|
4272 | }
|
4273 | return function() {
|
4274 | project = projectAt.apply(this, arguments);
|
4275 | projection.invert = project.invert && invert;
|
4276 | return reset();
|
4277 | };
|
4278 | }
|
4279 | function d3_geo_projectionRadians(stream) {
|
4280 | return d3_geo_transformPoint(stream, function(x, y) {
|
4281 | stream.point(x * d3_radians, y * d3_radians);
|
4282 | });
|
4283 | }
|
4284 | function d3_geo_equirectangular(λ, φ) {
|
4285 | return [ λ, φ ];
|
4286 | }
|
4287 | (d3.geo.equirectangular = function() {
|
4288 | return d3_geo_projection(d3_geo_equirectangular);
|
4289 | }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
|
4290 | d3.geo.rotation = function(rotate) {
|
4291 | rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
|
4292 | function forward(coordinates) {
|
4293 | coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
|
4294 | return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
|
4295 | }
|
4296 | forward.invert = function(coordinates) {
|
4297 | coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
|
4298 | return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
|
4299 | };
|
4300 | return forward;
|
4301 | };
|
4302 | function d3_geo_identityRotation(λ, φ) {
|
4303 | return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
|
4304 | }
|
4305 | d3_geo_identityRotation.invert = d3_geo_equirectangular;
|
4306 | function d3_geo_rotation(δλ, δφ, δγ) {
|
4307 | return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
|
4308 | }
|
4309 | function d3_geo_forwardRotationλ(δλ) {
|
4310 | return function(λ, φ) {
|
4311 | return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
|
4312 | };
|
4313 | }
|
4314 | function d3_geo_rotationλ(δλ) {
|
4315 | var rotation = d3_geo_forwardRotationλ(δλ);
|
4316 | rotation.invert = d3_geo_forwardRotationλ(-δλ);
|
4317 | return rotation;
|
4318 | }
|
4319 | function d3_geo_rotationφγ(δφ, δγ) {
|
4320 | var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
|
4321 | function rotation(λ, φ) {
|
4322 | var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
|
4323 | return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
|
4324 | }
|
4325 | rotation.invert = function(λ, φ) {
|
4326 | var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
|
4327 | return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
|
4328 | };
|
4329 | return rotation;
|
4330 | }
|
4331 | d3.geo.circle = function() {
|
4332 | var origin = [ 0, 0 ], angle, precision = 6, interpolate;
|
4333 | function circle() {
|
4334 | 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 = [];
|
4335 | interpolate(null, null, 1, {
|
4336 | point: function(x, y) {
|
4337 | ring.push(x = rotate(x, y));
|
4338 | x[0] *= d3_degrees, x[1] *= d3_degrees;
|
4339 | }
|
4340 | });
|
4341 | return {
|
4342 | type: "Polygon",
|
4343 | coordinates: [ ring ]
|
4344 | };
|
4345 | }
|
4346 | circle.origin = function(x) {
|
4347 | if (!arguments.length) return origin;
|
4348 | origin = x;
|
4349 | return circle;
|
4350 | };
|
4351 | circle.angle = function(x) {
|
4352 | if (!arguments.length) return angle;
|
4353 | interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
|
4354 | return circle;
|
4355 | };
|
4356 | circle.precision = function(_) {
|
4357 | if (!arguments.length) return precision;
|
4358 | interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
|
4359 | return circle;
|
4360 | };
|
4361 | return circle.angle(90);
|
4362 | };
|
4363 | function d3_geo_circleInterpolate(radius, precision) {
|
4364 | var cr = Math.cos(radius), sr = Math.sin(radius);
|
4365 | return function(from, to, direction, listener) {
|
4366 | var step = direction * precision;
|
4367 | if (from != null) {
|
4368 | from = d3_geo_circleAngle(cr, from);
|
4369 | to = d3_geo_circleAngle(cr, to);
|
4370 | if (direction > 0 ? from < to : from > to) from += direction * τ;
|
4371 | } else {
|
4372 | from = radius + direction * τ;
|
4373 | to = radius - .5 * step;
|
4374 | }
|
4375 | for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
|
4376 | listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
|
4377 | }
|
4378 | };
|
4379 | }
|
4380 | function d3_geo_circleAngle(cr, point) {
|
4381 | var a = d3_geo_cartesian(point);
|
4382 | a[0] -= cr;
|
4383 | d3_geo_cartesianNormalize(a);
|
4384 | var angle = d3_acos(-a[1]);
|
4385 | return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
|
4386 | }
|
4387 | d3.geo.distance = function(a, b) {
|
4388 | 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;
|
4389 | 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Δλ);
|
4390 | };
|
4391 | d3.geo.graticule = function() {
|
4392 | var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
|
4393 | function graticule() {
|
4394 | return {
|
4395 | type: "MultiLineString",
|
4396 | coordinates: lines()
|
4397 | };
|
4398 | }
|
4399 | function lines() {
|
4400 | 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) {
|
4401 | return abs(x % DX) > ε;
|
4402 | }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
|
4403 | return abs(y % DY) > ε;
|
4404 | }).map(y));
|
4405 | }
|
4406 | graticule.lines = function() {
|
4407 | return lines().map(function(coordinates) {
|
4408 | return {
|
4409 | type: "LineString",
|
4410 | coordinates: coordinates
|
4411 | };
|
4412 | });
|
4413 | };
|
4414 | graticule.outline = function() {
|
4415 | return {
|
4416 | type: "Polygon",
|
4417 | coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
|
4418 | };
|
4419 | };
|
4420 | graticule.extent = function(_) {
|
4421 | if (!arguments.length) return graticule.minorExtent();
|
4422 | return graticule.majorExtent(_).minorExtent(_);
|
4423 | };
|
4424 | graticule.majorExtent = function(_) {
|
4425 | if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
|
4426 | X0 = +_[0][0], X1 = +_[1][0];
|
4427 | Y0 = +_[0][1], Y1 = +_[1][1];
|
4428 | if (X0 > X1) _ = X0, X0 = X1, X1 = _;
|
4429 | if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
|
4430 | return graticule.precision(precision);
|
4431 | };
|
4432 | graticule.minorExtent = function(_) {
|
4433 | if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
|
4434 | x0 = +_[0][0], x1 = +_[1][0];
|
4435 | y0 = +_[0][1], y1 = +_[1][1];
|
4436 | if (x0 > x1) _ = x0, x0 = x1, x1 = _;
|
4437 | if (y0 > y1) _ = y0, y0 = y1, y1 = _;
|
4438 | return graticule.precision(precision);
|
4439 | };
|
4440 | graticule.step = function(_) {
|
4441 | if (!arguments.length) return graticule.minorStep();
|
4442 | return graticule.majorStep(_).minorStep(_);
|
4443 | };
|
4444 | graticule.majorStep = function(_) {
|
4445 | if (!arguments.length) return [ DX, DY ];
|
4446 | DX = +_[0], DY = +_[1];
|
4447 | return graticule;
|
4448 | };
|
4449 | graticule.minorStep = function(_) {
|
4450 | if (!arguments.length) return [ dx, dy ];
|
4451 | dx = +_[0], dy = +_[1];
|
4452 | return graticule;
|
4453 | };
|
4454 | graticule.precision = function(_) {
|
4455 | if (!arguments.length) return precision;
|
4456 | precision = +_;
|
4457 | x = d3_geo_graticuleX(y0, y1, 90);
|
4458 | y = d3_geo_graticuleY(x0, x1, precision);
|
4459 | X = d3_geo_graticuleX(Y0, Y1, 90);
|
4460 | Y = d3_geo_graticuleY(X0, X1, precision);
|
4461 | return graticule;
|
4462 | };
|
4463 | return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
|
4464 | };
|
4465 | function d3_geo_graticuleX(y0, y1, dy) {
|
4466 | var y = d3.range(y0, y1 - ε, dy).concat(y1);
|
4467 | return function(x) {
|
4468 | return y.map(function(y) {
|
4469 | return [ x, y ];
|
4470 | });
|
4471 | };
|
4472 | }
|
4473 | function d3_geo_graticuleY(x0, x1, dx) {
|
4474 | var x = d3.range(x0, x1 - ε, dx).concat(x1);
|
4475 | return function(y) {
|
4476 | return x.map(function(x) {
|
4477 | return [ x, y ];
|
4478 | });
|
4479 | };
|
4480 | }
|
4481 | function d3_source(d) {
|
4482 | return d.source;
|
4483 | }
|
4484 | function d3_target(d) {
|
4485 | return d.target;
|
4486 | }
|
4487 | d3.geo.greatArc = function() {
|
4488 | var source = d3_source, source_, target = d3_target, target_;
|
4489 | function greatArc() {
|
4490 | return {
|
4491 | type: "LineString",
|
4492 | coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
|
4493 | };
|
4494 | }
|
4495 | greatArc.distance = function() {
|
4496 | return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
|
4497 | };
|
4498 | greatArc.source = function(_) {
|
4499 | if (!arguments.length) return source;
|
4500 | source = _, source_ = typeof _ === "function" ? null : _;
|
4501 | return greatArc;
|
4502 | };
|
4503 | greatArc.target = function(_) {
|
4504 | if (!arguments.length) return target;
|
4505 | target = _, target_ = typeof _ === "function" ? null : _;
|
4506 | return greatArc;
|
4507 | };
|
4508 | greatArc.precision = function() {
|
4509 | return arguments.length ? greatArc : 0;
|
4510 | };
|
4511 | return greatArc;
|
4512 | };
|
4513 | d3.geo.interpolate = function(source, target) {
|
4514 | return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
|
4515 | };
|
4516 | function d3_geo_interpolate(x0, y0, x1, y1) {
|
4517 | 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);
|
4518 | var interpolate = d ? function(t) {
|
4519 | 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;
|
4520 | return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
|
4521 | } : function() {
|
4522 | return [ x0 * d3_degrees, y0 * d3_degrees ];
|
4523 | };
|
4524 | interpolate.distance = d;
|
4525 | return interpolate;
|
4526 | }
|
4527 | d3.geo.length = function(object) {
|
4528 | d3_geo_lengthSum = 0;
|
4529 | d3.geo.stream(object, d3_geo_length);
|
4530 | return d3_geo_lengthSum;
|
4531 | };
|
4532 | var d3_geo_lengthSum;
|
4533 | var d3_geo_length = {
|
4534 | sphere: d3_noop,
|
4535 | point: d3_noop,
|
4536 | lineStart: d3_geo_lengthLineStart,
|
4537 | lineEnd: d3_noop,
|
4538 | polygonStart: d3_noop,
|
4539 | polygonEnd: d3_noop
|
4540 | };
|
4541 | function d3_geo_lengthLineStart() {
|
4542 | var λ0, sinφ0, cosφ0;
|
4543 | d3_geo_length.point = function(λ, φ) {
|
4544 | λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
|
4545 | d3_geo_length.point = nextPoint;
|
4546 | };
|
4547 | d3_geo_length.lineEnd = function() {
|
4548 | d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
|
4549 | };
|
4550 | function nextPoint(λ, φ) {
|
4551 | var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
|
4552 | 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Δλ);
|
4553 | λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
|
4554 | }
|
4555 | }
|
4556 | function d3_geo_azimuthal(scale, angle) {
|
4557 | function azimuthal(λ, φ) {
|
4558 | var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
|
4559 | return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
|
4560 | }
|
4561 | azimuthal.invert = function(x, y) {
|
4562 | var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
|
4563 | return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
|
4564 | };
|
4565 | return azimuthal;
|
4566 | }
|
4567 | var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
|
4568 | return Math.sqrt(2 / (1 + cosλcosφ));
|
4569 | }, function(ρ) {
|
4570 | return 2 * Math.asin(ρ / 2);
|
4571 | });
|
4572 | (d3.geo.azimuthalEqualArea = function() {
|
4573 | return d3_geo_projection(d3_geo_azimuthalEqualArea);
|
4574 | }).raw = d3_geo_azimuthalEqualArea;
|
4575 | var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
|
4576 | var c = Math.acos(cosλcosφ);
|
4577 | return c && c / Math.sin(c);
|
4578 | }, d3_identity);
|
4579 | (d3.geo.azimuthalEquidistant = function() {
|
4580 | return d3_geo_projection(d3_geo_azimuthalEquidistant);
|
4581 | }).raw = d3_geo_azimuthalEquidistant;
|
4582 | function d3_geo_conicConformal(φ0, φ1) {
|
4583 | var cosφ0 = Math.cos(φ0), t = function(φ) {
|
4584 | return Math.tan(π / 4 + φ / 2);
|
4585 | }, 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;
|
4586 | if (!n) return d3_geo_mercator;
|
4587 | function forward(λ, φ) {
|
4588 | if (F > 0) {
|
4589 | if (φ < -halfπ + ε) φ = -halfπ + ε;
|
4590 | } else {
|
4591 | if (φ > halfπ - ε) φ = halfπ - ε;
|
4592 | }
|
4593 | var ρ = F / Math.pow(t(φ), n);
|
4594 | return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
|
4595 | }
|
4596 | forward.invert = function(x, y) {
|
4597 | var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
|
4598 | return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
|
4599 | };
|
4600 | return forward;
|
4601 | }
|
4602 | (d3.geo.conicConformal = function() {
|
4603 | return d3_geo_conic(d3_geo_conicConformal);
|
4604 | }).raw = d3_geo_conicConformal;
|
4605 | function d3_geo_conicEquidistant(φ0, φ1) {
|
4606 | var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
|
4607 | if (abs(n) < ε) return d3_geo_equirectangular;
|
4608 | function forward(λ, φ) {
|
4609 | var ρ = G - φ;
|
4610 | return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
|
4611 | }
|
4612 | forward.invert = function(x, y) {
|
4613 | var ρ0_y = G - y;
|
4614 | return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
|
4615 | };
|
4616 | return forward;
|
4617 | }
|
4618 | (d3.geo.conicEquidistant = function() {
|
4619 | return d3_geo_conic(d3_geo_conicEquidistant);
|
4620 | }).raw = d3_geo_conicEquidistant;
|
4621 | var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
|
4622 | return 1 / cosλcosφ;
|
4623 | }, Math.atan);
|
4624 | (d3.geo.gnomonic = function() {
|
4625 | return d3_geo_projection(d3_geo_gnomonic);
|
4626 | }).raw = d3_geo_gnomonic;
|
4627 | function d3_geo_mercator(λ, φ) {
|
4628 | return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
|
4629 | }
|
4630 | d3_geo_mercator.invert = function(x, y) {
|
4631 | return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
|
4632 | };
|
4633 | function d3_geo_mercatorProjection(project) {
|
4634 | var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
|
4635 | m.scale = function() {
|
4636 | var v = scale.apply(m, arguments);
|
4637 | return v === m ? clipAuto ? m.clipExtent(null) : m : v;
|
4638 | };
|
4639 | m.translate = function() {
|
4640 | var v = translate.apply(m, arguments);
|
4641 | return v === m ? clipAuto ? m.clipExtent(null) : m : v;
|
4642 | };
|
4643 | m.clipExtent = function(_) {
|
4644 | var v = clipExtent.apply(m, arguments);
|
4645 | if (v === m) {
|
4646 | if (clipAuto = _ == null) {
|
4647 | var k = π * scale(), t = translate();
|
4648 | clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
|
4649 | }
|
4650 | } else if (clipAuto) {
|
4651 | v = null;
|
4652 | }
|
4653 | return v;
|
4654 | };
|
4655 | return m.clipExtent(null);
|
4656 | }
|
4657 | (d3.geo.mercator = function() {
|
4658 | return d3_geo_mercatorProjection(d3_geo_mercator);
|
4659 | }).raw = d3_geo_mercator;
|
4660 | var d3_geo_orthographic = d3_geo_azimuthal(function() {
|
4661 | return 1;
|
4662 | }, Math.asin);
|
4663 | (d3.geo.orthographic = function() {
|
4664 | return d3_geo_projection(d3_geo_orthographic);
|
4665 | }).raw = d3_geo_orthographic;
|
4666 | var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
|
4667 | return 1 / (1 + cosλcosφ);
|
4668 | }, function(ρ) {
|
4669 | return 2 * Math.atan(ρ);
|
4670 | });
|
4671 | (d3.geo.stereographic = function() {
|
4672 | return d3_geo_projection(d3_geo_stereographic);
|
4673 | }).raw = d3_geo_stereographic;
|
4674 | function d3_geo_transverseMercator(λ, φ) {
|
4675 | return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
|
4676 | }
|
4677 | d3_geo_transverseMercator.invert = function(x, y) {
|
4678 | return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
|
4679 | };
|
4680 | (d3.geo.transverseMercator = function() {
|
4681 | var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
|
4682 | projection.center = function(_) {
|
4683 | return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
|
4684 | };
|
4685 | projection.rotate = function(_) {
|
4686 | return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
|
4687 | [ _[0], _[1], _[2] - 90 ]);
|
4688 | };
|
4689 | return rotate([ 0, 0, 90 ]);
|
4690 | }).raw = d3_geo_transverseMercator;
|
4691 | d3.geom = {};
|
4692 | function d3_geom_pointX(d) {
|
4693 | return d[0];
|
4694 | }
|
4695 | function d3_geom_pointY(d) {
|
4696 | return d[1];
|
4697 | }
|
4698 | d3.geom.hull = function(vertices) {
|
4699 | var x = d3_geom_pointX, y = d3_geom_pointY;
|
4700 | if (arguments.length) return hull(vertices);
|
4701 | function hull(data) {
|
4702 | if (data.length < 3) return [];
|
4703 | var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
|
4704 | for (i = 0; i < n; i++) {
|
4705 | points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
|
4706 | }
|
4707 | points.sort(d3_geom_hullOrder);
|
4708 | for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
|
4709 | var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
|
4710 | var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
|
4711 | for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
|
4712 | for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
|
4713 | return polygon;
|
4714 | }
|
4715 | hull.x = function(_) {
|
4716 | return arguments.length ? (x = _, hull) : x;
|
4717 | };
|
4718 | hull.y = function(_) {
|
4719 | return arguments.length ? (y = _, hull) : y;
|
4720 | };
|
4721 | return hull;
|
4722 | };
|
4723 | function d3_geom_hullUpper(points) {
|
4724 | var n = points.length, hull = [ 0, 1 ], hs = 2;
|
4725 | for (var i = 2; i < n; i++) {
|
4726 | while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
|
4727 | hull[hs++] = i;
|
4728 | }
|
4729 | return hull.slice(0, hs);
|
4730 | }
|
4731 | function d3_geom_hullOrder(a, b) {
|
4732 | return a[0] - b[0] || a[1] - b[1];
|
4733 | }
|
4734 | d3.geom.polygon = function(coordinates) {
|
4735 | d3_subclass(coordinates, d3_geom_polygonPrototype);
|
4736 | return coordinates;
|
4737 | };
|
4738 | var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
|
4739 | d3_geom_polygonPrototype.area = function() {
|
4740 | var i = -1, n = this.length, a, b = this[n - 1], area = 0;
|
4741 | while (++i < n) {
|
4742 | a = b;
|
4743 | b = this[i];
|
4744 | area += a[1] * b[0] - a[0] * b[1];
|
4745 | }
|
4746 | return area * .5;
|
4747 | };
|
4748 | d3_geom_polygonPrototype.centroid = function(k) {
|
4749 | var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
|
4750 | if (!arguments.length) k = -1 / (6 * this.area());
|
4751 | while (++i < n) {
|
4752 | a = b;
|
4753 | b = this[i];
|
4754 | c = a[0] * b[1] - b[0] * a[1];
|
4755 | x += (a[0] + b[0]) * c;
|
4756 | y += (a[1] + b[1]) * c;
|
4757 | }
|
4758 | return [ x * k, y * k ];
|
4759 | };
|
4760 | d3_geom_polygonPrototype.clip = function(subject) {
|
4761 | 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;
|
4762 | while (++i < n) {
|
4763 | input = subject.slice();
|
4764 | subject.length = 0;
|
4765 | b = this[i];
|
4766 | c = input[(m = input.length - closed) - 1];
|
4767 | j = -1;
|
4768 | while (++j < m) {
|
4769 | d = input[j];
|
4770 | if (d3_geom_polygonInside(d, a, b)) {
|
4771 | if (!d3_geom_polygonInside(c, a, b)) {
|
4772 | subject.push(d3_geom_polygonIntersect(c, d, a, b));
|
4773 | }
|
4774 | subject.push(d);
|
4775 | } else if (d3_geom_polygonInside(c, a, b)) {
|
4776 | subject.push(d3_geom_polygonIntersect(c, d, a, b));
|
4777 | }
|
4778 | c = d;
|
4779 | }
|
4780 | if (closed) subject.push(subject[0]);
|
4781 | a = b;
|
4782 | }
|
4783 | return subject;
|
4784 | };
|
4785 | function d3_geom_polygonInside(p, a, b) {
|
4786 | return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
|
4787 | }
|
4788 | function d3_geom_polygonIntersect(c, d, a, b) {
|
4789 | 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);
|
4790 | return [ x1 + ua * x21, y1 + ua * y21 ];
|
4791 | }
|
4792 | function d3_geom_polygonClosed(coordinates) {
|
4793 | var a = coordinates[0], b = coordinates[coordinates.length - 1];
|
4794 | return !(a[0] - b[0] || a[1] - b[1]);
|
4795 | }
|
4796 | var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
|
4797 | function d3_geom_voronoiBeach() {
|
4798 | d3_geom_voronoiRedBlackNode(this);
|
4799 | this.edge = this.site = this.circle = null;
|
4800 | }
|
4801 | function d3_geom_voronoiCreateBeach(site) {
|
4802 | var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
|
4803 | beach.site = site;
|
4804 | return beach;
|
4805 | }
|
4806 | function d3_geom_voronoiDetachBeach(beach) {
|
4807 | d3_geom_voronoiDetachCircle(beach);
|
4808 | d3_geom_voronoiBeaches.remove(beach);
|
4809 | d3_geom_voronoiBeachPool.push(beach);
|
4810 | d3_geom_voronoiRedBlackNode(beach);
|
4811 | }
|
4812 | function d3_geom_voronoiRemoveBeach(beach) {
|
4813 | var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
|
4814 | x: x,
|
4815 | y: y
|
4816 | }, previous = beach.P, next = beach.N, disappearing = [ beach ];
|
4817 | d3_geom_voronoiDetachBeach(beach);
|
4818 | var lArc = previous;
|
4819 | while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
|
4820 | previous = lArc.P;
|
4821 | disappearing.unshift(lArc);
|
4822 | d3_geom_voronoiDetachBeach(lArc);
|
4823 | lArc = previous;
|
4824 | }
|
4825 | disappearing.unshift(lArc);
|
4826 | d3_geom_voronoiDetachCircle(lArc);
|
4827 | var rArc = next;
|
4828 | while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
|
4829 | next = rArc.N;
|
4830 | disappearing.push(rArc);
|
4831 | d3_geom_voronoiDetachBeach(rArc);
|
4832 | rArc = next;
|
4833 | }
|
4834 | disappearing.push(rArc);
|
4835 | d3_geom_voronoiDetachCircle(rArc);
|
4836 | var nArcs = disappearing.length, iArc;
|
4837 | for (iArc = 1; iArc < nArcs; ++iArc) {
|
4838 | rArc = disappearing[iArc];
|
4839 | lArc = disappearing[iArc - 1];
|
4840 | d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
|
4841 | }
|
4842 | lArc = disappearing[0];
|
4843 | rArc = disappearing[nArcs - 1];
|
4844 | rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
|
4845 | d3_geom_voronoiAttachCircle(lArc);
|
4846 | d3_geom_voronoiAttachCircle(rArc);
|
4847 | }
|
4848 | function d3_geom_voronoiAddBeach(site) {
|
4849 | var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
|
4850 | while (node) {
|
4851 | dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
|
4852 | if (dxl > ε) node = node.L; else {
|
4853 | dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
|
4854 | if (dxr > ε) {
|
4855 | if (!node.R) {
|
4856 | lArc = node;
|
4857 | break;
|
4858 | }
|
4859 | node = node.R;
|
4860 | } else {
|
4861 | if (dxl > -ε) {
|
4862 | lArc = node.P;
|
4863 | rArc = node;
|
4864 | } else if (dxr > -ε) {
|
4865 | lArc = node;
|
4866 | rArc = node.N;
|
4867 | } else {
|
4868 | lArc = rArc = node;
|
4869 | }
|
4870 | break;
|
4871 | }
|
4872 | }
|
4873 | }
|
4874 | var newArc = d3_geom_voronoiCreateBeach(site);
|
4875 | d3_geom_voronoiBeaches.insert(lArc, newArc);
|
4876 | if (!lArc && !rArc) return;
|
4877 | if (lArc === rArc) {
|
4878 | d3_geom_voronoiDetachCircle(lArc);
|
4879 | rArc = d3_geom_voronoiCreateBeach(lArc.site);
|
4880 | d3_geom_voronoiBeaches.insert(newArc, rArc);
|
4881 | newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
|
4882 | d3_geom_voronoiAttachCircle(lArc);
|
4883 | d3_geom_voronoiAttachCircle(rArc);
|
4884 | return;
|
4885 | }
|
4886 | if (!rArc) {
|
4887 | newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
|
4888 | return;
|
4889 | }
|
4890 | d3_geom_voronoiDetachCircle(lArc);
|
4891 | d3_geom_voronoiDetachCircle(rArc);
|
4892 | 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 = {
|
4893 | x: (cy * hb - by * hc) / d + ax,
|
4894 | y: (bx * hc - cx * hb) / d + ay
|
4895 | };
|
4896 | d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
|
4897 | newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
|
4898 | rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
|
4899 | d3_geom_voronoiAttachCircle(lArc);
|
4900 | d3_geom_voronoiAttachCircle(rArc);
|
4901 | }
|
4902 | function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
|
4903 | var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
|
4904 | if (!pby2) return rfocx;
|
4905 | var lArc = arc.P;
|
4906 | if (!lArc) return -Infinity;
|
4907 | site = lArc.site;
|
4908 | var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
|
4909 | if (!plby2) return lfocx;
|
4910 | var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
|
4911 | if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
|
4912 | return (rfocx + lfocx) / 2;
|
4913 | }
|
4914 | function d3_geom_voronoiRightBreakPoint(arc, directrix) {
|
4915 | var rArc = arc.N;
|
4916 | if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
|
4917 | var site = arc.site;
|
4918 | return site.y === directrix ? site.x : Infinity;
|
4919 | }
|
4920 | function d3_geom_voronoiCell(site) {
|
4921 | this.site = site;
|
4922 | this.edges = [];
|
4923 | }
|
4924 | d3_geom_voronoiCell.prototype.prepare = function() {
|
4925 | var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
|
4926 | while (iHalfEdge--) {
|
4927 | edge = halfEdges[iHalfEdge].edge;
|
4928 | if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
|
4929 | }
|
4930 | halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
|
4931 | return halfEdges.length;
|
4932 | };
|
4933 | function d3_geom_voronoiCloseCells(extent) {
|
4934 | 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;
|
4935 | while (iCell--) {
|
4936 | cell = cells[iCell];
|
4937 | if (!cell || !cell.prepare()) continue;
|
4938 | halfEdges = cell.edges;
|
4939 | nHalfEdges = halfEdges.length;
|
4940 | iHalfEdge = 0;
|
4941 | while (iHalfEdge < nHalfEdges) {
|
4942 | end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
|
4943 | start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
|
4944 | if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
|
4945 | halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
|
4946 | x: x0,
|
4947 | y: abs(x2 - x0) < ε ? y2 : y1
|
4948 | } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
|
4949 | x: abs(y2 - y1) < ε ? x2 : x1,
|
4950 | y: y1
|
4951 | } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
|
4952 | x: x1,
|
4953 | y: abs(x2 - x1) < ε ? y2 : y0
|
4954 | } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
|
4955 | x: abs(y2 - y0) < ε ? x2 : x0,
|
4956 | y: y0
|
4957 | } : null), cell.site, null));
|
4958 | ++nHalfEdges;
|
4959 | }
|
4960 | }
|
4961 | }
|
4962 | }
|
4963 | function d3_geom_voronoiHalfEdgeOrder(a, b) {
|
4964 | return b.angle - a.angle;
|
4965 | }
|
4966 | function d3_geom_voronoiCircle() {
|
4967 | d3_geom_voronoiRedBlackNode(this);
|
4968 | this.x = this.y = this.arc = this.site = this.cy = null;
|
4969 | }
|
4970 | function d3_geom_voronoiAttachCircle(arc) {
|
4971 | var lArc = arc.P, rArc = arc.N;
|
4972 | if (!lArc || !rArc) return;
|
4973 | var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
|
4974 | if (lSite === rSite) return;
|
4975 | var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
|
4976 | var d = 2 * (ax * cy - ay * cx);
|
4977 | if (d >= -ε2) return;
|
4978 | 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;
|
4979 | var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
|
4980 | circle.arc = arc;
|
4981 | circle.site = cSite;
|
4982 | circle.x = x + bx;
|
4983 | circle.y = cy + Math.sqrt(x * x + y * y);
|
4984 | circle.cy = cy;
|
4985 | arc.circle = circle;
|
4986 | var before = null, node = d3_geom_voronoiCircles._;
|
4987 | while (node) {
|
4988 | if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
|
4989 | if (node.L) node = node.L; else {
|
4990 | before = node.P;
|
4991 | break;
|
4992 | }
|
4993 | } else {
|
4994 | if (node.R) node = node.R; else {
|
4995 | before = node;
|
4996 | break;
|
4997 | }
|
4998 | }
|
4999 | }
|
5000 | d3_geom_voronoiCircles.insert(before, circle);
|
5001 | if (!before) d3_geom_voronoiFirstCircle = circle;
|
5002 | }
|
5003 | function d3_geom_voronoiDetachCircle(arc) {
|
5004 | var circle = arc.circle;
|
5005 | if (circle) {
|
5006 | if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
|
5007 | d3_geom_voronoiCircles.remove(circle);
|
5008 | d3_geom_voronoiCirclePool.push(circle);
|
5009 | d3_geom_voronoiRedBlackNode(circle);
|
5010 | arc.circle = null;
|
5011 | }
|
5012 | }
|
5013 | function d3_geom_voronoiClipEdges(extent) {
|
5014 | 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;
|
5015 | while (i--) {
|
5016 | e = edges[i];
|
5017 | if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
|
5018 | e.a = e.b = null;
|
5019 | edges.splice(i, 1);
|
5020 | }
|
5021 | }
|
5022 | }
|
5023 | function d3_geom_voronoiConnectEdge(edge, extent) {
|
5024 | var vb = edge.b;
|
5025 | if (vb) return true;
|
5026 | 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;
|
5027 | if (ry === ly) {
|
5028 | if (fx < x0 || fx >= x1) return;
|
5029 | if (lx > rx) {
|
5030 | if (!va) va = {
|
5031 | x: fx,
|
5032 | y: y0
|
5033 | }; else if (va.y >= y1) return;
|
5034 | vb = {
|
5035 | x: fx,
|
5036 | y: y1
|
5037 | };
|
5038 | } else {
|
5039 | if (!va) va = {
|
5040 | x: fx,
|
5041 | y: y1
|
5042 | }; else if (va.y < y0) return;
|
5043 | vb = {
|
5044 | x: fx,
|
5045 | y: y0
|
5046 | };
|
5047 | }
|
5048 | } else {
|
5049 | fm = (lx - rx) / (ry - ly);
|
5050 | fb = fy - fm * fx;
|
5051 | if (fm < -1 || fm > 1) {
|
5052 | if (lx > rx) {
|
5053 | if (!va) va = {
|
5054 | x: (y0 - fb) / fm,
|
5055 | y: y0
|
5056 | }; else if (va.y >= y1) return;
|
5057 | vb = {
|
5058 | x: (y1 - fb) / fm,
|
5059 | y: y1
|
5060 | };
|
5061 | } else {
|
5062 | if (!va) va = {
|
5063 | x: (y1 - fb) / fm,
|
5064 | y: y1
|
5065 | }; else if (va.y < y0) return;
|
5066 | vb = {
|
5067 | x: (y0 - fb) / fm,
|
5068 | y: y0
|
5069 | };
|
5070 | }
|
5071 | } else {
|
5072 | if (ly < ry) {
|
5073 | if (!va) va = {
|
5074 | x: x0,
|
5075 | y: fm * x0 + fb
|
5076 | }; else if (va.x >= x1) return;
|
5077 | vb = {
|
5078 | x: x1,
|
5079 | y: fm * x1 + fb
|
5080 | };
|
5081 | } else {
|
5082 | if (!va) va = {
|
5083 | x: x1,
|
5084 | y: fm * x1 + fb
|
5085 | }; else if (va.x < x0) return;
|
5086 | vb = {
|
5087 | x: x0,
|
5088 | y: fm * x0 + fb
|
5089 | };
|
5090 | }
|
5091 | }
|
5092 | }
|
5093 | edge.a = va;
|
5094 | edge.b = vb;
|
5095 | return true;
|
5096 | }
|
5097 | function d3_geom_voronoiEdge(lSite, rSite) {
|
5098 | this.l = lSite;
|
5099 | this.r = rSite;
|
5100 | this.a = this.b = null;
|
5101 | }
|
5102 | function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
|
5103 | var edge = new d3_geom_voronoiEdge(lSite, rSite);
|
5104 | d3_geom_voronoiEdges.push(edge);
|
5105 | if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
|
5106 | if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
|
5107 | d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
|
5108 | d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
|
5109 | return edge;
|
5110 | }
|
5111 | function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
|
5112 | var edge = new d3_geom_voronoiEdge(lSite, null);
|
5113 | edge.a = va;
|
5114 | edge.b = vb;
|
5115 | d3_geom_voronoiEdges.push(edge);
|
5116 | return edge;
|
5117 | }
|
5118 | function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
|
5119 | if (!edge.a && !edge.b) {
|
5120 | edge.a = vertex;
|
5121 | edge.l = lSite;
|
5122 | edge.r = rSite;
|
5123 | } else if (edge.l === rSite) {
|
5124 | edge.b = vertex;
|
5125 | } else {
|
5126 | edge.a = vertex;
|
5127 | }
|
5128 | }
|
5129 | function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
|
5130 | var va = edge.a, vb = edge.b;
|
5131 | this.edge = edge;
|
5132 | this.site = lSite;
|
5133 | 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);
|
5134 | }
|
5135 | d3_geom_voronoiHalfEdge.prototype = {
|
5136 | start: function() {
|
5137 | return this.edge.l === this.site ? this.edge.a : this.edge.b;
|
5138 | },
|
5139 | end: function() {
|
5140 | return this.edge.l === this.site ? this.edge.b : this.edge.a;
|
5141 | }
|
5142 | };
|
5143 | function d3_geom_voronoiRedBlackTree() {
|
5144 | this._ = null;
|
5145 | }
|
5146 | function d3_geom_voronoiRedBlackNode(node) {
|
5147 | node.U = node.C = node.L = node.R = node.P = node.N = null;
|
5148 | }
|
5149 | d3_geom_voronoiRedBlackTree.prototype = {
|
5150 | insert: function(after, node) {
|
5151 | var parent, grandpa, uncle;
|
5152 | if (after) {
|
5153 | node.P = after;
|
5154 | node.N = after.N;
|
5155 | if (after.N) after.N.P = node;
|
5156 | after.N = node;
|
5157 | if (after.R) {
|
5158 | after = after.R;
|
5159 | while (after.L) after = after.L;
|
5160 | after.L = node;
|
5161 | } else {
|
5162 | after.R = node;
|
5163 | }
|
5164 | parent = after;
|
5165 | } else if (this._) {
|
5166 | after = d3_geom_voronoiRedBlackFirst(this._);
|
5167 | node.P = null;
|
5168 | node.N = after;
|
5169 | after.P = after.L = node;
|
5170 | parent = after;
|
5171 | } else {
|
5172 | node.P = node.N = null;
|
5173 | this._ = node;
|
5174 | parent = null;
|
5175 | }
|
5176 | node.L = node.R = null;
|
5177 | node.U = parent;
|
5178 | node.C = true;
|
5179 | after = node;
|
5180 | while (parent && parent.C) {
|
5181 | grandpa = parent.U;
|
5182 | if (parent === grandpa.L) {
|
5183 | uncle = grandpa.R;
|
5184 | if (uncle && uncle.C) {
|
5185 | parent.C = uncle.C = false;
|
5186 | grandpa.C = true;
|
5187 | after = grandpa;
|
5188 | } else {
|
5189 | if (after === parent.R) {
|
5190 | d3_geom_voronoiRedBlackRotateLeft(this, parent);
|
5191 | after = parent;
|
5192 | parent = after.U;
|
5193 | }
|
5194 | parent.C = false;
|
5195 | grandpa.C = true;
|
5196 | d3_geom_voronoiRedBlackRotateRight(this, grandpa);
|
5197 | }
|
5198 | } else {
|
5199 | uncle = grandpa.L;
|
5200 | if (uncle && uncle.C) {
|
5201 | parent.C = uncle.C = false;
|
5202 | grandpa.C = true;
|
5203 | after = grandpa;
|
5204 | } else {
|
5205 | if (after === parent.L) {
|
5206 | d3_geom_voronoiRedBlackRotateRight(this, parent);
|
5207 | after = parent;
|
5208 | parent = after.U;
|
5209 | }
|
5210 | parent.C = false;
|
5211 | grandpa.C = true;
|
5212 | d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
|
5213 | }
|
5214 | }
|
5215 | parent = after.U;
|
5216 | }
|
5217 | this._.C = false;
|
5218 | },
|
5219 | remove: function(node) {
|
5220 | if (node.N) node.N.P = node.P;
|
5221 | if (node.P) node.P.N = node.N;
|
5222 | node.N = node.P = null;
|
5223 | var parent = node.U, sibling, left = node.L, right = node.R, next, red;
|
5224 | if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
|
5225 | if (parent) {
|
5226 | if (parent.L === node) parent.L = next; else parent.R = next;
|
5227 | } else {
|
5228 | this._ = next;
|
5229 | }
|
5230 | if (left && right) {
|
5231 | red = next.C;
|
5232 | next.C = node.C;
|
5233 | next.L = left;
|
5234 | left.U = next;
|
5235 | if (next !== right) {
|
5236 | parent = next.U;
|
5237 | next.U = node.U;
|
5238 | node = next.R;
|
5239 | parent.L = node;
|
5240 | next.R = right;
|
5241 | right.U = next;
|
5242 | } else {
|
5243 | next.U = parent;
|
5244 | parent = next;
|
5245 | node = next.R;
|
5246 | }
|
5247 | } else {
|
5248 | red = node.C;
|
5249 | node = next;
|
5250 | }
|
5251 | if (node) node.U = parent;
|
5252 | if (red) return;
|
5253 | if (node && node.C) {
|
5254 | node.C = false;
|
5255 | return;
|
5256 | }
|
5257 | do {
|
5258 | if (node === this._) break;
|
5259 | if (node === parent.L) {
|
5260 | sibling = parent.R;
|
5261 | if (sibling.C) {
|
5262 | sibling.C = false;
|
5263 | parent.C = true;
|
5264 | d3_geom_voronoiRedBlackRotateLeft(this, parent);
|
5265 | sibling = parent.R;
|
5266 | }
|
5267 | if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
|
5268 | if (!sibling.R || !sibling.R.C) {
|
5269 | sibling.L.C = false;
|
5270 | sibling.C = true;
|
5271 | d3_geom_voronoiRedBlackRotateRight(this, sibling);
|
5272 | sibling = parent.R;
|
5273 | }
|
5274 | sibling.C = parent.C;
|
5275 | parent.C = sibling.R.C = false;
|
5276 | d3_geom_voronoiRedBlackRotateLeft(this, parent);
|
5277 | node = this._;
|
5278 | break;
|
5279 | }
|
5280 | } else {
|
5281 | sibling = parent.L;
|
5282 | if (sibling.C) {
|
5283 | sibling.C = false;
|
5284 | parent.C = true;
|
5285 | d3_geom_voronoiRedBlackRotateRight(this, parent);
|
5286 | sibling = parent.L;
|
5287 | }
|
5288 | if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
|
5289 | if (!sibling.L || !sibling.L.C) {
|
5290 | sibling.R.C = false;
|
5291 | sibling.C = true;
|
5292 | d3_geom_voronoiRedBlackRotateLeft(this, sibling);
|
5293 | sibling = parent.L;
|
5294 | }
|
5295 | sibling.C = parent.C;
|
5296 | parent.C = sibling.L.C = false;
|
5297 | d3_geom_voronoiRedBlackRotateRight(this, parent);
|
5298 | node = this._;
|
5299 | break;
|
5300 | }
|
5301 | }
|
5302 | sibling.C = true;
|
5303 | node = parent;
|
5304 | parent = parent.U;
|
5305 | } while (!node.C);
|
5306 | if (node) node.C = false;
|
5307 | }
|
5308 | };
|
5309 | function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
|
5310 | var p = node, q = node.R, parent = p.U;
|
5311 | if (parent) {
|
5312 | if (parent.L === p) parent.L = q; else parent.R = q;
|
5313 | } else {
|
5314 | tree._ = q;
|
5315 | }
|
5316 | q.U = parent;
|
5317 | p.U = q;
|
5318 | p.R = q.L;
|
5319 | if (p.R) p.R.U = p;
|
5320 | q.L = p;
|
5321 | }
|
5322 | function d3_geom_voronoiRedBlackRotateRight(tree, node) {
|
5323 | var p = node, q = node.L, parent = p.U;
|
5324 | if (parent) {
|
5325 | if (parent.L === p) parent.L = q; else parent.R = q;
|
5326 | } else {
|
5327 | tree._ = q;
|
5328 | }
|
5329 | q.U = parent;
|
5330 | p.U = q;
|
5331 | p.L = q.R;
|
5332 | if (p.L) p.L.U = p;
|
5333 | q.R = p;
|
5334 | }
|
5335 | function d3_geom_voronoiRedBlackFirst(node) {
|
5336 | while (node.L) node = node.L;
|
5337 | return node;
|
5338 | }
|
5339 | function d3_geom_voronoi(sites, bbox) {
|
5340 | var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
|
5341 | d3_geom_voronoiEdges = [];
|
5342 | d3_geom_voronoiCells = new Array(sites.length);
|
5343 | d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
|
5344 | d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
|
5345 | while (true) {
|
5346 | circle = d3_geom_voronoiFirstCircle;
|
5347 | if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
|
5348 | if (site.x !== x0 || site.y !== y0) {
|
5349 | d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
|
5350 | d3_geom_voronoiAddBeach(site);
|
5351 | x0 = site.x, y0 = site.y;
|
5352 | }
|
5353 | site = sites.pop();
|
5354 | } else if (circle) {
|
5355 | d3_geom_voronoiRemoveBeach(circle.arc);
|
5356 | } else {
|
5357 | break;
|
5358 | }
|
5359 | }
|
5360 | if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
|
5361 | var diagram = {
|
5362 | cells: d3_geom_voronoiCells,
|
5363 | edges: d3_geom_voronoiEdges
|
5364 | };
|
5365 | d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
|
5366 | return diagram;
|
5367 | }
|
5368 | function d3_geom_voronoiVertexOrder(a, b) {
|
5369 | return b.y - a.y || b.x - a.x;
|
5370 | }
|
5371 | d3.geom.voronoi = function(points) {
|
5372 | var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
|
5373 | if (points) return voronoi(points);
|
5374 | function voronoi(data) {
|
5375 | var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
|
5376 | d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
|
5377 | var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
|
5378 | var s = e.start();
|
5379 | return [ s.x, s.y ];
|
5380 | }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
|
5381 | polygon.point = data[i];
|
5382 | });
|
5383 | return polygons;
|
5384 | }
|
5385 | function sites(data) {
|
5386 | return data.map(function(d, i) {
|
5387 | return {
|
5388 | x: Math.round(fx(d, i) / ε) * ε,
|
5389 | y: Math.round(fy(d, i) / ε) * ε,
|
5390 | i: i
|
5391 | };
|
5392 | });
|
5393 | }
|
5394 | voronoi.links = function(data) {
|
5395 | return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
|
5396 | return edge.l && edge.r;
|
5397 | }).map(function(edge) {
|
5398 | return {
|
5399 | source: data[edge.l.i],
|
5400 | target: data[edge.r.i]
|
5401 | };
|
5402 | });
|
5403 | };
|
5404 | voronoi.triangles = function(data) {
|
5405 | var triangles = [];
|
5406 | d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
|
5407 | 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;
|
5408 | while (++j < m) {
|
5409 | e0 = e1;
|
5410 | s0 = s1;
|
5411 | e1 = edges[j].edge;
|
5412 | s1 = e1.l === site ? e1.r : e1.l;
|
5413 | if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
|
5414 | triangles.push([ data[i], data[s0.i], data[s1.i] ]);
|
5415 | }
|
5416 | }
|
5417 | });
|
5418 | return triangles;
|
5419 | };
|
5420 | voronoi.x = function(_) {
|
5421 | return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
|
5422 | };
|
5423 | voronoi.y = function(_) {
|
5424 | return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
|
5425 | };
|
5426 | voronoi.clipExtent = function(_) {
|
5427 | if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
|
5428 | clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
|
5429 | return voronoi;
|
5430 | };
|
5431 | voronoi.size = function(_) {
|
5432 | if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
|
5433 | return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
|
5434 | };
|
5435 | return voronoi;
|
5436 | };
|
5437 | var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
|
5438 | function d3_geom_voronoiTriangleArea(a, b, c) {
|
5439 | return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
|
5440 | }
|
5441 | d3.geom.delaunay = function(vertices) {
|
5442 | return d3.geom.voronoi().triangles(vertices);
|
5443 | };
|
5444 | d3.geom.quadtree = function(points, x1, y1, x2, y2) {
|
5445 | var x = d3_geom_pointX, y = d3_geom_pointY, compat;
|
5446 | if (compat = arguments.length) {
|
5447 | x = d3_geom_quadtreeCompatX;
|
5448 | y = d3_geom_quadtreeCompatY;
|
5449 | if (compat === 3) {
|
5450 | y2 = y1;
|
5451 | x2 = x1;
|
5452 | y1 = x1 = 0;
|
5453 | }
|
5454 | return quadtree(points);
|
5455 | }
|
5456 | function quadtree(data) {
|
5457 | var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
|
5458 | if (x1 != null) {
|
5459 | x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
|
5460 | } else {
|
5461 | x2_ = y2_ = -(x1_ = y1_ = Infinity);
|
5462 | xs = [], ys = [];
|
5463 | n = data.length;
|
5464 | if (compat) for (i = 0; i < n; ++i) {
|
5465 | d = data[i];
|
5466 | if (d.x < x1_) x1_ = d.x;
|
5467 | if (d.y < y1_) y1_ = d.y;
|
5468 | if (d.x > x2_) x2_ = d.x;
|
5469 | if (d.y > y2_) y2_ = d.y;
|
5470 | xs.push(d.x);
|
5471 | ys.push(d.y);
|
5472 | } else for (i = 0; i < n; ++i) {
|
5473 | var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
|
5474 | if (x_ < x1_) x1_ = x_;
|
5475 | if (y_ < y1_) y1_ = y_;
|
5476 | if (x_ > x2_) x2_ = x_;
|
5477 | if (y_ > y2_) y2_ = y_;
|
5478 | xs.push(x_);
|
5479 | ys.push(y_);
|
5480 | }
|
5481 | }
|
5482 | var dx = x2_ - x1_, dy = y2_ - y1_;
|
5483 | if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
|
5484 | function insert(n, d, x, y, x1, y1, x2, y2) {
|
5485 | if (isNaN(x) || isNaN(y)) return;
|
5486 | if (n.leaf) {
|
5487 | var nx = n.x, ny = n.y;
|
5488 | if (nx != null) {
|
5489 | if (abs(nx - x) + abs(ny - y) < .01) {
|
5490 | insertChild(n, d, x, y, x1, y1, x2, y2);
|
5491 | } else {
|
5492 | var nPoint = n.point;
|
5493 | n.x = n.y = n.point = null;
|
5494 | insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
|
5495 | insertChild(n, d, x, y, x1, y1, x2, y2);
|
5496 | }
|
5497 | } else {
|
5498 | n.x = x, n.y = y, n.point = d;
|
5499 | }
|
5500 | } else {
|
5501 | insertChild(n, d, x, y, x1, y1, x2, y2);
|
5502 | }
|
5503 | }
|
5504 | function insertChild(n, d, x, y, x1, y1, x2, y2) {
|
5505 | var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right;
|
5506 | n.leaf = false;
|
5507 | n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
|
5508 | if (right) x1 = sx; else x2 = sx;
|
5509 | if (bottom) y1 = sy; else y2 = sy;
|
5510 | insert(n, d, x, y, x1, y1, x2, y2);
|
5511 | }
|
5512 | var root = d3_geom_quadtreeNode();
|
5513 | root.add = function(d) {
|
5514 | insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
|
5515 | };
|
5516 | root.visit = function(f) {
|
5517 | d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
|
5518 | };
|
5519 | i = -1;
|
5520 | if (x1 == null) {
|
5521 | while (++i < n) {
|
5522 | insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
|
5523 | }
|
5524 | --i;
|
5525 | } else data.forEach(root.add);
|
5526 | xs = ys = data = d = null;
|
5527 | return root;
|
5528 | }
|
5529 | quadtree.x = function(_) {
|
5530 | return arguments.length ? (x = _, quadtree) : x;
|
5531 | };
|
5532 | quadtree.y = function(_) {
|
5533 | return arguments.length ? (y = _, quadtree) : y;
|
5534 | };
|
5535 | quadtree.extent = function(_) {
|
5536 | if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
|
5537 | if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
|
5538 | y2 = +_[1][1];
|
5539 | return quadtree;
|
5540 | };
|
5541 | quadtree.size = function(_) {
|
5542 | if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
|
5543 | if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
|
5544 | return quadtree;
|
5545 | };
|
5546 | return quadtree;
|
5547 | };
|
5548 | function d3_geom_quadtreeCompatX(d) {
|
5549 | return d.x;
|
5550 | }
|
5551 | function d3_geom_quadtreeCompatY(d) {
|
5552 | return d.y;
|
5553 | }
|
5554 | function d3_geom_quadtreeNode() {
|
5555 | return {
|
5556 | leaf: true,
|
5557 | nodes: [],
|
5558 | point: null,
|
5559 | x: null,
|
5560 | y: null
|
5561 | };
|
5562 | }
|
5563 | function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
|
5564 | if (!f(node, x1, y1, x2, y2)) {
|
5565 | var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
|
5566 | if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
|
5567 | if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
|
5568 | if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
|
5569 | if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
|
5570 | }
|
5571 | }
|
5572 | d3.interpolateRgb = d3_interpolateRgb;
|
5573 | function d3_interpolateRgb(a, b) {
|
5574 | a = d3.rgb(a);
|
5575 | b = d3.rgb(b);
|
5576 | var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
|
5577 | return function(t) {
|
5578 | 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));
|
5579 | };
|
5580 | }
|
5581 | d3.interpolateObject = d3_interpolateObject;
|
5582 | function d3_interpolateObject(a, b) {
|
5583 | var i = {}, c = {}, k;
|
5584 | for (k in a) {
|
5585 | if (k in b) {
|
5586 | i[k] = d3_interpolate(a[k], b[k]);
|
5587 | } else {
|
5588 | c[k] = a[k];
|
5589 | }
|
5590 | }
|
5591 | for (k in b) {
|
5592 | if (!(k in a)) {
|
5593 | c[k] = b[k];
|
5594 | }
|
5595 | }
|
5596 | return function(t) {
|
5597 | for (k in i) c[k] = i[k](t);
|
5598 | return c;
|
5599 | };
|
5600 | }
|
5601 | d3.interpolateNumber = d3_interpolateNumber;
|
5602 | function d3_interpolateNumber(a, b) {
|
5603 | b -= a = +a;
|
5604 | return function(t) {
|
5605 | return a + b * t;
|
5606 | };
|
5607 | }
|
5608 | d3.interpolateString = d3_interpolateString;
|
5609 | function d3_interpolateString(a, b) {
|
5610 | var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
|
5611 | a = a + "", b = b + "";
|
5612 | while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
|
5613 | if ((bs = bm.index) > bi) {
|
5614 | bs = b.substring(bi, bs);
|
5615 | if (s[i]) s[i] += bs; else s[++i] = bs;
|
5616 | }
|
5617 | if ((am = am[0]) === (bm = bm[0])) {
|
5618 | if (s[i]) s[i] += bm; else s[++i] = bm;
|
5619 | } else {
|
5620 | s[++i] = null;
|
5621 | q.push({
|
5622 | i: i,
|
5623 | x: d3_interpolateNumber(am, bm)
|
5624 | });
|
5625 | }
|
5626 | bi = d3_interpolate_numberB.lastIndex;
|
5627 | }
|
5628 | if (bi < b.length) {
|
5629 | bs = b.substring(bi);
|
5630 | if (s[i]) s[i] += bs; else s[++i] = bs;
|
5631 | }
|
5632 | return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
|
5633 | return b(t) + "";
|
5634 | }) : function() {
|
5635 | return b;
|
5636 | } : (b = q.length, function(t) {
|
5637 | for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
|
5638 | return s.join("");
|
5639 | });
|
5640 | }
|
5641 | var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
|
5642 | d3.interpolate = d3_interpolate;
|
5643 | function d3_interpolate(a, b) {
|
5644 | var i = d3.interpolators.length, f;
|
5645 | while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
|
5646 | return f;
|
5647 | }
|
5648 | d3.interpolators = [ function(a, b) {
|
5649 | var t = typeof b;
|
5650 | return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.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);
|
5651 | } ];
|
5652 | d3.interpolateArray = d3_interpolateArray;
|
5653 | function d3_interpolateArray(a, b) {
|
5654 | var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
|
5655 | for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
|
5656 | for (;i < na; ++i) c[i] = a[i];
|
5657 | for (;i < nb; ++i) c[i] = b[i];
|
5658 | return function(t) {
|
5659 | for (i = 0; i < n0; ++i) c[i] = x[i](t);
|
5660 | return c;
|
5661 | };
|
5662 | }
|
5663 | var d3_ease_default = function() {
|
5664 | return d3_identity;
|
5665 | };
|
5666 | var d3_ease = d3.map({
|
5667 | linear: d3_ease_default,
|
5668 | poly: d3_ease_poly,
|
5669 | quad: function() {
|
5670 | return d3_ease_quad;
|
5671 | },
|
5672 | cubic: function() {
|
5673 | return d3_ease_cubic;
|
5674 | },
|
5675 | sin: function() {
|
5676 | return d3_ease_sin;
|
5677 | },
|
5678 | exp: function() {
|
5679 | return d3_ease_exp;
|
5680 | },
|
5681 | circle: function() {
|
5682 | return d3_ease_circle;
|
5683 | },
|
5684 | elastic: d3_ease_elastic,
|
5685 | back: d3_ease_back,
|
5686 | bounce: function() {
|
5687 | return d3_ease_bounce;
|
5688 | }
|
5689 | });
|
5690 | var d3_ease_mode = d3.map({
|
5691 | "in": d3_identity,
|
5692 | out: d3_ease_reverse,
|
5693 | "in-out": d3_ease_reflect,
|
5694 | "out-in": function(f) {
|
5695 | return d3_ease_reflect(d3_ease_reverse(f));
|
5696 | }
|
5697 | });
|
5698 | d3.ease = function(name) {
|
5699 | var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
|
5700 | t = d3_ease.get(t) || d3_ease_default;
|
5701 | m = d3_ease_mode.get(m) || d3_identity;
|
5702 | return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
|
5703 | };
|
5704 | function d3_ease_clamp(f) {
|
5705 | return function(t) {
|
5706 | return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
|
5707 | };
|
5708 | }
|
5709 | function d3_ease_reverse(f) {
|
5710 | return function(t) {
|
5711 | return 1 - f(1 - t);
|
5712 | };
|
5713 | }
|
5714 | function d3_ease_reflect(f) {
|
5715 | return function(t) {
|
5716 | return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
|
5717 | };
|
5718 | }
|
5719 | function d3_ease_quad(t) {
|
5720 | return t * t;
|
5721 | }
|
5722 | function d3_ease_cubic(t) {
|
5723 | return t * t * t;
|
5724 | }
|
5725 | function d3_ease_cubicInOut(t) {
|
5726 | if (t <= 0) return 0;
|
5727 | if (t >= 1) return 1;
|
5728 | var t2 = t * t, t3 = t2 * t;
|
5729 | return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
|
5730 | }
|
5731 | function d3_ease_poly(e) {
|
5732 | return function(t) {
|
5733 | return Math.pow(t, e);
|
5734 | };
|
5735 | }
|
5736 | function d3_ease_sin(t) {
|
5737 | return 1 - Math.cos(t * halfπ);
|
5738 | }
|
5739 | function d3_ease_exp(t) {
|
5740 | return Math.pow(2, 10 * (t - 1));
|
5741 | }
|
5742 | function d3_ease_circle(t) {
|
5743 | return 1 - Math.sqrt(1 - t * t);
|
5744 | }
|
5745 | function d3_ease_elastic(a, p) {
|
5746 | var s;
|
5747 | if (arguments.length < 2) p = .45;
|
5748 | if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
|
5749 | return function(t) {
|
5750 | return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
|
5751 | };
|
5752 | }
|
5753 | function d3_ease_back(s) {
|
5754 | if (!s) s = 1.70158;
|
5755 | return function(t) {
|
5756 | return t * t * ((s + 1) * t - s);
|
5757 | };
|
5758 | }
|
5759 | function d3_ease_bounce(t) {
|
5760 | 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;
|
5761 | }
|
5762 | d3.interpolateHcl = d3_interpolateHcl;
|
5763 | function d3_interpolateHcl(a, b) {
|
5764 | a = d3.hcl(a);
|
5765 | b = d3.hcl(b);
|
5766 | var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
|
5767 | if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
|
5768 | if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
|
5769 | return function(t) {
|
5770 | return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
|
5771 | };
|
5772 | }
|
5773 | d3.interpolateHsl = d3_interpolateHsl;
|
5774 | function d3_interpolateHsl(a, b) {
|
5775 | a = d3.hsl(a);
|
5776 | b = d3.hsl(b);
|
5777 | var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
|
5778 | if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
|
5779 | if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
|
5780 | return function(t) {
|
5781 | return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
|
5782 | };
|
5783 | }
|
5784 | d3.interpolateLab = d3_interpolateLab;
|
5785 | function d3_interpolateLab(a, b) {
|
5786 | a = d3.lab(a);
|
5787 | b = d3.lab(b);
|
5788 | var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
|
5789 | return function(t) {
|
5790 | return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
|
5791 | };
|
5792 | }
|
5793 | d3.interpolateRound = d3_interpolateRound;
|
5794 | function d3_interpolateRound(a, b) {
|
5795 | b -= a;
|
5796 | return function(t) {
|
5797 | return Math.round(a + b * t);
|
5798 | };
|
5799 | }
|
5800 | d3.transform = function(string) {
|
5801 | var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
|
5802 | return (d3.transform = function(string) {
|
5803 | if (string != null) {
|
5804 | g.setAttribute("transform", string);
|
5805 | var t = g.transform.baseVal.consolidate();
|
5806 | }
|
5807 | return new d3_transform(t ? t.matrix : d3_transformIdentity);
|
5808 | })(string);
|
5809 | };
|
5810 | function d3_transform(m) {
|
5811 | 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;
|
5812 | if (r0[0] * r1[1] < r1[0] * r0[1]) {
|
5813 | r0[0] *= -1;
|
5814 | r0[1] *= -1;
|
5815 | kx *= -1;
|
5816 | kz *= -1;
|
5817 | }
|
5818 | this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
|
5819 | this.translate = [ m.e, m.f ];
|
5820 | this.scale = [ kx, ky ];
|
5821 | this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
|
5822 | }
|
5823 | d3_transform.prototype.toString = function() {
|
5824 | return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
|
5825 | };
|
5826 | function d3_transformDot(a, b) {
|
5827 | return a[0] * b[0] + a[1] * b[1];
|
5828 | }
|
5829 | function d3_transformNormalize(a) {
|
5830 | var k = Math.sqrt(d3_transformDot(a, a));
|
5831 | if (k) {
|
5832 | a[0] /= k;
|
5833 | a[1] /= k;
|
5834 | }
|
5835 | return k;
|
5836 | }
|
5837 | function d3_transformCombine(a, b, k) {
|
5838 | a[0] += k * b[0];
|
5839 | a[1] += k * b[1];
|
5840 | return a;
|
5841 | }
|
5842 | var d3_transformIdentity = {
|
5843 | a: 1,
|
5844 | b: 0,
|
5845 | c: 0,
|
5846 | d: 1,
|
5847 | e: 0,
|
5848 | f: 0
|
5849 | };
|
5850 | d3.interpolateTransform = d3_interpolateTransform;
|
5851 | function d3_interpolateTransform(a, b) {
|
5852 | var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
|
5853 | if (ta[0] != tb[0] || ta[1] != tb[1]) {
|
5854 | s.push("translate(", null, ",", null, ")");
|
5855 | q.push({
|
5856 | i: 1,
|
5857 | x: d3_interpolateNumber(ta[0], tb[0])
|
5858 | }, {
|
5859 | i: 3,
|
5860 | x: d3_interpolateNumber(ta[1], tb[1])
|
5861 | });
|
5862 | } else if (tb[0] || tb[1]) {
|
5863 | s.push("translate(" + tb + ")");
|
5864 | } else {
|
5865 | s.push("");
|
5866 | }
|
5867 | if (ra != rb) {
|
5868 | if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
|
5869 | q.push({
|
5870 | i: s.push(s.pop() + "rotate(", null, ")") - 2,
|
5871 | x: d3_interpolateNumber(ra, rb)
|
5872 | });
|
5873 | } else if (rb) {
|
5874 | s.push(s.pop() + "rotate(" + rb + ")");
|
5875 | }
|
5876 | if (wa != wb) {
|
5877 | q.push({
|
5878 | i: s.push(s.pop() + "skewX(", null, ")") - 2,
|
5879 | x: d3_interpolateNumber(wa, wb)
|
5880 | });
|
5881 | } else if (wb) {
|
5882 | s.push(s.pop() + "skewX(" + wb + ")");
|
5883 | }
|
5884 | if (ka[0] != kb[0] || ka[1] != kb[1]) {
|
5885 | n = s.push(s.pop() + "scale(", null, ",", null, ")");
|
5886 | q.push({
|
5887 | i: n - 4,
|
5888 | x: d3_interpolateNumber(ka[0], kb[0])
|
5889 | }, {
|
5890 | i: n - 2,
|
5891 | x: d3_interpolateNumber(ka[1], kb[1])
|
5892 | });
|
5893 | } else if (kb[0] != 1 || kb[1] != 1) {
|
5894 | s.push(s.pop() + "scale(" + kb + ")");
|
5895 | }
|
5896 | n = q.length;
|
5897 | return function(t) {
|
5898 | var i = -1, o;
|
5899 | while (++i < n) s[(o = q[i]).i] = o.x(t);
|
5900 | return s.join("");
|
5901 | };
|
5902 | }
|
5903 | function d3_uninterpolateNumber(a, b) {
|
5904 | b = b - (a = +a) ? 1 / (b - a) : 0;
|
5905 | return function(x) {
|
5906 | return (x - a) * b;
|
5907 | };
|
5908 | }
|
5909 | function d3_uninterpolateClamp(a, b) {
|
5910 | b = b - (a = +a) ? 1 / (b - a) : 0;
|
5911 | return function(x) {
|
5912 | return Math.max(0, Math.min(1, (x - a) * b));
|
5913 | };
|
5914 | }
|
5915 | d3.layout = {};
|
5916 | d3.layout.bundle = function() {
|
5917 | return function(links) {
|
5918 | var paths = [], i = -1, n = links.length;
|
5919 | while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
|
5920 | return paths;
|
5921 | };
|
5922 | };
|
5923 | function d3_layout_bundlePath(link) {
|
5924 | var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
|
5925 | while (start !== lca) {
|
5926 | start = start.parent;
|
5927 | points.push(start);
|
5928 | }
|
5929 | var k = points.length;
|
5930 | while (end !== lca) {
|
5931 | points.splice(k, 0, end);
|
5932 | end = end.parent;
|
5933 | }
|
5934 | return points;
|
5935 | }
|
5936 | function d3_layout_bundleAncestors(node) {
|
5937 | var ancestors = [], parent = node.parent;
|
5938 | while (parent != null) {
|
5939 | ancestors.push(node);
|
5940 | node = parent;
|
5941 | parent = parent.parent;
|
5942 | }
|
5943 | ancestors.push(node);
|
5944 | return ancestors;
|
5945 | }
|
5946 | function d3_layout_bundleLeastCommonAncestor(a, b) {
|
5947 | if (a === b) return a;
|
5948 | var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
|
5949 | while (aNode === bNode) {
|
5950 | sharedNode = aNode;
|
5951 | aNode = aNodes.pop();
|
5952 | bNode = bNodes.pop();
|
5953 | }
|
5954 | return sharedNode;
|
5955 | }
|
5956 | d3.layout.chord = function() {
|
5957 | var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
|
5958 | function relayout() {
|
5959 | var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
|
5960 | chords = [];
|
5961 | groups = [];
|
5962 | k = 0, i = -1;
|
5963 | while (++i < n) {
|
5964 | x = 0, j = -1;
|
5965 | while (++j < n) {
|
5966 | x += matrix[i][j];
|
5967 | }
|
5968 | groupSums.push(x);
|
5969 | subgroupIndex.push(d3.range(n));
|
5970 | k += x;
|
5971 | }
|
5972 | if (sortGroups) {
|
5973 | groupIndex.sort(function(a, b) {
|
5974 | return sortGroups(groupSums[a], groupSums[b]);
|
5975 | });
|
5976 | }
|
5977 | if (sortSubgroups) {
|
5978 | subgroupIndex.forEach(function(d, i) {
|
5979 | d.sort(function(a, b) {
|
5980 | return sortSubgroups(matrix[i][a], matrix[i][b]);
|
5981 | });
|
5982 | });
|
5983 | }
|
5984 | k = (τ - padding * n) / k;
|
5985 | x = 0, i = -1;
|
5986 | while (++i < n) {
|
5987 | x0 = x, j = -1;
|
5988 | while (++j < n) {
|
5989 | var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
|
5990 | subgroups[di + "-" + dj] = {
|
5991 | index: di,
|
5992 | subindex: dj,
|
5993 | startAngle: a0,
|
5994 | endAngle: a1,
|
5995 | value: v
|
5996 | };
|
5997 | }
|
5998 | groups[di] = {
|
5999 | index: di,
|
6000 | startAngle: x0,
|
6001 | endAngle: x,
|
6002 | value: (x - x0) / k
|
6003 | };
|
6004 | x += padding;
|
6005 | }
|
6006 | i = -1;
|
6007 | while (++i < n) {
|
6008 | j = i - 1;
|
6009 | while (++j < n) {
|
6010 | var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
|
6011 | if (source.value || target.value) {
|
6012 | chords.push(source.value < target.value ? {
|
6013 | source: target,
|
6014 | target: source
|
6015 | } : {
|
6016 | source: source,
|
6017 | target: target
|
6018 | });
|
6019 | }
|
6020 | }
|
6021 | }
|
6022 | if (sortChords) resort();
|
6023 | }
|
6024 | function resort() {
|
6025 | chords.sort(function(a, b) {
|
6026 | return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
|
6027 | });
|
6028 | }
|
6029 | chord.matrix = function(x) {
|
6030 | if (!arguments.length) return matrix;
|
6031 | n = (matrix = x) && matrix.length;
|
6032 | chords = groups = null;
|
6033 | return chord;
|
6034 | };
|
6035 | chord.padding = function(x) {
|
6036 | if (!arguments.length) return padding;
|
6037 | padding = x;
|
6038 | chords = groups = null;
|
6039 | return chord;
|
6040 | };
|
6041 | chord.sortGroups = function(x) {
|
6042 | if (!arguments.length) return sortGroups;
|
6043 | sortGroups = x;
|
6044 | chords = groups = null;
|
6045 | return chord;
|
6046 | };
|
6047 | chord.sortSubgroups = function(x) {
|
6048 | if (!arguments.length) return sortSubgroups;
|
6049 | sortSubgroups = x;
|
6050 | chords = null;
|
6051 | return chord;
|
6052 | };
|
6053 | chord.sortChords = function(x) {
|
6054 | if (!arguments.length) return sortChords;
|
6055 | sortChords = x;
|
6056 | if (chords) resort();
|
6057 | return chord;
|
6058 | };
|
6059 | chord.chords = function() {
|
6060 | if (!chords) relayout();
|
6061 | return chords;
|
6062 | };
|
6063 | chord.groups = function() {
|
6064 | if (!groups) relayout();
|
6065 | return groups;
|
6066 | };
|
6067 | return chord;
|
6068 | };
|
6069 | d3.layout.force = function() {
|
6070 | var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
|
6071 | function repulse(node) {
|
6072 | return function(quad, x1, _, x2) {
|
6073 | if (quad.point !== node) {
|
6074 | var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
|
6075 | if (dw * dw / theta2 < dn) {
|
6076 | if (dn < chargeDistance2) {
|
6077 | var k = quad.charge / dn;
|
6078 | node.px -= dx * k;
|
6079 | node.py -= dy * k;
|
6080 | }
|
6081 | return true;
|
6082 | }
|
6083 | if (quad.point && dn && dn < chargeDistance2) {
|
6084 | var k = quad.pointCharge / dn;
|
6085 | node.px -= dx * k;
|
6086 | node.py -= dy * k;
|
6087 | }
|
6088 | }
|
6089 | return !quad.charge;
|
6090 | };
|
6091 | }
|
6092 | force.tick = function() {
|
6093 | if ((alpha *= .99) < .005) {
|
6094 | event.end({
|
6095 | type: "end",
|
6096 | alpha: alpha = 0
|
6097 | });
|
6098 | return true;
|
6099 | }
|
6100 | var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
|
6101 | for (i = 0; i < m; ++i) {
|
6102 | o = links[i];
|
6103 | s = o.source;
|
6104 | t = o.target;
|
6105 | x = t.x - s.x;
|
6106 | y = t.y - s.y;
|
6107 | if (l = x * x + y * y) {
|
6108 | l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
|
6109 | x *= l;
|
6110 | y *= l;
|
6111 | t.x -= x * (k = s.weight / (t.weight + s.weight));
|
6112 | t.y -= y * k;
|
6113 | s.x += x * (k = 1 - k);
|
6114 | s.y += y * k;
|
6115 | }
|
6116 | }
|
6117 | if (k = alpha * gravity) {
|
6118 | x = size[0] / 2;
|
6119 | y = size[1] / 2;
|
6120 | i = -1;
|
6121 | if (k) while (++i < n) {
|
6122 | o = nodes[i];
|
6123 | o.x += (x - o.x) * k;
|
6124 | o.y += (y - o.y) * k;
|
6125 | }
|
6126 | }
|
6127 | if (charge) {
|
6128 | d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
|
6129 | i = -1;
|
6130 | while (++i < n) {
|
6131 | if (!(o = nodes[i]).fixed) {
|
6132 | q.visit(repulse(o));
|
6133 | }
|
6134 | }
|
6135 | }
|
6136 | i = -1;
|
6137 | while (++i < n) {
|
6138 | o = nodes[i];
|
6139 | if (o.fixed) {
|
6140 | o.x = o.px;
|
6141 | o.y = o.py;
|
6142 | } else {
|
6143 | o.x -= (o.px - (o.px = o.x)) * friction;
|
6144 | o.y -= (o.py - (o.py = o.y)) * friction;
|
6145 | }
|
6146 | }
|
6147 | event.tick({
|
6148 | type: "tick",
|
6149 | alpha: alpha
|
6150 | });
|
6151 | };
|
6152 | force.nodes = function(x) {
|
6153 | if (!arguments.length) return nodes;
|
6154 | nodes = x;
|
6155 | return force;
|
6156 | };
|
6157 | force.links = function(x) {
|
6158 | if (!arguments.length) return links;
|
6159 | links = x;
|
6160 | return force;
|
6161 | };
|
6162 | force.size = function(x) {
|
6163 | if (!arguments.length) return size;
|
6164 | size = x;
|
6165 | return force;
|
6166 | };
|
6167 | force.linkDistance = function(x) {
|
6168 | if (!arguments.length) return linkDistance;
|
6169 | linkDistance = typeof x === "function" ? x : +x;
|
6170 | return force;
|
6171 | };
|
6172 | force.distance = force.linkDistance;
|
6173 | force.linkStrength = function(x) {
|
6174 | if (!arguments.length) return linkStrength;
|
6175 | linkStrength = typeof x === "function" ? x : +x;
|
6176 | return force;
|
6177 | };
|
6178 | force.friction = function(x) {
|
6179 | if (!arguments.length) return friction;
|
6180 | friction = +x;
|
6181 | return force;
|
6182 | };
|
6183 | force.charge = function(x) {
|
6184 | if (!arguments.length) return charge;
|
6185 | charge = typeof x === "function" ? x : +x;
|
6186 | return force;
|
6187 | };
|
6188 | force.chargeDistance = function(x) {
|
6189 | if (!arguments.length) return Math.sqrt(chargeDistance2);
|
6190 | chargeDistance2 = x * x;
|
6191 | return force;
|
6192 | };
|
6193 | force.gravity = function(x) {
|
6194 | if (!arguments.length) return gravity;
|
6195 | gravity = +x;
|
6196 | return force;
|
6197 | };
|
6198 | force.theta = function(x) {
|
6199 | if (!arguments.length) return Math.sqrt(theta2);
|
6200 | theta2 = x * x;
|
6201 | return force;
|
6202 | };
|
6203 | force.alpha = function(x) {
|
6204 | if (!arguments.length) return alpha;
|
6205 | x = +x;
|
6206 | if (alpha) {
|
6207 | if (x > 0) alpha = x; else alpha = 0;
|
6208 | } else if (x > 0) {
|
6209 | event.start({
|
6210 | type: "start",
|
6211 | alpha: alpha = x
|
6212 | });
|
6213 | d3.timer(force.tick);
|
6214 | }
|
6215 | return force;
|
6216 | };
|
6217 | force.start = function() {
|
6218 | var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
|
6219 | for (i = 0; i < n; ++i) {
|
6220 | (o = nodes[i]).index = i;
|
6221 | o.weight = 0;
|
6222 | }
|
6223 | for (i = 0; i < m; ++i) {
|
6224 | o = links[i];
|
6225 | if (typeof o.source == "number") o.source = nodes[o.source];
|
6226 | if (typeof o.target == "number") o.target = nodes[o.target];
|
6227 | ++o.source.weight;
|
6228 | ++o.target.weight;
|
6229 | }
|
6230 | for (i = 0; i < n; ++i) {
|
6231 | o = nodes[i];
|
6232 | if (isNaN(o.x)) o.x = position("x", w);
|
6233 | if (isNaN(o.y)) o.y = position("y", h);
|
6234 | if (isNaN(o.px)) o.px = o.x;
|
6235 | if (isNaN(o.py)) o.py = o.y;
|
6236 | }
|
6237 | distances = [];
|
6238 | 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;
|
6239 | strengths = [];
|
6240 | 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;
|
6241 | charges = [];
|
6242 | 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;
|
6243 | function position(dimension, size) {
|
6244 | if (!neighbors) {
|
6245 | neighbors = new Array(n);
|
6246 | for (j = 0; j < n; ++j) {
|
6247 | neighbors[j] = [];
|
6248 | }
|
6249 | for (j = 0; j < m; ++j) {
|
6250 | var o = links[j];
|
6251 | neighbors[o.source.index].push(o.target);
|
6252 | neighbors[o.target.index].push(o.source);
|
6253 | }
|
6254 | }
|
6255 | var candidates = neighbors[i], j = -1, m = candidates.length, x;
|
6256 | while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
|
6257 | return Math.random() * size;
|
6258 | }
|
6259 | return force.resume();
|
6260 | };
|
6261 | force.resume = function() {
|
6262 | return force.alpha(.1);
|
6263 | };
|
6264 | force.stop = function() {
|
6265 | return force.alpha(0);
|
6266 | };
|
6267 | force.drag = function() {
|
6268 | 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);
|
6269 | if (!arguments.length) return drag;
|
6270 | this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
|
6271 | };
|
6272 | function dragmove(d) {
|
6273 | d.px = d3.event.x, d.py = d3.event.y;
|
6274 | force.resume();
|
6275 | }
|
6276 | return d3.rebind(force, event, "on");
|
6277 | };
|
6278 | function d3_layout_forceDragstart(d) {
|
6279 | d.fixed |= 2;
|
6280 | }
|
6281 | function d3_layout_forceDragend(d) {
|
6282 | d.fixed &= ~6;
|
6283 | }
|
6284 | function d3_layout_forceMouseover(d) {
|
6285 | d.fixed |= 4;
|
6286 | d.px = d.x, d.py = d.y;
|
6287 | }
|
6288 | function d3_layout_forceMouseout(d) {
|
6289 | d.fixed &= ~4;
|
6290 | }
|
6291 | function d3_layout_forceAccumulate(quad, alpha, charges) {
|
6292 | var cx = 0, cy = 0;
|
6293 | quad.charge = 0;
|
6294 | if (!quad.leaf) {
|
6295 | var nodes = quad.nodes, n = nodes.length, i = -1, c;
|
6296 | while (++i < n) {
|
6297 | c = nodes[i];
|
6298 | if (c == null) continue;
|
6299 | d3_layout_forceAccumulate(c, alpha, charges);
|
6300 | quad.charge += c.charge;
|
6301 | cx += c.charge * c.cx;
|
6302 | cy += c.charge * c.cy;
|
6303 | }
|
6304 | }
|
6305 | if (quad.point) {
|
6306 | if (!quad.leaf) {
|
6307 | quad.point.x += Math.random() - .5;
|
6308 | quad.point.y += Math.random() - .5;
|
6309 | }
|
6310 | var k = alpha * charges[quad.point.index];
|
6311 | quad.charge += quad.pointCharge = k;
|
6312 | cx += k * quad.point.x;
|
6313 | cy += k * quad.point.y;
|
6314 | }
|
6315 | quad.cx = cx / quad.charge;
|
6316 | quad.cy = cy / quad.charge;
|
6317 | }
|
6318 | var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
|
6319 | d3.layout.hierarchy = function() {
|
6320 | var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
|
6321 | function hierarchy(root) {
|
6322 | var stack = [ root ], nodes = [], node;
|
6323 | root.depth = 0;
|
6324 | while ((node = stack.pop()) != null) {
|
6325 | nodes.push(node);
|
6326 | if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
|
6327 | var n, childs, child;
|
6328 | while (--n >= 0) {
|
6329 | stack.push(child = childs[n]);
|
6330 | child.parent = node;
|
6331 | child.depth = node.depth + 1;
|
6332 | }
|
6333 | if (value) node.value = 0;
|
6334 | node.children = childs;
|
6335 | } else {
|
6336 | if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
|
6337 | delete node.children;
|
6338 | }
|
6339 | }
|
6340 | d3_layout_hierarchyVisitAfter(root, function(node) {
|
6341 | var childs, parent;
|
6342 | if (sort && (childs = node.children)) childs.sort(sort);
|
6343 | if (value && (parent = node.parent)) parent.value += node.value;
|
6344 | });
|
6345 | return nodes;
|
6346 | }
|
6347 | hierarchy.sort = function(x) {
|
6348 | if (!arguments.length) return sort;
|
6349 | sort = x;
|
6350 | return hierarchy;
|
6351 | };
|
6352 | hierarchy.children = function(x) {
|
6353 | if (!arguments.length) return children;
|
6354 | children = x;
|
6355 | return hierarchy;
|
6356 | };
|
6357 | hierarchy.value = function(x) {
|
6358 | if (!arguments.length) return value;
|
6359 | value = x;
|
6360 | return hierarchy;
|
6361 | };
|
6362 | hierarchy.revalue = function(root) {
|
6363 | if (value) {
|
6364 | d3_layout_hierarchyVisitBefore(root, function(node) {
|
6365 | if (node.children) node.value = 0;
|
6366 | });
|
6367 | d3_layout_hierarchyVisitAfter(root, function(node) {
|
6368 | var parent;
|
6369 | if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
|
6370 | if (parent = node.parent) parent.value += node.value;
|
6371 | });
|
6372 | }
|
6373 | return root;
|
6374 | };
|
6375 | return hierarchy;
|
6376 | };
|
6377 | function d3_layout_hierarchyRebind(object, hierarchy) {
|
6378 | d3.rebind(object, hierarchy, "sort", "children", "value");
|
6379 | object.nodes = object;
|
6380 | object.links = d3_layout_hierarchyLinks;
|
6381 | return object;
|
6382 | }
|
6383 | function d3_layout_hierarchyVisitBefore(node, callback) {
|
6384 | var nodes = [ node ];
|
6385 | while ((node = nodes.pop()) != null) {
|
6386 | callback(node);
|
6387 | if ((children = node.children) && (n = children.length)) {
|
6388 | var n, children;
|
6389 | while (--n >= 0) nodes.push(children[n]);
|
6390 | }
|
6391 | }
|
6392 | }
|
6393 | function d3_layout_hierarchyVisitAfter(node, callback) {
|
6394 | var nodes = [ node ], nodes2 = [];
|
6395 | while ((node = nodes.pop()) != null) {
|
6396 | nodes2.push(node);
|
6397 | if ((children = node.children) && (n = children.length)) {
|
6398 | var i = -1, n, children;
|
6399 | while (++i < n) nodes.push(children[i]);
|
6400 | }
|
6401 | }
|
6402 | while ((node = nodes2.pop()) != null) {
|
6403 | callback(node);
|
6404 | }
|
6405 | }
|
6406 | function d3_layout_hierarchyChildren(d) {
|
6407 | return d.children;
|
6408 | }
|
6409 | function d3_layout_hierarchyValue(d) {
|
6410 | return d.value;
|
6411 | }
|
6412 | function d3_layout_hierarchySort(a, b) {
|
6413 | return b.value - a.value;
|
6414 | }
|
6415 | function d3_layout_hierarchyLinks(nodes) {
|
6416 | return d3.merge(nodes.map(function(parent) {
|
6417 | return (parent.children || []).map(function(child) {
|
6418 | return {
|
6419 | source: parent,
|
6420 | target: child
|
6421 | };
|
6422 | });
|
6423 | }));
|
6424 | }
|
6425 | d3.layout.partition = function() {
|
6426 | var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
|
6427 | function position(node, x, dx, dy) {
|
6428 | var children = node.children;
|
6429 | node.x = x;
|
6430 | node.y = node.depth * dy;
|
6431 | node.dx = dx;
|
6432 | node.dy = dy;
|
6433 | if (children && (n = children.length)) {
|
6434 | var i = -1, n, c, d;
|
6435 | dx = node.value ? dx / node.value : 0;
|
6436 | while (++i < n) {
|
6437 | position(c = children[i], x, d = c.value * dx, dy);
|
6438 | x += d;
|
6439 | }
|
6440 | }
|
6441 | }
|
6442 | function depth(node) {
|
6443 | var children = node.children, d = 0;
|
6444 | if (children && (n = children.length)) {
|
6445 | var i = -1, n;
|
6446 | while (++i < n) d = Math.max(d, depth(children[i]));
|
6447 | }
|
6448 | return 1 + d;
|
6449 | }
|
6450 | function partition(d, i) {
|
6451 | var nodes = hierarchy.call(this, d, i);
|
6452 | position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
|
6453 | return nodes;
|
6454 | }
|
6455 | partition.size = function(x) {
|
6456 | if (!arguments.length) return size;
|
6457 | size = x;
|
6458 | return partition;
|
6459 | };
|
6460 | return d3_layout_hierarchyRebind(partition, hierarchy);
|
6461 | };
|
6462 | d3.layout.pie = function() {
|
6463 | var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ;
|
6464 | function pie(data) {
|
6465 | var values = data.map(function(d, i) {
|
6466 | return +value.call(pie, d, i);
|
6467 | });
|
6468 | var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
|
6469 | var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values);
|
6470 | var index = d3.range(data.length);
|
6471 | if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
|
6472 | return values[j] - values[i];
|
6473 | } : function(i, j) {
|
6474 | return sort(data[i], data[j]);
|
6475 | });
|
6476 | var arcs = [];
|
6477 | index.forEach(function(i) {
|
6478 | var d;
|
6479 | arcs[i] = {
|
6480 | data: data[i],
|
6481 | value: d = values[i],
|
6482 | startAngle: a,
|
6483 | endAngle: a += d * k
|
6484 | };
|
6485 | });
|
6486 | return arcs;
|
6487 | }
|
6488 | pie.value = function(x) {
|
6489 | if (!arguments.length) return value;
|
6490 | value = x;
|
6491 | return pie;
|
6492 | };
|
6493 | pie.sort = function(x) {
|
6494 | if (!arguments.length) return sort;
|
6495 | sort = x;
|
6496 | return pie;
|
6497 | };
|
6498 | pie.startAngle = function(x) {
|
6499 | if (!arguments.length) return startAngle;
|
6500 | startAngle = x;
|
6501 | return pie;
|
6502 | };
|
6503 | pie.endAngle = function(x) {
|
6504 | if (!arguments.length) return endAngle;
|
6505 | endAngle = x;
|
6506 | return pie;
|
6507 | };
|
6508 | return pie;
|
6509 | };
|
6510 | var d3_layout_pieSortByValue = {};
|
6511 | d3.layout.stack = function() {
|
6512 | var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
|
6513 | function stack(data, index) {
|
6514 | var series = data.map(function(d, i) {
|
6515 | return values.call(stack, d, i);
|
6516 | });
|
6517 | var points = series.map(function(d) {
|
6518 | return d.map(function(v, i) {
|
6519 | return [ x.call(stack, v, i), y.call(stack, v, i) ];
|
6520 | });
|
6521 | });
|
6522 | var orders = order.call(stack, points, index);
|
6523 | series = d3.permute(series, orders);
|
6524 | points = d3.permute(points, orders);
|
6525 | var offsets = offset.call(stack, points, index);
|
6526 | var n = series.length, m = series[0].length, i, j, o;
|
6527 | for (j = 0; j < m; ++j) {
|
6528 | out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
|
6529 | for (i = 1; i < n; ++i) {
|
6530 | out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
|
6531 | }
|
6532 | }
|
6533 | return data;
|
6534 | }
|
6535 | stack.values = function(x) {
|
6536 | if (!arguments.length) return values;
|
6537 | values = x;
|
6538 | return stack;
|
6539 | };
|
6540 | stack.order = function(x) {
|
6541 | if (!arguments.length) return order;
|
6542 | order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
|
6543 | return stack;
|
6544 | };
|
6545 | stack.offset = function(x) {
|
6546 | if (!arguments.length) return offset;
|
6547 | offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
|
6548 | return stack;
|
6549 | };
|
6550 | stack.x = function(z) {
|
6551 | if (!arguments.length) return x;
|
6552 | x = z;
|
6553 | return stack;
|
6554 | };
|
6555 | stack.y = function(z) {
|
6556 | if (!arguments.length) return y;
|
6557 | y = z;
|
6558 | return stack;
|
6559 | };
|
6560 | stack.out = function(z) {
|
6561 | if (!arguments.length) return out;
|
6562 | out = z;
|
6563 | return stack;
|
6564 | };
|
6565 | return stack;
|
6566 | };
|
6567 | function d3_layout_stackX(d) {
|
6568 | return d.x;
|
6569 | }
|
6570 | function d3_layout_stackY(d) {
|
6571 | return d.y;
|
6572 | }
|
6573 | function d3_layout_stackOut(d, y0, y) {
|
6574 | d.y0 = y0;
|
6575 | d.y = y;
|
6576 | }
|
6577 | var d3_layout_stackOrders = d3.map({
|
6578 | "inside-out": function(data) {
|
6579 | 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) {
|
6580 | return max[a] - max[b];
|
6581 | }), top = 0, bottom = 0, tops = [], bottoms = [];
|
6582 | for (i = 0; i < n; ++i) {
|
6583 | j = index[i];
|
6584 | if (top < bottom) {
|
6585 | top += sums[j];
|
6586 | tops.push(j);
|
6587 | } else {
|
6588 | bottom += sums[j];
|
6589 | bottoms.push(j);
|
6590 | }
|
6591 | }
|
6592 | return bottoms.reverse().concat(tops);
|
6593 | },
|
6594 | reverse: function(data) {
|
6595 | return d3.range(data.length).reverse();
|
6596 | },
|
6597 | "default": d3_layout_stackOrderDefault
|
6598 | });
|
6599 | var d3_layout_stackOffsets = d3.map({
|
6600 | silhouette: function(data) {
|
6601 | var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
|
6602 | for (j = 0; j < m; ++j) {
|
6603 | for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
|
6604 | if (o > max) max = o;
|
6605 | sums.push(o);
|
6606 | }
|
6607 | for (j = 0; j < m; ++j) {
|
6608 | y0[j] = (max - sums[j]) / 2;
|
6609 | }
|
6610 | return y0;
|
6611 | },
|
6612 | wiggle: function(data) {
|
6613 | var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
|
6614 | y0[0] = o = o0 = 0;
|
6615 | for (j = 1; j < m; ++j) {
|
6616 | for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
|
6617 | for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
|
6618 | for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
|
6619 | s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
|
6620 | }
|
6621 | s2 += s3 * data[i][j][1];
|
6622 | }
|
6623 | y0[j] = o -= s1 ? s2 / s1 * dx : 0;
|
6624 | if (o < o0) o0 = o;
|
6625 | }
|
6626 | for (j = 0; j < m; ++j) y0[j] -= o0;
|
6627 | return y0;
|
6628 | },
|
6629 | expand: function(data) {
|
6630 | var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
|
6631 | for (j = 0; j < m; ++j) {
|
6632 | for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
|
6633 | 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;
|
6634 | }
|
6635 | for (j = 0; j < m; ++j) y0[j] = 0;
|
6636 | return y0;
|
6637 | },
|
6638 | zero: d3_layout_stackOffsetZero
|
6639 | });
|
6640 | function d3_layout_stackOrderDefault(data) {
|
6641 | return d3.range(data.length);
|
6642 | }
|
6643 | function d3_layout_stackOffsetZero(data) {
|
6644 | var j = -1, m = data[0].length, y0 = [];
|
6645 | while (++j < m) y0[j] = 0;
|
6646 | return y0;
|
6647 | }
|
6648 | function d3_layout_stackMaxIndex(array) {
|
6649 | var i = 1, j = 0, v = array[0][1], k, n = array.length;
|
6650 | for (;i < n; ++i) {
|
6651 | if ((k = array[i][1]) > v) {
|
6652 | j = i;
|
6653 | v = k;
|
6654 | }
|
6655 | }
|
6656 | return j;
|
6657 | }
|
6658 | function d3_layout_stackReduceSum(d) {
|
6659 | return d.reduce(d3_layout_stackSum, 0);
|
6660 | }
|
6661 | function d3_layout_stackSum(p, d) {
|
6662 | return p + d[1];
|
6663 | }
|
6664 | d3.layout.histogram = function() {
|
6665 | var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
|
6666 | function histogram(data, i) {
|
6667 | 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;
|
6668 | while (++i < m) {
|
6669 | bin = bins[i] = [];
|
6670 | bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
|
6671 | bin.y = 0;
|
6672 | }
|
6673 | if (m > 0) {
|
6674 | i = -1;
|
6675 | while (++i < n) {
|
6676 | x = values[i];
|
6677 | if (x >= range[0] && x <= range[1]) {
|
6678 | bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
|
6679 | bin.y += k;
|
6680 | bin.push(data[i]);
|
6681 | }
|
6682 | }
|
6683 | }
|
6684 | return bins;
|
6685 | }
|
6686 | histogram.value = function(x) {
|
6687 | if (!arguments.length) return valuer;
|
6688 | valuer = x;
|
6689 | return histogram;
|
6690 | };
|
6691 | histogram.range = function(x) {
|
6692 | if (!arguments.length) return ranger;
|
6693 | ranger = d3_functor(x);
|
6694 | return histogram;
|
6695 | };
|
6696 | histogram.bins = function(x) {
|
6697 | if (!arguments.length) return binner;
|
6698 | binner = typeof x === "number" ? function(range) {
|
6699 | return d3_layout_histogramBinFixed(range, x);
|
6700 | } : d3_functor(x);
|
6701 | return histogram;
|
6702 | };
|
6703 | histogram.frequency = function(x) {
|
6704 | if (!arguments.length) return frequency;
|
6705 | frequency = !!x;
|
6706 | return histogram;
|
6707 | };
|
6708 | return histogram;
|
6709 | };
|
6710 | function d3_layout_histogramBinSturges(range, values) {
|
6711 | return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
|
6712 | }
|
6713 | function d3_layout_histogramBinFixed(range, n) {
|
6714 | var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
|
6715 | while (++x <= n) f[x] = m * x + b;
|
6716 | return f;
|
6717 | }
|
6718 | function d3_layout_histogramRange(values) {
|
6719 | return [ d3.min(values), d3.max(values) ];
|
6720 | }
|
6721 | d3.layout.pack = function() {
|
6722 | var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
|
6723 | function pack(d, i) {
|
6724 | 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() {
|
6725 | return radius;
|
6726 | };
|
6727 | root.x = root.y = 0;
|
6728 | d3_layout_hierarchyVisitAfter(root, function(d) {
|
6729 | d.r = +r(d.value);
|
6730 | });
|
6731 | d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
|
6732 | if (padding) {
|
6733 | var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
|
6734 | d3_layout_hierarchyVisitAfter(root, function(d) {
|
6735 | d.r += dr;
|
6736 | });
|
6737 | d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
|
6738 | d3_layout_hierarchyVisitAfter(root, function(d) {
|
6739 | d.r -= dr;
|
6740 | });
|
6741 | }
|
6742 | d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
|
6743 | return nodes;
|
6744 | }
|
6745 | pack.size = function(_) {
|
6746 | if (!arguments.length) return size;
|
6747 | size = _;
|
6748 | return pack;
|
6749 | };
|
6750 | pack.radius = function(_) {
|
6751 | if (!arguments.length) return radius;
|
6752 | radius = _ == null || typeof _ === "function" ? _ : +_;
|
6753 | return pack;
|
6754 | };
|
6755 | pack.padding = function(_) {
|
6756 | if (!arguments.length) return padding;
|
6757 | padding = +_;
|
6758 | return pack;
|
6759 | };
|
6760 | return d3_layout_hierarchyRebind(pack, hierarchy);
|
6761 | };
|
6762 | function d3_layout_packSort(a, b) {
|
6763 | return a.value - b.value;
|
6764 | }
|
6765 | function d3_layout_packInsert(a, b) {
|
6766 | var c = a._pack_next;
|
6767 | a._pack_next = b;
|
6768 | b._pack_prev = a;
|
6769 | b._pack_next = c;
|
6770 | c._pack_prev = b;
|
6771 | }
|
6772 | function d3_layout_packSplice(a, b) {
|
6773 | a._pack_next = b;
|
6774 | b._pack_prev = a;
|
6775 | }
|
6776 | function d3_layout_packIntersects(a, b) {
|
6777 | var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
|
6778 | return .999 * dr * dr > dx * dx + dy * dy;
|
6779 | }
|
6780 | function d3_layout_packSiblings(node) {
|
6781 | if (!(nodes = node.children) || !(n = nodes.length)) return;
|
6782 | var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
|
6783 | function bound(node) {
|
6784 | xMin = Math.min(node.x - node.r, xMin);
|
6785 | xMax = Math.max(node.x + node.r, xMax);
|
6786 | yMin = Math.min(node.y - node.r, yMin);
|
6787 | yMax = Math.max(node.y + node.r, yMax);
|
6788 | }
|
6789 | nodes.forEach(d3_layout_packLink);
|
6790 | a = nodes[0];
|
6791 | a.x = -a.r;
|
6792 | a.y = 0;
|
6793 | bound(a);
|
6794 | if (n > 1) {
|
6795 | b = nodes[1];
|
6796 | b.x = b.r;
|
6797 | b.y = 0;
|
6798 | bound(b);
|
6799 | if (n > 2) {
|
6800 | c = nodes[2];
|
6801 | d3_layout_packPlace(a, b, c);
|
6802 | bound(c);
|
6803 | d3_layout_packInsert(a, c);
|
6804 | a._pack_prev = c;
|
6805 | d3_layout_packInsert(c, b);
|
6806 | b = a._pack_next;
|
6807 | for (i = 3; i < n; i++) {
|
6808 | d3_layout_packPlace(a, b, c = nodes[i]);
|
6809 | var isect = 0, s1 = 1, s2 = 1;
|
6810 | for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
|
6811 | if (d3_layout_packIntersects(j, c)) {
|
6812 | isect = 1;
|
6813 | break;
|
6814 | }
|
6815 | }
|
6816 | if (isect == 1) {
|
6817 | for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
|
6818 | if (d3_layout_packIntersects(k, c)) {
|
6819 | break;
|
6820 | }
|
6821 | }
|
6822 | }
|
6823 | if (isect) {
|
6824 | if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
|
6825 | i--;
|
6826 | } else {
|
6827 | d3_layout_packInsert(a, c);
|
6828 | b = c;
|
6829 | bound(c);
|
6830 | }
|
6831 | }
|
6832 | }
|
6833 | }
|
6834 | var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
|
6835 | for (i = 0; i < n; i++) {
|
6836 | c = nodes[i];
|
6837 | c.x -= cx;
|
6838 | c.y -= cy;
|
6839 | cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
|
6840 | }
|
6841 | node.r = cr;
|
6842 | nodes.forEach(d3_layout_packUnlink);
|
6843 | }
|
6844 | function d3_layout_packLink(node) {
|
6845 | node._pack_next = node._pack_prev = node;
|
6846 | }
|
6847 | function d3_layout_packUnlink(node) {
|
6848 | delete node._pack_next;
|
6849 | delete node._pack_prev;
|
6850 | }
|
6851 | function d3_layout_packTransform(node, x, y, k) {
|
6852 | var children = node.children;
|
6853 | node.x = x += k * node.x;
|
6854 | node.y = y += k * node.y;
|
6855 | node.r *= k;
|
6856 | if (children) {
|
6857 | var i = -1, n = children.length;
|
6858 | while (++i < n) d3_layout_packTransform(children[i], x, y, k);
|
6859 | }
|
6860 | }
|
6861 | function d3_layout_packPlace(a, b, c) {
|
6862 | var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
|
6863 | if (db && (dx || dy)) {
|
6864 | var da = b.r + c.r, dc = dx * dx + dy * dy;
|
6865 | da *= da;
|
6866 | db *= db;
|
6867 | var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
|
6868 | c.x = a.x + x * dx + y * dy;
|
6869 | c.y = a.y + x * dy - y * dx;
|
6870 | } else {
|
6871 | c.x = a.x + db;
|
6872 | c.y = a.y;
|
6873 | }
|
6874 | }
|
6875 | d3.layout.tree = function() {
|
6876 | var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
|
6877 | function tree(d, i) {
|
6878 | var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
|
6879 | d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
|
6880 | d3_layout_hierarchyVisitBefore(root1, secondWalk);
|
6881 | if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
|
6882 | var left = root0, right = root0, bottom = root0;
|
6883 | d3_layout_hierarchyVisitBefore(root0, function(node) {
|
6884 | if (node.x < left.x) left = node;
|
6885 | if (node.x > right.x) right = node;
|
6886 | if (node.depth > bottom.depth) bottom = node;
|
6887 | });
|
6888 | var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
|
6889 | d3_layout_hierarchyVisitBefore(root0, function(node) {
|
6890 | node.x = (node.x + tx) * kx;
|
6891 | node.y = node.depth * ky;
|
6892 | });
|
6893 | }
|
6894 | return nodes;
|
6895 | }
|
6896 | function wrapTree(root0) {
|
6897 | var root1 = {
|
6898 | A: null,
|
6899 | children: [ root0 ]
|
6900 | }, queue = [ root1 ], node1;
|
6901 | while ((node1 = queue.pop()) != null) {
|
6902 | for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
|
6903 | queue.push((children[i] = child = {
|
6904 | _: children[i],
|
6905 | parent: node1,
|
6906 | children: (child = children[i].children) && child.slice() || [],
|
6907 | A: null,
|
6908 | a: null,
|
6909 | z: 0,
|
6910 | m: 0,
|
6911 | c: 0,
|
6912 | s: 0,
|
6913 | t: null,
|
6914 | i: i
|
6915 | }).a = child);
|
6916 | }
|
6917 | }
|
6918 | return root1.children[0];
|
6919 | }
|
6920 | function firstWalk(v) {
|
6921 | var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
|
6922 | if (children.length) {
|
6923 | d3_layout_treeShift(v);
|
6924 | var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
6925 | if (w) {
|
6926 | v.z = w.z + separation(v._, w._);
|
6927 | v.m = v.z - midpoint;
|
6928 | } else {
|
6929 | v.z = midpoint;
|
6930 | }
|
6931 | } else if (w) {
|
6932 | v.z = w.z + separation(v._, w._);
|
6933 | }
|
6934 | v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
6935 | }
|
6936 | function secondWalk(v) {
|
6937 | v._.x = v.z + v.parent.m;
|
6938 | v.m += v.parent.m;
|
6939 | }
|
6940 | function apportion(v, w, ancestor) {
|
6941 | if (w) {
|
6942 | 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;
|
6943 | while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
|
6944 | vom = d3_layout_treeLeft(vom);
|
6945 | vop = d3_layout_treeRight(vop);
|
6946 | vop.a = v;
|
6947 | shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
6948 | if (shift > 0) {
|
6949 | d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
|
6950 | sip += shift;
|
6951 | sop += shift;
|
6952 | }
|
6953 | sim += vim.m;
|
6954 | sip += vip.m;
|
6955 | som += vom.m;
|
6956 | sop += vop.m;
|
6957 | }
|
6958 | if (vim && !d3_layout_treeRight(vop)) {
|
6959 | vop.t = vim;
|
6960 | vop.m += sim - sop;
|
6961 | }
|
6962 | if (vip && !d3_layout_treeLeft(vom)) {
|
6963 | vom.t = vip;
|
6964 | vom.m += sip - som;
|
6965 | ancestor = v;
|
6966 | }
|
6967 | }
|
6968 | return ancestor;
|
6969 | }
|
6970 | function sizeNode(node) {
|
6971 | node.x *= size[0];
|
6972 | node.y = node.depth * size[1];
|
6973 | }
|
6974 | tree.separation = function(x) {
|
6975 | if (!arguments.length) return separation;
|
6976 | separation = x;
|
6977 | return tree;
|
6978 | };
|
6979 | tree.size = function(x) {
|
6980 | if (!arguments.length) return nodeSize ? null : size;
|
6981 | nodeSize = (size = x) == null ? sizeNode : null;
|
6982 | return tree;
|
6983 | };
|
6984 | tree.nodeSize = function(x) {
|
6985 | if (!arguments.length) return nodeSize ? size : null;
|
6986 | nodeSize = (size = x) == null ? null : sizeNode;
|
6987 | return tree;
|
6988 | };
|
6989 | return d3_layout_hierarchyRebind(tree, hierarchy);
|
6990 | };
|
6991 | function d3_layout_treeSeparation(a, b) {
|
6992 | return a.parent == b.parent ? 1 : 2;
|
6993 | }
|
6994 | function d3_layout_treeLeft(v) {
|
6995 | var children = v.children;
|
6996 | return children.length ? children[0] : v.t;
|
6997 | }
|
6998 | function d3_layout_treeRight(v) {
|
6999 | var children = v.children, n;
|
7000 | return (n = children.length) ? children[n - 1] : v.t;
|
7001 | }
|
7002 | function d3_layout_treeMove(wm, wp, shift) {
|
7003 | var change = shift / (wp.i - wm.i);
|
7004 | wp.c -= change;
|
7005 | wp.s += shift;
|
7006 | wm.c += change;
|
7007 | wp.z += shift;
|
7008 | wp.m += shift;
|
7009 | }
|
7010 | function d3_layout_treeShift(v) {
|
7011 | var shift = 0, change = 0, children = v.children, i = children.length, w;
|
7012 | while (--i >= 0) {
|
7013 | w = children[i];
|
7014 | w.z += shift;
|
7015 | w.m += shift;
|
7016 | shift += w.s + (change += w.c);
|
7017 | }
|
7018 | }
|
7019 | function d3_layout_treeAncestor(vim, v, ancestor) {
|
7020 | return vim.a.parent === v.parent ? vim.a : ancestor;
|
7021 | }
|
7022 | d3.layout.cluster = function() {
|
7023 | var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
|
7024 | function cluster(d, i) {
|
7025 | var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
|
7026 | d3_layout_hierarchyVisitAfter(root, function(node) {
|
7027 | var children = node.children;
|
7028 | if (children && children.length) {
|
7029 | node.x = d3_layout_clusterX(children);
|
7030 | node.y = d3_layout_clusterY(children);
|
7031 | } else {
|
7032 | node.x = previousNode ? x += separation(node, previousNode) : 0;
|
7033 | node.y = 0;
|
7034 | previousNode = node;
|
7035 | }
|
7036 | });
|
7037 | 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;
|
7038 | d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
|
7039 | node.x = (node.x - root.x) * size[0];
|
7040 | node.y = (root.y - node.y) * size[1];
|
7041 | } : function(node) {
|
7042 | node.x = (node.x - x0) / (x1 - x0) * size[0];
|
7043 | node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
|
7044 | });
|
7045 | return nodes;
|
7046 | }
|
7047 | cluster.separation = function(x) {
|
7048 | if (!arguments.length) return separation;
|
7049 | separation = x;
|
7050 | return cluster;
|
7051 | };
|
7052 | cluster.size = function(x) {
|
7053 | if (!arguments.length) return nodeSize ? null : size;
|
7054 | nodeSize = (size = x) == null;
|
7055 | return cluster;
|
7056 | };
|
7057 | cluster.nodeSize = function(x) {
|
7058 | if (!arguments.length) return nodeSize ? size : null;
|
7059 | nodeSize = (size = x) != null;
|
7060 | return cluster;
|
7061 | };
|
7062 | return d3_layout_hierarchyRebind(cluster, hierarchy);
|
7063 | };
|
7064 | function d3_layout_clusterY(children) {
|
7065 | return 1 + d3.max(children, function(child) {
|
7066 | return child.y;
|
7067 | });
|
7068 | }
|
7069 | function d3_layout_clusterX(children) {
|
7070 | return children.reduce(function(x, child) {
|
7071 | return x + child.x;
|
7072 | }, 0) / children.length;
|
7073 | }
|
7074 | function d3_layout_clusterLeft(node) {
|
7075 | var children = node.children;
|
7076 | return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
|
7077 | }
|
7078 | function d3_layout_clusterRight(node) {
|
7079 | var children = node.children, n;
|
7080 | return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
|
7081 | }
|
7082 | d3.layout.treemap = function() {
|
7083 | 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));
|
7084 | function scale(children, k) {
|
7085 | var i = -1, n = children.length, child, area;
|
7086 | while (++i < n) {
|
7087 | area = (child = children[i]).value * (k < 0 ? 0 : k);
|
7088 | child.area = isNaN(area) || area <= 0 ? 0 : area;
|
7089 | }
|
7090 | }
|
7091 | function squarify(node) {
|
7092 | var children = node.children;
|
7093 | if (children && children.length) {
|
7094 | 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;
|
7095 | scale(remaining, rect.dx * rect.dy / node.value);
|
7096 | row.area = 0;
|
7097 | while ((n = remaining.length) > 0) {
|
7098 | row.push(child = remaining[n - 1]);
|
7099 | row.area += child.area;
|
7100 | if (mode !== "squarify" || (score = worst(row, u)) <= best) {
|
7101 | remaining.pop();
|
7102 | best = score;
|
7103 | } else {
|
7104 | row.area -= row.pop().area;
|
7105 | position(row, u, rect, false);
|
7106 | u = Math.min(rect.dx, rect.dy);
|
7107 | row.length = row.area = 0;
|
7108 | best = Infinity;
|
7109 | }
|
7110 | }
|
7111 | if (row.length) {
|
7112 | position(row, u, rect, true);
|
7113 | row.length = row.area = 0;
|
7114 | }
|
7115 | children.forEach(squarify);
|
7116 | }
|
7117 | }
|
7118 | function stickify(node) {
|
7119 | var children = node.children;
|
7120 | if (children && children.length) {
|
7121 | var rect = pad(node), remaining = children.slice(), child, row = [];
|
7122 | scale(remaining, rect.dx * rect.dy / node.value);
|
7123 | row.area = 0;
|
7124 | while (child = remaining.pop()) {
|
7125 | row.push(child);
|
7126 | row.area += child.area;
|
7127 | if (child.z != null) {
|
7128 | position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
|
7129 | row.length = row.area = 0;
|
7130 | }
|
7131 | }
|
7132 | children.forEach(stickify);
|
7133 | }
|
7134 | }
|
7135 | function worst(row, u) {
|
7136 | var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
|
7137 | while (++i < n) {
|
7138 | if (!(r = row[i].area)) continue;
|
7139 | if (r < rmin) rmin = r;
|
7140 | if (r > rmax) rmax = r;
|
7141 | }
|
7142 | s *= s;
|
7143 | u *= u;
|
7144 | return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
|
7145 | }
|
7146 | function position(row, u, rect, flush) {
|
7147 | var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
|
7148 | if (u == rect.dx) {
|
7149 | if (flush || v > rect.dy) v = rect.dy;
|
7150 | while (++i < n) {
|
7151 | o = row[i];
|
7152 | o.x = x;
|
7153 | o.y = y;
|
7154 | o.dy = v;
|
7155 | x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
|
7156 | }
|
7157 | o.z = true;
|
7158 | o.dx += rect.x + rect.dx - x;
|
7159 | rect.y += v;
|
7160 | rect.dy -= v;
|
7161 | } else {
|
7162 | if (flush || v > rect.dx) v = rect.dx;
|
7163 | while (++i < n) {
|
7164 | o = row[i];
|
7165 | o.x = x;
|
7166 | o.y = y;
|
7167 | o.dx = v;
|
7168 | y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
|
7169 | }
|
7170 | o.z = false;
|
7171 | o.dy += rect.y + rect.dy - y;
|
7172 | rect.x += v;
|
7173 | rect.dx -= v;
|
7174 | }
|
7175 | }
|
7176 | function treemap(d) {
|
7177 | var nodes = stickies || hierarchy(d), root = nodes[0];
|
7178 | root.x = 0;
|
7179 | root.y = 0;
|
7180 | root.dx = size[0];
|
7181 | root.dy = size[1];
|
7182 | if (stickies) hierarchy.revalue(root);
|
7183 | scale([ root ], root.dx * root.dy / root.value);
|
7184 | (stickies ? stickify : squarify)(root);
|
7185 | if (sticky) stickies = nodes;
|
7186 | return nodes;
|
7187 | }
|
7188 | treemap.size = function(x) {
|
7189 | if (!arguments.length) return size;
|
7190 | size = x;
|
7191 | return treemap;
|
7192 | };
|
7193 | treemap.padding = function(x) {
|
7194 | if (!arguments.length) return padding;
|
7195 | function padFunction(node) {
|
7196 | var p = x.call(treemap, node, node.depth);
|
7197 | return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
|
7198 | }
|
7199 | function padConstant(node) {
|
7200 | return d3_layout_treemapPad(node, x);
|
7201 | }
|
7202 | var type;
|
7203 | pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
|
7204 | padConstant) : padConstant;
|
7205 | return treemap;
|
7206 | };
|
7207 | treemap.round = function(x) {
|
7208 | if (!arguments.length) return round != Number;
|
7209 | round = x ? Math.round : Number;
|
7210 | return treemap;
|
7211 | };
|
7212 | treemap.sticky = function(x) {
|
7213 | if (!arguments.length) return sticky;
|
7214 | sticky = x;
|
7215 | stickies = null;
|
7216 | return treemap;
|
7217 | };
|
7218 | treemap.ratio = function(x) {
|
7219 | if (!arguments.length) return ratio;
|
7220 | ratio = x;
|
7221 | return treemap;
|
7222 | };
|
7223 | treemap.mode = function(x) {
|
7224 | if (!arguments.length) return mode;
|
7225 | mode = x + "";
|
7226 | return treemap;
|
7227 | };
|
7228 | return d3_layout_hierarchyRebind(treemap, hierarchy);
|
7229 | };
|
7230 | function d3_layout_treemapPadNull(node) {
|
7231 | return {
|
7232 | x: node.x,
|
7233 | y: node.y,
|
7234 | dx: node.dx,
|
7235 | dy: node.dy
|
7236 | };
|
7237 | }
|
7238 | function d3_layout_treemapPad(node, padding) {
|
7239 | 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];
|
7240 | if (dx < 0) {
|
7241 | x += dx / 2;
|
7242 | dx = 0;
|
7243 | }
|
7244 | if (dy < 0) {
|
7245 | y += dy / 2;
|
7246 | dy = 0;
|
7247 | }
|
7248 | return {
|
7249 | x: x,
|
7250 | y: y,
|
7251 | dx: dx,
|
7252 | dy: dy
|
7253 | };
|
7254 | }
|
7255 | d3.random = {
|
7256 | normal: function(µ, σ) {
|
7257 | var n = arguments.length;
|
7258 | if (n < 2) σ = 1;
|
7259 | if (n < 1) µ = 0;
|
7260 | return function() {
|
7261 | var x, y, r;
|
7262 | do {
|
7263 | x = Math.random() * 2 - 1;
|
7264 | y = Math.random() * 2 - 1;
|
7265 | r = x * x + y * y;
|
7266 | } while (!r || r > 1);
|
7267 | return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
|
7268 | };
|
7269 | },
|
7270 | logNormal: function() {
|
7271 | var random = d3.random.normal.apply(d3, arguments);
|
7272 | return function() {
|
7273 | return Math.exp(random());
|
7274 | };
|
7275 | },
|
7276 | bates: function(m) {
|
7277 | var random = d3.random.irwinHall(m);
|
7278 | return function() {
|
7279 | return random() / m;
|
7280 | };
|
7281 | },
|
7282 | irwinHall: function(m) {
|
7283 | return function() {
|
7284 | for (var s = 0, j = 0; j < m; j++) s += Math.random();
|
7285 | return s;
|
7286 | };
|
7287 | }
|
7288 | };
|
7289 | d3.scale = {};
|
7290 | function d3_scaleExtent(domain) {
|
7291 | var start = domain[0], stop = domain[domain.length - 1];
|
7292 | return start < stop ? [ start, stop ] : [ stop, start ];
|
7293 | }
|
7294 | function d3_scaleRange(scale) {
|
7295 | return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
|
7296 | }
|
7297 | function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
|
7298 | var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
|
7299 | return function(x) {
|
7300 | return i(u(x));
|
7301 | };
|
7302 | }
|
7303 | function d3_scale_nice(domain, nice) {
|
7304 | var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
|
7305 | if (x1 < x0) {
|
7306 | dx = i0, i0 = i1, i1 = dx;
|
7307 | dx = x0, x0 = x1, x1 = dx;
|
7308 | }
|
7309 | domain[i0] = nice.floor(x0);
|
7310 | domain[i1] = nice.ceil(x1);
|
7311 | return domain;
|
7312 | }
|
7313 | function d3_scale_niceStep(step) {
|
7314 | return step ? {
|
7315 | floor: function(x) {
|
7316 | return Math.floor(x / step) * step;
|
7317 | },
|
7318 | ceil: function(x) {
|
7319 | return Math.ceil(x / step) * step;
|
7320 | }
|
7321 | } : d3_scale_niceIdentity;
|
7322 | }
|
7323 | var d3_scale_niceIdentity = {
|
7324 | floor: d3_identity,
|
7325 | ceil: d3_identity
|
7326 | };
|
7327 | function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
|
7328 | var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
|
7329 | if (domain[k] < domain[0]) {
|
7330 | domain = domain.slice().reverse();
|
7331 | range = range.slice().reverse();
|
7332 | }
|
7333 | while (++j <= k) {
|
7334 | u.push(uninterpolate(domain[j - 1], domain[j]));
|
7335 | i.push(interpolate(range[j - 1], range[j]));
|
7336 | }
|
7337 | return function(x) {
|
7338 | var j = d3.bisect(domain, x, 1, k) - 1;
|
7339 | return i[j](u[j](x));
|
7340 | };
|
7341 | }
|
7342 | d3.scale.linear = function() {
|
7343 | return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
|
7344 | };
|
7345 | function d3_scale_linear(domain, range, interpolate, clamp) {
|
7346 | var output, input;
|
7347 | function rescale() {
|
7348 | var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
|
7349 | output = linear(domain, range, uninterpolate, interpolate);
|
7350 | input = linear(range, domain, uninterpolate, d3_interpolate);
|
7351 | return scale;
|
7352 | }
|
7353 | function scale(x) {
|
7354 | return output(x);
|
7355 | }
|
7356 | scale.invert = function(y) {
|
7357 | return input(y);
|
7358 | };
|
7359 | scale.domain = function(x) {
|
7360 | if (!arguments.length) return domain;
|
7361 | domain = x.map(Number);
|
7362 | return rescale();
|
7363 | };
|
7364 | scale.range = function(x) {
|
7365 | if (!arguments.length) return range;
|
7366 | range = x;
|
7367 | return rescale();
|
7368 | };
|
7369 | scale.rangeRound = function(x) {
|
7370 | return scale.range(x).interpolate(d3_interpolateRound);
|
7371 | };
|
7372 | scale.clamp = function(x) {
|
7373 | if (!arguments.length) return clamp;
|
7374 | clamp = x;
|
7375 | return rescale();
|
7376 | };
|
7377 | scale.interpolate = function(x) {
|
7378 | if (!arguments.length) return interpolate;
|
7379 | interpolate = x;
|
7380 | return rescale();
|
7381 | };
|
7382 | scale.ticks = function(m) {
|
7383 | return d3_scale_linearTicks(domain, m);
|
7384 | };
|
7385 | scale.tickFormat = function(m, format) {
|
7386 | return d3_scale_linearTickFormat(domain, m, format);
|
7387 | };
|
7388 | scale.nice = function(m) {
|
7389 | d3_scale_linearNice(domain, m);
|
7390 | return rescale();
|
7391 | };
|
7392 | scale.copy = function() {
|
7393 | return d3_scale_linear(domain, range, interpolate, clamp);
|
7394 | };
|
7395 | return rescale();
|
7396 | }
|
7397 | function d3_scale_linearRebind(scale, linear) {
|
7398 | return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
|
7399 | }
|
7400 | function d3_scale_linearNice(domain, m) {
|
7401 | return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
|
7402 | }
|
7403 | function d3_scale_linearTickRange(domain, m) {
|
7404 | if (m == null) m = 10;
|
7405 | 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;
|
7406 | if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
|
7407 | extent[0] = Math.ceil(extent[0] / step) * step;
|
7408 | extent[1] = Math.floor(extent[1] / step) * step + step * .5;
|
7409 | extent[2] = step;
|
7410 | return extent;
|
7411 | }
|
7412 | function d3_scale_linearTicks(domain, m) {
|
7413 | return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
|
7414 | }
|
7415 | function d3_scale_linearTickFormat(domain, m, format) {
|
7416 | var range = d3_scale_linearTickRange(domain, m);
|
7417 | if (format) {
|
7418 | var match = d3_format_re.exec(format);
|
7419 | match.shift();
|
7420 | if (match[8] === "s") {
|
7421 | var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
|
7422 | if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
|
7423 | match[8] = "f";
|
7424 | format = d3.format(match.join(""));
|
7425 | return function(d) {
|
7426 | return format(prefix.scale(d)) + prefix.symbol;
|
7427 | };
|
7428 | }
|
7429 | if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
|
7430 | format = match.join("");
|
7431 | } else {
|
7432 | format = ",." + d3_scale_linearPrecision(range[2]) + "f";
|
7433 | }
|
7434 | return d3.format(format);
|
7435 | }
|
7436 | var d3_scale_linearFormatSignificant = {
|
7437 | s: 1,
|
7438 | g: 1,
|
7439 | p: 1,
|
7440 | r: 1,
|
7441 | e: 1
|
7442 | };
|
7443 | function d3_scale_linearPrecision(value) {
|
7444 | return -Math.floor(Math.log(value) / Math.LN10 + .01);
|
7445 | }
|
7446 | function d3_scale_linearFormatPrecision(type, range) {
|
7447 | var p = d3_scale_linearPrecision(range[2]);
|
7448 | 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;
|
7449 | }
|
7450 | d3.scale.log = function() {
|
7451 | return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
|
7452 | };
|
7453 | function d3_scale_log(linear, base, positive, domain) {
|
7454 | function log(x) {
|
7455 | return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
|
7456 | }
|
7457 | function pow(x) {
|
7458 | return positive ? Math.pow(base, x) : -Math.pow(base, -x);
|
7459 | }
|
7460 | function scale(x) {
|
7461 | return linear(log(x));
|
7462 | }
|
7463 | scale.invert = function(x) {
|
7464 | return pow(linear.invert(x));
|
7465 | };
|
7466 | scale.domain = function(x) {
|
7467 | if (!arguments.length) return domain;
|
7468 | positive = x[0] >= 0;
|
7469 | linear.domain((domain = x.map(Number)).map(log));
|
7470 | return scale;
|
7471 | };
|
7472 | scale.base = function(_) {
|
7473 | if (!arguments.length) return base;
|
7474 | base = +_;
|
7475 | linear.domain(domain.map(log));
|
7476 | return scale;
|
7477 | };
|
7478 | scale.nice = function() {
|
7479 | var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
|
7480 | linear.domain(niced);
|
7481 | domain = niced.map(pow);
|
7482 | return scale;
|
7483 | };
|
7484 | scale.ticks = function() {
|
7485 | 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;
|
7486 | if (isFinite(j - i)) {
|
7487 | if (positive) {
|
7488 | for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
|
7489 | ticks.push(pow(i));
|
7490 | } else {
|
7491 | ticks.push(pow(i));
|
7492 | for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
|
7493 | }
|
7494 | for (i = 0; ticks[i] < u; i++) {}
|
7495 | for (j = ticks.length; ticks[j - 1] > v; j--) {}
|
7496 | ticks = ticks.slice(i, j);
|
7497 | }
|
7498 | return ticks;
|
7499 | };
|
7500 | scale.tickFormat = function(n, format) {
|
7501 | if (!arguments.length) return d3_scale_logFormat;
|
7502 | if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
|
7503 | var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
|
7504 | Math.floor), e;
|
7505 | return function(d) {
|
7506 | return d / pow(f(log(d) + e)) <= k ? format(d) : "";
|
7507 | };
|
7508 | };
|
7509 | scale.copy = function() {
|
7510 | return d3_scale_log(linear.copy(), base, positive, domain);
|
7511 | };
|
7512 | return d3_scale_linearRebind(scale, linear);
|
7513 | }
|
7514 | var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
|
7515 | floor: function(x) {
|
7516 | return -Math.ceil(-x);
|
7517 | },
|
7518 | ceil: function(x) {
|
7519 | return -Math.floor(-x);
|
7520 | }
|
7521 | };
|
7522 | d3.scale.pow = function() {
|
7523 | return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
|
7524 | };
|
7525 | function d3_scale_pow(linear, exponent, domain) {
|
7526 | var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
|
7527 | function scale(x) {
|
7528 | return linear(powp(x));
|
7529 | }
|
7530 | scale.invert = function(x) {
|
7531 | return powb(linear.invert(x));
|
7532 | };
|
7533 | scale.domain = function(x) {
|
7534 | if (!arguments.length) return domain;
|
7535 | linear.domain((domain = x.map(Number)).map(powp));
|
7536 | return scale;
|
7537 | };
|
7538 | scale.ticks = function(m) {
|
7539 | return d3_scale_linearTicks(domain, m);
|
7540 | };
|
7541 | scale.tickFormat = function(m, format) {
|
7542 | return d3_scale_linearTickFormat(domain, m, format);
|
7543 | };
|
7544 | scale.nice = function(m) {
|
7545 | return scale.domain(d3_scale_linearNice(domain, m));
|
7546 | };
|
7547 | scale.exponent = function(x) {
|
7548 | if (!arguments.length) return exponent;
|
7549 | powp = d3_scale_powPow(exponent = x);
|
7550 | powb = d3_scale_powPow(1 / exponent);
|
7551 | linear.domain(domain.map(powp));
|
7552 | return scale;
|
7553 | };
|
7554 | scale.copy = function() {
|
7555 | return d3_scale_pow(linear.copy(), exponent, domain);
|
7556 | };
|
7557 | return d3_scale_linearRebind(scale, linear);
|
7558 | }
|
7559 | function d3_scale_powPow(e) {
|
7560 | return function(x) {
|
7561 | return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
|
7562 | };
|
7563 | }
|
7564 | d3.scale.sqrt = function() {
|
7565 | return d3.scale.pow().exponent(.5);
|
7566 | };
|
7567 | d3.scale.ordinal = function() {
|
7568 | return d3_scale_ordinal([], {
|
7569 | t: "range",
|
7570 | a: [ [] ]
|
7571 | });
|
7572 | };
|
7573 | function d3_scale_ordinal(domain, ranger) {
|
7574 | var index, range, rangeBand;
|
7575 | function scale(x) {
|
7576 | return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
|
7577 | }
|
7578 | function steps(start, step) {
|
7579 | return d3.range(domain.length).map(function(i) {
|
7580 | return start + step * i;
|
7581 | });
|
7582 | }
|
7583 | scale.domain = function(x) {
|
7584 | if (!arguments.length) return domain;
|
7585 | domain = [];
|
7586 | index = new d3_Map();
|
7587 | var i = -1, n = x.length, xi;
|
7588 | while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
|
7589 | return scale[ranger.t].apply(scale, ranger.a);
|
7590 | };
|
7591 | scale.range = function(x) {
|
7592 | if (!arguments.length) return range;
|
7593 | range = x;
|
7594 | rangeBand = 0;
|
7595 | ranger = {
|
7596 | t: "range",
|
7597 | a: arguments
|
7598 | };
|
7599 | return scale;
|
7600 | };
|
7601 | scale.rangePoints = function(x, padding) {
|
7602 | if (arguments.length < 2) padding = 0;
|
7603 | var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
|
7604 | range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
|
7605 | rangeBand = 0;
|
7606 | ranger = {
|
7607 | t: "rangePoints",
|
7608 | a: arguments
|
7609 | };
|
7610 | return scale;
|
7611 | };
|
7612 | scale.rangeBands = function(x, padding, outerPadding) {
|
7613 | if (arguments.length < 2) padding = 0;
|
7614 | if (arguments.length < 3) outerPadding = padding;
|
7615 | var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
|
7616 | range = steps(start + step * outerPadding, step);
|
7617 | if (reverse) range.reverse();
|
7618 | rangeBand = step * (1 - padding);
|
7619 | ranger = {
|
7620 | t: "rangeBands",
|
7621 | a: arguments
|
7622 | };
|
7623 | return scale;
|
7624 | };
|
7625 | scale.rangeRoundBands = function(x, padding, outerPadding) {
|
7626 | if (arguments.length < 2) padding = 0;
|
7627 | if (arguments.length < 3) outerPadding = padding;
|
7628 | var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), error = stop - start - (domain.length - padding) * step;
|
7629 | range = steps(start + Math.round(error / 2), step);
|
7630 | if (reverse) range.reverse();
|
7631 | rangeBand = Math.round(step * (1 - padding));
|
7632 | ranger = {
|
7633 | t: "rangeRoundBands",
|
7634 | a: arguments
|
7635 | };
|
7636 | return scale;
|
7637 | };
|
7638 | scale.rangeBand = function() {
|
7639 | return rangeBand;
|
7640 | };
|
7641 | scale.rangeExtent = function() {
|
7642 | return d3_scaleExtent(ranger.a[0]);
|
7643 | };
|
7644 | scale.copy = function() {
|
7645 | return d3_scale_ordinal(domain, ranger);
|
7646 | };
|
7647 | return scale.domain(domain);
|
7648 | }
|
7649 | d3.scale.category10 = function() {
|
7650 | return d3.scale.ordinal().range(d3_category10);
|
7651 | };
|
7652 | d3.scale.category20 = function() {
|
7653 | return d3.scale.ordinal().range(d3_category20);
|
7654 | };
|
7655 | d3.scale.category20b = function() {
|
7656 | return d3.scale.ordinal().range(d3_category20b);
|
7657 | };
|
7658 | d3.scale.category20c = function() {
|
7659 | return d3.scale.ordinal().range(d3_category20c);
|
7660 | };
|
7661 | var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
|
7662 | 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);
|
7663 | 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);
|
7664 | 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);
|
7665 | d3.scale.quantile = function() {
|
7666 | return d3_scale_quantile([], []);
|
7667 | };
|
7668 | function d3_scale_quantile(domain, range) {
|
7669 | var thresholds;
|
7670 | function rescale() {
|
7671 | var k = 0, q = range.length;
|
7672 | thresholds = [];
|
7673 | while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
|
7674 | return scale;
|
7675 | }
|
7676 | function scale(x) {
|
7677 | if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
|
7678 | }
|
7679 | scale.domain = function(x) {
|
7680 | if (!arguments.length) return domain;
|
7681 | domain = x.filter(d3_number).sort(d3_ascending);
|
7682 | return rescale();
|
7683 | };
|
7684 | scale.range = function(x) {
|
7685 | if (!arguments.length) return range;
|
7686 | range = x;
|
7687 | return rescale();
|
7688 | };
|
7689 | scale.quantiles = function() {
|
7690 | return thresholds;
|
7691 | };
|
7692 | scale.invertExtent = function(y) {
|
7693 | y = range.indexOf(y);
|
7694 | return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
|
7695 | };
|
7696 | scale.copy = function() {
|
7697 | return d3_scale_quantile(domain, range);
|
7698 | };
|
7699 | return rescale();
|
7700 | }
|
7701 | d3.scale.quantize = function() {
|
7702 | return d3_scale_quantize(0, 1, [ 0, 1 ]);
|
7703 | };
|
7704 | function d3_scale_quantize(x0, x1, range) {
|
7705 | var kx, i;
|
7706 | function scale(x) {
|
7707 | return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
|
7708 | }
|
7709 | function rescale() {
|
7710 | kx = range.length / (x1 - x0);
|
7711 | i = range.length - 1;
|
7712 | return scale;
|
7713 | }
|
7714 | scale.domain = function(x) {
|
7715 | if (!arguments.length) return [ x0, x1 ];
|
7716 | x0 = +x[0];
|
7717 | x1 = +x[x.length - 1];
|
7718 | return rescale();
|
7719 | };
|
7720 | scale.range = function(x) {
|
7721 | if (!arguments.length) return range;
|
7722 | range = x;
|
7723 | return rescale();
|
7724 | };
|
7725 | scale.invertExtent = function(y) {
|
7726 | y = range.indexOf(y);
|
7727 | y = y < 0 ? NaN : y / kx + x0;
|
7728 | return [ y, y + 1 / kx ];
|
7729 | };
|
7730 | scale.copy = function() {
|
7731 | return d3_scale_quantize(x0, x1, range);
|
7732 | };
|
7733 | return rescale();
|
7734 | }
|
7735 | d3.scale.threshold = function() {
|
7736 | return d3_scale_threshold([ .5 ], [ 0, 1 ]);
|
7737 | };
|
7738 | function d3_scale_threshold(domain, range) {
|
7739 | function scale(x) {
|
7740 | if (x <= x) return range[d3.bisect(domain, x)];
|
7741 | }
|
7742 | scale.domain = function(_) {
|
7743 | if (!arguments.length) return domain;
|
7744 | domain = _;
|
7745 | return scale;
|
7746 | };
|
7747 | scale.range = function(_) {
|
7748 | if (!arguments.length) return range;
|
7749 | range = _;
|
7750 | return scale;
|
7751 | };
|
7752 | scale.invertExtent = function(y) {
|
7753 | y = range.indexOf(y);
|
7754 | return [ domain[y - 1], domain[y] ];
|
7755 | };
|
7756 | scale.copy = function() {
|
7757 | return d3_scale_threshold(domain, range);
|
7758 | };
|
7759 | return scale;
|
7760 | }
|
7761 | d3.scale.identity = function() {
|
7762 | return d3_scale_identity([ 0, 1 ]);
|
7763 | };
|
7764 | function d3_scale_identity(domain) {
|
7765 | function identity(x) {
|
7766 | return +x;
|
7767 | }
|
7768 | identity.invert = identity;
|
7769 | identity.domain = identity.range = function(x) {
|
7770 | if (!arguments.length) return domain;
|
7771 | domain = x.map(identity);
|
7772 | return identity;
|
7773 | };
|
7774 | identity.ticks = function(m) {
|
7775 | return d3_scale_linearTicks(domain, m);
|
7776 | };
|
7777 | identity.tickFormat = function(m, format) {
|
7778 | return d3_scale_linearTickFormat(domain, m, format);
|
7779 | };
|
7780 | identity.copy = function() {
|
7781 | return d3_scale_identity(domain);
|
7782 | };
|
7783 | return identity;
|
7784 | }
|
7785 | d3.svg = {};
|
7786 | d3.svg.arc = function() {
|
7787 | var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
|
7788 | function arc() {
|
7789 | var r0 = innerRadius.apply(this, arguments), r1 = outerRadius.apply(this, arguments), a0 = startAngle.apply(this, arguments) + d3_svg_arcOffset, a1 = endAngle.apply(this, arguments) + d3_svg_arcOffset, da = (a1 < a0 && (da = a0,
|
7790 | a0 = a1, a1 = da), a1 - a0), df = da < π ? "0" : "1", c0 = Math.cos(a0), s0 = Math.sin(a0), c1 = Math.cos(a1), s1 = Math.sin(a1);
|
7791 | return da >= d3_svg_arcMax ? r0 ? "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "M0," + r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + -r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + r0 + "Z" : "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "Z" : r0 ? "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L" + r0 * c1 + "," + r0 * s1 + "A" + r0 + "," + r0 + " 0 " + df + ",0 " + r0 * c0 + "," + r0 * s0 + "Z" : "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L0,0" + "Z";
|
7792 | }
|
7793 | arc.innerRadius = function(v) {
|
7794 | if (!arguments.length) return innerRadius;
|
7795 | innerRadius = d3_functor(v);
|
7796 | return arc;
|
7797 | };
|
7798 | arc.outerRadius = function(v) {
|
7799 | if (!arguments.length) return outerRadius;
|
7800 | outerRadius = d3_functor(v);
|
7801 | return arc;
|
7802 | };
|
7803 | arc.startAngle = function(v) {
|
7804 | if (!arguments.length) return startAngle;
|
7805 | startAngle = d3_functor(v);
|
7806 | return arc;
|
7807 | };
|
7808 | arc.endAngle = function(v) {
|
7809 | if (!arguments.length) return endAngle;
|
7810 | endAngle = d3_functor(v);
|
7811 | return arc;
|
7812 | };
|
7813 | arc.centroid = function() {
|
7814 | var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
|
7815 | return [ Math.cos(a) * r, Math.sin(a) * r ];
|
7816 | };
|
7817 | return arc;
|
7818 | };
|
7819 | var d3_svg_arcOffset = -halfπ, d3_svg_arcMax = τ - ε;
|
7820 | function d3_svg_arcInnerRadius(d) {
|
7821 | return d.innerRadius;
|
7822 | }
|
7823 | function d3_svg_arcOuterRadius(d) {
|
7824 | return d.outerRadius;
|
7825 | }
|
7826 | function d3_svg_arcStartAngle(d) {
|
7827 | return d.startAngle;
|
7828 | }
|
7829 | function d3_svg_arcEndAngle(d) {
|
7830 | return d.endAngle;
|
7831 | }
|
7832 | function d3_svg_line(projection) {
|
7833 | var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
|
7834 | function line(data) {
|
7835 | var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
|
7836 | function segment() {
|
7837 | segments.push("M", interpolate(projection(points), tension));
|
7838 | }
|
7839 | while (++i < n) {
|
7840 | if (defined.call(this, d = data[i], i)) {
|
7841 | points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
|
7842 | } else if (points.length) {
|
7843 | segment();
|
7844 | points = [];
|
7845 | }
|
7846 | }
|
7847 | if (points.length) segment();
|
7848 | return segments.length ? segments.join("") : null;
|
7849 | }
|
7850 | line.x = function(_) {
|
7851 | if (!arguments.length) return x;
|
7852 | x = _;
|
7853 | return line;
|
7854 | };
|
7855 | line.y = function(_) {
|
7856 | if (!arguments.length) return y;
|
7857 | y = _;
|
7858 | return line;
|
7859 | };
|
7860 | line.defined = function(_) {
|
7861 | if (!arguments.length) return defined;
|
7862 | defined = _;
|
7863 | return line;
|
7864 | };
|
7865 | line.interpolate = function(_) {
|
7866 | if (!arguments.length) return interpolateKey;
|
7867 | if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
|
7868 | return line;
|
7869 | };
|
7870 | line.tension = function(_) {
|
7871 | if (!arguments.length) return tension;
|
7872 | tension = _;
|
7873 | return line;
|
7874 | };
|
7875 | return line;
|
7876 | }
|
7877 | d3.svg.line = function() {
|
7878 | return d3_svg_line(d3_identity);
|
7879 | };
|
7880 | var d3_svg_lineInterpolators = d3.map({
|
7881 | linear: d3_svg_lineLinear,
|
7882 | "linear-closed": d3_svg_lineLinearClosed,
|
7883 | step: d3_svg_lineStep,
|
7884 | "step-before": d3_svg_lineStepBefore,
|
7885 | "step-after": d3_svg_lineStepAfter,
|
7886 | basis: d3_svg_lineBasis,
|
7887 | "basis-open": d3_svg_lineBasisOpen,
|
7888 | "basis-closed": d3_svg_lineBasisClosed,
|
7889 | bundle: d3_svg_lineBundle,
|
7890 | cardinal: d3_svg_lineCardinal,
|
7891 | "cardinal-open": d3_svg_lineCardinalOpen,
|
7892 | "cardinal-closed": d3_svg_lineCardinalClosed,
|
7893 | monotone: d3_svg_lineMonotone
|
7894 | });
|
7895 | d3_svg_lineInterpolators.forEach(function(key, value) {
|
7896 | value.key = key;
|
7897 | value.closed = /-closed$/.test(key);
|
7898 | });
|
7899 | function d3_svg_lineLinear(points) {
|
7900 | return points.join("L");
|
7901 | }
|
7902 | function d3_svg_lineLinearClosed(points) {
|
7903 | return d3_svg_lineLinear(points) + "Z";
|
7904 | }
|
7905 | function d3_svg_lineStep(points) {
|
7906 | var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
|
7907 | while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
|
7908 | if (n > 1) path.push("H", p[0]);
|
7909 | return path.join("");
|
7910 | }
|
7911 | function d3_svg_lineStepBefore(points) {
|
7912 | var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
|
7913 | while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
|
7914 | return path.join("");
|
7915 | }
|
7916 | function d3_svg_lineStepAfter(points) {
|
7917 | var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
|
7918 | while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
|
7919 | return path.join("");
|
7920 | }
|
7921 | function d3_svg_lineCardinalOpen(points, tension) {
|
7922 | return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
|
7923 | }
|
7924 | function d3_svg_lineCardinalClosed(points, tension) {
|
7925 | return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
|
7926 | points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
|
7927 | }
|
7928 | function d3_svg_lineCardinal(points, tension) {
|
7929 | return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
|
7930 | }
|
7931 | function d3_svg_lineHermite(points, tangents) {
|
7932 | if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
|
7933 | return d3_svg_lineLinear(points);
|
7934 | }
|
7935 | var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
|
7936 | if (quad) {
|
7937 | path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
|
7938 | p0 = points[1];
|
7939 | pi = 2;
|
7940 | }
|
7941 | if (tangents.length > 1) {
|
7942 | t = tangents[1];
|
7943 | p = points[pi];
|
7944 | pi++;
|
7945 | path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
|
7946 | for (var i = 2; i < tangents.length; i++, pi++) {
|
7947 | p = points[pi];
|
7948 | t = tangents[i];
|
7949 | path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
|
7950 | }
|
7951 | }
|
7952 | if (quad) {
|
7953 | var lp = points[pi];
|
7954 | path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
|
7955 | }
|
7956 | return path;
|
7957 | }
|
7958 | function d3_svg_lineCardinalTangents(points, tension) {
|
7959 | var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
|
7960 | while (++i < n) {
|
7961 | p0 = p1;
|
7962 | p1 = p2;
|
7963 | p2 = points[i];
|
7964 | tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
|
7965 | }
|
7966 | return tangents;
|
7967 | }
|
7968 | function d3_svg_lineBasis(points) {
|
7969 | if (points.length < 3) return d3_svg_lineLinear(points);
|
7970 | 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) ];
|
7971 | points.push(points[n - 1]);
|
7972 | while (++i <= n) {
|
7973 | pi = points[i];
|
7974 | px.shift();
|
7975 | px.push(pi[0]);
|
7976 | py.shift();
|
7977 | py.push(pi[1]);
|
7978 | d3_svg_lineBasisBezier(path, px, py);
|
7979 | }
|
7980 | points.pop();
|
7981 | path.push("L", pi);
|
7982 | return path.join("");
|
7983 | }
|
7984 | function d3_svg_lineBasisOpen(points) {
|
7985 | if (points.length < 4) return d3_svg_lineLinear(points);
|
7986 | var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
|
7987 | while (++i < 3) {
|
7988 | pi = points[i];
|
7989 | px.push(pi[0]);
|
7990 | py.push(pi[1]);
|
7991 | }
|
7992 | path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
|
7993 | --i;
|
7994 | while (++i < n) {
|
7995 | pi = points[i];
|
7996 | px.shift();
|
7997 | px.push(pi[0]);
|
7998 | py.shift();
|
7999 | py.push(pi[1]);
|
8000 | d3_svg_lineBasisBezier(path, px, py);
|
8001 | }
|
8002 | return path.join("");
|
8003 | }
|
8004 | function d3_svg_lineBasisClosed(points) {
|
8005 | var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
|
8006 | while (++i < 4) {
|
8007 | pi = points[i % n];
|
8008 | px.push(pi[0]);
|
8009 | py.push(pi[1]);
|
8010 | }
|
8011 | path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
|
8012 | --i;
|
8013 | while (++i < m) {
|
8014 | pi = points[i % n];
|
8015 | px.shift();
|
8016 | px.push(pi[0]);
|
8017 | py.shift();
|
8018 | py.push(pi[1]);
|
8019 | d3_svg_lineBasisBezier(path, px, py);
|
8020 | }
|
8021 | return path.join("");
|
8022 | }
|
8023 | function d3_svg_lineBundle(points, tension) {
|
8024 | var n = points.length - 1;
|
8025 | if (n) {
|
8026 | var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
|
8027 | while (++i <= n) {
|
8028 | p = points[i];
|
8029 | t = i / n;
|
8030 | p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
|
8031 | p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
|
8032 | }
|
8033 | }
|
8034 | return d3_svg_lineBasis(points);
|
8035 | }
|
8036 | function d3_svg_lineDot4(a, b) {
|
8037 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
8038 | }
|
8039 | 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 ];
|
8040 | function d3_svg_lineBasisBezier(path, x, y) {
|
8041 | 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));
|
8042 | }
|
8043 | function d3_svg_lineSlope(p0, p1) {
|
8044 | return (p1[1] - p0[1]) / (p1[0] - p0[0]);
|
8045 | }
|
8046 | function d3_svg_lineFiniteDifferences(points) {
|
8047 | var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
|
8048 | while (++i < j) {
|
8049 | m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
|
8050 | }
|
8051 | m[i] = d;
|
8052 | return m;
|
8053 | }
|
8054 | function d3_svg_lineMonotoneTangents(points) {
|
8055 | var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
|
8056 | while (++i < j) {
|
8057 | d = d3_svg_lineSlope(points[i], points[i + 1]);
|
8058 | if (abs(d) < ε) {
|
8059 | m[i] = m[i + 1] = 0;
|
8060 | } else {
|
8061 | a = m[i] / d;
|
8062 | b = m[i + 1] / d;
|
8063 | s = a * a + b * b;
|
8064 | if (s > 9) {
|
8065 | s = d * 3 / Math.sqrt(s);
|
8066 | m[i] = s * a;
|
8067 | m[i + 1] = s * b;
|
8068 | }
|
8069 | }
|
8070 | }
|
8071 | i = -1;
|
8072 | while (++i <= j) {
|
8073 | s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
|
8074 | tangents.push([ s || 0, m[i] * s || 0 ]);
|
8075 | }
|
8076 | return tangents;
|
8077 | }
|
8078 | function d3_svg_lineMonotone(points) {
|
8079 | return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
|
8080 | }
|
8081 | d3.svg.line.radial = function() {
|
8082 | var line = d3_svg_line(d3_svg_lineRadial);
|
8083 | line.radius = line.x, delete line.x;
|
8084 | line.angle = line.y, delete line.y;
|
8085 | return line;
|
8086 | };
|
8087 | function d3_svg_lineRadial(points) {
|
8088 | var point, i = -1, n = points.length, r, a;
|
8089 | while (++i < n) {
|
8090 | point = points[i];
|
8091 | r = point[0];
|
8092 | a = point[1] + d3_svg_arcOffset;
|
8093 | point[0] = r * Math.cos(a);
|
8094 | point[1] = r * Math.sin(a);
|
8095 | }
|
8096 | return points;
|
8097 | }
|
8098 | function d3_svg_area(projection) {
|
8099 | 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;
|
8100 | function area(data) {
|
8101 | var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
|
8102 | return x;
|
8103 | } : d3_functor(x1), fy1 = y0 === y1 ? function() {
|
8104 | return y;
|
8105 | } : d3_functor(y1), x, y;
|
8106 | function segment() {
|
8107 | segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
|
8108 | }
|
8109 | while (++i < n) {
|
8110 | if (defined.call(this, d = data[i], i)) {
|
8111 | points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
|
8112 | points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
|
8113 | } else if (points0.length) {
|
8114 | segment();
|
8115 | points0 = [];
|
8116 | points1 = [];
|
8117 | }
|
8118 | }
|
8119 | if (points0.length) segment();
|
8120 | return segments.length ? segments.join("") : null;
|
8121 | }
|
8122 | area.x = function(_) {
|
8123 | if (!arguments.length) return x1;
|
8124 | x0 = x1 = _;
|
8125 | return area;
|
8126 | };
|
8127 | area.x0 = function(_) {
|
8128 | if (!arguments.length) return x0;
|
8129 | x0 = _;
|
8130 | return area;
|
8131 | };
|
8132 | area.x1 = function(_) {
|
8133 | if (!arguments.length) return x1;
|
8134 | x1 = _;
|
8135 | return area;
|
8136 | };
|
8137 | area.y = function(_) {
|
8138 | if (!arguments.length) return y1;
|
8139 | y0 = y1 = _;
|
8140 | return area;
|
8141 | };
|
8142 | area.y0 = function(_) {
|
8143 | if (!arguments.length) return y0;
|
8144 | y0 = _;
|
8145 | return area;
|
8146 | };
|
8147 | area.y1 = function(_) {
|
8148 | if (!arguments.length) return y1;
|
8149 | y1 = _;
|
8150 | return area;
|
8151 | };
|
8152 | area.defined = function(_) {
|
8153 | if (!arguments.length) return defined;
|
8154 | defined = _;
|
8155 | return area;
|
8156 | };
|
8157 | area.interpolate = function(_) {
|
8158 | if (!arguments.length) return interpolateKey;
|
8159 | if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
|
8160 | interpolateReverse = interpolate.reverse || interpolate;
|
8161 | L = interpolate.closed ? "M" : "L";
|
8162 | return area;
|
8163 | };
|
8164 | area.tension = function(_) {
|
8165 | if (!arguments.length) return tension;
|
8166 | tension = _;
|
8167 | return area;
|
8168 | };
|
8169 | return area;
|
8170 | }
|
8171 | d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
|
8172 | d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
|
8173 | d3.svg.area = function() {
|
8174 | return d3_svg_area(d3_identity);
|
8175 | };
|
8176 | d3.svg.area.radial = function() {
|
8177 | var area = d3_svg_area(d3_svg_lineRadial);
|
8178 | area.radius = area.x, delete area.x;
|
8179 | area.innerRadius = area.x0, delete area.x0;
|
8180 | area.outerRadius = area.x1, delete area.x1;
|
8181 | area.angle = area.y, delete area.y;
|
8182 | area.startAngle = area.y0, delete area.y0;
|
8183 | area.endAngle = area.y1, delete area.y1;
|
8184 | return area;
|
8185 | };
|
8186 | d3.svg.chord = function() {
|
8187 | var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
|
8188 | function chord(d, i) {
|
8189 | var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
|
8190 | 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";
|
8191 | }
|
8192 | function subgroup(self, f, d, i) {
|
8193 | var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) + d3_svg_arcOffset, a1 = endAngle.call(self, subgroup, i) + d3_svg_arcOffset;
|
8194 | return {
|
8195 | r: r,
|
8196 | a0: a0,
|
8197 | a1: a1,
|
8198 | p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
|
8199 | p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
|
8200 | };
|
8201 | }
|
8202 | function equals(a, b) {
|
8203 | return a.a0 == b.a0 && a.a1 == b.a1;
|
8204 | }
|
8205 | function arc(r, p, a) {
|
8206 | return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
|
8207 | }
|
8208 | function curve(r0, p0, r1, p1) {
|
8209 | return "Q 0,0 " + p1;
|
8210 | }
|
8211 | chord.radius = function(v) {
|
8212 | if (!arguments.length) return radius;
|
8213 | radius = d3_functor(v);
|
8214 | return chord;
|
8215 | };
|
8216 | chord.source = function(v) {
|
8217 | if (!arguments.length) return source;
|
8218 | source = d3_functor(v);
|
8219 | return chord;
|
8220 | };
|
8221 | chord.target = function(v) {
|
8222 | if (!arguments.length) return target;
|
8223 | target = d3_functor(v);
|
8224 | return chord;
|
8225 | };
|
8226 | chord.startAngle = function(v) {
|
8227 | if (!arguments.length) return startAngle;
|
8228 | startAngle = d3_functor(v);
|
8229 | return chord;
|
8230 | };
|
8231 | chord.endAngle = function(v) {
|
8232 | if (!arguments.length) return endAngle;
|
8233 | endAngle = d3_functor(v);
|
8234 | return chord;
|
8235 | };
|
8236 | return chord;
|
8237 | };
|
8238 | function d3_svg_chordRadius(d) {
|
8239 | return d.radius;
|
8240 | }
|
8241 | d3.svg.diagonal = function() {
|
8242 | var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
|
8243 | function diagonal(d, i) {
|
8244 | var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
|
8245 | x: p0.x,
|
8246 | y: m
|
8247 | }, {
|
8248 | x: p3.x,
|
8249 | y: m
|
8250 | }, p3 ];
|
8251 | p = p.map(projection);
|
8252 | return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
|
8253 | }
|
8254 | diagonal.source = function(x) {
|
8255 | if (!arguments.length) return source;
|
8256 | source = d3_functor(x);
|
8257 | return diagonal;
|
8258 | };
|
8259 | diagonal.target = function(x) {
|
8260 | if (!arguments.length) return target;
|
8261 | target = d3_functor(x);
|
8262 | return diagonal;
|
8263 | };
|
8264 | diagonal.projection = function(x) {
|
8265 | if (!arguments.length) return projection;
|
8266 | projection = x;
|
8267 | return diagonal;
|
8268 | };
|
8269 | return diagonal;
|
8270 | };
|
8271 | function d3_svg_diagonalProjection(d) {
|
8272 | return [ d.x, d.y ];
|
8273 | }
|
8274 | d3.svg.diagonal.radial = function() {
|
8275 | var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
|
8276 | diagonal.projection = function(x) {
|
8277 | return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
|
8278 | };
|
8279 | return diagonal;
|
8280 | };
|
8281 | function d3_svg_diagonalRadialProjection(projection) {
|
8282 | return function() {
|
8283 | var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
|
8284 | return [ r * Math.cos(a), r * Math.sin(a) ];
|
8285 | };
|
8286 | }
|
8287 | d3.svg.symbol = function() {
|
8288 | var type = d3_svg_symbolType, size = d3_svg_symbolSize;
|
8289 | function symbol(d, i) {
|
8290 | return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
|
8291 | }
|
8292 | symbol.type = function(x) {
|
8293 | if (!arguments.length) return type;
|
8294 | type = d3_functor(x);
|
8295 | return symbol;
|
8296 | };
|
8297 | symbol.size = function(x) {
|
8298 | if (!arguments.length) return size;
|
8299 | size = d3_functor(x);
|
8300 | return symbol;
|
8301 | };
|
8302 | return symbol;
|
8303 | };
|
8304 | function d3_svg_symbolSize() {
|
8305 | return 64;
|
8306 | }
|
8307 | function d3_svg_symbolType() {
|
8308 | return "circle";
|
8309 | }
|
8310 | function d3_svg_symbolCircle(size) {
|
8311 | var r = Math.sqrt(size / π);
|
8312 | return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
|
8313 | }
|
8314 | var d3_svg_symbols = d3.map({
|
8315 | circle: d3_svg_symbolCircle,
|
8316 | cross: function(size) {
|
8317 | var r = Math.sqrt(size / 5) / 2;
|
8318 | 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";
|
8319 | },
|
8320 | diamond: function(size) {
|
8321 | var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
|
8322 | return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
|
8323 | },
|
8324 | square: function(size) {
|
8325 | var r = Math.sqrt(size) / 2;
|
8326 | return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
|
8327 | },
|
8328 | "triangle-down": function(size) {
|
8329 | var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
|
8330 | return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
|
8331 | },
|
8332 | "triangle-up": function(size) {
|
8333 | var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
|
8334 | return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
|
8335 | }
|
8336 | });
|
8337 | d3.svg.symbolTypes = d3_svg_symbols.keys();
|
8338 | var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
|
8339 | function d3_transition(groups, id) {
|
8340 | d3_subclass(groups, d3_transitionPrototype);
|
8341 | groups.id = id;
|
8342 | return groups;
|
8343 | }
|
8344 | var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
|
8345 | d3_transitionPrototype.call = d3_selectionPrototype.call;
|
8346 | d3_transitionPrototype.empty = d3_selectionPrototype.empty;
|
8347 | d3_transitionPrototype.node = d3_selectionPrototype.node;
|
8348 | d3_transitionPrototype.size = d3_selectionPrototype.size;
|
8349 | d3.transition = function(selection) {
|
8350 | return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
|
8351 | };
|
8352 | d3.transition.prototype = d3_transitionPrototype;
|
8353 | d3_transitionPrototype.select = function(selector) {
|
8354 | var id = this.id, subgroups = [], subgroup, subnode, node;
|
8355 | selector = d3_selection_selector(selector);
|
8356 | for (var j = -1, m = this.length; ++j < m; ) {
|
8357 | subgroups.push(subgroup = []);
|
8358 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
|
8359 | if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
|
8360 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
8361 | d3_transitionNode(subnode, i, id, node.__transition__[id]);
|
8362 | subgroup.push(subnode);
|
8363 | } else {
|
8364 | subgroup.push(null);
|
8365 | }
|
8366 | }
|
8367 | }
|
8368 | return d3_transition(subgroups, id);
|
8369 | };
|
8370 | d3_transitionPrototype.selectAll = function(selector) {
|
8371 | var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
|
8372 | selector = d3_selection_selectorAll(selector);
|
8373 | for (var j = -1, m = this.length; ++j < m; ) {
|
8374 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
|
8375 | if (node = group[i]) {
|
8376 | transition = node.__transition__[id];
|
8377 | subnodes = selector.call(node, node.__data__, i, j);
|
8378 | subgroups.push(subgroup = []);
|
8379 | for (var k = -1, o = subnodes.length; ++k < o; ) {
|
8380 | if (subnode = subnodes[k]) d3_transitionNode(subnode, k, id, transition);
|
8381 | subgroup.push(subnode);
|
8382 | }
|
8383 | }
|
8384 | }
|
8385 | }
|
8386 | return d3_transition(subgroups, id);
|
8387 | };
|
8388 | d3_transitionPrototype.filter = function(filter) {
|
8389 | var subgroups = [], subgroup, group, node;
|
8390 | if (typeof filter !== "function") filter = d3_selection_filter(filter);
|
8391 | for (var j = 0, m = this.length; j < m; j++) {
|
8392 | subgroups.push(subgroup = []);
|
8393 | for (var group = this[j], i = 0, n = group.length; i < n; i++) {
|
8394 | if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
|
8395 | subgroup.push(node);
|
8396 | }
|
8397 | }
|
8398 | }
|
8399 | return d3_transition(subgroups, this.id);
|
8400 | };
|
8401 | d3_transitionPrototype.tween = function(name, tween) {
|
8402 | var id = this.id;
|
8403 | if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
|
8404 | return d3_selection_each(this, tween == null ? function(node) {
|
8405 | node.__transition__[id].tween.remove(name);
|
8406 | } : function(node) {
|
8407 | node.__transition__[id].tween.set(name, tween);
|
8408 | });
|
8409 | };
|
8410 | function d3_transition_tween(groups, name, value, tween) {
|
8411 | var id = groups.id;
|
8412 | return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
|
8413 | node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
|
8414 | } : (value = tween(value), function(node) {
|
8415 | node.__transition__[id].tween.set(name, value);
|
8416 | }));
|
8417 | }
|
8418 | d3_transitionPrototype.attr = function(nameNS, value) {
|
8419 | if (arguments.length < 2) {
|
8420 | for (value in nameNS) this.attr(value, nameNS[value]);
|
8421 | return this;
|
8422 | }
|
8423 | var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
|
8424 | function attrNull() {
|
8425 | this.removeAttribute(name);
|
8426 | }
|
8427 | function attrNullNS() {
|
8428 | this.removeAttributeNS(name.space, name.local);
|
8429 | }
|
8430 | function attrTween(b) {
|
8431 | return b == null ? attrNull : (b += "", function() {
|
8432 | var a = this.getAttribute(name), i;
|
8433 | return a !== b && (i = interpolate(a, b), function(t) {
|
8434 | this.setAttribute(name, i(t));
|
8435 | });
|
8436 | });
|
8437 | }
|
8438 | function attrTweenNS(b) {
|
8439 | return b == null ? attrNullNS : (b += "", function() {
|
8440 | var a = this.getAttributeNS(name.space, name.local), i;
|
8441 | return a !== b && (i = interpolate(a, b), function(t) {
|
8442 | this.setAttributeNS(name.space, name.local, i(t));
|
8443 | });
|
8444 | });
|
8445 | }
|
8446 | return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
|
8447 | };
|
8448 | d3_transitionPrototype.attrTween = function(nameNS, tween) {
|
8449 | var name = d3.ns.qualify(nameNS);
|
8450 | function attrTween(d, i) {
|
8451 | var f = tween.call(this, d, i, this.getAttribute(name));
|
8452 | return f && function(t) {
|
8453 | this.setAttribute(name, f(t));
|
8454 | };
|
8455 | }
|
8456 | function attrTweenNS(d, i) {
|
8457 | var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
|
8458 | return f && function(t) {
|
8459 | this.setAttributeNS(name.space, name.local, f(t));
|
8460 | };
|
8461 | }
|
8462 | return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
|
8463 | };
|
8464 | d3_transitionPrototype.style = function(name, value, priority) {
|
8465 | var n = arguments.length;
|
8466 | if (n < 3) {
|
8467 | if (typeof name !== "string") {
|
8468 | if (n < 2) value = "";
|
8469 | for (priority in name) this.style(priority, name[priority], value);
|
8470 | return this;
|
8471 | }
|
8472 | priority = "";
|
8473 | }
|
8474 | function styleNull() {
|
8475 | this.style.removeProperty(name);
|
8476 | }
|
8477 | function styleString(b) {
|
8478 | return b == null ? styleNull : (b += "", function() {
|
8479 | var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
|
8480 | return a !== b && (i = d3_interpolate(a, b), function(t) {
|
8481 | this.style.setProperty(name, i(t), priority);
|
8482 | });
|
8483 | });
|
8484 | }
|
8485 | return d3_transition_tween(this, "style." + name, value, styleString);
|
8486 | };
|
8487 | d3_transitionPrototype.styleTween = function(name, tween, priority) {
|
8488 | if (arguments.length < 3) priority = "";
|
8489 | function styleTween(d, i) {
|
8490 | var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
|
8491 | return f && function(t) {
|
8492 | this.style.setProperty(name, f(t), priority);
|
8493 | };
|
8494 | }
|
8495 | return this.tween("style." + name, styleTween);
|
8496 | };
|
8497 | d3_transitionPrototype.text = function(value) {
|
8498 | return d3_transition_tween(this, "text", value, d3_transition_text);
|
8499 | };
|
8500 | function d3_transition_text(b) {
|
8501 | if (b == null) b = "";
|
8502 | return function() {
|
8503 | this.textContent = b;
|
8504 | };
|
8505 | }
|
8506 | d3_transitionPrototype.remove = function() {
|
8507 | return this.each("end.transition", function() {
|
8508 | var p;
|
8509 | if (this.__transition__.count < 2 && (p = this.parentNode)) p.removeChild(this);
|
8510 | });
|
8511 | };
|
8512 | d3_transitionPrototype.ease = function(value) {
|
8513 | var id = this.id;
|
8514 | if (arguments.length < 1) return this.node().__transition__[id].ease;
|
8515 | if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
|
8516 | return d3_selection_each(this, function(node) {
|
8517 | node.__transition__[id].ease = value;
|
8518 | });
|
8519 | };
|
8520 | d3_transitionPrototype.delay = function(value) {
|
8521 | var id = this.id;
|
8522 | if (arguments.length < 1) return this.node().__transition__[id].delay;
|
8523 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
|
8524 | node.__transition__[id].delay = +value.call(node, node.__data__, i, j);
|
8525 | } : (value = +value, function(node) {
|
8526 | node.__transition__[id].delay = value;
|
8527 | }));
|
8528 | };
|
8529 | d3_transitionPrototype.duration = function(value) {
|
8530 | var id = this.id;
|
8531 | if (arguments.length < 1) return this.node().__transition__[id].duration;
|
8532 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
|
8533 | node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j));
|
8534 | } : (value = Math.max(1, value), function(node) {
|
8535 | node.__transition__[id].duration = value;
|
8536 | }));
|
8537 | };
|
8538 | d3_transitionPrototype.each = function(type, listener) {
|
8539 | var id = this.id;
|
8540 | if (arguments.length < 2) {
|
8541 | var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
|
8542 | d3_transitionInheritId = id;
|
8543 | d3_selection_each(this, function(node, i, j) {
|
8544 | d3_transitionInherit = node.__transition__[id];
|
8545 | type.call(node, node.__data__, i, j);
|
8546 | });
|
8547 | d3_transitionInherit = inherit;
|
8548 | d3_transitionInheritId = inheritId;
|
8549 | } else {
|
8550 | d3_selection_each(this, function(node) {
|
8551 | var transition = node.__transition__[id];
|
8552 | (transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
|
8553 | });
|
8554 | }
|
8555 | return this;
|
8556 | };
|
8557 | d3_transitionPrototype.transition = function() {
|
8558 | var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
|
8559 | for (var j = 0, m = this.length; j < m; j++) {
|
8560 | subgroups.push(subgroup = []);
|
8561 | for (var group = this[j], i = 0, n = group.length; i < n; i++) {
|
8562 | if (node = group[i]) {
|
8563 | transition = Object.create(node.__transition__[id0]);
|
8564 | transition.delay += transition.duration;
|
8565 | d3_transitionNode(node, i, id1, transition);
|
8566 | }
|
8567 | subgroup.push(node);
|
8568 | }
|
8569 | }
|
8570 | return d3_transition(subgroups, id1);
|
8571 | };
|
8572 | function d3_transitionNode(node, i, id, inherit) {
|
8573 | var lock = node.__transition__ || (node.__transition__ = {
|
8574 | active: 0,
|
8575 | count: 0
|
8576 | }), transition = lock[id];
|
8577 | if (!transition) {
|
8578 | var time = inherit.time;
|
8579 | transition = lock[id] = {
|
8580 | tween: new d3_Map(),
|
8581 | time: time,
|
8582 | ease: inherit.ease,
|
8583 | delay: inherit.delay,
|
8584 | duration: inherit.duration
|
8585 | };
|
8586 | ++lock.count;
|
8587 | d3.timer(function(elapsed) {
|
8588 | var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = [];
|
8589 | timer.t = delay + time;
|
8590 | if (delay <= elapsed) return start(elapsed - delay);
|
8591 | timer.c = start;
|
8592 | function start(elapsed) {
|
8593 | if (lock.active > id) return stop();
|
8594 | lock.active = id;
|
8595 | transition.event && transition.event.start.call(node, d, i);
|
8596 | transition.tween.forEach(function(key, value) {
|
8597 | if (value = value.call(node, d, i)) {
|
8598 | tweened.push(value);
|
8599 | }
|
8600 | });
|
8601 | d3.timer(function() {
|
8602 | timer.c = tick(elapsed || 1) ? d3_true : tick;
|
8603 | return 1;
|
8604 | }, 0, time);
|
8605 | }
|
8606 | function tick(elapsed) {
|
8607 | if (lock.active !== id) return stop();
|
8608 | var t = elapsed / duration, e = ease(t), n = tweened.length;
|
8609 | while (n > 0) {
|
8610 | tweened[--n].call(node, e);
|
8611 | }
|
8612 | if (t >= 1) {
|
8613 | transition.event && transition.event.end.call(node, d, i);
|
8614 | return stop();
|
8615 | }
|
8616 | }
|
8617 | function stop() {
|
8618 | if (--lock.count) delete lock[id]; else delete node.__transition__;
|
8619 | return 1;
|
8620 | }
|
8621 | }, 0, time);
|
8622 | }
|
8623 | }
|
8624 | d3.svg.axis = function() {
|
8625 | var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
|
8626 | function axis(g) {
|
8627 | g.each(function() {
|
8628 | var g = d3.select(this);
|
8629 | var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
|
8630 | 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), tickTransform;
|
8631 | var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
|
8632 | d3.transition(path));
|
8633 | tickEnter.append("line");
|
8634 | tickEnter.append("text");
|
8635 | var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
|
8636 | switch (orient) {
|
8637 | case "bottom":
|
8638 | {
|
8639 | tickTransform = d3_svg_axisX;
|
8640 | lineEnter.attr("y2", innerTickSize);
|
8641 | textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding);
|
8642 | lineUpdate.attr("x2", 0).attr("y2", innerTickSize);
|
8643 | textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding);
|
8644 | text.attr("dy", ".71em").style("text-anchor", "middle");
|
8645 | pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize);
|
8646 | break;
|
8647 | }
|
8648 |
|
8649 | case "top":
|
8650 | {
|
8651 | tickTransform = d3_svg_axisX;
|
8652 | lineEnter.attr("y2", -innerTickSize);
|
8653 | textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
|
8654 | lineUpdate.attr("x2", 0).attr("y2", -innerTickSize);
|
8655 | textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
|
8656 | text.attr("dy", "0em").style("text-anchor", "middle");
|
8657 | pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize);
|
8658 | break;
|
8659 | }
|
8660 |
|
8661 | case "left":
|
8662 | {
|
8663 | tickTransform = d3_svg_axisY;
|
8664 | lineEnter.attr("x2", -innerTickSize);
|
8665 | textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding));
|
8666 | lineUpdate.attr("x2", -innerTickSize).attr("y2", 0);
|
8667 | textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", 0);
|
8668 | text.attr("dy", ".32em").style("text-anchor", "end");
|
8669 | pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize);
|
8670 | break;
|
8671 | }
|
8672 |
|
8673 | case "right":
|
8674 | {
|
8675 | tickTransform = d3_svg_axisY;
|
8676 | lineEnter.attr("x2", innerTickSize);
|
8677 | textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding);
|
8678 | lineUpdate.attr("x2", innerTickSize).attr("y2", 0);
|
8679 | textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0);
|
8680 | text.attr("dy", ".32em").style("text-anchor", "start");
|
8681 | pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize);
|
8682 | break;
|
8683 | }
|
8684 | }
|
8685 | if (scale1.rangeBand) {
|
8686 | var x = scale1, dx = x.rangeBand() / 2;
|
8687 | scale0 = scale1 = function(d) {
|
8688 | return x(d) + dx;
|
8689 | };
|
8690 | } else if (scale0.rangeBand) {
|
8691 | scale0 = scale1;
|
8692 | } else {
|
8693 | tickExit.call(tickTransform, scale1);
|
8694 | }
|
8695 | tickEnter.call(tickTransform, scale0);
|
8696 | tickUpdate.call(tickTransform, scale1);
|
8697 | });
|
8698 | }
|
8699 | axis.scale = function(x) {
|
8700 | if (!arguments.length) return scale;
|
8701 | scale = x;
|
8702 | return axis;
|
8703 | };
|
8704 | axis.orient = function(x) {
|
8705 | if (!arguments.length) return orient;
|
8706 | orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
|
8707 | return axis;
|
8708 | };
|
8709 | axis.ticks = function() {
|
8710 | if (!arguments.length) return tickArguments_;
|
8711 | tickArguments_ = arguments;
|
8712 | return axis;
|
8713 | };
|
8714 | axis.tickValues = function(x) {
|
8715 | if (!arguments.length) return tickValues;
|
8716 | tickValues = x;
|
8717 | return axis;
|
8718 | };
|
8719 | axis.tickFormat = function(x) {
|
8720 | if (!arguments.length) return tickFormat_;
|
8721 | tickFormat_ = x;
|
8722 | return axis;
|
8723 | };
|
8724 | axis.tickSize = function(x) {
|
8725 | var n = arguments.length;
|
8726 | if (!n) return innerTickSize;
|
8727 | innerTickSize = +x;
|
8728 | outerTickSize = +arguments[n - 1];
|
8729 | return axis;
|
8730 | };
|
8731 | axis.innerTickSize = function(x) {
|
8732 | if (!arguments.length) return innerTickSize;
|
8733 | innerTickSize = +x;
|
8734 | return axis;
|
8735 | };
|
8736 | axis.outerTickSize = function(x) {
|
8737 | if (!arguments.length) return outerTickSize;
|
8738 | outerTickSize = +x;
|
8739 | return axis;
|
8740 | };
|
8741 | axis.tickPadding = function(x) {
|
8742 | if (!arguments.length) return tickPadding;
|
8743 | tickPadding = +x;
|
8744 | return axis;
|
8745 | };
|
8746 | axis.tickSubdivide = function() {
|
8747 | return arguments.length && axis;
|
8748 | };
|
8749 | return axis;
|
8750 | };
|
8751 | var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
|
8752 | top: 1,
|
8753 | right: 1,
|
8754 | bottom: 1,
|
8755 | left: 1
|
8756 | };
|
8757 | function d3_svg_axisX(selection, x) {
|
8758 | selection.attr("transform", function(d) {
|
8759 | return "translate(" + x(d) + ",0)";
|
8760 | });
|
8761 | }
|
8762 | function d3_svg_axisY(selection, y) {
|
8763 | selection.attr("transform", function(d) {
|
8764 | return "translate(0," + y(d) + ")";
|
8765 | });
|
8766 | }
|
8767 | d3.svg.brush = function() {
|
8768 | 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];
|
8769 | function brush(g) {
|
8770 | g.each(function() {
|
8771 | 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);
|
8772 | var background = g.selectAll(".background").data([ 0 ]);
|
8773 | background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
|
8774 | g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
|
8775 | var resize = g.selectAll(".resize").data(resizes, d3_identity);
|
8776 | resize.exit().remove();
|
8777 | resize.enter().append("g").attr("class", function(d) {
|
8778 | return "resize " + d;
|
8779 | }).style("cursor", function(d) {
|
8780 | return d3_svg_brushCursor[d];
|
8781 | }).append("rect").attr("x", function(d) {
|
8782 | return /[ew]$/.test(d) ? -3 : null;
|
8783 | }).attr("y", function(d) {
|
8784 | return /^[ns]/.test(d) ? -3 : null;
|
8785 | }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
|
8786 | resize.style("display", brush.empty() ? "none" : null);
|
8787 | var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
|
8788 | if (x) {
|
8789 | range = d3_scaleRange(x);
|
8790 | backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
|
8791 | redrawX(gUpdate);
|
8792 | }
|
8793 | if (y) {
|
8794 | range = d3_scaleRange(y);
|
8795 | backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
|
8796 | redrawY(gUpdate);
|
8797 | }
|
8798 | redraw(gUpdate);
|
8799 | });
|
8800 | }
|
8801 | brush.event = function(g) {
|
8802 | g.each(function() {
|
8803 | var event_ = event.of(this, arguments), extent1 = {
|
8804 | x: xExtent,
|
8805 | y: yExtent,
|
8806 | i: xExtentDomain,
|
8807 | j: yExtentDomain
|
8808 | }, extent0 = this.__chart__ || extent1;
|
8809 | this.__chart__ = extent1;
|
8810 | if (d3_transitionInheritId) {
|
8811 | d3.select(this).transition().each("start.brush", function() {
|
8812 | xExtentDomain = extent0.i;
|
8813 | yExtentDomain = extent0.j;
|
8814 | xExtent = extent0.x;
|
8815 | yExtent = extent0.y;
|
8816 | event_({
|
8817 | type: "brushstart"
|
8818 | });
|
8819 | }).tween("brush:brush", function() {
|
8820 | var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
|
8821 | xExtentDomain = yExtentDomain = null;
|
8822 | return function(t) {
|
8823 | xExtent = extent1.x = xi(t);
|
8824 | yExtent = extent1.y = yi(t);
|
8825 | event_({
|
8826 | type: "brush",
|
8827 | mode: "resize"
|
8828 | });
|
8829 | };
|
8830 | }).each("end.brush", function() {
|
8831 | xExtentDomain = extent1.i;
|
8832 | yExtentDomain = extent1.j;
|
8833 | event_({
|
8834 | type: "brush",
|
8835 | mode: "resize"
|
8836 | });
|
8837 | event_({
|
8838 | type: "brushend"
|
8839 | });
|
8840 | });
|
8841 | } else {
|
8842 | event_({
|
8843 | type: "brushstart"
|
8844 | });
|
8845 | event_({
|
8846 | type: "brush",
|
8847 | mode: "resize"
|
8848 | });
|
8849 | event_({
|
8850 | type: "brushend"
|
8851 | });
|
8852 | }
|
8853 | });
|
8854 | };
|
8855 | function redraw(g) {
|
8856 | g.selectAll(".resize").attr("transform", function(d) {
|
8857 | return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
|
8858 | });
|
8859 | }
|
8860 | function redrawX(g) {
|
8861 | g.select(".extent").attr("x", xExtent[0]);
|
8862 | g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
|
8863 | }
|
8864 | function redrawY(g) {
|
8865 | g.select(".extent").attr("y", yExtent[0]);
|
8866 | g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
|
8867 | }
|
8868 | function brushstart() {
|
8869 | 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(), center, origin = d3.mouse(target), offset;
|
8870 | var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
|
8871 | if (d3.event.changedTouches) {
|
8872 | w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
|
8873 | } else {
|
8874 | w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
|
8875 | }
|
8876 | g.interrupt().selectAll("*").interrupt();
|
8877 | if (dragging) {
|
8878 | origin[0] = xExtent[0] - origin[0];
|
8879 | origin[1] = yExtent[0] - origin[1];
|
8880 | } else if (resizing) {
|
8881 | var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
|
8882 | offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
|
8883 | origin[0] = xExtent[ex];
|
8884 | origin[1] = yExtent[ey];
|
8885 | } else if (d3.event.altKey) center = origin.slice();
|
8886 | g.style("pointer-events", "none").selectAll(".resize").style("display", null);
|
8887 | d3.select("body").style("cursor", eventTarget.style("cursor"));
|
8888 | event_({
|
8889 | type: "brushstart"
|
8890 | });
|
8891 | brushmove();
|
8892 | function keydown() {
|
8893 | if (d3.event.keyCode == 32) {
|
8894 | if (!dragging) {
|
8895 | center = null;
|
8896 | origin[0] -= xExtent[1];
|
8897 | origin[1] -= yExtent[1];
|
8898 | dragging = 2;
|
8899 | }
|
8900 | d3_eventPreventDefault();
|
8901 | }
|
8902 | }
|
8903 | function keyup() {
|
8904 | if (d3.event.keyCode == 32 && dragging == 2) {
|
8905 | origin[0] += xExtent[1];
|
8906 | origin[1] += yExtent[1];
|
8907 | dragging = 0;
|
8908 | d3_eventPreventDefault();
|
8909 | }
|
8910 | }
|
8911 | function brushmove() {
|
8912 | var point = d3.mouse(target), moved = false;
|
8913 | if (offset) {
|
8914 | point[0] += offset[0];
|
8915 | point[1] += offset[1];
|
8916 | }
|
8917 | if (!dragging) {
|
8918 | if (d3.event.altKey) {
|
8919 | if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
|
8920 | origin[0] = xExtent[+(point[0] < center[0])];
|
8921 | origin[1] = yExtent[+(point[1] < center[1])];
|
8922 | } else center = null;
|
8923 | }
|
8924 | if (resizingX && move1(point, x, 0)) {
|
8925 | redrawX(g);
|
8926 | moved = true;
|
8927 | }
|
8928 | if (resizingY && move1(point, y, 1)) {
|
8929 | redrawY(g);
|
8930 | moved = true;
|
8931 | }
|
8932 | if (moved) {
|
8933 | redraw(g);
|
8934 | event_({
|
8935 | type: "brush",
|
8936 | mode: dragging ? "move" : "resize"
|
8937 | });
|
8938 | }
|
8939 | }
|
8940 | function move1(point, scale, i) {
|
8941 | 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;
|
8942 | if (dragging) {
|
8943 | r0 -= position;
|
8944 | r1 -= size + position;
|
8945 | }
|
8946 | min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
|
8947 | if (dragging) {
|
8948 | max = (min += position) + size;
|
8949 | } else {
|
8950 | if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
|
8951 | if (position < min) {
|
8952 | max = min;
|
8953 | min = position;
|
8954 | } else {
|
8955 | max = position;
|
8956 | }
|
8957 | }
|
8958 | if (extent[0] != min || extent[1] != max) {
|
8959 | if (i) yExtentDomain = null; else xExtentDomain = null;
|
8960 | extent[0] = min;
|
8961 | extent[1] = max;
|
8962 | return true;
|
8963 | }
|
8964 | }
|
8965 | function brushend() {
|
8966 | brushmove();
|
8967 | g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
|
8968 | d3.select("body").style("cursor", null);
|
8969 | 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);
|
8970 | dragRestore();
|
8971 | event_({
|
8972 | type: "brushend"
|
8973 | });
|
8974 | }
|
8975 | }
|
8976 | brush.x = function(z) {
|
8977 | if (!arguments.length) return x;
|
8978 | x = z;
|
8979 | resizes = d3_svg_brushResizes[!x << 1 | !y];
|
8980 | return brush;
|
8981 | };
|
8982 | brush.y = function(z) {
|
8983 | if (!arguments.length) return y;
|
8984 | y = z;
|
8985 | resizes = d3_svg_brushResizes[!x << 1 | !y];
|
8986 | return brush;
|
8987 | };
|
8988 | brush.clamp = function(z) {
|
8989 | if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
|
8990 | if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
|
8991 | return brush;
|
8992 | };
|
8993 | brush.extent = function(z) {
|
8994 | var x0, x1, y0, y1, t;
|
8995 | if (!arguments.length) {
|
8996 | if (x) {
|
8997 | if (xExtentDomain) {
|
8998 | x0 = xExtentDomain[0], x1 = xExtentDomain[1];
|
8999 | } else {
|
9000 | x0 = xExtent[0], x1 = xExtent[1];
|
9001 | if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
|
9002 | if (x1 < x0) t = x0, x0 = x1, x1 = t;
|
9003 | }
|
9004 | }
|
9005 | if (y) {
|
9006 | if (yExtentDomain) {
|
9007 | y0 = yExtentDomain[0], y1 = yExtentDomain[1];
|
9008 | } else {
|
9009 | y0 = yExtent[0], y1 = yExtent[1];
|
9010 | if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
|
9011 | if (y1 < y0) t = y0, y0 = y1, y1 = t;
|
9012 | }
|
9013 | }
|
9014 | return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
|
9015 | }
|
9016 | if (x) {
|
9017 | x0 = z[0], x1 = z[1];
|
9018 | if (y) x0 = x0[0], x1 = x1[0];
|
9019 | xExtentDomain = [ x0, x1 ];
|
9020 | if (x.invert) x0 = x(x0), x1 = x(x1);
|
9021 | if (x1 < x0) t = x0, x0 = x1, x1 = t;
|
9022 | if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
|
9023 | }
|
9024 | if (y) {
|
9025 | y0 = z[0], y1 = z[1];
|
9026 | if (x) y0 = y0[1], y1 = y1[1];
|
9027 | yExtentDomain = [ y0, y1 ];
|
9028 | if (y.invert) y0 = y(y0), y1 = y(y1);
|
9029 | if (y1 < y0) t = y0, y0 = y1, y1 = t;
|
9030 | if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
|
9031 | }
|
9032 | return brush;
|
9033 | };
|
9034 | brush.clear = function() {
|
9035 | if (!brush.empty()) {
|
9036 | xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
|
9037 | xExtentDomain = yExtentDomain = null;
|
9038 | }
|
9039 | return brush;
|
9040 | };
|
9041 | brush.empty = function() {
|
9042 | return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
|
9043 | };
|
9044 | return d3.rebind(brush, event, "on");
|
9045 | };
|
9046 | var d3_svg_brushCursor = {
|
9047 | n: "ns-resize",
|
9048 | e: "ew-resize",
|
9049 | s: "ns-resize",
|
9050 | w: "ew-resize",
|
9051 | nw: "nwse-resize",
|
9052 | ne: "nesw-resize",
|
9053 | se: "nwse-resize",
|
9054 | sw: "nesw-resize"
|
9055 | };
|
9056 | var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
|
9057 | var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
|
9058 | var d3_time_formatUtc = d3_time_format.utc;
|
9059 | var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
|
9060 | d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
|
9061 | function d3_time_formatIsoNative(date) {
|
9062 | return date.toISOString();
|
9063 | }
|
9064 | d3_time_formatIsoNative.parse = function(string) {
|
9065 | var date = new Date(string);
|
9066 | return isNaN(date) ? null : date;
|
9067 | };
|
9068 | d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
|
9069 | d3_time.second = d3_time_interval(function(date) {
|
9070 | return new d3_date(Math.floor(date / 1e3) * 1e3);
|
9071 | }, function(date, offset) {
|
9072 | date.setTime(date.getTime() + Math.floor(offset) * 1e3);
|
9073 | }, function(date) {
|
9074 | return date.getSeconds();
|
9075 | });
|
9076 | d3_time.seconds = d3_time.second.range;
|
9077 | d3_time.seconds.utc = d3_time.second.utc.range;
|
9078 | d3_time.minute = d3_time_interval(function(date) {
|
9079 | return new d3_date(Math.floor(date / 6e4) * 6e4);
|
9080 | }, function(date, offset) {
|
9081 | date.setTime(date.getTime() + Math.floor(offset) * 6e4);
|
9082 | }, function(date) {
|
9083 | return date.getMinutes();
|
9084 | });
|
9085 | d3_time.minutes = d3_time.minute.range;
|
9086 | d3_time.minutes.utc = d3_time.minute.utc.range;
|
9087 | d3_time.hour = d3_time_interval(function(date) {
|
9088 | var timezone = date.getTimezoneOffset() / 60;
|
9089 | return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
|
9090 | }, function(date, offset) {
|
9091 | date.setTime(date.getTime() + Math.floor(offset) * 36e5);
|
9092 | }, function(date) {
|
9093 | return date.getHours();
|
9094 | });
|
9095 | d3_time.hours = d3_time.hour.range;
|
9096 | d3_time.hours.utc = d3_time.hour.utc.range;
|
9097 | d3_time.month = d3_time_interval(function(date) {
|
9098 | date = d3_time.day(date);
|
9099 | date.setDate(1);
|
9100 | return date;
|
9101 | }, function(date, offset) {
|
9102 | date.setMonth(date.getMonth() + offset);
|
9103 | }, function(date) {
|
9104 | return date.getMonth();
|
9105 | });
|
9106 | d3_time.months = d3_time.month.range;
|
9107 | d3_time.months.utc = d3_time.month.utc.range;
|
9108 | function d3_time_scale(linear, methods, format) {
|
9109 | function scale(x) {
|
9110 | return linear(x);
|
9111 | }
|
9112 | scale.invert = function(x) {
|
9113 | return d3_time_scaleDate(linear.invert(x));
|
9114 | };
|
9115 | scale.domain = function(x) {
|
9116 | if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
|
9117 | linear.domain(x);
|
9118 | return scale;
|
9119 | };
|
9120 | function tickMethod(extent, count) {
|
9121 | var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
|
9122 | return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
|
9123 | return d / 31536e6;
|
9124 | }), 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];
|
9125 | }
|
9126 | scale.nice = function(interval, skip) {
|
9127 | var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
|
9128 | if (method) interval = method[0], skip = method[1];
|
9129 | function skipped(date) {
|
9130 | return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
|
9131 | }
|
9132 | return scale.domain(d3_scale_nice(domain, skip > 1 ? {
|
9133 | floor: function(date) {
|
9134 | while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
|
9135 | return date;
|
9136 | },
|
9137 | ceil: function(date) {
|
9138 | while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
|
9139 | return date;
|
9140 | }
|
9141 | } : interval));
|
9142 | };
|
9143 | scale.ticks = function(interval, skip) {
|
9144 | var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
|
9145 | range: interval
|
9146 | }, skip ];
|
9147 | if (method) interval = method[0], skip = method[1];
|
9148 | return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
|
9149 | };
|
9150 | scale.tickFormat = function() {
|
9151 | return format;
|
9152 | };
|
9153 | scale.copy = function() {
|
9154 | return d3_time_scale(linear.copy(), methods, format);
|
9155 | };
|
9156 | return d3_scale_linearRebind(scale, linear);
|
9157 | }
|
9158 | function d3_time_scaleDate(t) {
|
9159 | return new Date(t);
|
9160 | }
|
9161 | var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
|
9162 | 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 ] ];
|
9163 | var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
|
9164 | return d.getMilliseconds();
|
9165 | } ], [ ":%S", function(d) {
|
9166 | return d.getSeconds();
|
9167 | } ], [ "%I:%M", function(d) {
|
9168 | return d.getMinutes();
|
9169 | } ], [ "%I %p", function(d) {
|
9170 | return d.getHours();
|
9171 | } ], [ "%a %d", function(d) {
|
9172 | return d.getDay() && d.getDate() != 1;
|
9173 | } ], [ "%b %d", function(d) {
|
9174 | return d.getDate() != 1;
|
9175 | } ], [ "%B", function(d) {
|
9176 | return d.getMonth();
|
9177 | } ], [ "%Y", d3_true ] ]);
|
9178 | var d3_time_scaleMilliseconds = {
|
9179 | range: function(start, stop, step) {
|
9180 | return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
|
9181 | },
|
9182 | floor: d3_identity,
|
9183 | ceil: d3_identity
|
9184 | };
|
9185 | d3_time_scaleLocalMethods.year = d3_time.year;
|
9186 | d3_time.scale = function() {
|
9187 | return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
|
9188 | };
|
9189 | var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
|
9190 | return [ m[0].utc, m[1] ];
|
9191 | });
|
9192 | var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
|
9193 | return d.getUTCMilliseconds();
|
9194 | } ], [ ":%S", function(d) {
|
9195 | return d.getUTCSeconds();
|
9196 | } ], [ "%I:%M", function(d) {
|
9197 | return d.getUTCMinutes();
|
9198 | } ], [ "%I %p", function(d) {
|
9199 | return d.getUTCHours();
|
9200 | } ], [ "%a %d", function(d) {
|
9201 | return d.getUTCDay() && d.getUTCDate() != 1;
|
9202 | } ], [ "%b %d", function(d) {
|
9203 | return d.getUTCDate() != 1;
|
9204 | } ], [ "%B", function(d) {
|
9205 | return d.getUTCMonth();
|
9206 | } ], [ "%Y", d3_true ] ]);
|
9207 | d3_time_scaleUtcMethods.year = d3_time.year.utc;
|
9208 | d3_time.scale.utc = function() {
|
9209 | return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
|
9210 | };
|
9211 | d3.text = d3_xhrType(function(request) {
|
9212 | return request.responseText;
|
9213 | });
|
9214 | d3.json = function(url, callback) {
|
9215 | return d3_xhr(url, "application/json", d3_json, callback);
|
9216 | };
|
9217 | function d3_json(request) {
|
9218 | return JSON.parse(request.responseText);
|
9219 | }
|
9220 | d3.html = function(url, callback) {
|
9221 | return d3_xhr(url, "text/html", d3_html, callback);
|
9222 | };
|
9223 | function d3_html(request) {
|
9224 | var range = d3_document.createRange();
|
9225 | range.selectNode(d3_document.body);
|
9226 | return range.createContextualFragment(request.responseText);
|
9227 | }
|
9228 | d3.xml = d3_xhrType(function(request) {
|
9229 | return request.responseXML;
|
9230 | });
|
9231 | if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;
|
9232 | this.d3 = d3;
|
9233 | }(); |
\ | No newline at end of file |