CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
adasegroup

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: adasegroup/NEUROML2022
Path: blob/main/seminar4/hello/d3.js
Views: 63
1
!function() {
2
var d3 = {
3
version: "3.4.8"
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[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
function d3_mousePoint(container, e) {
1093
if (e.changedTouches) e = e.changedTouches[0];
1094
var svg = container.ownerSVGElement || container;
1095
if (svg.createSVGPoint) {
1096
var point = svg.createSVGPoint();
1097
point.x = e.clientX, point.y = e.clientY;
1098
point = point.matrixTransform(container.getScreenCTM().inverse());
1099
return [ point.x, point.y ];
1100
}
1101
var rect = container.getBoundingClientRect();
1102
return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
1103
}
1104
d3.touches = function(container, touches) {
1105
if (arguments.length < 2) touches = d3_eventSource().touches;
1106
return touches ? d3_array(touches).map(function(touch) {
1107
var point = d3_mousePoint(container, touch);
1108
point.identifier = touch.identifier;
1109
return point;
1110
}) : [];
1111
};
1112
d3.behavior.drag = function() {
1113
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");
1114
function drag() {
1115
this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
1116
}
1117
function dragstart(id, position, subject, move, end) {
1118
return function() {
1119
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);
1120
if (origin) {
1121
dragOffset = origin.apply(that, arguments);
1122
dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
1123
} else {
1124
dragOffset = [ 0, 0 ];
1125
}
1126
dispatch({
1127
type: "dragstart"
1128
});
1129
function moved() {
1130
var position1 = position(parent, dragId), dx, dy;
1131
if (!position1) return;
1132
dx = position1[0] - position0[0];
1133
dy = position1[1] - position0[1];
1134
dragged |= dx | dy;
1135
position0 = position1;
1136
dispatch({
1137
type: "drag",
1138
x: position1[0] + dragOffset[0],
1139
y: position1[1] + dragOffset[1],
1140
dx: dx,
1141
dy: dy
1142
});
1143
}
1144
function ended() {
1145
if (!position(parent, dragId)) return;
1146
dragSubject.on(move + dragName, null).on(end + dragName, null);
1147
dragRestore(dragged && d3.event.target === target);
1148
dispatch({
1149
type: "dragend"
1150
});
1151
}
1152
};
1153
}
1154
drag.origin = function(x) {
1155
if (!arguments.length) return origin;
1156
origin = x;
1157
return drag;
1158
};
1159
return d3.rebind(drag, event, "on");
1160
};
1161
function d3_behavior_dragTouchId() {
1162
return d3.event.changedTouches[0].identifier;
1163
}
1164
function d3_behavior_dragTouchSubject() {
1165
return d3.event.target;
1166
}
1167
function d3_behavior_dragMouseSubject() {
1168
return d3_window;
1169
}
1170
var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
1171
function d3_sgn(x) {
1172
return x > 0 ? 1 : x < 0 ? -1 : 0;
1173
}
1174
function d3_cross2d(a, b, c) {
1175
return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1176
}
1177
function d3_acos(x) {
1178
return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1179
}
1180
function d3_asin(x) {
1181
return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
1182
}
1183
function d3_sinh(x) {
1184
return ((x = Math.exp(x)) - 1 / x) / 2;
1185
}
1186
function d3_cosh(x) {
1187
return ((x = Math.exp(x)) + 1 / x) / 2;
1188
}
1189
function d3_tanh(x) {
1190
return ((x = Math.exp(2 * x)) - 1) / (x + 1);
1191
}
1192
function d3_haversin(x) {
1193
return (x = Math.sin(x / 2)) * x;
1194
}
1195
var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
1196
d3.interpolateZoom = function(p0, p1) {
1197
var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
1198
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)) / ρ;
1199
function interpolate(t) {
1200
var s = t * S;
1201
if (dr) {
1202
var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
1203
return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
1204
}
1205
return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
1206
}
1207
interpolate.duration = S * 1e3;
1208
return interpolate;
1209
};
1210
d3.behavior.zoom = function() {
1211
var view = {
1212
x: 0,
1213
y: 0,
1214
k: 1
1215
}, translate0, 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;
1216
function zoom(g) {
1217
g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
1218
}
1219
zoom.event = function(g) {
1220
g.each(function() {
1221
var dispatch = event.of(this, arguments), view1 = view;
1222
if (d3_transitionInheritId) {
1223
d3.select(this).transition().each("start.zoom", function() {
1224
view = this.__chart__ || {
1225
x: 0,
1226
y: 0,
1227
k: 1
1228
};
1229
zoomstarted(dispatch);
1230
}).tween("zoom:zoom", function() {
1231
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 ]);
1232
return function(t) {
1233
var l = i(t), k = dx / l[2];
1234
this.__chart__ = view = {
1235
x: cx - l[0] * k,
1236
y: cy - l[1] * k,
1237
k: k
1238
};
1239
zoomed(dispatch);
1240
};
1241
}).each("end.zoom", function() {
1242
zoomended(dispatch);
1243
});
1244
} else {
1245
this.__chart__ = view;
1246
zoomstarted(dispatch);
1247
zoomed(dispatch);
1248
zoomended(dispatch);
1249
}
1250
});
1251
};
1252
zoom.translate = function(_) {
1253
if (!arguments.length) return [ view.x, view.y ];
1254
view = {
1255
x: +_[0],
1256
y: +_[1],
1257
k: view.k
1258
};
1259
rescale();
1260
return zoom;
1261
};
1262
zoom.scale = function(_) {
1263
if (!arguments.length) return view.k;
1264
view = {
1265
x: view.x,
1266
y: view.y,
1267
k: +_
1268
};
1269
rescale();
1270
return zoom;
1271
};
1272
zoom.scaleExtent = function(_) {
1273
if (!arguments.length) return scaleExtent;
1274
scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
1275
return zoom;
1276
};
1277
zoom.center = function(_) {
1278
if (!arguments.length) return center;
1279
center = _ && [ +_[0], +_[1] ];
1280
return zoom;
1281
};
1282
zoom.size = function(_) {
1283
if (!arguments.length) return size;
1284
size = _ && [ +_[0], +_[1] ];
1285
return zoom;
1286
};
1287
zoom.x = function(z) {
1288
if (!arguments.length) return x1;
1289
x1 = z;
1290
x0 = z.copy();
1291
view = {
1292
x: 0,
1293
y: 0,
1294
k: 1
1295
};
1296
return zoom;
1297
};
1298
zoom.y = function(z) {
1299
if (!arguments.length) return y1;
1300
y1 = z;
1301
y0 = z.copy();
1302
view = {
1303
x: 0,
1304
y: 0,
1305
k: 1
1306
};
1307
return zoom;
1308
};
1309
function location(p) {
1310
return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
1311
}
1312
function point(l) {
1313
return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
1314
}
1315
function scaleTo(s) {
1316
view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1317
}
1318
function translateTo(p, l) {
1319
l = point(l);
1320
view.x += p[0] - l[0];
1321
view.y += p[1] - l[1];
1322
}
1323
function rescale() {
1324
if (x1) x1.domain(x0.range().map(function(x) {
1325
return (x - view.x) / view.k;
1326
}).map(x0.invert));
1327
if (y1) y1.domain(y0.range().map(function(y) {
1328
return (y - view.y) / view.k;
1329
}).map(y0.invert));
1330
}
1331
function zoomstarted(dispatch) {
1332
dispatch({
1333
type: "zoomstart"
1334
});
1335
}
1336
function zoomed(dispatch) {
1337
rescale();
1338
dispatch({
1339
type: "zoom",
1340
scale: view.k,
1341
translate: [ view.x, view.y ]
1342
});
1343
}
1344
function zoomended(dispatch) {
1345
dispatch({
1346
type: "zoomend"
1347
});
1348
}
1349
function mousedowned() {
1350
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();
1351
d3_selection_interrupt.call(that);
1352
zoomstarted(dispatch);
1353
function moved() {
1354
dragged = 1;
1355
translateTo(d3.mouse(that), location0);
1356
zoomed(dispatch);
1357
}
1358
function ended() {
1359
subject.on(mousemove, d3_window === that ? mousewheelreset : null).on(mouseup, null);
1360
dragRestore(dragged && d3.event.target === target);
1361
zoomended(dispatch);
1362
}
1363
}
1364
function touchstarted() {
1365
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();
1366
d3_selection_interrupt.call(that);
1367
started();
1368
zoomstarted(dispatch);
1369
function relocate() {
1370
var touches = d3.touches(that);
1371
scale0 = view.k;
1372
touches.forEach(function(t) {
1373
if (t.identifier in locations0) locations0[t.identifier] = location(t);
1374
});
1375
return touches;
1376
}
1377
function started() {
1378
var target = d3.event.target;
1379
d3.select(target).on(touchmove, moved).on(touchend, ended);
1380
targets.push(target);
1381
var changed = d3.event.changedTouches;
1382
for (var i = 0, n = changed.length; i < n; ++i) {
1383
locations0[changed[i].identifier] = null;
1384
}
1385
var touches = relocate(), now = Date.now();
1386
if (touches.length === 1) {
1387
if (now - touchtime < 500) {
1388
var p = touches[0], l = locations0[p.identifier];
1389
scaleTo(view.k * 2);
1390
translateTo(p, l);
1391
d3_eventPreventDefault();
1392
zoomed(dispatch);
1393
}
1394
touchtime = now;
1395
} else if (touches.length > 1) {
1396
var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1397
distance0 = dx * dx + dy * dy;
1398
}
1399
}
1400
function moved() {
1401
var touches = d3.touches(that), p0, l0, p1, l1;
1402
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1403
p1 = touches[i];
1404
if (l1 = locations0[p1.identifier]) {
1405
if (l0) break;
1406
p0 = p1, l0 = l1;
1407
}
1408
}
1409
if (l1) {
1410
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
1411
p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1412
l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
1413
scaleTo(scale1 * scale0);
1414
}
1415
touchtime = null;
1416
translateTo(p0, l0);
1417
zoomed(dispatch);
1418
}
1419
function ended() {
1420
if (d3.event.touches.length) {
1421
var changed = d3.event.changedTouches;
1422
for (var i = 0, n = changed.length; i < n; ++i) {
1423
delete locations0[changed[i].identifier];
1424
}
1425
for (var identifier in locations0) {
1426
return void relocate();
1427
}
1428
}
1429
d3.selectAll(targets).on(zoomName, null);
1430
subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
1431
dragRestore();
1432
zoomended(dispatch);
1433
}
1434
}
1435
function mousewheeled() {
1436
var dispatch = event.of(this, arguments);
1437
if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
1438
zoomstarted(dispatch);
1439
mousewheelTimer = setTimeout(function() {
1440
mousewheelTimer = null;
1441
zoomended(dispatch);
1442
}, 50);
1443
d3_eventPreventDefault();
1444
var point = center || d3.mouse(this);
1445
if (!translate0) translate0 = location(point);
1446
scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
1447
translateTo(point, translate0);
1448
zoomed(dispatch);
1449
}
1450
function mousewheelreset() {
1451
translate0 = null;
1452
}
1453
function dblclicked() {
1454
var dispatch = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2;
1455
zoomstarted(dispatch);
1456
scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
1457
translateTo(p, l);
1458
zoomed(dispatch);
1459
zoomended(dispatch);
1460
}
1461
return d3.rebind(zoom, event, "on");
1462
};
1463
var d3_behavior_zoomInfinity = [ 0, Infinity ];
1464
var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1465
return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1466
}, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1467
return d3.event.wheelDelta;
1468
}, "mousewheel") : (d3_behavior_zoomDelta = function() {
1469
return -d3.event.detail;
1470
}, "MozMousePixelScroll");
1471
function d3_Color() {}
1472
d3_Color.prototype.toString = function() {
1473
return this.rgb() + "";
1474
};
1475
d3.hsl = function(h, s, l) {
1476
return arguments.length === 1 ? h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : d3_hsl(+h, +s, +l);
1477
};
1478
function d3_hsl(h, s, l) {
1479
return new d3_Hsl(h, s, l);
1480
}
1481
function d3_Hsl(h, s, l) {
1482
this.h = h;
1483
this.s = s;
1484
this.l = l;
1485
}
1486
var d3_hslPrototype = d3_Hsl.prototype = new d3_Color();
1487
d3_hslPrototype.brighter = function(k) {
1488
k = Math.pow(.7, arguments.length ? k : 1);
1489
return d3_hsl(this.h, this.s, this.l / k);
1490
};
1491
d3_hslPrototype.darker = function(k) {
1492
k = Math.pow(.7, arguments.length ? k : 1);
1493
return d3_hsl(this.h, this.s, k * this.l);
1494
};
1495
d3_hslPrototype.rgb = function() {
1496
return d3_hsl_rgb(this.h, this.s, this.l);
1497
};
1498
function d3_hsl_rgb(h, s, l) {
1499
var m1, m2;
1500
h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
1501
s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
1502
l = l < 0 ? 0 : l > 1 ? 1 : l;
1503
m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1504
m1 = 2 * l - m2;
1505
function v(h) {
1506
if (h > 360) h -= 360; else if (h < 0) h += 360;
1507
if (h < 60) return m1 + (m2 - m1) * h / 60;
1508
if (h < 180) return m2;
1509
if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
1510
return m1;
1511
}
1512
function vv(h) {
1513
return Math.round(v(h) * 255);
1514
}
1515
return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1516
}
1517
d3.hcl = function(h, c, l) {
1518
return arguments.length === 1 ? h instanceof d3_Hcl ? d3_hcl(h.h, h.c, h.l) : h instanceof d3_Lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : d3_hcl(+h, +c, +l);
1519
};
1520
function d3_hcl(h, c, l) {
1521
return new d3_Hcl(h, c, l);
1522
}
1523
function d3_Hcl(h, c, l) {
1524
this.h = h;
1525
this.c = c;
1526
this.l = l;
1527
}
1528
var d3_hclPrototype = d3_Hcl.prototype = new d3_Color();
1529
d3_hclPrototype.brighter = function(k) {
1530
return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1531
};
1532
d3_hclPrototype.darker = function(k) {
1533
return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1534
};
1535
d3_hclPrototype.rgb = function() {
1536
return d3_hcl_lab(this.h, this.c, this.l).rgb();
1537
};
1538
function d3_hcl_lab(h, c, l) {
1539
if (isNaN(h)) h = 0;
1540
if (isNaN(c)) c = 0;
1541
return d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1542
}
1543
d3.lab = function(l, a, b) {
1544
return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
1545
};
1546
function d3_lab(l, a, b) {
1547
return new d3_Lab(l, a, b);
1548
}
1549
function d3_Lab(l, a, b) {
1550
this.l = l;
1551
this.a = a;
1552
this.b = b;
1553
}
1554
var d3_lab_K = 18;
1555
var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1556
var d3_labPrototype = d3_Lab.prototype = new d3_Color();
1557
d3_labPrototype.brighter = function(k) {
1558
return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1559
};
1560
d3_labPrototype.darker = function(k) {
1561
return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1562
};
1563
d3_labPrototype.rgb = function() {
1564
return d3_lab_rgb(this.l, this.a, this.b);
1565
};
1566
function d3_lab_rgb(l, a, b) {
1567
var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1568
x = d3_lab_xyz(x) * d3_lab_X;
1569
y = d3_lab_xyz(y) * d3_lab_Y;
1570
z = d3_lab_xyz(z) * d3_lab_Z;
1571
return d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
1572
}
1573
function d3_lab_hcl(l, a, b) {
1574
return l > 0 ? d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : d3_hcl(NaN, NaN, l);
1575
}
1576
function d3_lab_xyz(x) {
1577
return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1578
}
1579
function d3_xyz_lab(x) {
1580
return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1581
}
1582
function d3_xyz_rgb(r) {
1583
return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1584
}
1585
d3.rgb = function(r, g, b) {
1586
return arguments.length === 1 ? r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : d3_rgb(~~r, ~~g, ~~b);
1587
};
1588
function d3_rgbNumber(value) {
1589
return d3_rgb(value >> 16, value >> 8 & 255, value & 255);
1590
}
1591
function d3_rgbString(value) {
1592
return d3_rgbNumber(value) + "";
1593
}
1594
function d3_rgb(r, g, b) {
1595
return new d3_Rgb(r, g, b);
1596
}
1597
function d3_Rgb(r, g, b) {
1598
this.r = r;
1599
this.g = g;
1600
this.b = b;
1601
}
1602
var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color();
1603
d3_rgbPrototype.brighter = function(k) {
1604
k = Math.pow(.7, arguments.length ? k : 1);
1605
var r = this.r, g = this.g, b = this.b, i = 30;
1606
if (!r && !g && !b) return d3_rgb(i, i, i);
1607
if (r && r < i) r = i;
1608
if (g && g < i) g = i;
1609
if (b && b < i) b = i;
1610
return d3_rgb(Math.min(255, ~~(r / k)), Math.min(255, ~~(g / k)), Math.min(255, ~~(b / k)));
1611
};
1612
d3_rgbPrototype.darker = function(k) {
1613
k = Math.pow(.7, arguments.length ? k : 1);
1614
return d3_rgb(~~(k * this.r), ~~(k * this.g), ~~(k * this.b));
1615
};
1616
d3_rgbPrototype.hsl = function() {
1617
return d3_rgb_hsl(this.r, this.g, this.b);
1618
};
1619
d3_rgbPrototype.toString = function() {
1620
return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1621
};
1622
function d3_rgb_hex(v) {
1623
return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1624
}
1625
function d3_rgb_parse(format, rgb, hsl) {
1626
var r = 0, g = 0, b = 0, m1, m2, color;
1627
m1 = /([a-z]+)\((.*)\)/i.exec(format);
1628
if (m1) {
1629
m2 = m1[2].split(",");
1630
switch (m1[1]) {
1631
case "hsl":
1632
{
1633
return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1634
}
1635
1636
case "rgb":
1637
{
1638
return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1639
}
1640
}
1641
}
1642
if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b);
1643
if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.substring(1), 16))) {
1644
if (format.length === 4) {
1645
r = (color & 3840) >> 4;
1646
r = r >> 4 | r;
1647
g = color & 240;
1648
g = g >> 4 | g;
1649
b = color & 15;
1650
b = b << 4 | b;
1651
} else if (format.length === 7) {
1652
r = (color & 16711680) >> 16;
1653
g = (color & 65280) >> 8;
1654
b = color & 255;
1655
}
1656
}
1657
return rgb(r, g, b);
1658
}
1659
function d3_rgb_hsl(r, g, b) {
1660
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;
1661
if (d) {
1662
s = l < .5 ? d / (max + min) : d / (2 - max - min);
1663
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;
1664
h *= 60;
1665
} else {
1666
h = NaN;
1667
s = l > 0 && l < 1 ? 0 : h;
1668
}
1669
return d3_hsl(h, s, l);
1670
}
1671
function d3_rgb_lab(r, g, b) {
1672
r = d3_rgb_xyz(r);
1673
g = d3_rgb_xyz(g);
1674
b = d3_rgb_xyz(b);
1675
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);
1676
return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1677
}
1678
function d3_rgb_xyz(r) {
1679
return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1680
}
1681
function d3_rgb_parseNumber(c) {
1682
var f = parseFloat(c);
1683
return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1684
}
1685
var d3_rgb_names = d3.map({
1686
aliceblue: 15792383,
1687
antiquewhite: 16444375,
1688
aqua: 65535,
1689
aquamarine: 8388564,
1690
azure: 15794175,
1691
beige: 16119260,
1692
bisque: 16770244,
1693
black: 0,
1694
blanchedalmond: 16772045,
1695
blue: 255,
1696
blueviolet: 9055202,
1697
brown: 10824234,
1698
burlywood: 14596231,
1699
cadetblue: 6266528,
1700
chartreuse: 8388352,
1701
chocolate: 13789470,
1702
coral: 16744272,
1703
cornflowerblue: 6591981,
1704
cornsilk: 16775388,
1705
crimson: 14423100,
1706
cyan: 65535,
1707
darkblue: 139,
1708
darkcyan: 35723,
1709
darkgoldenrod: 12092939,
1710
darkgray: 11119017,
1711
darkgreen: 25600,
1712
darkgrey: 11119017,
1713
darkkhaki: 12433259,
1714
darkmagenta: 9109643,
1715
darkolivegreen: 5597999,
1716
darkorange: 16747520,
1717
darkorchid: 10040012,
1718
darkred: 9109504,
1719
darksalmon: 15308410,
1720
darkseagreen: 9419919,
1721
darkslateblue: 4734347,
1722
darkslategray: 3100495,
1723
darkslategrey: 3100495,
1724
darkturquoise: 52945,
1725
darkviolet: 9699539,
1726
deeppink: 16716947,
1727
deepskyblue: 49151,
1728
dimgray: 6908265,
1729
dimgrey: 6908265,
1730
dodgerblue: 2003199,
1731
firebrick: 11674146,
1732
floralwhite: 16775920,
1733
forestgreen: 2263842,
1734
fuchsia: 16711935,
1735
gainsboro: 14474460,
1736
ghostwhite: 16316671,
1737
gold: 16766720,
1738
goldenrod: 14329120,
1739
gray: 8421504,
1740
green: 32768,
1741
greenyellow: 11403055,
1742
grey: 8421504,
1743
honeydew: 15794160,
1744
hotpink: 16738740,
1745
indianred: 13458524,
1746
indigo: 4915330,
1747
ivory: 16777200,
1748
khaki: 15787660,
1749
lavender: 15132410,
1750
lavenderblush: 16773365,
1751
lawngreen: 8190976,
1752
lemonchiffon: 16775885,
1753
lightblue: 11393254,
1754
lightcoral: 15761536,
1755
lightcyan: 14745599,
1756
lightgoldenrodyellow: 16448210,
1757
lightgray: 13882323,
1758
lightgreen: 9498256,
1759
lightgrey: 13882323,
1760
lightpink: 16758465,
1761
lightsalmon: 16752762,
1762
lightseagreen: 2142890,
1763
lightskyblue: 8900346,
1764
lightslategray: 7833753,
1765
lightslategrey: 7833753,
1766
lightsteelblue: 11584734,
1767
lightyellow: 16777184,
1768
lime: 65280,
1769
limegreen: 3329330,
1770
linen: 16445670,
1771
magenta: 16711935,
1772
maroon: 8388608,
1773
mediumaquamarine: 6737322,
1774
mediumblue: 205,
1775
mediumorchid: 12211667,
1776
mediumpurple: 9662683,
1777
mediumseagreen: 3978097,
1778
mediumslateblue: 8087790,
1779
mediumspringgreen: 64154,
1780
mediumturquoise: 4772300,
1781
mediumvioletred: 13047173,
1782
midnightblue: 1644912,
1783
mintcream: 16121850,
1784
mistyrose: 16770273,
1785
moccasin: 16770229,
1786
navajowhite: 16768685,
1787
navy: 128,
1788
oldlace: 16643558,
1789
olive: 8421376,
1790
olivedrab: 7048739,
1791
orange: 16753920,
1792
orangered: 16729344,
1793
orchid: 14315734,
1794
palegoldenrod: 15657130,
1795
palegreen: 10025880,
1796
paleturquoise: 11529966,
1797
palevioletred: 14381203,
1798
papayawhip: 16773077,
1799
peachpuff: 16767673,
1800
peru: 13468991,
1801
pink: 16761035,
1802
plum: 14524637,
1803
powderblue: 11591910,
1804
purple: 8388736,
1805
red: 16711680,
1806
rosybrown: 12357519,
1807
royalblue: 4286945,
1808
saddlebrown: 9127187,
1809
salmon: 16416882,
1810
sandybrown: 16032864,
1811
seagreen: 3050327,
1812
seashell: 16774638,
1813
sienna: 10506797,
1814
silver: 12632256,
1815
skyblue: 8900331,
1816
slateblue: 6970061,
1817
slategray: 7372944,
1818
slategrey: 7372944,
1819
snow: 16775930,
1820
springgreen: 65407,
1821
steelblue: 4620980,
1822
tan: 13808780,
1823
teal: 32896,
1824
thistle: 14204888,
1825
tomato: 16737095,
1826
turquoise: 4251856,
1827
violet: 15631086,
1828
wheat: 16113331,
1829
white: 16777215,
1830
whitesmoke: 16119285,
1831
yellow: 16776960,
1832
yellowgreen: 10145074
1833
});
1834
d3_rgb_names.forEach(function(key, value) {
1835
d3_rgb_names.set(key, d3_rgbNumber(value));
1836
});
1837
function d3_functor(v) {
1838
return typeof v === "function" ? v : function() {
1839
return v;
1840
};
1841
}
1842
d3.functor = d3_functor;
1843
function d3_identity(d) {
1844
return d;
1845
}
1846
d3.xhr = d3_xhrType(d3_identity);
1847
function d3_xhrType(response) {
1848
return function(url, mimeType, callback) {
1849
if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
1850
mimeType = null;
1851
return d3_xhr(url, mimeType, response, callback);
1852
};
1853
}
1854
function d3_xhr(url, mimeType, response, callback) {
1855
var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
1856
if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
1857
"onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1858
request.readyState > 3 && respond();
1859
};
1860
function respond() {
1861
var status = request.status, result;
1862
if (!status && request.responseText || status >= 200 && status < 300 || status === 304) {
1863
try {
1864
result = response.call(xhr, request);
1865
} catch (e) {
1866
dispatch.error.call(xhr, e);
1867
return;
1868
}
1869
dispatch.load.call(xhr, result);
1870
} else {
1871
dispatch.error.call(xhr, request);
1872
}
1873
}
1874
request.onprogress = function(event) {
1875
var o = d3.event;
1876
d3.event = event;
1877
try {
1878
dispatch.progress.call(xhr, request);
1879
} finally {
1880
d3.event = o;
1881
}
1882
};
1883
xhr.header = function(name, value) {
1884
name = (name + "").toLowerCase();
1885
if (arguments.length < 2) return headers[name];
1886
if (value == null) delete headers[name]; else headers[name] = value + "";
1887
return xhr;
1888
};
1889
xhr.mimeType = function(value) {
1890
if (!arguments.length) return mimeType;
1891
mimeType = value == null ? null : value + "";
1892
return xhr;
1893
};
1894
xhr.responseType = function(value) {
1895
if (!arguments.length) return responseType;
1896
responseType = value;
1897
return xhr;
1898
};
1899
xhr.response = function(value) {
1900
response = value;
1901
return xhr;
1902
};
1903
[ "get", "post" ].forEach(function(method) {
1904
xhr[method] = function() {
1905
return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
1906
};
1907
});
1908
xhr.send = function(method, data, callback) {
1909
if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
1910
request.open(method, url, true);
1911
if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
1912
if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
1913
if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
1914
if (responseType != null) request.responseType = responseType;
1915
if (callback != null) xhr.on("error", callback).on("load", function(request) {
1916
callback(null, request);
1917
});
1918
dispatch.beforesend.call(xhr, request);
1919
request.send(data == null ? null : data);
1920
return xhr;
1921
};
1922
xhr.abort = function() {
1923
request.abort();
1924
return xhr;
1925
};
1926
d3.rebind(xhr, dispatch, "on");
1927
return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
1928
}
1929
function d3_xhr_fixCallback(callback) {
1930
return callback.length === 1 ? function(error, request) {
1931
callback(error == null ? request : null);
1932
} : callback;
1933
}
1934
d3.dsv = function(delimiter, mimeType) {
1935
var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
1936
function dsv(url, row, callback) {
1937
if (arguments.length < 3) callback = row, row = null;
1938
var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
1939
xhr.row = function(_) {
1940
return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
1941
};
1942
return xhr;
1943
}
1944
function response(request) {
1945
return dsv.parse(request.responseText);
1946
}
1947
function typedResponse(f) {
1948
return function(request) {
1949
return dsv.parse(request.responseText, f);
1950
};
1951
}
1952
dsv.parse = function(text, f) {
1953
var o;
1954
return dsv.parseRows(text, function(row, i) {
1955
if (o) return o(row, i - 1);
1956
var a = new Function("d", "return {" + row.map(function(name, i) {
1957
return JSON.stringify(name) + ": d[" + i + "]";
1958
}).join(",") + "}");
1959
o = f ? function(row, i) {
1960
return f(a(row), i);
1961
} : a;
1962
});
1963
};
1964
dsv.parseRows = function(text, f) {
1965
var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
1966
function token() {
1967
if (I >= N) return EOF;
1968
if (eol) return eol = false, EOL;
1969
var j = I;
1970
if (text.charCodeAt(j) === 34) {
1971
var i = j;
1972
while (i++ < N) {
1973
if (text.charCodeAt(i) === 34) {
1974
if (text.charCodeAt(i + 1) !== 34) break;
1975
++i;
1976
}
1977
}
1978
I = i + 2;
1979
var c = text.charCodeAt(i + 1);
1980
if (c === 13) {
1981
eol = true;
1982
if (text.charCodeAt(i + 2) === 10) ++I;
1983
} else if (c === 10) {
1984
eol = true;
1985
}
1986
return text.substring(j + 1, i).replace(/""/g, '"');
1987
}
1988
while (I < N) {
1989
var c = text.charCodeAt(I++), k = 1;
1990
if (c === 10) eol = true; else if (c === 13) {
1991
eol = true;
1992
if (text.charCodeAt(I) === 10) ++I, ++k;
1993
} else if (c !== delimiterCode) continue;
1994
return text.substring(j, I - k);
1995
}
1996
return text.substring(j);
1997
}
1998
while ((t = token()) !== EOF) {
1999
var a = [];
2000
while (t !== EOL && t !== EOF) {
2001
a.push(t);
2002
t = token();
2003
}
2004
if (f && !(a = f(a, n++))) continue;
2005
rows.push(a);
2006
}
2007
return rows;
2008
};
2009
dsv.format = function(rows) {
2010
if (Array.isArray(rows[0])) return dsv.formatRows(rows);
2011
var fieldSet = new d3_Set(), fields = [];
2012
rows.forEach(function(row) {
2013
for (var field in row) {
2014
if (!fieldSet.has(field)) {
2015
fields.push(fieldSet.add(field));
2016
}
2017
}
2018
});
2019
return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
2020
return fields.map(function(field) {
2021
return formatValue(row[field]);
2022
}).join(delimiter);
2023
})).join("\n");
2024
};
2025
dsv.formatRows = function(rows) {
2026
return rows.map(formatRow).join("\n");
2027
};
2028
function formatRow(row) {
2029
return row.map(formatValue).join(delimiter);
2030
}
2031
function formatValue(text) {
2032
return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
2033
}
2034
return dsv;
2035
};
2036
d3.csv = d3.dsv(",", "text/csv");
2037
d3.tsv = d3.dsv(" ", "text/tab-separated-values");
2038
d3.touch = function(container, touches, identifier) {
2039
if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
2040
if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
2041
if ((touch = touches[i]).identifier === identifier) {
2042
return d3_mousePoint(container, touch);
2043
}
2044
}
2045
};
2046
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) {
2047
setTimeout(callback, 17);
2048
};
2049
d3.timer = function(callback, delay, then) {
2050
var n = arguments.length;
2051
if (n < 2) delay = 0;
2052
if (n < 3) then = Date.now();
2053
var time = then + delay, timer = {
2054
c: callback,
2055
t: time,
2056
f: false,
2057
n: null
2058
};
2059
if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
2060
d3_timer_queueTail = timer;
2061
if (!d3_timer_interval) {
2062
d3_timer_timeout = clearTimeout(d3_timer_timeout);
2063
d3_timer_interval = 1;
2064
d3_timer_frame(d3_timer_step);
2065
}
2066
};
2067
function d3_timer_step() {
2068
var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
2069
if (delay > 24) {
2070
if (isFinite(delay)) {
2071
clearTimeout(d3_timer_timeout);
2072
d3_timer_timeout = setTimeout(d3_timer_step, delay);
2073
}
2074
d3_timer_interval = 0;
2075
} else {
2076
d3_timer_interval = 1;
2077
d3_timer_frame(d3_timer_step);
2078
}
2079
}
2080
d3.timer.flush = function() {
2081
d3_timer_mark();
2082
d3_timer_sweep();
2083
};
2084
function d3_timer_mark() {
2085
var now = Date.now();
2086
d3_timer_active = d3_timer_queueHead;
2087
while (d3_timer_active) {
2088
if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
2089
d3_timer_active = d3_timer_active.n;
2090
}
2091
return now;
2092
}
2093
function d3_timer_sweep() {
2094
var t0, t1 = d3_timer_queueHead, time = Infinity;
2095
while (t1) {
2096
if (t1.f) {
2097
t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2098
} else {
2099
if (t1.t < time) time = t1.t;
2100
t1 = (t0 = t1).n;
2101
}
2102
}
2103
d3_timer_queueTail = t0;
2104
return time;
2105
}
2106
function d3_format_precision(x, p) {
2107
return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
2108
}
2109
d3.round = function(x, n) {
2110
return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2111
};
2112
var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
2113
d3.formatPrefix = function(value, precision) {
2114
var i = 0;
2115
if (value) {
2116
if (value < 0) value *= -1;
2117
if (precision) value = d3.round(value, d3_format_precision(value, precision));
2118
i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
2119
i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
2120
}
2121
return d3_formatPrefixes[8 + i / 3];
2122
};
2123
function d3_formatPrefix(d, i) {
2124
var k = Math.pow(10, abs(8 - i) * 3);
2125
return {
2126
scale: i > 8 ? function(d) {
2127
return d / k;
2128
} : function(d) {
2129
return d * k;
2130
},
2131
symbol: d
2132
};
2133
}
2134
function d3_locale_numberFormat(locale) {
2135
var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping ? function(value) {
2136
var i = value.length, t = [], j = 0, g = locale_grouping[0];
2137
while (i > 0 && g > 0) {
2138
t.push(value.substring(i -= g, i + g));
2139
g = locale_grouping[j = (j + 1) % locale_grouping.length];
2140
}
2141
return t.reverse().join(locale_thousands);
2142
} : d3_identity;
2143
return function(specifier) {
2144
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;
2145
if (precision) precision = +precision.substring(1);
2146
if (zfill || fill === "0" && align === "=") {
2147
zfill = fill = "0";
2148
align = "=";
2149
if (comma) width -= Math.floor((width - 1) / 4);
2150
}
2151
switch (type) {
2152
case "n":
2153
comma = true;
2154
type = "g";
2155
break;
2156
2157
case "%":
2158
scale = 100;
2159
suffix = "%";
2160
type = "f";
2161
break;
2162
2163
case "p":
2164
scale = 100;
2165
suffix = "%";
2166
type = "r";
2167
break;
2168
2169
case "b":
2170
case "o":
2171
case "x":
2172
case "X":
2173
if (symbol === "#") prefix = "0" + type.toLowerCase();
2174
2175
case "c":
2176
case "d":
2177
integer = true;
2178
precision = 0;
2179
break;
2180
2181
case "s":
2182
scale = -1;
2183
type = "r";
2184
break;
2185
}
2186
if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
2187
if (type == "r" && !precision) type = "g";
2188
if (precision != null) {
2189
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));
2190
}
2191
type = d3_format_types.get(type) || d3_format_typeDefault;
2192
var zcomma = zfill && comma;
2193
return function(value) {
2194
var fullSuffix = suffix;
2195
if (integer && value % 1) return "";
2196
var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
2197
if (scale < 0) {
2198
var unit = d3.formatPrefix(value, precision);
2199
value = unit.scale(value);
2200
fullSuffix = unit.symbol + suffix;
2201
} else {
2202
value *= scale;
2203
}
2204
value = type(value, precision);
2205
var i = value.lastIndexOf("."), before = i < 0 ? value : value.substring(0, i), after = i < 0 ? "" : locale_decimal + value.substring(i + 1);
2206
if (!zfill && comma) before = formatGroup(before);
2207
var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
2208
if (zcomma) before = formatGroup(padding + before);
2209
negative += prefix;
2210
value = before + after;
2211
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;
2212
};
2213
};
2214
}
2215
var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
2216
var d3_format_types = d3.map({
2217
b: function(x) {
2218
return x.toString(2);
2219
},
2220
c: function(x) {
2221
return String.fromCharCode(x);
2222
},
2223
o: function(x) {
2224
return x.toString(8);
2225
},
2226
x: function(x) {
2227
return x.toString(16);
2228
},
2229
X: function(x) {
2230
return x.toString(16).toUpperCase();
2231
},
2232
g: function(x, p) {
2233
return x.toPrecision(p);
2234
},
2235
e: function(x, p) {
2236
return x.toExponential(p);
2237
},
2238
f: function(x, p) {
2239
return x.toFixed(p);
2240
},
2241
r: function(x, p) {
2242
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))));
2243
}
2244
});
2245
function d3_format_typeDefault(x) {
2246
return x + "";
2247
}
2248
var d3_time = d3.time = {}, d3_date = Date;
2249
function d3_date_utc() {
2250
this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2251
}
2252
d3_date_utc.prototype = {
2253
getDate: function() {
2254
return this._.getUTCDate();
2255
},
2256
getDay: function() {
2257
return this._.getUTCDay();
2258
},
2259
getFullYear: function() {
2260
return this._.getUTCFullYear();
2261
},
2262
getHours: function() {
2263
return this._.getUTCHours();
2264
},
2265
getMilliseconds: function() {
2266
return this._.getUTCMilliseconds();
2267
},
2268
getMinutes: function() {
2269
return this._.getUTCMinutes();
2270
},
2271
getMonth: function() {
2272
return this._.getUTCMonth();
2273
},
2274
getSeconds: function() {
2275
return this._.getUTCSeconds();
2276
},
2277
getTime: function() {
2278
return this._.getTime();
2279
},
2280
getTimezoneOffset: function() {
2281
return 0;
2282
},
2283
valueOf: function() {
2284
return this._.valueOf();
2285
},
2286
setDate: function() {
2287
d3_time_prototype.setUTCDate.apply(this._, arguments);
2288
},
2289
setDay: function() {
2290
d3_time_prototype.setUTCDay.apply(this._, arguments);
2291
},
2292
setFullYear: function() {
2293
d3_time_prototype.setUTCFullYear.apply(this._, arguments);
2294
},
2295
setHours: function() {
2296
d3_time_prototype.setUTCHours.apply(this._, arguments);
2297
},
2298
setMilliseconds: function() {
2299
d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
2300
},
2301
setMinutes: function() {
2302
d3_time_prototype.setUTCMinutes.apply(this._, arguments);
2303
},
2304
setMonth: function() {
2305
d3_time_prototype.setUTCMonth.apply(this._, arguments);
2306
},
2307
setSeconds: function() {
2308
d3_time_prototype.setUTCSeconds.apply(this._, arguments);
2309
},
2310
setTime: function() {
2311
d3_time_prototype.setTime.apply(this._, arguments);
2312
}
2313
};
2314
var d3_time_prototype = Date.prototype;
2315
function d3_time_interval(local, step, number) {
2316
function round(date) {
2317
var d0 = local(date), d1 = offset(d0, 1);
2318
return date - d0 < d1 - date ? d0 : d1;
2319
}
2320
function ceil(date) {
2321
step(date = local(new d3_date(date - 1)), 1);
2322
return date;
2323
}
2324
function offset(date, k) {
2325
step(date = new d3_date(+date), k);
2326
return date;
2327
}
2328
function range(t0, t1, dt) {
2329
var time = ceil(t0), times = [];
2330
if (dt > 1) {
2331
while (time < t1) {
2332
if (!(number(time) % dt)) times.push(new Date(+time));
2333
step(time, 1);
2334
}
2335
} else {
2336
while (time < t1) times.push(new Date(+time)), step(time, 1);
2337
}
2338
return times;
2339
}
2340
function range_utc(t0, t1, dt) {
2341
try {
2342
d3_date = d3_date_utc;
2343
var utc = new d3_date_utc();
2344
utc._ = t0;
2345
return range(utc, t1, dt);
2346
} finally {
2347
d3_date = Date;
2348
}
2349
}
2350
local.floor = local;
2351
local.round = round;
2352
local.ceil = ceil;
2353
local.offset = offset;
2354
local.range = range;
2355
var utc = local.utc = d3_time_interval_utc(local);
2356
utc.floor = utc;
2357
utc.round = d3_time_interval_utc(round);
2358
utc.ceil = d3_time_interval_utc(ceil);
2359
utc.offset = d3_time_interval_utc(offset);
2360
utc.range = range_utc;
2361
return local;
2362
}
2363
function d3_time_interval_utc(method) {
2364
return function(date, k) {
2365
try {
2366
d3_date = d3_date_utc;
2367
var utc = new d3_date_utc();
2368
utc._ = date;
2369
return method(utc, k)._;
2370
} finally {
2371
d3_date = Date;
2372
}
2373
};
2374
}
2375
d3_time.year = d3_time_interval(function(date) {
2376
date = d3_time.day(date);
2377
date.setMonth(0, 1);
2378
return date;
2379
}, function(date, offset) {
2380
date.setFullYear(date.getFullYear() + offset);
2381
}, function(date) {
2382
return date.getFullYear();
2383
});
2384
d3_time.years = d3_time.year.range;
2385
d3_time.years.utc = d3_time.year.utc.range;
2386
d3_time.day = d3_time_interval(function(date) {
2387
var day = new d3_date(2e3, 0);
2388
day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
2389
return day;
2390
}, function(date, offset) {
2391
date.setDate(date.getDate() + offset);
2392
}, function(date) {
2393
return date.getDate() - 1;
2394
});
2395
d3_time.days = d3_time.day.range;
2396
d3_time.days.utc = d3_time.day.utc.range;
2397
d3_time.dayOfYear = function(date) {
2398
var year = d3_time.year(date);
2399
return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2400
};
2401
[ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
2402
i = 7 - i;
2403
var interval = d3_time[day] = d3_time_interval(function(date) {
2404
(date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
2405
return date;
2406
}, function(date, offset) {
2407
date.setDate(date.getDate() + Math.floor(offset) * 7);
2408
}, function(date) {
2409
var day = d3_time.year(date).getDay();
2410
return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
2411
});
2412
d3_time[day + "s"] = interval.range;
2413
d3_time[day + "s"].utc = interval.utc.range;
2414
d3_time[day + "OfYear"] = function(date) {
2415
var day = d3_time.year(date).getDay();
2416
return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
2417
};
2418
});
2419
d3_time.week = d3_time.sunday;
2420
d3_time.weeks = d3_time.sunday.range;
2421
d3_time.weeks.utc = d3_time.sunday.utc.range;
2422
d3_time.weekOfYear = d3_time.sundayOfYear;
2423
function d3_locale_timeFormat(locale) {
2424
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;
2425
function d3_time_format(template) {
2426
var n = template.length;
2427
function format(date) {
2428
var string = [], i = -1, j = 0, c, p, f;
2429
while (++i < n) {
2430
if (template.charCodeAt(i) === 37) {
2431
string.push(template.substring(j, i));
2432
if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
2433
if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
2434
string.push(c);
2435
j = i + 1;
2436
}
2437
}
2438
string.push(template.substring(j, i));
2439
return string.join("");
2440
}
2441
format.parse = function(string) {
2442
var d = {
2443
y: 1900,
2444
m: 0,
2445
d: 1,
2446
H: 0,
2447
M: 0,
2448
S: 0,
2449
L: 0,
2450
Z: null
2451
}, i = d3_time_parse(d, template, string, 0);
2452
if (i != string.length) return null;
2453
if ("p" in d) d.H = d.H % 12 + d.p * 12;
2454
var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
2455
if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
2456
date.setFullYear(d.y, 0, 1);
2457
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);
2458
} else date.setFullYear(d.y, d.m, d.d);
2459
date.setHours(d.H + Math.floor(d.Z / 100), d.M + d.Z % 100, d.S, d.L);
2460
return localZ ? date._ : date;
2461
};
2462
format.toString = function() {
2463
return template;
2464
};
2465
return format;
2466
}
2467
function d3_time_parse(date, template, string, j) {
2468
var c, p, t, i = 0, n = template.length, m = string.length;
2469
while (i < n) {
2470
if (j >= m) return -1;
2471
c = template.charCodeAt(i++);
2472
if (c === 37) {
2473
t = template.charAt(i++);
2474
p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
2475
if (!p || (j = p(date, string, j)) < 0) return -1;
2476
} else if (c != string.charCodeAt(j++)) {
2477
return -1;
2478
}
2479
}
2480
return j;
2481
}
2482
d3_time_format.utc = function(template) {
2483
var local = d3_time_format(template);
2484
function format(date) {
2485
try {
2486
d3_date = d3_date_utc;
2487
var utc = new d3_date();
2488
utc._ = date;
2489
return local(utc);
2490
} finally {
2491
d3_date = Date;
2492
}
2493
}
2494
format.parse = function(string) {
2495
try {
2496
d3_date = d3_date_utc;
2497
var date = local.parse(string);
2498
return date && date._;
2499
} finally {
2500
d3_date = Date;
2501
}
2502
};
2503
format.toString = local.toString;
2504
return format;
2505
};
2506
d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
2507
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);
2508
locale_periods.forEach(function(p, i) {
2509
d3_time_periodLookup.set(p.toLowerCase(), i);
2510
});
2511
var d3_time_formats = {
2512
a: function(d) {
2513
return locale_shortDays[d.getDay()];
2514
},
2515
A: function(d) {
2516
return locale_days[d.getDay()];
2517
},
2518
b: function(d) {
2519
return locale_shortMonths[d.getMonth()];
2520
},
2521
B: function(d) {
2522
return locale_months[d.getMonth()];
2523
},
2524
c: d3_time_format(locale_dateTime),
2525
d: function(d, p) {
2526
return d3_time_formatPad(d.getDate(), p, 2);
2527
},
2528
e: function(d, p) {
2529
return d3_time_formatPad(d.getDate(), p, 2);
2530
},
2531
H: function(d, p) {
2532
return d3_time_formatPad(d.getHours(), p, 2);
2533
},
2534
I: function(d, p) {
2535
return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
2536
},
2537
j: function(d, p) {
2538
return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
2539
},
2540
L: function(d, p) {
2541
return d3_time_formatPad(d.getMilliseconds(), p, 3);
2542
},
2543
m: function(d, p) {
2544
return d3_time_formatPad(d.getMonth() + 1, p, 2);
2545
},
2546
M: function(d, p) {
2547
return d3_time_formatPad(d.getMinutes(), p, 2);
2548
},
2549
p: function(d) {
2550
return locale_periods[+(d.getHours() >= 12)];
2551
},
2552
S: function(d, p) {
2553
return d3_time_formatPad(d.getSeconds(), p, 2);
2554
},
2555
U: function(d, p) {
2556
return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
2557
},
2558
w: function(d) {
2559
return d.getDay();
2560
},
2561
W: function(d, p) {
2562
return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
2563
},
2564
x: d3_time_format(locale_date),
2565
X: d3_time_format(locale_time),
2566
y: function(d, p) {
2567
return d3_time_formatPad(d.getFullYear() % 100, p, 2);
2568
},
2569
Y: function(d, p) {
2570
return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
2571
},
2572
Z: d3_time_zone,
2573
"%": function() {
2574
return "%";
2575
}
2576
};
2577
var d3_time_parsers = {
2578
a: d3_time_parseWeekdayAbbrev,
2579
A: d3_time_parseWeekday,
2580
b: d3_time_parseMonthAbbrev,
2581
B: d3_time_parseMonth,
2582
c: d3_time_parseLocaleFull,
2583
d: d3_time_parseDay,
2584
e: d3_time_parseDay,
2585
H: d3_time_parseHour24,
2586
I: d3_time_parseHour24,
2587
j: d3_time_parseDayOfYear,
2588
L: d3_time_parseMilliseconds,
2589
m: d3_time_parseMonthNumber,
2590
M: d3_time_parseMinutes,
2591
p: d3_time_parseAmPm,
2592
S: d3_time_parseSeconds,
2593
U: d3_time_parseWeekNumberSunday,
2594
w: d3_time_parseWeekdayNumber,
2595
W: d3_time_parseWeekNumberMonday,
2596
x: d3_time_parseLocaleDate,
2597
X: d3_time_parseLocaleTime,
2598
y: d3_time_parseYear,
2599
Y: d3_time_parseFullYear,
2600
Z: d3_time_parseZone,
2601
"%": d3_time_parseLiteralPercent
2602
};
2603
function d3_time_parseWeekdayAbbrev(date, string, i) {
2604
d3_time_dayAbbrevRe.lastIndex = 0;
2605
var n = d3_time_dayAbbrevRe.exec(string.substring(i));
2606
return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2607
}
2608
function d3_time_parseWeekday(date, string, i) {
2609
d3_time_dayRe.lastIndex = 0;
2610
var n = d3_time_dayRe.exec(string.substring(i));
2611
return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2612
}
2613
function d3_time_parseMonthAbbrev(date, string, i) {
2614
d3_time_monthAbbrevRe.lastIndex = 0;
2615
var n = d3_time_monthAbbrevRe.exec(string.substring(i));
2616
return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2617
}
2618
function d3_time_parseMonth(date, string, i) {
2619
d3_time_monthRe.lastIndex = 0;
2620
var n = d3_time_monthRe.exec(string.substring(i));
2621
return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2622
}
2623
function d3_time_parseLocaleFull(date, string, i) {
2624
return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2625
}
2626
function d3_time_parseLocaleDate(date, string, i) {
2627
return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2628
}
2629
function d3_time_parseLocaleTime(date, string, i) {
2630
return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2631
}
2632
function d3_time_parseAmPm(date, string, i) {
2633
var n = d3_time_periodLookup.get(string.substring(i, i += 2).toLowerCase());
2634
return n == null ? -1 : (date.p = n, i);
2635
}
2636
return d3_time_format;
2637
}
2638
var d3_time_formatPads = {
2639
"-": "",
2640
_: " ",
2641
"0": "0"
2642
}, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
2643
function d3_time_formatPad(value, fill, width) {
2644
var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
2645
return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2646
}
2647
function d3_time_formatRe(names) {
2648
return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2649
}
2650
function d3_time_formatLookup(names) {
2651
var map = new d3_Map(), i = -1, n = names.length;
2652
while (++i < n) map.set(names[i].toLowerCase(), i);
2653
return map;
2654
}
2655
function d3_time_parseWeekdayNumber(date, string, i) {
2656
d3_time_numberRe.lastIndex = 0;
2657
var n = d3_time_numberRe.exec(string.substring(i, i + 1));
2658
return n ? (date.w = +n[0], i + n[0].length) : -1;
2659
}
2660
function d3_time_parseWeekNumberSunday(date, string, i) {
2661
d3_time_numberRe.lastIndex = 0;
2662
var n = d3_time_numberRe.exec(string.substring(i));
2663
return n ? (date.U = +n[0], i + n[0].length) : -1;
2664
}
2665
function d3_time_parseWeekNumberMonday(date, string, i) {
2666
d3_time_numberRe.lastIndex = 0;
2667
var n = d3_time_numberRe.exec(string.substring(i));
2668
return n ? (date.W = +n[0], i + n[0].length) : -1;
2669
}
2670
function d3_time_parseFullYear(date, string, i) {
2671
d3_time_numberRe.lastIndex = 0;
2672
var n = d3_time_numberRe.exec(string.substring(i, i + 4));
2673
return n ? (date.y = +n[0], i + n[0].length) : -1;
2674
}
2675
function d3_time_parseYear(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.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
2679
}
2680
function d3_time_parseZone(date, string, i) {
2681
return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = -string,
2682
i + 5) : -1;
2683
}
2684
function d3_time_expandYear(d) {
2685
return d + (d > 68 ? 1900 : 2e3);
2686
}
2687
function d3_time_parseMonthNumber(date, string, i) {
2688
d3_time_numberRe.lastIndex = 0;
2689
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2690
return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
2691
}
2692
function d3_time_parseDay(date, string, i) {
2693
d3_time_numberRe.lastIndex = 0;
2694
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2695
return n ? (date.d = +n[0], i + n[0].length) : -1;
2696
}
2697
function d3_time_parseDayOfYear(date, string, i) {
2698
d3_time_numberRe.lastIndex = 0;
2699
var n = d3_time_numberRe.exec(string.substring(i, i + 3));
2700
return n ? (date.j = +n[0], i + n[0].length) : -1;
2701
}
2702
function d3_time_parseHour24(date, string, i) {
2703
d3_time_numberRe.lastIndex = 0;
2704
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2705
return n ? (date.H = +n[0], i + n[0].length) : -1;
2706
}
2707
function d3_time_parseMinutes(date, string, i) {
2708
d3_time_numberRe.lastIndex = 0;
2709
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2710
return n ? (date.M = +n[0], i + n[0].length) : -1;
2711
}
2712
function d3_time_parseSeconds(date, string, i) {
2713
d3_time_numberRe.lastIndex = 0;
2714
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2715
return n ? (date.S = +n[0], i + n[0].length) : -1;
2716
}
2717
function d3_time_parseMilliseconds(date, string, i) {
2718
d3_time_numberRe.lastIndex = 0;
2719
var n = d3_time_numberRe.exec(string.substring(i, i + 3));
2720
return n ? (date.L = +n[0], i + n[0].length) : -1;
2721
}
2722
function d3_time_zone(d) {
2723
var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(abs(z) / 60), zm = abs(z) % 60;
2724
return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
2725
}
2726
function d3_time_parseLiteralPercent(date, string, i) {
2727
d3_time_percentRe.lastIndex = 0;
2728
var n = d3_time_percentRe.exec(string.substring(i, i + 1));
2729
return n ? i + n[0].length : -1;
2730
}
2731
function d3_time_formatMulti(formats) {
2732
var n = formats.length, i = -1;
2733
while (++i < n) formats[i][0] = this(formats[i][0]);
2734
return function(date) {
2735
var i = 0, f = formats[i];
2736
while (!f[1](date)) f = formats[++i];
2737
return f[0](date);
2738
};
2739
}
2740
d3.locale = function(locale) {
2741
return {
2742
numberFormat: d3_locale_numberFormat(locale),
2743
timeFormat: d3_locale_timeFormat(locale)
2744
};
2745
};
2746
var d3_locale_enUS = d3.locale({
2747
decimal: ".",
2748
thousands: ",",
2749
grouping: [ 3 ],
2750
currency: [ "$", "" ],
2751
dateTime: "%a %b %e %X %Y",
2752
date: "%m/%d/%Y",
2753
time: "%H:%M:%S",
2754
periods: [ "AM", "PM" ],
2755
days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
2756
shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
2757
months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
2758
shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
2759
});
2760
d3.format = d3_locale_enUS.numberFormat;
2761
d3.geo = {};
2762
function d3_adder() {}
2763
d3_adder.prototype = {
2764
s: 0,
2765
t: 0,
2766
add: function(y) {
2767
d3_adderSum(y, this.t, d3_adderTemp);
2768
d3_adderSum(d3_adderTemp.s, this.s, this);
2769
if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
2770
},
2771
reset: function() {
2772
this.s = this.t = 0;
2773
},
2774
valueOf: function() {
2775
return this.s;
2776
}
2777
};
2778
var d3_adderTemp = new d3_adder();
2779
function d3_adderSum(a, b, o) {
2780
var x = o.s = a + b, bv = x - a, av = x - bv;
2781
o.t = a - av + (b - bv);
2782
}
2783
d3.geo.stream = function(object, listener) {
2784
if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2785
d3_geo_streamObjectType[object.type](object, listener);
2786
} else {
2787
d3_geo_streamGeometry(object, listener);
2788
}
2789
};
2790
function d3_geo_streamGeometry(geometry, listener) {
2791
if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2792
d3_geo_streamGeometryType[geometry.type](geometry, listener);
2793
}
2794
}
2795
var d3_geo_streamObjectType = {
2796
Feature: function(feature, listener) {
2797
d3_geo_streamGeometry(feature.geometry, listener);
2798
},
2799
FeatureCollection: function(object, listener) {
2800
var features = object.features, i = -1, n = features.length;
2801
while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
2802
}
2803
};
2804
var d3_geo_streamGeometryType = {
2805
Sphere: function(object, listener) {
2806
listener.sphere();
2807
},
2808
Point: function(object, listener) {
2809
object = object.coordinates;
2810
listener.point(object[0], object[1], object[2]);
2811
},
2812
MultiPoint: function(object, listener) {
2813
var coordinates = object.coordinates, i = -1, n = coordinates.length;
2814
while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
2815
},
2816
LineString: function(object, listener) {
2817
d3_geo_streamLine(object.coordinates, listener, 0);
2818
},
2819
MultiLineString: function(object, listener) {
2820
var coordinates = object.coordinates, i = -1, n = coordinates.length;
2821
while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
2822
},
2823
Polygon: function(object, listener) {
2824
d3_geo_streamPolygon(object.coordinates, listener);
2825
},
2826
MultiPolygon: function(object, listener) {
2827
var coordinates = object.coordinates, i = -1, n = coordinates.length;
2828
while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
2829
},
2830
GeometryCollection: function(object, listener) {
2831
var geometries = object.geometries, i = -1, n = geometries.length;
2832
while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
2833
}
2834
};
2835
function d3_geo_streamLine(coordinates, listener, closed) {
2836
var i = -1, n = coordinates.length - closed, coordinate;
2837
listener.lineStart();
2838
while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
2839
listener.lineEnd();
2840
}
2841
function d3_geo_streamPolygon(coordinates, listener) {
2842
var i = -1, n = coordinates.length;
2843
listener.polygonStart();
2844
while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
2845
listener.polygonEnd();
2846
}
2847
d3.geo.area = function(object) {
2848
d3_geo_areaSum = 0;
2849
d3.geo.stream(object, d3_geo_area);
2850
return d3_geo_areaSum;
2851
};
2852
var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
2853
var d3_geo_area = {
2854
sphere: function() {
2855
d3_geo_areaSum += 4 * π;
2856
},
2857
point: d3_noop,
2858
lineStart: d3_noop,
2859
lineEnd: d3_noop,
2860
polygonStart: function() {
2861
d3_geo_areaRingSum.reset();
2862
d3_geo_area.lineStart = d3_geo_areaRingStart;
2863
},
2864
polygonEnd: function() {
2865
var area = 2 * d3_geo_areaRingSum;
2866
d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2867
d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2868
}
2869
};
2870
function d3_geo_areaRingStart() {
2871
var λ00, φ00, λ0, cosφ0, sinφ0;
2872
d3_geo_area.point = function(λ, φ) {
2873
d3_geo_area.point = nextPoint;
2874
λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
2875
sinφ0 = Math.sin(φ);
2876
};
2877
function nextPoint(λ, φ) {
2878
λ *= d3_radians;
2879
φ = φ * d3_radians / 2 + π / 4;
2880
var = λ - λ0, sdλ = >= 0 ? 1 : -1, adλ = sdλ * , cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
2881
d3_geo_areaRingSum.add(Math.atan2(v, u));
2882
λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
2883
}
2884
d3_geo_area.lineEnd = function() {
2885
nextPoint(λ00, φ00);
2886
};
2887
}
2888
function d3_geo_cartesian(spherical) {
2889
var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2890
return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2891
}
2892
function d3_geo_cartesianDot(a, b) {
2893
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2894
}
2895
function d3_geo_cartesianCross(a, b) {
2896
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] ];
2897
}
2898
function d3_geo_cartesianAdd(a, b) {
2899
a[0] += b[0];
2900
a[1] += b[1];
2901
a[2] += b[2];
2902
}
2903
function d3_geo_cartesianScale(vector, k) {
2904
return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2905
}
2906
function d3_geo_cartesianNormalize(d) {
2907
var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2908
d[0] /= l;
2909
d[1] /= l;
2910
d[2] /= l;
2911
}
2912
function d3_geo_spherical(cartesian) {
2913
return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
2914
}
2915
function d3_geo_sphericalEqual(a, b) {
2916
return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
2917
}
2918
d3.geo.bounds = function() {
2919
var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
2920
var bound = {
2921
point: point,
2922
lineStart: lineStart,
2923
lineEnd: lineEnd,
2924
polygonStart: function() {
2925
bound.point = ringPoint;
2926
bound.lineStart = ringStart;
2927
bound.lineEnd = ringEnd;
2928
dλSum = 0;
2929
d3_geo_area.polygonStart();
2930
},
2931
polygonEnd: function() {
2932
d3_geo_area.polygonEnd();
2933
bound.point = point;
2934
bound.lineStart = lineStart;
2935
bound.lineEnd = lineEnd;
2936
if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
2937
range[0] = λ0, range[1] = λ1;
2938
}
2939
};
2940
function point(λ, φ) {
2941
ranges.push(range = [ λ0 = λ, λ1 = λ ]);
2942
if (φ < φ0) φ0 = φ;
2943
if (φ > φ1) φ1 = φ;
2944
}
2945
function linePoint(λ, φ) {
2946
var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
2947
if (p0) {
2948
var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
2949
d3_geo_cartesianNormalize(inflection);
2950
inflection = d3_geo_spherical(inflection);
2951
var = λ - λ_, s = > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs() > 180;
2952
if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
2953
var φi = inflection[1] * d3_degrees;
2954
if (φi > φ1) φ1 = φi;
2955
} else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
2956
var φi = -inflection[1] * d3_degrees;
2957
if (φi < φ0) φ0 = φi;
2958
} else {
2959
if (φ < φ0) φ0 = φ;
2960
if (φ > φ1) φ1 = φ;
2961
}
2962
if (antimeridian) {
2963
if (λ < λ_) {
2964
if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
2965
} else {
2966
if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
2967
}
2968
} else {
2969
if (λ1 >= λ0) {
2970
if (λ < λ0) λ0 = λ;
2971
if (λ > λ1) λ1 = λ;
2972
} else {
2973
if (λ > λ_) {
2974
if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
2975
} else {
2976
if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
2977
}
2978
}
2979
}
2980
} else {
2981
point(λ, φ);
2982
}
2983
p0 = p, λ_ = λ;
2984
}
2985
function lineStart() {
2986
bound.point = linePoint;
2987
}
2988
function lineEnd() {
2989
range[0] = λ0, range[1] = λ1;
2990
bound.point = point;
2991
p0 = null;
2992
}
2993
function ringPoint(λ, φ) {
2994
if (p0) {
2995
var = λ - λ_;
2996
dλSum += abs() > 180 ? + ( > 0 ? 360 : -360) : ;
2997
} else λ__ = λ, φ__ = φ;
2998
d3_geo_area.point(λ, φ);
2999
linePoint(λ, φ);
3000
}
3001
function ringStart() {
3002
d3_geo_area.lineStart();
3003
}
3004
function ringEnd() {
3005
ringPoint(λ__, φ__);
3006
d3_geo_area.lineEnd();
3007
if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
3008
range[0] = λ0, range[1] = λ1;
3009
p0 = null;
3010
}
3011
function angle(λ0, λ1) {
3012
return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
3013
}
3014
function compareRanges(a, b) {
3015
return a[0] - b[0];
3016
}
3017
function withinRange(x, range) {
3018
return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
3019
}
3020
return function(feature) {
3021
φ1 = λ1 = -(λ0 = φ0 = Infinity);
3022
ranges = [];
3023
d3.geo.stream(feature, bound);
3024
var n = ranges.length;
3025
if (n) {
3026
ranges.sort(compareRanges);
3027
for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
3028
b = ranges[i];
3029
if (withinRange(b[0], a) || withinRange(b[1], a)) {
3030
if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
3031
if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
3032
} else {
3033
merged.push(a = b);
3034
}
3035
}
3036
var best = -Infinity, ;
3037
for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
3038
b = merged[i];
3039
if (( = angle(a[1], b[0])) > best) best = , λ0 = b[0], λ1 = a[1];
3040
}
3041
}
3042
ranges = range = null;
3043
return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
3044
};
3045
}();
3046
d3.geo.centroid = function(object) {
3047
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;
3048
d3.geo.stream(object, d3_geo_centroid);
3049
var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
3050
if (m < ε2) {
3051
x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
3052
if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
3053
m = x * x + y * y + z * z;
3054
if (m < ε2) return [ NaN, NaN ];
3055
}
3056
return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
3057
};
3058
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;
3059
var d3_geo_centroid = {
3060
sphere: d3_noop,
3061
point: d3_geo_centroidPoint,
3062
lineStart: d3_geo_centroidLineStart,
3063
lineEnd: d3_geo_centroidLineEnd,
3064
polygonStart: function() {
3065
d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
3066
},
3067
polygonEnd: function() {
3068
d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
3069
}
3070
};
3071
function d3_geo_centroidPoint(λ, φ) {
3072
λ *= d3_radians;
3073
var cosφ = Math.cos(φ *= d3_radians);
3074
d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
3075
}
3076
function d3_geo_centroidPointXYZ(x, y, z) {
3077
++d3_geo_centroidW0;
3078
d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
3079
d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
3080
d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
3081
}
3082
function d3_geo_centroidLineStart() {
3083
var x0, y0, z0;
3084
d3_geo_centroid.point = function(λ, φ) {
3085
λ *= d3_radians;
3086
var cosφ = Math.cos(φ *= d3_radians);
3087
x0 = cosφ * Math.cos(λ);
3088
y0 = cosφ * Math.sin(λ);
3089
z0 = Math.sin(φ);
3090
d3_geo_centroid.point = nextPoint;
3091
d3_geo_centroidPointXYZ(x0, y0, z0);
3092
};
3093
function nextPoint(λ, φ) {
3094
λ *= d3_radians;
3095
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);
3096
d3_geo_centroidW1 += w;
3097
d3_geo_centroidX1 += w * (x0 + (x0 = x));
3098
d3_geo_centroidY1 += w * (y0 + (y0 = y));
3099
d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3100
d3_geo_centroidPointXYZ(x0, y0, z0);
3101
}
3102
}
3103
function d3_geo_centroidLineEnd() {
3104
d3_geo_centroid.point = d3_geo_centroidPoint;
3105
}
3106
function d3_geo_centroidRingStart() {
3107
var λ00, φ00, x0, y0, z0;
3108
d3_geo_centroid.point = function(λ, φ) {
3109
λ00 = λ, φ00 = φ;
3110
d3_geo_centroid.point = nextPoint;
3111
λ *= d3_radians;
3112
var cosφ = Math.cos(φ *= d3_radians);
3113
x0 = cosφ * Math.cos(λ);
3114
y0 = cosφ * Math.sin(λ);
3115
z0 = Math.sin(φ);
3116
d3_geo_centroidPointXYZ(x0, y0, z0);
3117
};
3118
d3_geo_centroid.lineEnd = function() {
3119
nextPoint(λ00, φ00);
3120
d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
3121
d3_geo_centroid.point = d3_geo_centroidPoint;
3122
};
3123
function nextPoint(λ, φ) {
3124
λ *= d3_radians;
3125
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);
3126
d3_geo_centroidX2 += v * cx;
3127
d3_geo_centroidY2 += v * cy;
3128
d3_geo_centroidZ2 += v * cz;
3129
d3_geo_centroidW1 += w;
3130
d3_geo_centroidX1 += w * (x0 + (x0 = x));
3131
d3_geo_centroidY1 += w * (y0 + (y0 = y));
3132
d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3133
d3_geo_centroidPointXYZ(x0, y0, z0);
3134
}
3135
}
3136
function d3_true() {
3137
return true;
3138
}
3139
function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
3140
var subject = [], clip = [];
3141
segments.forEach(function(segment) {
3142
if ((n = segment.length - 1) <= 0) return;
3143
var n, p0 = segment[0], p1 = segment[n];
3144
if (d3_geo_sphericalEqual(p0, p1)) {
3145
listener.lineStart();
3146
for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
3147
listener.lineEnd();
3148
return;
3149
}
3150
var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
3151
a.o = b;
3152
subject.push(a);
3153
clip.push(b);
3154
a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
3155
b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
3156
a.o = b;
3157
subject.push(a);
3158
clip.push(b);
3159
});
3160
clip.sort(compare);
3161
d3_geo_clipPolygonLinkCircular(subject);
3162
d3_geo_clipPolygonLinkCircular(clip);
3163
if (!subject.length) return;
3164
for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
3165
clip[i].e = entry = !entry;
3166
}
3167
var start = subject[0], points, point;
3168
while (1) {
3169
var current = start, isSubject = true;
3170
while (current.v) if ((current = current.n) === start) return;
3171
points = current.z;
3172
listener.lineStart();
3173
do {
3174
current.v = current.o.v = true;
3175
if (current.e) {
3176
if (isSubject) {
3177
for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
3178
} else {
3179
interpolate(current.x, current.n.x, 1, listener);
3180
}
3181
current = current.n;
3182
} else {
3183
if (isSubject) {
3184
points = current.p.z;
3185
for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
3186
} else {
3187
interpolate(current.x, current.p.x, -1, listener);
3188
}
3189
current = current.p;
3190
}
3191
current = current.o;
3192
points = current.z;
3193
isSubject = !isSubject;
3194
} while (!current.v);
3195
listener.lineEnd();
3196
}
3197
}
3198
function d3_geo_clipPolygonLinkCircular(array) {
3199
if (!(n = array.length)) return;
3200
var n, i = 0, a = array[0], b;
3201
while (++i < n) {
3202
a.n = b = array[i];
3203
b.p = a;
3204
a = b;
3205
}
3206
a.n = b = array[0];
3207
b.p = a;
3208
}
3209
function d3_geo_clipPolygonIntersection(point, points, other, entry) {
3210
this.x = point;
3211
this.z = points;
3212
this.o = other;
3213
this.e = entry;
3214
this.v = false;
3215
this.n = this.p = null;
3216
}
3217
function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
3218
return function(rotate, listener) {
3219
var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
3220
var clip = {
3221
point: point,
3222
lineStart: lineStart,
3223
lineEnd: lineEnd,
3224
polygonStart: function() {
3225
clip.point = pointRing;
3226
clip.lineStart = ringStart;
3227
clip.lineEnd = ringEnd;
3228
segments = [];
3229
polygon = [];
3230
},
3231
polygonEnd: function() {
3232
clip.point = point;
3233
clip.lineStart = lineStart;
3234
clip.lineEnd = lineEnd;
3235
segments = d3.merge(segments);
3236
var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
3237
if (segments.length) {
3238
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3239
d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
3240
} else if (clipStartInside) {
3241
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3242
listener.lineStart();
3243
interpolate(null, null, 1, listener);
3244
listener.lineEnd();
3245
}
3246
if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
3247
segments = polygon = null;
3248
},
3249
sphere: function() {
3250
listener.polygonStart();
3251
listener.lineStart();
3252
interpolate(null, null, 1, listener);
3253
listener.lineEnd();
3254
listener.polygonEnd();
3255
}
3256
};
3257
function point(λ, φ) {
3258
var point = rotate(λ, φ);
3259
if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
3260
}
3261
function pointLine(λ, φ) {
3262
var point = rotate(λ, φ);
3263
line.point(point[0], point[1]);
3264
}
3265
function lineStart() {
3266
clip.point = pointLine;
3267
line.lineStart();
3268
}
3269
function lineEnd() {
3270
clip.point = point;
3271
line.lineEnd();
3272
}
3273
var segments;
3274
var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
3275
function pointRing(λ, φ) {
3276
ring.push([ λ, φ ]);
3277
var point = rotate(λ, φ);
3278
ringListener.point(point[0], point[1]);
3279
}
3280
function ringStart() {
3281
ringListener.lineStart();
3282
ring = [];
3283
}
3284
function ringEnd() {
3285
pointRing(ring[0][0], ring[0][1]);
3286
ringListener.lineEnd();
3287
var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
3288
ring.pop();
3289
polygon.push(ring);
3290
ring = null;
3291
if (!n) return;
3292
if (clean & 1) {
3293
segment = ringSegments[0];
3294
var n = segment.length - 1, i = -1, point;
3295
if (n > 0) {
3296
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3297
listener.lineStart();
3298
while (++i < n) listener.point((point = segment[i])[0], point[1]);
3299
listener.lineEnd();
3300
}
3301
return;
3302
}
3303
if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
3304
segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
3305
}
3306
return clip;
3307
};
3308
}
3309
function d3_geo_clipSegmentLength1(segment) {
3310
return segment.length > 1;
3311
}
3312
function d3_geo_clipBufferListener() {
3313
var lines = [], line;
3314
return {
3315
lineStart: function() {
3316
lines.push(line = []);
3317
},
3318
point: function(λ, φ) {
3319
line.push([ λ, φ ]);
3320
},
3321
lineEnd: d3_noop,
3322
buffer: function() {
3323
var buffer = lines;
3324
lines = [];
3325
line = null;
3326
return buffer;
3327
},
3328
rejoin: function() {
3329
if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
3330
}
3331
};
3332
}
3333
function d3_geo_clipSort(a, b) {
3334
return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
3335
}
3336
function d3_geo_pointInPolygon(point, polygon) {
3337
var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
3338
d3_geo_areaRingSum.reset();
3339
for (var i = 0, n = polygon.length; i < n; ++i) {
3340
var ring = polygon[i], m = ring.length;
3341
if (!m) continue;
3342
var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
3343
while (true) {
3344
if (j === m) j = 0;
3345
point = ring[j];
3346
var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), = λ - λ0, sdλ = >= 0 ? 1 : -1, adλ = sdλ * , antimeridian = adλ > π, k = sinφ0 * sinφ;
3347
d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
3348
polarAngle += antimeridian ? + sdλ * τ : ;
3349
if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
3350
var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
3351
d3_geo_cartesianNormalize(arc);
3352
var intersection = d3_geo_cartesianCross(meridianNormal, arc);
3353
d3_geo_cartesianNormalize(intersection);
3354
var φarc = (antimeridian ^ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
3355
if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
3356
winding += antimeridian ^ >= 0 ? 1 : -1;
3357
}
3358
}
3359
if (!j++) break;
3360
λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
3361
}
3362
}
3363
return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
3364
}
3365
var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
3366
function d3_geo_clipAntimeridianLine(listener) {
3367
var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
3368
return {
3369
lineStart: function() {
3370
listener.lineStart();
3371
clean = 1;
3372
},
3373
point: function(λ1, φ1) {
3374
var sλ1 = λ1 > 0 ? π : -π, = abs(λ1 - λ0);
3375
if (abs( - π) < ε) {
3376
listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
3377
listener.point(sλ0, φ0);
3378
listener.lineEnd();
3379
listener.lineStart();
3380
listener.point(sλ1, φ0);
3381
listener.point(λ1, φ0);
3382
clean = 0;
3383
} else if (sλ0 !== sλ1 && >= π) {
3384
if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
3385
if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
3386
φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
3387
listener.point(sλ0, φ0);
3388
listener.lineEnd();
3389
listener.lineStart();
3390
listener.point(sλ1, φ0);
3391
clean = 0;
3392
}
3393
listener.point(λ0 = λ1, φ0 = φ1);
3394
sλ0 = sλ1;
3395
},
3396
lineEnd: function() {
3397
listener.lineEnd();
3398
λ0 = φ0 = NaN;
3399
},
3400
clean: function() {
3401
return 2 - clean;
3402
}
3403
};
3404
}
3405
function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
3406
var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
3407
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;
3408
}
3409
function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
3410
var φ;
3411
if (from == null) {
3412
φ = direction * halfπ;
3413
listener.point(-π, φ);
3414
listener.point(0, φ);
3415
listener.point(π, φ);
3416
listener.point(π, 0);
3417
listener.point(π, -φ);
3418
listener.point(0, -φ);
3419
listener.point(-π, -φ);
3420
listener.point(-π, 0);
3421
listener.point(-π, φ);
3422
} else if (abs(from[0] - to[0]) > ε) {
3423
var s = from[0] < to[0] ? π : -π;
3424
φ = direction * s / 2;
3425
listener.point(-s, φ);
3426
listener.point(0, φ);
3427
listener.point(s, φ);
3428
} else {
3429
listener.point(to[0], to[1]);
3430
}
3431
}
3432
function d3_geo_clipCircle(radius) {
3433
var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
3434
return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
3435
function visible(λ, φ) {
3436
return Math.cos(λ) * Math.cos(φ) > cr;
3437
}
3438
function clipLine(listener) {
3439
var point0, c0, v0, v00, clean;
3440
return {
3441
lineStart: function() {
3442
v00 = v0 = false;
3443
clean = 1;
3444
},
3445
point: function(λ, φ) {
3446
var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
3447
if (!point0 && (v00 = v0 = v)) listener.lineStart();
3448
if (v !== v0) {
3449
point2 = intersect(point0, point1);
3450
if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
3451
point1[0] += ε;
3452
point1[1] += ε;
3453
v = visible(point1[0], point1[1]);
3454
}
3455
}
3456
if (v !== v0) {
3457
clean = 0;
3458
if (v) {
3459
listener.lineStart();
3460
point2 = intersect(point1, point0);
3461
listener.point(point2[0], point2[1]);
3462
} else {
3463
point2 = intersect(point0, point1);
3464
listener.point(point2[0], point2[1]);
3465
listener.lineEnd();
3466
}
3467
point0 = point2;
3468
} else if (notHemisphere && point0 && smallRadius ^ v) {
3469
var t;
3470
if (!(c & c0) && (t = intersect(point1, point0, true))) {
3471
clean = 0;
3472
if (smallRadius) {
3473
listener.lineStart();
3474
listener.point(t[0][0], t[0][1]);
3475
listener.point(t[1][0], t[1][1]);
3476
listener.lineEnd();
3477
} else {
3478
listener.point(t[1][0], t[1][1]);
3479
listener.lineEnd();
3480
listener.lineStart();
3481
listener.point(t[0][0], t[0][1]);
3482
}
3483
}
3484
}
3485
if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
3486
listener.point(point1[0], point1[1]);
3487
}
3488
point0 = point1, v0 = v, c0 = c;
3489
},
3490
lineEnd: function() {
3491
if (v0) listener.lineEnd();
3492
point0 = null;
3493
},
3494
clean: function() {
3495
return clean | (v00 && v0) << 1;
3496
}
3497
};
3498
}
3499
function intersect(a, b, two) {
3500
var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
3501
var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
3502
if (!determinant) return !two && a;
3503
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);
3504
d3_geo_cartesianAdd(A, B);
3505
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);
3506
if (t2 < 0) return;
3507
var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
3508
d3_geo_cartesianAdd(q, A);
3509
q = d3_geo_spherical(q);
3510
if (!two) return q;
3511
var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3512
if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
3513
var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3514
if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
3515
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)) {
3516
var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3517
d3_geo_cartesianAdd(q1, A);
3518
return [ q, d3_geo_spherical(q1) ];
3519
}
3520
}
3521
function code(λ, φ) {
3522
var r = smallRadius ? radius : π - radius, code = 0;
3523
if (λ < -r) code |= 1; else if (λ > r) code |= 2;
3524
if (φ < -r) code |= 4; else if (φ > r) code |= 8;
3525
return code;
3526
}
3527
}
3528
function d3_geom_clipLine(x0, y0, x1, y1) {
3529
return function(line) {
3530
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;
3531
r = x0 - ax;
3532
if (!dx && r > 0) return;
3533
r /= dx;
3534
if (dx < 0) {
3535
if (r < t0) return;
3536
if (r < t1) t1 = r;
3537
} else if (dx > 0) {
3538
if (r > t1) return;
3539
if (r > t0) t0 = r;
3540
}
3541
r = x1 - ax;
3542
if (!dx && r < 0) return;
3543
r /= dx;
3544
if (dx < 0) {
3545
if (r > t1) return;
3546
if (r > t0) t0 = r;
3547
} else if (dx > 0) {
3548
if (r < t0) return;
3549
if (r < t1) t1 = r;
3550
}
3551
r = y0 - ay;
3552
if (!dy && r > 0) return;
3553
r /= dy;
3554
if (dy < 0) {
3555
if (r < t0) return;
3556
if (r < t1) t1 = r;
3557
} else if (dy > 0) {
3558
if (r > t1) return;
3559
if (r > t0) t0 = r;
3560
}
3561
r = y1 - ay;
3562
if (!dy && r < 0) return;
3563
r /= dy;
3564
if (dy < 0) {
3565
if (r > t1) return;
3566
if (r > t0) t0 = r;
3567
} else if (dy > 0) {
3568
if (r < t0) return;
3569
if (r < t1) t1 = r;
3570
}
3571
if (t0 > 0) line.a = {
3572
x: ax + t0 * dx,
3573
y: ay + t0 * dy
3574
};
3575
if (t1 < 1) line.b = {
3576
x: ax + t1 * dx,
3577
y: ay + t1 * dy
3578
};
3579
return line;
3580
};
3581
}
3582
var d3_geo_clipExtentMAX = 1e9;
3583
d3.geo.clipExtent = function() {
3584
var x0, y0, x1, y1, stream, clip, clipExtent = {
3585
stream: function(output) {
3586
if (stream) stream.valid = false;
3587
stream = clip(output);
3588
stream.valid = true;
3589
return stream;
3590
},
3591
extent: function(_) {
3592
if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3593
clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
3594
if (stream) stream.valid = false, stream = null;
3595
return clipExtent;
3596
}
3597
};
3598
return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
3599
};
3600
function d3_geo_clipExtent(x0, y0, x1, y1) {
3601
return function(listener) {
3602
var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3603
var clip = {
3604
point: point,
3605
lineStart: lineStart,
3606
lineEnd: lineEnd,
3607
polygonStart: function() {
3608
listener = bufferListener;
3609
segments = [];
3610
polygon = [];
3611
clean = true;
3612
},
3613
polygonEnd: function() {
3614
listener = listener_;
3615
segments = d3.merge(segments);
3616
var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
3617
if (inside || visible) {
3618
listener.polygonStart();
3619
if (inside) {
3620
listener.lineStart();
3621
interpolate(null, null, 1, listener);
3622
listener.lineEnd();
3623
}
3624
if (visible) {
3625
d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
3626
}
3627
listener.polygonEnd();
3628
}
3629
segments = polygon = ring = null;
3630
}
3631
};
3632
function insidePolygon(p) {
3633
var wn = 0, n = polygon.length, y = p[1];
3634
for (var i = 0; i < n; ++i) {
3635
for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
3636
b = v[j];
3637
if (a[1] <= y) {
3638
if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
3639
} else {
3640
if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
3641
}
3642
a = b;
3643
}
3644
}
3645
return wn !== 0;
3646
}
3647
function interpolate(from, to, direction, listener) {
3648
var a = 0, a1 = 0;
3649
if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
3650
do {
3651
listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
3652
} while ((a = (a + direction + 4) % 4) !== a1);
3653
} else {
3654
listener.point(to[0], to[1]);
3655
}
3656
}
3657
function pointVisible(x, y) {
3658
return x0 <= x && x <= x1 && y0 <= y && y <= y1;
3659
}
3660
function point(x, y) {
3661
if (pointVisible(x, y)) listener.point(x, y);
3662
}
3663
var x__, y__, v__, x_, y_, v_, first, clean;
3664
function lineStart() {
3665
clip.point = linePoint;
3666
if (polygon) polygon.push(ring = []);
3667
first = true;
3668
v_ = false;
3669
x_ = y_ = NaN;
3670
}
3671
function lineEnd() {
3672
if (segments) {
3673
linePoint(x__, y__);
3674
if (v__ && v_) bufferListener.rejoin();
3675
segments.push(bufferListener.buffer());
3676
}
3677
clip.point = point;
3678
if (v_) listener.lineEnd();
3679
}
3680
function linePoint(x, y) {
3681
x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
3682
y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
3683
var v = pointVisible(x, y);
3684
if (polygon) ring.push([ x, y ]);
3685
if (first) {
3686
x__ = x, y__ = y, v__ = v;
3687
first = false;
3688
if (v) {
3689
listener.lineStart();
3690
listener.point(x, y);
3691
}
3692
} else {
3693
if (v && v_) listener.point(x, y); else {
3694
var l = {
3695
a: {
3696
x: x_,
3697
y: y_
3698
},
3699
b: {
3700
x: x,
3701
y: y
3702
}
3703
};
3704
if (clipLine(l)) {
3705
if (!v_) {
3706
listener.lineStart();
3707
listener.point(l.a.x, l.a.y);
3708
}
3709
listener.point(l.b.x, l.b.y);
3710
if (!v) listener.lineEnd();
3711
clean = false;
3712
} else if (v) {
3713
listener.lineStart();
3714
listener.point(x, y);
3715
clean = false;
3716
}
3717
}
3718
}
3719
x_ = x, y_ = y, v_ = v;
3720
}
3721
return clip;
3722
};
3723
function corner(p, direction) {
3724
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;
3725
}
3726
function compare(a, b) {
3727
return comparePoints(a.x, b.x);
3728
}
3729
function comparePoints(a, b) {
3730
var ca = corner(a, 1), cb = corner(b, 1);
3731
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];
3732
}
3733
}
3734
function d3_geo_compose(a, b) {
3735
function compose(x, y) {
3736
return x = a(x, y), b(x[0], x[1]);
3737
}
3738
if (a.invert && b.invert) compose.invert = function(x, y) {
3739
return x = b.invert(x, y), x && a.invert(x[0], x[1]);
3740
};
3741
return compose;
3742
}
3743
function d3_geo_conic(projectAt) {
3744
var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3745
p.parallels = function(_) {
3746
if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3747
return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3748
};
3749
return p;
3750
}
3751
function d3_geo_conicEqualArea(φ0, φ1) {
3752
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;
3753
function forward(λ, φ) {
3754
var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3755
return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3756
}
3757
forward.invert = function(x, y) {
3758
var ρ0_y = ρ0 - y;
3759
return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3760
};
3761
return forward;
3762
}
3763
(d3.geo.conicEqualArea = function() {
3764
return d3_geo_conic(d3_geo_conicEqualArea);
3765
}).raw = d3_geo_conicEqualArea;
3766
d3.geo.albers = function() {
3767
return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3768
};
3769
d3.geo.albersUsa = function() {
3770
var lower48 = d3.geo.albers();
3771
var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3772
var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3773
var point, pointStream = {
3774
point: function(x, y) {
3775
point = [ x, y ];
3776
}
3777
}, lower48Point, alaskaPoint, hawaiiPoint;
3778
function albersUsa(coordinates) {
3779
var x = coordinates[0], y = coordinates[1];
3780
point = null;
3781
(lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3782
return point;
3783
}
3784
albersUsa.invert = function(coordinates) {
3785
var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3786
return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3787
};
3788
albersUsa.stream = function(stream) {
3789
var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3790
return {
3791
point: function(x, y) {
3792
lower48Stream.point(x, y);
3793
alaskaStream.point(x, y);
3794
hawaiiStream.point(x, y);
3795
},
3796
sphere: function() {
3797
lower48Stream.sphere();
3798
alaskaStream.sphere();
3799
hawaiiStream.sphere();
3800
},
3801
lineStart: function() {
3802
lower48Stream.lineStart();
3803
alaskaStream.lineStart();
3804
hawaiiStream.lineStart();
3805
},
3806
lineEnd: function() {
3807
lower48Stream.lineEnd();
3808
alaskaStream.lineEnd();
3809
hawaiiStream.lineEnd();
3810
},
3811
polygonStart: function() {
3812
lower48Stream.polygonStart();
3813
alaskaStream.polygonStart();
3814
hawaiiStream.polygonStart();
3815
},
3816
polygonEnd: function() {
3817
lower48Stream.polygonEnd();
3818
alaskaStream.polygonEnd();
3819
hawaiiStream.polygonEnd();
3820
}
3821
};
3822
};
3823
albersUsa.precision = function(_) {
3824
if (!arguments.length) return lower48.precision();
3825
lower48.precision(_);
3826
alaska.precision(_);
3827
hawaii.precision(_);
3828
return albersUsa;
3829
};
3830
albersUsa.scale = function(_) {
3831
if (!arguments.length) return lower48.scale();
3832
lower48.scale(_);
3833
alaska.scale(_ * .35);
3834
hawaii.scale(_);
3835
return albersUsa.translate(lower48.translate());
3836
};
3837
albersUsa.translate = function(_) {
3838
if (!arguments.length) return lower48.translate();
3839
var k = lower48.scale(), x = +_[0], y = +_[1];
3840
lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3841
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;
3842
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;
3843
return albersUsa;
3844
};
3845
return albersUsa.scale(1070);
3846
};
3847
var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3848
point: d3_noop,
3849
lineStart: d3_noop,
3850
lineEnd: d3_noop,
3851
polygonStart: function() {
3852
d3_geo_pathAreaPolygon = 0;
3853
d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3854
},
3855
polygonEnd: function() {
3856
d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3857
d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3858
}
3859
};
3860
function d3_geo_pathAreaRingStart() {
3861
var x00, y00, x0, y0;
3862
d3_geo_pathArea.point = function(x, y) {
3863
d3_geo_pathArea.point = nextPoint;
3864
x00 = x0 = x, y00 = y0 = y;
3865
};
3866
function nextPoint(x, y) {
3867
d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3868
x0 = x, y0 = y;
3869
}
3870
d3_geo_pathArea.lineEnd = function() {
3871
nextPoint(x00, y00);
3872
};
3873
}
3874
var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3875
var d3_geo_pathBounds = {
3876
point: d3_geo_pathBoundsPoint,
3877
lineStart: d3_noop,
3878
lineEnd: d3_noop,
3879
polygonStart: d3_noop,
3880
polygonEnd: d3_noop
3881
};
3882
function d3_geo_pathBoundsPoint(x, y) {
3883
if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
3884
if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
3885
if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
3886
if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
3887
}
3888
function d3_geo_pathBuffer() {
3889
var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3890
var stream = {
3891
point: point,
3892
lineStart: function() {
3893
stream.point = pointLineStart;
3894
},
3895
lineEnd: lineEnd,
3896
polygonStart: function() {
3897
stream.lineEnd = lineEndPolygon;
3898
},
3899
polygonEnd: function() {
3900
stream.lineEnd = lineEnd;
3901
stream.point = point;
3902
},
3903
pointRadius: function(_) {
3904
pointCircle = d3_geo_pathBufferCircle(_);
3905
return stream;
3906
},
3907
result: function() {
3908
if (buffer.length) {
3909
var result = buffer.join("");
3910
buffer = [];
3911
return result;
3912
}
3913
}
3914
};
3915
function point(x, y) {
3916
buffer.push("M", x, ",", y, pointCircle);
3917
}
3918
function pointLineStart(x, y) {
3919
buffer.push("M", x, ",", y);
3920
stream.point = pointLine;
3921
}
3922
function pointLine(x, y) {
3923
buffer.push("L", x, ",", y);
3924
}
3925
function lineEnd() {
3926
stream.point = point;
3927
}
3928
function lineEndPolygon() {
3929
buffer.push("Z");
3930
}
3931
return stream;
3932
}
3933
function d3_geo_pathBufferCircle(radius) {
3934
return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
3935
}
3936
var d3_geo_pathCentroid = {
3937
point: d3_geo_pathCentroidPoint,
3938
lineStart: d3_geo_pathCentroidLineStart,
3939
lineEnd: d3_geo_pathCentroidLineEnd,
3940
polygonStart: function() {
3941
d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
3942
},
3943
polygonEnd: function() {
3944
d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3945
d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
3946
d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
3947
}
3948
};
3949
function d3_geo_pathCentroidPoint(x, y) {
3950
d3_geo_centroidX0 += x;
3951
d3_geo_centroidY0 += y;
3952
++d3_geo_centroidZ0;
3953
}
3954
function d3_geo_pathCentroidLineStart() {
3955
var x0, y0;
3956
d3_geo_pathCentroid.point = function(x, y) {
3957
d3_geo_pathCentroid.point = nextPoint;
3958
d3_geo_pathCentroidPoint(x0 = x, 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
d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3966
}
3967
}
3968
function d3_geo_pathCentroidLineEnd() {
3969
d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3970
}
3971
function d3_geo_pathCentroidRingStart() {
3972
var x00, y00, x0, y0;
3973
d3_geo_pathCentroid.point = function(x, y) {
3974
d3_geo_pathCentroid.point = nextPoint;
3975
d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
3976
};
3977
function nextPoint(x, y) {
3978
var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
3979
d3_geo_centroidX1 += z * (x0 + x) / 2;
3980
d3_geo_centroidY1 += z * (y0 + y) / 2;
3981
d3_geo_centroidZ1 += z;
3982
z = y0 * x - x0 * y;
3983
d3_geo_centroidX2 += z * (x0 + x);
3984
d3_geo_centroidY2 += z * (y0 + y);
3985
d3_geo_centroidZ2 += z * 3;
3986
d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3987
}
3988
d3_geo_pathCentroid.lineEnd = function() {
3989
nextPoint(x00, y00);
3990
};
3991
}
3992
function d3_geo_pathContext(context) {
3993
var pointRadius = 4.5;
3994
var stream = {
3995
point: point,
3996
lineStart: function() {
3997
stream.point = pointLineStart;
3998
},
3999
lineEnd: lineEnd,
4000
polygonStart: function() {
4001
stream.lineEnd = lineEndPolygon;
4002
},
4003
polygonEnd: function() {
4004
stream.lineEnd = lineEnd;
4005
stream.point = point;
4006
},
4007
pointRadius: function(_) {
4008
pointRadius = _;
4009
return stream;
4010
},
4011
result: d3_noop
4012
};
4013
function point(x, y) {
4014
context.moveTo(x, y);
4015
context.arc(x, y, pointRadius, 0, τ);
4016
}
4017
function pointLineStart(x, y) {
4018
context.moveTo(x, y);
4019
stream.point = pointLine;
4020
}
4021
function pointLine(x, y) {
4022
context.lineTo(x, y);
4023
}
4024
function lineEnd() {
4025
stream.point = point;
4026
}
4027
function lineEndPolygon() {
4028
context.closePath();
4029
}
4030
return stream;
4031
}
4032
function d3_geo_resample(project) {
4033
var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4034
function resample(stream) {
4035
return (maxDepth ? resampleRecursive : resampleNone)(stream);
4036
}
4037
function resampleNone(stream) {
4038
return d3_geo_transformPoint(stream, function(x, y) {
4039
x = project(x, y);
4040
stream.point(x[0], x[1]);
4041
});
4042
}
4043
function resampleRecursive(stream) {
4044
var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
4045
var resample = {
4046
point: point,
4047
lineStart: lineStart,
4048
lineEnd: lineEnd,
4049
polygonStart: function() {
4050
stream.polygonStart();
4051
resample.lineStart = ringStart;
4052
},
4053
polygonEnd: function() {
4054
stream.polygonEnd();
4055
resample.lineStart = lineStart;
4056
}
4057
};
4058
function point(x, y) {
4059
x = project(x, y);
4060
stream.point(x[0], x[1]);
4061
}
4062
function lineStart() {
4063
x0 = NaN;
4064
resample.point = linePoint;
4065
stream.lineStart();
4066
}
4067
function linePoint(λ, φ) {
4068
var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4069
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);
4070
stream.point(x0, y0);
4071
}
4072
function lineEnd() {
4073
resample.point = point;
4074
stream.lineEnd();
4075
}
4076
function ringStart() {
4077
lineStart();
4078
resample.point = ringPoint;
4079
resample.lineEnd = ringEnd;
4080
}
4081
function ringPoint(λ, φ) {
4082
linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
4083
resample.point = linePoint;
4084
}
4085
function ringEnd() {
4086
resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4087
resample.lineEnd = lineEnd;
4088
lineEnd();
4089
}
4090
return resample;
4091
}
4092
function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
4093
var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
4094
if (d2 > 4 * δ2 && depth--) {
4095
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;
4096
if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
4097
resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
4098
stream.point(x2, y2);
4099
resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
4100
}
4101
}
4102
}
4103
resample.precision = function(_) {
4104
if (!arguments.length) return Math.sqrt(δ2);
4105
maxDepth = (δ2 = _ * _) > 0 && 16;
4106
return resample;
4107
};
4108
return resample;
4109
}
4110
d3.geo.path = function() {
4111
var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
4112
function path(object) {
4113
if (object) {
4114
if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
4115
if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
4116
d3.geo.stream(object, cacheStream);
4117
}
4118
return contextStream.result();
4119
}
4120
path.area = function(object) {
4121
d3_geo_pathAreaSum = 0;
4122
d3.geo.stream(object, projectStream(d3_geo_pathArea));
4123
return d3_geo_pathAreaSum;
4124
};
4125
path.centroid = function(object) {
4126
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;
4127
d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
4128
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 ];
4129
};
4130
path.bounds = function(object) {
4131
d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
4132
d3.geo.stream(object, projectStream(d3_geo_pathBounds));
4133
return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
4134
};
4135
path.projection = function(_) {
4136
if (!arguments.length) return projection;
4137
projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
4138
return reset();
4139
};
4140
path.context = function(_) {
4141
if (!arguments.length) return context;
4142
contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
4143
if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
4144
return reset();
4145
};
4146
path.pointRadius = function(_) {
4147
if (!arguments.length) return pointRadius;
4148
pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
4149
return path;
4150
};
4151
function reset() {
4152
cacheStream = null;
4153
return path;
4154
}
4155
return path.projection(d3.geo.albersUsa()).context(null);
4156
};
4157
function d3_geo_pathProjectStream(project) {
4158
var resample = d3_geo_resample(function(x, y) {
4159
return project([ x * d3_degrees, y * d3_degrees ]);
4160
});
4161
return function(stream) {
4162
return d3_geo_projectionRadians(resample(stream));
4163
};
4164
}
4165
d3.geo.transform = function(methods) {
4166
return {
4167
stream: function(stream) {
4168
var transform = new d3_geo_transform(stream);
4169
for (var k in methods) transform[k] = methods[k];
4170
return transform;
4171
}
4172
};
4173
};
4174
function d3_geo_transform(stream) {
4175
this.stream = stream;
4176
}
4177
d3_geo_transform.prototype = {
4178
point: function(x, y) {
4179
this.stream.point(x, y);
4180
},
4181
sphere: function() {
4182
this.stream.sphere();
4183
},
4184
lineStart: function() {
4185
this.stream.lineStart();
4186
},
4187
lineEnd: function() {
4188
this.stream.lineEnd();
4189
},
4190
polygonStart: function() {
4191
this.stream.polygonStart();
4192
},
4193
polygonEnd: function() {
4194
this.stream.polygonEnd();
4195
}
4196
};
4197
function d3_geo_transformPoint(stream, point) {
4198
return {
4199
point: point,
4200
sphere: function() {
4201
stream.sphere();
4202
},
4203
lineStart: function() {
4204
stream.lineStart();
4205
},
4206
lineEnd: function() {
4207
stream.lineEnd();
4208
},
4209
polygonStart: function() {
4210
stream.polygonStart();
4211
},
4212
polygonEnd: function() {
4213
stream.polygonEnd();
4214
}
4215
};
4216
}
4217
d3.geo.projection = d3_geo_projection;
4218
d3.geo.projectionMutator = d3_geo_projectionMutator;
4219
function d3_geo_projection(project) {
4220
return d3_geo_projectionMutator(function() {
4221
return project;
4222
})();
4223
}
4224
function d3_geo_projectionMutator(projectAt) {
4225
var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
4226
x = project(x, y);
4227
return [ x[0] * k + δx, δy - x[1] * k ];
4228
}), 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;
4229
function projection(point) {
4230
point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
4231
return [ point[0] * k + δx, δy - point[1] * k ];
4232
}
4233
function invert(point) {
4234
point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
4235
return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
4236
}
4237
projection.stream = function(output) {
4238
if (stream) stream.valid = false;
4239
stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
4240
stream.valid = true;
4241
return stream;
4242
};
4243
projection.clipAngle = function(_) {
4244
if (!arguments.length) return clipAngle;
4245
preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
4246
return invalidate();
4247
};
4248
projection.clipExtent = function(_) {
4249
if (!arguments.length) return clipExtent;
4250
clipExtent = _;
4251
postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
4252
return invalidate();
4253
};
4254
projection.scale = function(_) {
4255
if (!arguments.length) return k;
4256
k = +_;
4257
return reset();
4258
};
4259
projection.translate = function(_) {
4260
if (!arguments.length) return [ x, y ];
4261
x = +_[0];
4262
y = +_[1];
4263
return reset();
4264
};
4265
projection.center = function(_) {
4266
if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
4267
λ = _[0] % 360 * d3_radians;
4268
φ = _[1] % 360 * d3_radians;
4269
return reset();
4270
};
4271
projection.rotate = function(_) {
4272
if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
4273
δλ = _[0] % 360 * d3_radians;
4274
δφ = _[1] % 360 * d3_radians;
4275
δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
4276
return reset();
4277
};
4278
d3.rebind(projection, projectResample, "precision");
4279
function reset() {
4280
projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
4281
var center = project(λ, φ);
4282
δx = x - center[0] * k;
4283
δy = y + center[1] * k;
4284
return invalidate();
4285
}
4286
function invalidate() {
4287
if (stream) stream.valid = false, stream = null;
4288
return projection;
4289
}
4290
return function() {
4291
project = projectAt.apply(this, arguments);
4292
projection.invert = project.invert && invert;
4293
return reset();
4294
};
4295
}
4296
function d3_geo_projectionRadians(stream) {
4297
return d3_geo_transformPoint(stream, function(x, y) {
4298
stream.point(x * d3_radians, y * d3_radians);
4299
});
4300
}
4301
function d3_geo_equirectangular(λ, φ) {
4302
return [ λ, φ ];
4303
}
4304
(d3.geo.equirectangular = function() {
4305
return d3_geo_projection(d3_geo_equirectangular);
4306
}).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
4307
d3.geo.rotation = function(rotate) {
4308
rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
4309
function forward(coordinates) {
4310
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4311
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4312
}
4313
forward.invert = function(coordinates) {
4314
coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4315
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4316
};
4317
return forward;
4318
};
4319
function d3_geo_identityRotation(λ, φ) {
4320
return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4321
}
4322
d3_geo_identityRotation.invert = d3_geo_equirectangular;
4323
function d3_geo_rotation(δλ, δφ, δγ) {
4324
return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
4325
}
4326
function d3_geo_forwardRotationλ(δλ) {
4327
return function(λ, φ) {
4328
return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4329
};
4330
}
4331
function d3_geo_rotationλ(δλ) {
4332
var rotation = d3_geo_forwardRotationλ(δλ);
4333
rotation.invert = d3_geo_forwardRotationλ(-δλ);
4334
return rotation;
4335
}
4336
function d3_geo_rotationφγ(δφ, δγ) {
4337
var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
4338
function rotation(λ, φ) {
4339
var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
4340
return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
4341
}
4342
rotation.invert = function(λ, φ) {
4343
var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
4344
return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
4345
};
4346
return rotation;
4347
}
4348
d3.geo.circle = function() {
4349
var origin = [ 0, 0 ], angle, precision = 6, interpolate;
4350
function circle() {
4351
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 = [];
4352
interpolate(null, null, 1, {
4353
point: function(x, y) {
4354
ring.push(x = rotate(x, y));
4355
x[0] *= d3_degrees, x[1] *= d3_degrees;
4356
}
4357
});
4358
return {
4359
type: "Polygon",
4360
coordinates: [ ring ]
4361
};
4362
}
4363
circle.origin = function(x) {
4364
if (!arguments.length) return origin;
4365
origin = x;
4366
return circle;
4367
};
4368
circle.angle = function(x) {
4369
if (!arguments.length) return angle;
4370
interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
4371
return circle;
4372
};
4373
circle.precision = function(_) {
4374
if (!arguments.length) return precision;
4375
interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
4376
return circle;
4377
};
4378
return circle.angle(90);
4379
};
4380
function d3_geo_circleInterpolate(radius, precision) {
4381
var cr = Math.cos(radius), sr = Math.sin(radius);
4382
return function(from, to, direction, listener) {
4383
var step = direction * precision;
4384
if (from != null) {
4385
from = d3_geo_circleAngle(cr, from);
4386
to = d3_geo_circleAngle(cr, to);
4387
if (direction > 0 ? from < to : from > to) from += direction * τ;
4388
} else {
4389
from = radius + direction * τ;
4390
to = radius - .5 * step;
4391
}
4392
for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
4393
listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
4394
}
4395
};
4396
}
4397
function d3_geo_circleAngle(cr, point) {
4398
var a = d3_geo_cartesian(point);
4399
a[0] -= cr;
4400
d3_geo_cartesianNormalize(a);
4401
var angle = d3_acos(-a[1]);
4402
return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
4403
}
4404
d3.geo.distance = function(a, b) {
4405
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;
4406
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Δλ);
4407
};
4408
d3.geo.graticule = function() {
4409
var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
4410
function graticule() {
4411
return {
4412
type: "MultiLineString",
4413
coordinates: lines()
4414
};
4415
}
4416
function lines() {
4417
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) {
4418
return abs(x % DX) > ε;
4419
}).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
4420
return abs(y % DY) > ε;
4421
}).map(y));
4422
}
4423
graticule.lines = function() {
4424
return lines().map(function(coordinates) {
4425
return {
4426
type: "LineString",
4427
coordinates: coordinates
4428
};
4429
});
4430
};
4431
graticule.outline = function() {
4432
return {
4433
type: "Polygon",
4434
coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
4435
};
4436
};
4437
graticule.extent = function(_) {
4438
if (!arguments.length) return graticule.minorExtent();
4439
return graticule.majorExtent(_).minorExtent(_);
4440
};
4441
graticule.majorExtent = function(_) {
4442
if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
4443
X0 = +_[0][0], X1 = +_[1][0];
4444
Y0 = +_[0][1], Y1 = +_[1][1];
4445
if (X0 > X1) _ = X0, X0 = X1, X1 = _;
4446
if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
4447
return graticule.precision(precision);
4448
};
4449
graticule.minorExtent = function(_) {
4450
if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
4451
x0 = +_[0][0], x1 = +_[1][0];
4452
y0 = +_[0][1], y1 = +_[1][1];
4453
if (x0 > x1) _ = x0, x0 = x1, x1 = _;
4454
if (y0 > y1) _ = y0, y0 = y1, y1 = _;
4455
return graticule.precision(precision);
4456
};
4457
graticule.step = function(_) {
4458
if (!arguments.length) return graticule.minorStep();
4459
return graticule.majorStep(_).minorStep(_);
4460
};
4461
graticule.majorStep = function(_) {
4462
if (!arguments.length) return [ DX, DY ];
4463
DX = +_[0], DY = +_[1];
4464
return graticule;
4465
};
4466
graticule.minorStep = function(_) {
4467
if (!arguments.length) return [ dx, dy ];
4468
dx = +_[0], dy = +_[1];
4469
return graticule;
4470
};
4471
graticule.precision = function(_) {
4472
if (!arguments.length) return precision;
4473
precision = +_;
4474
x = d3_geo_graticuleX(y0, y1, 90);
4475
y = d3_geo_graticuleY(x0, x1, precision);
4476
X = d3_geo_graticuleX(Y0, Y1, 90);
4477
Y = d3_geo_graticuleY(X0, X1, precision);
4478
return graticule;
4479
};
4480
return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
4481
};
4482
function d3_geo_graticuleX(y0, y1, dy) {
4483
var y = d3.range(y0, y1 - ε, dy).concat(y1);
4484
return function(x) {
4485
return y.map(function(y) {
4486
return [ x, y ];
4487
});
4488
};
4489
}
4490
function d3_geo_graticuleY(x0, x1, dx) {
4491
var x = d3.range(x0, x1 - ε, dx).concat(x1);
4492
return function(y) {
4493
return x.map(function(x) {
4494
return [ x, y ];
4495
});
4496
};
4497
}
4498
function d3_source(d) {
4499
return d.source;
4500
}
4501
function d3_target(d) {
4502
return d.target;
4503
}
4504
d3.geo.greatArc = function() {
4505
var source = d3_source, source_, target = d3_target, target_;
4506
function greatArc() {
4507
return {
4508
type: "LineString",
4509
coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
4510
};
4511
}
4512
greatArc.distance = function() {
4513
return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
4514
};
4515
greatArc.source = function(_) {
4516
if (!arguments.length) return source;
4517
source = _, source_ = typeof _ === "function" ? null : _;
4518
return greatArc;
4519
};
4520
greatArc.target = function(_) {
4521
if (!arguments.length) return target;
4522
target = _, target_ = typeof _ === "function" ? null : _;
4523
return greatArc;
4524
};
4525
greatArc.precision = function() {
4526
return arguments.length ? greatArc : 0;
4527
};
4528
return greatArc;
4529
};
4530
d3.geo.interpolate = function(source, target) {
4531
return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
4532
};
4533
function d3_geo_interpolate(x0, y0, x1, y1) {
4534
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);
4535
var interpolate = d ? function(t) {
4536
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;
4537
return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
4538
} : function() {
4539
return [ x0 * d3_degrees, y0 * d3_degrees ];
4540
};
4541
interpolate.distance = d;
4542
return interpolate;
4543
}
4544
d3.geo.length = function(object) {
4545
d3_geo_lengthSum = 0;
4546
d3.geo.stream(object, d3_geo_length);
4547
return d3_geo_lengthSum;
4548
};
4549
var d3_geo_lengthSum;
4550
var d3_geo_length = {
4551
sphere: d3_noop,
4552
point: d3_noop,
4553
lineStart: d3_geo_lengthLineStart,
4554
lineEnd: d3_noop,
4555
polygonStart: d3_noop,
4556
polygonEnd: d3_noop
4557
};
4558
function d3_geo_lengthLineStart() {
4559
var λ0, sinφ0, cosφ0;
4560
d3_geo_length.point = function(λ, φ) {
4561
λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
4562
d3_geo_length.point = nextPoint;
4563
};
4564
d3_geo_length.lineEnd = function() {
4565
d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4566
};
4567
function nextPoint(λ, φ) {
4568
var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4569
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Δλ);
4570
λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
4571
}
4572
}
4573
function d3_geo_azimuthal(scale, angle) {
4574
function azimuthal(λ, φ) {
4575
var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
4576
return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
4577
}
4578
azimuthal.invert = function(x, y) {
4579
var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
4580
return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
4581
};
4582
return azimuthal;
4583
}
4584
var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
4585
return Math.sqrt(2 / (1 + cosλcosφ));
4586
}, function(ρ) {
4587
return 2 * Math.asin(ρ / 2);
4588
});
4589
(d3.geo.azimuthalEqualArea = function() {
4590
return d3_geo_projection(d3_geo_azimuthalEqualArea);
4591
}).raw = d3_geo_azimuthalEqualArea;
4592
var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
4593
var c = Math.acos(cosλcosφ);
4594
return c && c / Math.sin(c);
4595
}, d3_identity);
4596
(d3.geo.azimuthalEquidistant = function() {
4597
return d3_geo_projection(d3_geo_azimuthalEquidistant);
4598
}).raw = d3_geo_azimuthalEquidistant;
4599
function d3_geo_conicConformal(φ0, φ1) {
4600
var cosφ0 = Math.cos(φ0), t = function(φ) {
4601
return Math.tan(π / 4 + φ / 2);
4602
}, 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;
4603
if (!n) return d3_geo_mercator;
4604
function forward(λ, φ) {
4605
if (F > 0) {
4606
if (φ < -halfπ + ε) φ = -halfπ + ε;
4607
} else {
4608
if (φ > halfπ - ε) φ = halfπ - ε;
4609
}
4610
var ρ = F / Math.pow(t(φ), n);
4611
return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4612
}
4613
forward.invert = function(x, y) {
4614
var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
4615
return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
4616
};
4617
return forward;
4618
}
4619
(d3.geo.conicConformal = function() {
4620
return d3_geo_conic(d3_geo_conicConformal);
4621
}).raw = d3_geo_conicConformal;
4622
function d3_geo_conicEquidistant(φ0, φ1) {
4623
var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
4624
if (abs(n) < ε) return d3_geo_equirectangular;
4625
function forward(λ, φ) {
4626
var ρ = G - φ;
4627
return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
4628
}
4629
forward.invert = function(x, y) {
4630
var ρ0_y = G - y;
4631
return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
4632
};
4633
return forward;
4634
}
4635
(d3.geo.conicEquidistant = function() {
4636
return d3_geo_conic(d3_geo_conicEquidistant);
4637
}).raw = d3_geo_conicEquidistant;
4638
var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
4639
return 1 / cosλcosφ;
4640
}, Math.atan);
4641
(d3.geo.gnomonic = function() {
4642
return d3_geo_projection(d3_geo_gnomonic);
4643
}).raw = d3_geo_gnomonic;
4644
function d3_geo_mercator(λ, φ) {
4645
return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
4646
}
4647
d3_geo_mercator.invert = function(x, y) {
4648
return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
4649
};
4650
function d3_geo_mercatorProjection(project) {
4651
var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
4652
m.scale = function() {
4653
var v = scale.apply(m, arguments);
4654
return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4655
};
4656
m.translate = function() {
4657
var v = translate.apply(m, arguments);
4658
return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4659
};
4660
m.clipExtent = function(_) {
4661
var v = clipExtent.apply(m, arguments);
4662
if (v === m) {
4663
if (clipAuto = _ == null) {
4664
var k = π * scale(), t = translate();
4665
clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
4666
}
4667
} else if (clipAuto) {
4668
v = null;
4669
}
4670
return v;
4671
};
4672
return m.clipExtent(null);
4673
}
4674
(d3.geo.mercator = function() {
4675
return d3_geo_mercatorProjection(d3_geo_mercator);
4676
}).raw = d3_geo_mercator;
4677
var d3_geo_orthographic = d3_geo_azimuthal(function() {
4678
return 1;
4679
}, Math.asin);
4680
(d3.geo.orthographic = function() {
4681
return d3_geo_projection(d3_geo_orthographic);
4682
}).raw = d3_geo_orthographic;
4683
var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
4684
return 1 / (1 + cosλcosφ);
4685
}, function(ρ) {
4686
return 2 * Math.atan(ρ);
4687
});
4688
(d3.geo.stereographic = function() {
4689
return d3_geo_projection(d3_geo_stereographic);
4690
}).raw = d3_geo_stereographic;
4691
function d3_geo_transverseMercator(λ, φ) {
4692
return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
4693
}
4694
d3_geo_transverseMercator.invert = function(x, y) {
4695
return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
4696
};
4697
(d3.geo.transverseMercator = function() {
4698
var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
4699
projection.center = function(_) {
4700
return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ -_[1], _[0] ]);
4701
};
4702
projection.rotate = function(_) {
4703
return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
4704
[ _[0], _[1], _[2] - 90 ]);
4705
};
4706
return projection.rotate([ 0, 0 ]);
4707
}).raw = d3_geo_transverseMercator;
4708
d3.geom = {};
4709
function d3_geom_pointX(d) {
4710
return d[0];
4711
}
4712
function d3_geom_pointY(d) {
4713
return d[1];
4714
}
4715
d3.geom.hull = function(vertices) {
4716
var x = d3_geom_pointX, y = d3_geom_pointY;
4717
if (arguments.length) return hull(vertices);
4718
function hull(data) {
4719
if (data.length < 3) return [];
4720
var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
4721
for (i = 0; i < n; i++) {
4722
points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
4723
}
4724
points.sort(d3_geom_hullOrder);
4725
for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
4726
var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
4727
var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
4728
for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
4729
for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
4730
return polygon;
4731
}
4732
hull.x = function(_) {
4733
return arguments.length ? (x = _, hull) : x;
4734
};
4735
hull.y = function(_) {
4736
return arguments.length ? (y = _, hull) : y;
4737
};
4738
return hull;
4739
};
4740
function d3_geom_hullUpper(points) {
4741
var n = points.length, hull = [ 0, 1 ], hs = 2;
4742
for (var i = 2; i < n; i++) {
4743
while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
4744
hull[hs++] = i;
4745
}
4746
return hull.slice(0, hs);
4747
}
4748
function d3_geom_hullOrder(a, b) {
4749
return a[0] - b[0] || a[1] - b[1];
4750
}
4751
d3.geom.polygon = function(coordinates) {
4752
d3_subclass(coordinates, d3_geom_polygonPrototype);
4753
return coordinates;
4754
};
4755
var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
4756
d3_geom_polygonPrototype.area = function() {
4757
var i = -1, n = this.length, a, b = this[n - 1], area = 0;
4758
while (++i < n) {
4759
a = b;
4760
b = this[i];
4761
area += a[1] * b[0] - a[0] * b[1];
4762
}
4763
return area * .5;
4764
};
4765
d3_geom_polygonPrototype.centroid = function(k) {
4766
var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
4767
if (!arguments.length) k = -1 / (6 * this.area());
4768
while (++i < n) {
4769
a = b;
4770
b = this[i];
4771
c = a[0] * b[1] - b[0] * a[1];
4772
x += (a[0] + b[0]) * c;
4773
y += (a[1] + b[1]) * c;
4774
}
4775
return [ x * k, y * k ];
4776
};
4777
d3_geom_polygonPrototype.clip = function(subject) {
4778
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;
4779
while (++i < n) {
4780
input = subject.slice();
4781
subject.length = 0;
4782
b = this[i];
4783
c = input[(m = input.length - closed) - 1];
4784
j = -1;
4785
while (++j < m) {
4786
d = input[j];
4787
if (d3_geom_polygonInside(d, a, b)) {
4788
if (!d3_geom_polygonInside(c, a, b)) {
4789
subject.push(d3_geom_polygonIntersect(c, d, a, b));
4790
}
4791
subject.push(d);
4792
} else if (d3_geom_polygonInside(c, a, b)) {
4793
subject.push(d3_geom_polygonIntersect(c, d, a, b));
4794
}
4795
c = d;
4796
}
4797
if (closed) subject.push(subject[0]);
4798
a = b;
4799
}
4800
return subject;
4801
};
4802
function d3_geom_polygonInside(p, a, b) {
4803
return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4804
}
4805
function d3_geom_polygonIntersect(c, d, a, b) {
4806
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);
4807
return [ x1 + ua * x21, y1 + ua * y21 ];
4808
}
4809
function d3_geom_polygonClosed(coordinates) {
4810
var a = coordinates[0], b = coordinates[coordinates.length - 1];
4811
return !(a[0] - b[0] || a[1] - b[1]);
4812
}
4813
var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4814
function d3_geom_voronoiBeach() {
4815
d3_geom_voronoiRedBlackNode(this);
4816
this.edge = this.site = this.circle = null;
4817
}
4818
function d3_geom_voronoiCreateBeach(site) {
4819
var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
4820
beach.site = site;
4821
return beach;
4822
}
4823
function d3_geom_voronoiDetachBeach(beach) {
4824
d3_geom_voronoiDetachCircle(beach);
4825
d3_geom_voronoiBeaches.remove(beach);
4826
d3_geom_voronoiBeachPool.push(beach);
4827
d3_geom_voronoiRedBlackNode(beach);
4828
}
4829
function d3_geom_voronoiRemoveBeach(beach) {
4830
var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4831
x: x,
4832
y: y
4833
}, previous = beach.P, next = beach.N, disappearing = [ beach ];
4834
d3_geom_voronoiDetachBeach(beach);
4835
var lArc = previous;
4836
while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4837
previous = lArc.P;
4838
disappearing.unshift(lArc);
4839
d3_geom_voronoiDetachBeach(lArc);
4840
lArc = previous;
4841
}
4842
disappearing.unshift(lArc);
4843
d3_geom_voronoiDetachCircle(lArc);
4844
var rArc = next;
4845
while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4846
next = rArc.N;
4847
disappearing.push(rArc);
4848
d3_geom_voronoiDetachBeach(rArc);
4849
rArc = next;
4850
}
4851
disappearing.push(rArc);
4852
d3_geom_voronoiDetachCircle(rArc);
4853
var nArcs = disappearing.length, iArc;
4854
for (iArc = 1; iArc < nArcs; ++iArc) {
4855
rArc = disappearing[iArc];
4856
lArc = disappearing[iArc - 1];
4857
d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4858
}
4859
lArc = disappearing[0];
4860
rArc = disappearing[nArcs - 1];
4861
rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4862
d3_geom_voronoiAttachCircle(lArc);
4863
d3_geom_voronoiAttachCircle(rArc);
4864
}
4865
function d3_geom_voronoiAddBeach(site) {
4866
var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4867
while (node) {
4868
dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4869
if (dxl > ε) node = node.L; else {
4870
dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
4871
if (dxr > ε) {
4872
if (!node.R) {
4873
lArc = node;
4874
break;
4875
}
4876
node = node.R;
4877
} else {
4878
if (dxl > -ε) {
4879
lArc = node.P;
4880
rArc = node;
4881
} else if (dxr > -ε) {
4882
lArc = node;
4883
rArc = node.N;
4884
} else {
4885
lArc = rArc = node;
4886
}
4887
break;
4888
}
4889
}
4890
}
4891
var newArc = d3_geom_voronoiCreateBeach(site);
4892
d3_geom_voronoiBeaches.insert(lArc, newArc);
4893
if (!lArc && !rArc) return;
4894
if (lArc === rArc) {
4895
d3_geom_voronoiDetachCircle(lArc);
4896
rArc = d3_geom_voronoiCreateBeach(lArc.site);
4897
d3_geom_voronoiBeaches.insert(newArc, rArc);
4898
newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4899
d3_geom_voronoiAttachCircle(lArc);
4900
d3_geom_voronoiAttachCircle(rArc);
4901
return;
4902
}
4903
if (!rArc) {
4904
newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4905
return;
4906
}
4907
d3_geom_voronoiDetachCircle(lArc);
4908
d3_geom_voronoiDetachCircle(rArc);
4909
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 = {
4910
x: (cy * hb - by * hc) / d + ax,
4911
y: (bx * hc - cx * hb) / d + ay
4912
};
4913
d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
4914
newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
4915
rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
4916
d3_geom_voronoiAttachCircle(lArc);
4917
d3_geom_voronoiAttachCircle(rArc);
4918
}
4919
function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
4920
var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
4921
if (!pby2) return rfocx;
4922
var lArc = arc.P;
4923
if (!lArc) return -Infinity;
4924
site = lArc.site;
4925
var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
4926
if (!plby2) return lfocx;
4927
var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
4928
if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
4929
return (rfocx + lfocx) / 2;
4930
}
4931
function d3_geom_voronoiRightBreakPoint(arc, directrix) {
4932
var rArc = arc.N;
4933
if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
4934
var site = arc.site;
4935
return site.y === directrix ? site.x : Infinity;
4936
}
4937
function d3_geom_voronoiCell(site) {
4938
this.site = site;
4939
this.edges = [];
4940
}
4941
d3_geom_voronoiCell.prototype.prepare = function() {
4942
var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
4943
while (iHalfEdge--) {
4944
edge = halfEdges[iHalfEdge].edge;
4945
if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
4946
}
4947
halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
4948
return halfEdges.length;
4949
};
4950
function d3_geom_voronoiCloseCells(extent) {
4951
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;
4952
while (iCell--) {
4953
cell = cells[iCell];
4954
if (!cell || !cell.prepare()) continue;
4955
halfEdges = cell.edges;
4956
nHalfEdges = halfEdges.length;
4957
iHalfEdge = 0;
4958
while (iHalfEdge < nHalfEdges) {
4959
end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
4960
start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
4961
if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
4962
halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
4963
x: x0,
4964
y: abs(x2 - x0) < ε ? y2 : y1
4965
} : abs(y3 - y1) < ε && x1 - x3 > ε ? {
4966
x: abs(y2 - y1) < ε ? x2 : x1,
4967
y: y1
4968
} : abs(x3 - x1) < ε && y3 - y0 > ε ? {
4969
x: x1,
4970
y: abs(x2 - x1) < ε ? y2 : y0
4971
} : abs(y3 - y0) < ε && x3 - x0 > ε ? {
4972
x: abs(y2 - y0) < ε ? x2 : x0,
4973
y: y0
4974
} : null), cell.site, null));
4975
++nHalfEdges;
4976
}
4977
}
4978
}
4979
}
4980
function d3_geom_voronoiHalfEdgeOrder(a, b) {
4981
return b.angle - a.angle;
4982
}
4983
function d3_geom_voronoiCircle() {
4984
d3_geom_voronoiRedBlackNode(this);
4985
this.x = this.y = this.arc = this.site = this.cy = null;
4986
}
4987
function d3_geom_voronoiAttachCircle(arc) {
4988
var lArc = arc.P, rArc = arc.N;
4989
if (!lArc || !rArc) return;
4990
var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
4991
if (lSite === rSite) return;
4992
var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
4993
var d = 2 * (ax * cy - ay * cx);
4994
if (d >= -ε2) return;
4995
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;
4996
var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
4997
circle.arc = arc;
4998
circle.site = cSite;
4999
circle.x = x + bx;
5000
circle.y = cy + Math.sqrt(x * x + y * y);
5001
circle.cy = cy;
5002
arc.circle = circle;
5003
var before = null, node = d3_geom_voronoiCircles._;
5004
while (node) {
5005
if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
5006
if (node.L) node = node.L; else {
5007
before = node.P;
5008
break;
5009
}
5010
} else {
5011
if (node.R) node = node.R; else {
5012
before = node;
5013
break;
5014
}
5015
}
5016
}
5017
d3_geom_voronoiCircles.insert(before, circle);
5018
if (!before) d3_geom_voronoiFirstCircle = circle;
5019
}
5020
function d3_geom_voronoiDetachCircle(arc) {
5021
var circle = arc.circle;
5022
if (circle) {
5023
if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
5024
d3_geom_voronoiCircles.remove(circle);
5025
d3_geom_voronoiCirclePool.push(circle);
5026
d3_geom_voronoiRedBlackNode(circle);
5027
arc.circle = null;
5028
}
5029
}
5030
function d3_geom_voronoiClipEdges(extent) {
5031
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;
5032
while (i--) {
5033
e = edges[i];
5034
if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
5035
e.a = e.b = null;
5036
edges.splice(i, 1);
5037
}
5038
}
5039
}
5040
function d3_geom_voronoiConnectEdge(edge, extent) {
5041
var vb = edge.b;
5042
if (vb) return true;
5043
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;
5044
if (ry === ly) {
5045
if (fx < x0 || fx >= x1) return;
5046
if (lx > rx) {
5047
if (!va) va = {
5048
x: fx,
5049
y: y0
5050
}; else if (va.y >= y1) return;
5051
vb = {
5052
x: fx,
5053
y: y1
5054
};
5055
} else {
5056
if (!va) va = {
5057
x: fx,
5058
y: y1
5059
}; else if (va.y < y0) return;
5060
vb = {
5061
x: fx,
5062
y: y0
5063
};
5064
}
5065
} else {
5066
fm = (lx - rx) / (ry - ly);
5067
fb = fy - fm * fx;
5068
if (fm < -1 || fm > 1) {
5069
if (lx > rx) {
5070
if (!va) va = {
5071
x: (y0 - fb) / fm,
5072
y: y0
5073
}; else if (va.y >= y1) return;
5074
vb = {
5075
x: (y1 - fb) / fm,
5076
y: y1
5077
};
5078
} else {
5079
if (!va) va = {
5080
x: (y1 - fb) / fm,
5081
y: y1
5082
}; else if (va.y < y0) return;
5083
vb = {
5084
x: (y0 - fb) / fm,
5085
y: y0
5086
};
5087
}
5088
} else {
5089
if (ly < ry) {
5090
if (!va) va = {
5091
x: x0,
5092
y: fm * x0 + fb
5093
}; else if (va.x >= x1) return;
5094
vb = {
5095
x: x1,
5096
y: fm * x1 + fb
5097
};
5098
} else {
5099
if (!va) va = {
5100
x: x1,
5101
y: fm * x1 + fb
5102
}; else if (va.x < x0) return;
5103
vb = {
5104
x: x0,
5105
y: fm * x0 + fb
5106
};
5107
}
5108
}
5109
}
5110
edge.a = va;
5111
edge.b = vb;
5112
return true;
5113
}
5114
function d3_geom_voronoiEdge(lSite, rSite) {
5115
this.l = lSite;
5116
this.r = rSite;
5117
this.a = this.b = null;
5118
}
5119
function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
5120
var edge = new d3_geom_voronoiEdge(lSite, rSite);
5121
d3_geom_voronoiEdges.push(edge);
5122
if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
5123
if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
5124
d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
5125
d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
5126
return edge;
5127
}
5128
function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
5129
var edge = new d3_geom_voronoiEdge(lSite, null);
5130
edge.a = va;
5131
edge.b = vb;
5132
d3_geom_voronoiEdges.push(edge);
5133
return edge;
5134
}
5135
function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
5136
if (!edge.a && !edge.b) {
5137
edge.a = vertex;
5138
edge.l = lSite;
5139
edge.r = rSite;
5140
} else if (edge.l === rSite) {
5141
edge.b = vertex;
5142
} else {
5143
edge.a = vertex;
5144
}
5145
}
5146
function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
5147
var va = edge.a, vb = edge.b;
5148
this.edge = edge;
5149
this.site = lSite;
5150
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);
5151
}
5152
d3_geom_voronoiHalfEdge.prototype = {
5153
start: function() {
5154
return this.edge.l === this.site ? this.edge.a : this.edge.b;
5155
},
5156
end: function() {
5157
return this.edge.l === this.site ? this.edge.b : this.edge.a;
5158
}
5159
};
5160
function d3_geom_voronoiRedBlackTree() {
5161
this._ = null;
5162
}
5163
function d3_geom_voronoiRedBlackNode(node) {
5164
node.U = node.C = node.L = node.R = node.P = node.N = null;
5165
}
5166
d3_geom_voronoiRedBlackTree.prototype = {
5167
insert: function(after, node) {
5168
var parent, grandpa, uncle;
5169
if (after) {
5170
node.P = after;
5171
node.N = after.N;
5172
if (after.N) after.N.P = node;
5173
after.N = node;
5174
if (after.R) {
5175
after = after.R;
5176
while (after.L) after = after.L;
5177
after.L = node;
5178
} else {
5179
after.R = node;
5180
}
5181
parent = after;
5182
} else if (this._) {
5183
after = d3_geom_voronoiRedBlackFirst(this._);
5184
node.P = null;
5185
node.N = after;
5186
after.P = after.L = node;
5187
parent = after;
5188
} else {
5189
node.P = node.N = null;
5190
this._ = node;
5191
parent = null;
5192
}
5193
node.L = node.R = null;
5194
node.U = parent;
5195
node.C = true;
5196
after = node;
5197
while (parent && parent.C) {
5198
grandpa = parent.U;
5199
if (parent === grandpa.L) {
5200
uncle = grandpa.R;
5201
if (uncle && uncle.C) {
5202
parent.C = uncle.C = false;
5203
grandpa.C = true;
5204
after = grandpa;
5205
} else {
5206
if (after === parent.R) {
5207
d3_geom_voronoiRedBlackRotateLeft(this, parent);
5208
after = parent;
5209
parent = after.U;
5210
}
5211
parent.C = false;
5212
grandpa.C = true;
5213
d3_geom_voronoiRedBlackRotateRight(this, grandpa);
5214
}
5215
} else {
5216
uncle = grandpa.L;
5217
if (uncle && uncle.C) {
5218
parent.C = uncle.C = false;
5219
grandpa.C = true;
5220
after = grandpa;
5221
} else {
5222
if (after === parent.L) {
5223
d3_geom_voronoiRedBlackRotateRight(this, parent);
5224
after = parent;
5225
parent = after.U;
5226
}
5227
parent.C = false;
5228
grandpa.C = true;
5229
d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
5230
}
5231
}
5232
parent = after.U;
5233
}
5234
this._.C = false;
5235
},
5236
remove: function(node) {
5237
if (node.N) node.N.P = node.P;
5238
if (node.P) node.P.N = node.N;
5239
node.N = node.P = null;
5240
var parent = node.U, sibling, left = node.L, right = node.R, next, red;
5241
if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
5242
if (parent) {
5243
if (parent.L === node) parent.L = next; else parent.R = next;
5244
} else {
5245
this._ = next;
5246
}
5247
if (left && right) {
5248
red = next.C;
5249
next.C = node.C;
5250
next.L = left;
5251
left.U = next;
5252
if (next !== right) {
5253
parent = next.U;
5254
next.U = node.U;
5255
node = next.R;
5256
parent.L = node;
5257
next.R = right;
5258
right.U = next;
5259
} else {
5260
next.U = parent;
5261
parent = next;
5262
node = next.R;
5263
}
5264
} else {
5265
red = node.C;
5266
node = next;
5267
}
5268
if (node) node.U = parent;
5269
if (red) return;
5270
if (node && node.C) {
5271
node.C = false;
5272
return;
5273
}
5274
do {
5275
if (node === this._) break;
5276
if (node === parent.L) {
5277
sibling = parent.R;
5278
if (sibling.C) {
5279
sibling.C = false;
5280
parent.C = true;
5281
d3_geom_voronoiRedBlackRotateLeft(this, parent);
5282
sibling = parent.R;
5283
}
5284
if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5285
if (!sibling.R || !sibling.R.C) {
5286
sibling.L.C = false;
5287
sibling.C = true;
5288
d3_geom_voronoiRedBlackRotateRight(this, sibling);
5289
sibling = parent.R;
5290
}
5291
sibling.C = parent.C;
5292
parent.C = sibling.R.C = false;
5293
d3_geom_voronoiRedBlackRotateLeft(this, parent);
5294
node = this._;
5295
break;
5296
}
5297
} else {
5298
sibling = parent.L;
5299
if (sibling.C) {
5300
sibling.C = false;
5301
parent.C = true;
5302
d3_geom_voronoiRedBlackRotateRight(this, parent);
5303
sibling = parent.L;
5304
}
5305
if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5306
if (!sibling.L || !sibling.L.C) {
5307
sibling.R.C = false;
5308
sibling.C = true;
5309
d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5310
sibling = parent.L;
5311
}
5312
sibling.C = parent.C;
5313
parent.C = sibling.L.C = false;
5314
d3_geom_voronoiRedBlackRotateRight(this, parent);
5315
node = this._;
5316
break;
5317
}
5318
}
5319
sibling.C = true;
5320
node = parent;
5321
parent = parent.U;
5322
} while (!node.C);
5323
if (node) node.C = false;
5324
}
5325
};
5326
function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5327
var p = node, q = node.R, parent = p.U;
5328
if (parent) {
5329
if (parent.L === p) parent.L = q; else parent.R = q;
5330
} else {
5331
tree._ = q;
5332
}
5333
q.U = parent;
5334
p.U = q;
5335
p.R = q.L;
5336
if (p.R) p.R.U = p;
5337
q.L = p;
5338
}
5339
function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5340
var p = node, q = node.L, parent = p.U;
5341
if (parent) {
5342
if (parent.L === p) parent.L = q; else parent.R = q;
5343
} else {
5344
tree._ = q;
5345
}
5346
q.U = parent;
5347
p.U = q;
5348
p.L = q.R;
5349
if (p.L) p.L.U = p;
5350
q.R = p;
5351
}
5352
function d3_geom_voronoiRedBlackFirst(node) {
5353
while (node.L) node = node.L;
5354
return node;
5355
}
5356
function d3_geom_voronoi(sites, bbox) {
5357
var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5358
d3_geom_voronoiEdges = [];
5359
d3_geom_voronoiCells = new Array(sites.length);
5360
d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
5361
d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
5362
while (true) {
5363
circle = d3_geom_voronoiFirstCircle;
5364
if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5365
if (site.x !== x0 || site.y !== y0) {
5366
d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
5367
d3_geom_voronoiAddBeach(site);
5368
x0 = site.x, y0 = site.y;
5369
}
5370
site = sites.pop();
5371
} else if (circle) {
5372
d3_geom_voronoiRemoveBeach(circle.arc);
5373
} else {
5374
break;
5375
}
5376
}
5377
if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
5378
var diagram = {
5379
cells: d3_geom_voronoiCells,
5380
edges: d3_geom_voronoiEdges
5381
};
5382
d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5383
return diagram;
5384
}
5385
function d3_geom_voronoiVertexOrder(a, b) {
5386
return b.y - a.y || b.x - a.x;
5387
}
5388
d3.geom.voronoi = function(points) {
5389
var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5390
if (points) return voronoi(points);
5391
function voronoi(data) {
5392
var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
5393
d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5394
var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
5395
var s = e.start();
5396
return [ s.x, s.y ];
5397
}) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
5398
polygon.point = data[i];
5399
});
5400
return polygons;
5401
}
5402
function sites(data) {
5403
return data.map(function(d, i) {
5404
return {
5405
x: Math.round(fx(d, i) / ε) * ε,
5406
y: Math.round(fy(d, i) / ε) * ε,
5407
i: i
5408
};
5409
});
5410
}
5411
voronoi.links = function(data) {
5412
return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5413
return edge.l && edge.r;
5414
}).map(function(edge) {
5415
return {
5416
source: data[edge.l.i],
5417
target: data[edge.r.i]
5418
};
5419
});
5420
};
5421
voronoi.triangles = function(data) {
5422
var triangles = [];
5423
d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5424
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;
5425
while (++j < m) {
5426
e0 = e1;
5427
s0 = s1;
5428
e1 = edges[j].edge;
5429
s1 = e1.l === site ? e1.r : e1.l;
5430
if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5431
triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5432
}
5433
}
5434
});
5435
return triangles;
5436
};
5437
voronoi.x = function(_) {
5438
return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
5439
};
5440
voronoi.y = function(_) {
5441
return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
5442
};
5443
voronoi.clipExtent = function(_) {
5444
if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
5445
clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5446
return voronoi;
5447
};
5448
voronoi.size = function(_) {
5449
if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
5450
return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5451
};
5452
return voronoi;
5453
};
5454
var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5455
function d3_geom_voronoiTriangleArea(a, b, c) {
5456
return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
5457
}
5458
d3.geom.delaunay = function(vertices) {
5459
return d3.geom.voronoi().triangles(vertices);
5460
};
5461
d3.geom.quadtree = function(points, x1, y1, x2, y2) {
5462
var x = d3_geom_pointX, y = d3_geom_pointY, compat;
5463
if (compat = arguments.length) {
5464
x = d3_geom_quadtreeCompatX;
5465
y = d3_geom_quadtreeCompatY;
5466
if (compat === 3) {
5467
y2 = y1;
5468
x2 = x1;
5469
y1 = x1 = 0;
5470
}
5471
return quadtree(points);
5472
}
5473
function quadtree(data) {
5474
var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
5475
if (x1 != null) {
5476
x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
5477
} else {
5478
x2_ = y2_ = -(x1_ = y1_ = Infinity);
5479
xs = [], ys = [];
5480
n = data.length;
5481
if (compat) for (i = 0; i < n; ++i) {
5482
d = data[i];
5483
if (d.x < x1_) x1_ = d.x;
5484
if (d.y < y1_) y1_ = d.y;
5485
if (d.x > x2_) x2_ = d.x;
5486
if (d.y > y2_) y2_ = d.y;
5487
xs.push(d.x);
5488
ys.push(d.y);
5489
} else for (i = 0; i < n; ++i) {
5490
var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
5491
if (x_ < x1_) x1_ = x_;
5492
if (y_ < y1_) y1_ = y_;
5493
if (x_ > x2_) x2_ = x_;
5494
if (y_ > y2_) y2_ = y_;
5495
xs.push(x_);
5496
ys.push(y_);
5497
}
5498
}
5499
var dx = x2_ - x1_, dy = y2_ - y1_;
5500
if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
5501
function insert(n, d, x, y, x1, y1, x2, y2) {
5502
if (isNaN(x) || isNaN(y)) return;
5503
if (n.leaf) {
5504
var nx = n.x, ny = n.y;
5505
if (nx != null) {
5506
if (abs(nx - x) + abs(ny - y) < .01) {
5507
insertChild(n, d, x, y, x1, y1, x2, y2);
5508
} else {
5509
var nPoint = n.point;
5510
n.x = n.y = n.point = null;
5511
insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
5512
insertChild(n, d, x, y, x1, y1, x2, y2);
5513
}
5514
} else {
5515
n.x = x, n.y = y, n.point = d;
5516
}
5517
} else {
5518
insertChild(n, d, x, y, x1, y1, x2, y2);
5519
}
5520
}
5521
function insertChild(n, d, x, y, x1, y1, x2, y2) {
5522
var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right;
5523
n.leaf = false;
5524
n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
5525
if (right) x1 = sx; else x2 = sx;
5526
if (bottom) y1 = sy; else y2 = sy;
5527
insert(n, d, x, y, x1, y1, x2, y2);
5528
}
5529
var root = d3_geom_quadtreeNode();
5530
root.add = function(d) {
5531
insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
5532
};
5533
root.visit = function(f) {
5534
d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
5535
};
5536
i = -1;
5537
if (x1 == null) {
5538
while (++i < n) {
5539
insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
5540
}
5541
--i;
5542
} else data.forEach(root.add);
5543
xs = ys = data = d = null;
5544
return root;
5545
}
5546
quadtree.x = function(_) {
5547
return arguments.length ? (x = _, quadtree) : x;
5548
};
5549
quadtree.y = function(_) {
5550
return arguments.length ? (y = _, quadtree) : y;
5551
};
5552
quadtree.extent = function(_) {
5553
if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
5554
if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
5555
y2 = +_[1][1];
5556
return quadtree;
5557
};
5558
quadtree.size = function(_) {
5559
if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
5560
if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
5561
return quadtree;
5562
};
5563
return quadtree;
5564
};
5565
function d3_geom_quadtreeCompatX(d) {
5566
return d.x;
5567
}
5568
function d3_geom_quadtreeCompatY(d) {
5569
return d.y;
5570
}
5571
function d3_geom_quadtreeNode() {
5572
return {
5573
leaf: true,
5574
nodes: [],
5575
point: null,
5576
x: null,
5577
y: null
5578
};
5579
}
5580
function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
5581
if (!f(node, x1, y1, x2, y2)) {
5582
var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
5583
if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
5584
if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
5585
if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
5586
if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
5587
}
5588
}
5589
d3.interpolateRgb = d3_interpolateRgb;
5590
function d3_interpolateRgb(a, b) {
5591
a = d3.rgb(a);
5592
b = d3.rgb(b);
5593
var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
5594
return function(t) {
5595
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));
5596
};
5597
}
5598
d3.interpolateObject = d3_interpolateObject;
5599
function d3_interpolateObject(a, b) {
5600
var i = {}, c = {}, k;
5601
for (k in a) {
5602
if (k in b) {
5603
i[k] = d3_interpolate(a[k], b[k]);
5604
} else {
5605
c[k] = a[k];
5606
}
5607
}
5608
for (k in b) {
5609
if (!(k in a)) {
5610
c[k] = b[k];
5611
}
5612
}
5613
return function(t) {
5614
for (k in i) c[k] = i[k](t);
5615
return c;
5616
};
5617
}
5618
d3.interpolateNumber = d3_interpolateNumber;
5619
function d3_interpolateNumber(a, b) {
5620
b -= a = +a;
5621
return function(t) {
5622
return a + b * t;
5623
};
5624
}
5625
d3.interpolateString = d3_interpolateString;
5626
function d3_interpolateString(a, b) {
5627
var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
5628
a = a + "", b = b + "";
5629
while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
5630
if ((bs = bm.index) > bi) {
5631
bs = b.substring(bi, bs);
5632
if (s[i]) s[i] += bs; else s[++i] = bs;
5633
}
5634
if ((am = am[0]) === (bm = bm[0])) {
5635
if (s[i]) s[i] += bm; else s[++i] = bm;
5636
} else {
5637
s[++i] = null;
5638
q.push({
5639
i: i,
5640
x: d3_interpolateNumber(am, bm)
5641
});
5642
}
5643
bi = d3_interpolate_numberB.lastIndex;
5644
}
5645
if (bi < b.length) {
5646
bs = b.substring(bi);
5647
if (s[i]) s[i] += bs; else s[++i] = bs;
5648
}
5649
return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
5650
return b(t) + "";
5651
}) : function() {
5652
return b;
5653
} : (b = q.length, function(t) {
5654
for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
5655
return s.join("");
5656
});
5657
}
5658
var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
5659
d3.interpolate = d3_interpolate;
5660
function d3_interpolate(a, b) {
5661
var i = d3.interpolators.length, f;
5662
while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
5663
return f;
5664
}
5665
d3.interpolators = [ function(a, b) {
5666
var t = typeof b;
5667
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);
5668
} ];
5669
d3.interpolateArray = d3_interpolateArray;
5670
function d3_interpolateArray(a, b) {
5671
var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
5672
for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
5673
for (;i < na; ++i) c[i] = a[i];
5674
for (;i < nb; ++i) c[i] = b[i];
5675
return function(t) {
5676
for (i = 0; i < n0; ++i) c[i] = x[i](t);
5677
return c;
5678
};
5679
}
5680
var d3_ease_default = function() {
5681
return d3_identity;
5682
};
5683
var d3_ease = d3.map({
5684
linear: d3_ease_default,
5685
poly: d3_ease_poly,
5686
quad: function() {
5687
return d3_ease_quad;
5688
},
5689
cubic: function() {
5690
return d3_ease_cubic;
5691
},
5692
sin: function() {
5693
return d3_ease_sin;
5694
},
5695
exp: function() {
5696
return d3_ease_exp;
5697
},
5698
circle: function() {
5699
return d3_ease_circle;
5700
},
5701
elastic: d3_ease_elastic,
5702
back: d3_ease_back,
5703
bounce: function() {
5704
return d3_ease_bounce;
5705
}
5706
});
5707
var d3_ease_mode = d3.map({
5708
"in": d3_identity,
5709
out: d3_ease_reverse,
5710
"in-out": d3_ease_reflect,
5711
"out-in": function(f) {
5712
return d3_ease_reflect(d3_ease_reverse(f));
5713
}
5714
});
5715
d3.ease = function(name) {
5716
var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
5717
t = d3_ease.get(t) || d3_ease_default;
5718
m = d3_ease_mode.get(m) || d3_identity;
5719
return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5720
};
5721
function d3_ease_clamp(f) {
5722
return function(t) {
5723
return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
5724
};
5725
}
5726
function d3_ease_reverse(f) {
5727
return function(t) {
5728
return 1 - f(1 - t);
5729
};
5730
}
5731
function d3_ease_reflect(f) {
5732
return function(t) {
5733
return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
5734
};
5735
}
5736
function d3_ease_quad(t) {
5737
return t * t;
5738
}
5739
function d3_ease_cubic(t) {
5740
return t * t * t;
5741
}
5742
function d3_ease_cubicInOut(t) {
5743
if (t <= 0) return 0;
5744
if (t >= 1) return 1;
5745
var t2 = t * t, t3 = t2 * t;
5746
return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
5747
}
5748
function d3_ease_poly(e) {
5749
return function(t) {
5750
return Math.pow(t, e);
5751
};
5752
}
5753
function d3_ease_sin(t) {
5754
return 1 - Math.cos(t * halfπ);
5755
}
5756
function d3_ease_exp(t) {
5757
return Math.pow(2, 10 * (t - 1));
5758
}
5759
function d3_ease_circle(t) {
5760
return 1 - Math.sqrt(1 - t * t);
5761
}
5762
function d3_ease_elastic(a, p) {
5763
var s;
5764
if (arguments.length < 2) p = .45;
5765
if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
5766
return function(t) {
5767
return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
5768
};
5769
}
5770
function d3_ease_back(s) {
5771
if (!s) s = 1.70158;
5772
return function(t) {
5773
return t * t * ((s + 1) * t - s);
5774
};
5775
}
5776
function d3_ease_bounce(t) {
5777
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;
5778
}
5779
d3.interpolateHcl = d3_interpolateHcl;
5780
function d3_interpolateHcl(a, b) {
5781
a = d3.hcl(a);
5782
b = d3.hcl(b);
5783
var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
5784
if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
5785
if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5786
return function(t) {
5787
return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
5788
};
5789
}
5790
d3.interpolateHsl = d3_interpolateHsl;
5791
function d3_interpolateHsl(a, b) {
5792
a = d3.hsl(a);
5793
b = d3.hsl(b);
5794
var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
5795
if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
5796
if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5797
return function(t) {
5798
return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
5799
};
5800
}
5801
d3.interpolateLab = d3_interpolateLab;
5802
function d3_interpolateLab(a, b) {
5803
a = d3.lab(a);
5804
b = d3.lab(b);
5805
var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
5806
return function(t) {
5807
return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
5808
};
5809
}
5810
d3.interpolateRound = d3_interpolateRound;
5811
function d3_interpolateRound(a, b) {
5812
b -= a;
5813
return function(t) {
5814
return Math.round(a + b * t);
5815
};
5816
}
5817
d3.transform = function(string) {
5818
var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
5819
return (d3.transform = function(string) {
5820
if (string != null) {
5821
g.setAttribute("transform", string);
5822
var t = g.transform.baseVal.consolidate();
5823
}
5824
return new d3_transform(t ? t.matrix : d3_transformIdentity);
5825
})(string);
5826
};
5827
function d3_transform(m) {
5828
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;
5829
if (r0[0] * r1[1] < r1[0] * r0[1]) {
5830
r0[0] *= -1;
5831
r0[1] *= -1;
5832
kx *= -1;
5833
kz *= -1;
5834
}
5835
this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
5836
this.translate = [ m.e, m.f ];
5837
this.scale = [ kx, ky ];
5838
this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
5839
}
5840
d3_transform.prototype.toString = function() {
5841
return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
5842
};
5843
function d3_transformDot(a, b) {
5844
return a[0] * b[0] + a[1] * b[1];
5845
}
5846
function d3_transformNormalize(a) {
5847
var k = Math.sqrt(d3_transformDot(a, a));
5848
if (k) {
5849
a[0] /= k;
5850
a[1] /= k;
5851
}
5852
return k;
5853
}
5854
function d3_transformCombine(a, b, k) {
5855
a[0] += k * b[0];
5856
a[1] += k * b[1];
5857
return a;
5858
}
5859
var d3_transformIdentity = {
5860
a: 1,
5861
b: 0,
5862
c: 0,
5863
d: 1,
5864
e: 0,
5865
f: 0
5866
};
5867
d3.interpolateTransform = d3_interpolateTransform;
5868
function d3_interpolateTransform(a, b) {
5869
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;
5870
if (ta[0] != tb[0] || ta[1] != tb[1]) {
5871
s.push("translate(", null, ",", null, ")");
5872
q.push({
5873
i: 1,
5874
x: d3_interpolateNumber(ta[0], tb[0])
5875
}, {
5876
i: 3,
5877
x: d3_interpolateNumber(ta[1], tb[1])
5878
});
5879
} else if (tb[0] || tb[1]) {
5880
s.push("translate(" + tb + ")");
5881
} else {
5882
s.push("");
5883
}
5884
if (ra != rb) {
5885
if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
5886
q.push({
5887
i: s.push(s.pop() + "rotate(", null, ")") - 2,
5888
x: d3_interpolateNumber(ra, rb)
5889
});
5890
} else if (rb) {
5891
s.push(s.pop() + "rotate(" + rb + ")");
5892
}
5893
if (wa != wb) {
5894
q.push({
5895
i: s.push(s.pop() + "skewX(", null, ")") - 2,
5896
x: d3_interpolateNumber(wa, wb)
5897
});
5898
} else if (wb) {
5899
s.push(s.pop() + "skewX(" + wb + ")");
5900
}
5901
if (ka[0] != kb[0] || ka[1] != kb[1]) {
5902
n = s.push(s.pop() + "scale(", null, ",", null, ")");
5903
q.push({
5904
i: n - 4,
5905
x: d3_interpolateNumber(ka[0], kb[0])
5906
}, {
5907
i: n - 2,
5908
x: d3_interpolateNumber(ka[1], kb[1])
5909
});
5910
} else if (kb[0] != 1 || kb[1] != 1) {
5911
s.push(s.pop() + "scale(" + kb + ")");
5912
}
5913
n = q.length;
5914
return function(t) {
5915
var i = -1, o;
5916
while (++i < n) s[(o = q[i]).i] = o.x(t);
5917
return s.join("");
5918
};
5919
}
5920
function d3_uninterpolateNumber(a, b) {
5921
b = b - (a = +a) ? 1 / (b - a) : 0;
5922
return function(x) {
5923
return (x - a) * b;
5924
};
5925
}
5926
function d3_uninterpolateClamp(a, b) {
5927
b = b - (a = +a) ? 1 / (b - a) : 0;
5928
return function(x) {
5929
return Math.max(0, Math.min(1, (x - a) * b));
5930
};
5931
}
5932
d3.layout = {};
5933
d3.layout.bundle = function() {
5934
return function(links) {
5935
var paths = [], i = -1, n = links.length;
5936
while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
5937
return paths;
5938
};
5939
};
5940
function d3_layout_bundlePath(link) {
5941
var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
5942
while (start !== lca) {
5943
start = start.parent;
5944
points.push(start);
5945
}
5946
var k = points.length;
5947
while (end !== lca) {
5948
points.splice(k, 0, end);
5949
end = end.parent;
5950
}
5951
return points;
5952
}
5953
function d3_layout_bundleAncestors(node) {
5954
var ancestors = [], parent = node.parent;
5955
while (parent != null) {
5956
ancestors.push(node);
5957
node = parent;
5958
parent = parent.parent;
5959
}
5960
ancestors.push(node);
5961
return ancestors;
5962
}
5963
function d3_layout_bundleLeastCommonAncestor(a, b) {
5964
if (a === b) return a;
5965
var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
5966
while (aNode === bNode) {
5967
sharedNode = aNode;
5968
aNode = aNodes.pop();
5969
bNode = bNodes.pop();
5970
}
5971
return sharedNode;
5972
}
5973
d3.layout.chord = function() {
5974
var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
5975
function relayout() {
5976
var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
5977
chords = [];
5978
groups = [];
5979
k = 0, i = -1;
5980
while (++i < n) {
5981
x = 0, j = -1;
5982
while (++j < n) {
5983
x += matrix[i][j];
5984
}
5985
groupSums.push(x);
5986
subgroupIndex.push(d3.range(n));
5987
k += x;
5988
}
5989
if (sortGroups) {
5990
groupIndex.sort(function(a, b) {
5991
return sortGroups(groupSums[a], groupSums[b]);
5992
});
5993
}
5994
if (sortSubgroups) {
5995
subgroupIndex.forEach(function(d, i) {
5996
d.sort(function(a, b) {
5997
return sortSubgroups(matrix[i][a], matrix[i][b]);
5998
});
5999
});
6000
}
6001
k = (τ - padding * n) / k;
6002
x = 0, i = -1;
6003
while (++i < n) {
6004
x0 = x, j = -1;
6005
while (++j < n) {
6006
var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
6007
subgroups[di + "-" + dj] = {
6008
index: di,
6009
subindex: dj,
6010
startAngle: a0,
6011
endAngle: a1,
6012
value: v
6013
};
6014
}
6015
groups[di] = {
6016
index: di,
6017
startAngle: x0,
6018
endAngle: x,
6019
value: (x - x0) / k
6020
};
6021
x += padding;
6022
}
6023
i = -1;
6024
while (++i < n) {
6025
j = i - 1;
6026
while (++j < n) {
6027
var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
6028
if (source.value || target.value) {
6029
chords.push(source.value < target.value ? {
6030
source: target,
6031
target: source
6032
} : {
6033
source: source,
6034
target: target
6035
});
6036
}
6037
}
6038
}
6039
if (sortChords) resort();
6040
}
6041
function resort() {
6042
chords.sort(function(a, b) {
6043
return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
6044
});
6045
}
6046
chord.matrix = function(x) {
6047
if (!arguments.length) return matrix;
6048
n = (matrix = x) && matrix.length;
6049
chords = groups = null;
6050
return chord;
6051
};
6052
chord.padding = function(x) {
6053
if (!arguments.length) return padding;
6054
padding = x;
6055
chords = groups = null;
6056
return chord;
6057
};
6058
chord.sortGroups = function(x) {
6059
if (!arguments.length) return sortGroups;
6060
sortGroups = x;
6061
chords = groups = null;
6062
return chord;
6063
};
6064
chord.sortSubgroups = function(x) {
6065
if (!arguments.length) return sortSubgroups;
6066
sortSubgroups = x;
6067
chords = null;
6068
return chord;
6069
};
6070
chord.sortChords = function(x) {
6071
if (!arguments.length) return sortChords;
6072
sortChords = x;
6073
if (chords) resort();
6074
return chord;
6075
};
6076
chord.chords = function() {
6077
if (!chords) relayout();
6078
return chords;
6079
};
6080
chord.groups = function() {
6081
if (!groups) relayout();
6082
return groups;
6083
};
6084
return chord;
6085
};
6086
d3.layout.force = function() {
6087
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;
6088
function repulse(node) {
6089
return function(quad, x1, _, x2) {
6090
if (quad.point !== node) {
6091
var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
6092
if (dw * dw / theta2 < dn) {
6093
if (dn < chargeDistance2) {
6094
var k = quad.charge / dn;
6095
node.px -= dx * k;
6096
node.py -= dy * k;
6097
}
6098
return true;
6099
}
6100
if (quad.point && dn && dn < chargeDistance2) {
6101
var k = quad.pointCharge / dn;
6102
node.px -= dx * k;
6103
node.py -= dy * k;
6104
}
6105
}
6106
return !quad.charge;
6107
};
6108
}
6109
force.tick = function() {
6110
if ((alpha *= .99) < .005) {
6111
event.end({
6112
type: "end",
6113
alpha: alpha = 0
6114
});
6115
return true;
6116
}
6117
var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
6118
for (i = 0; i < m; ++i) {
6119
o = links[i];
6120
s = o.source;
6121
t = o.target;
6122
x = t.x - s.x;
6123
y = t.y - s.y;
6124
if (l = x * x + y * y) {
6125
l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
6126
x *= l;
6127
y *= l;
6128
t.x -= x * (k = s.weight / (t.weight + s.weight));
6129
t.y -= y * k;
6130
s.x += x * (k = 1 - k);
6131
s.y += y * k;
6132
}
6133
}
6134
if (k = alpha * gravity) {
6135
x = size[0] / 2;
6136
y = size[1] / 2;
6137
i = -1;
6138
if (k) while (++i < n) {
6139
o = nodes[i];
6140
o.x += (x - o.x) * k;
6141
o.y += (y - o.y) * k;
6142
}
6143
}
6144
if (charge) {
6145
d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
6146
i = -1;
6147
while (++i < n) {
6148
if (!(o = nodes[i]).fixed) {
6149
q.visit(repulse(o));
6150
}
6151
}
6152
}
6153
i = -1;
6154
while (++i < n) {
6155
o = nodes[i];
6156
if (o.fixed) {
6157
o.x = o.px;
6158
o.y = o.py;
6159
} else {
6160
o.x -= (o.px - (o.px = o.x)) * friction;
6161
o.y -= (o.py - (o.py = o.y)) * friction;
6162
}
6163
}
6164
event.tick({
6165
type: "tick",
6166
alpha: alpha
6167
});
6168
};
6169
force.nodes = function(x) {
6170
if (!arguments.length) return nodes;
6171
nodes = x;
6172
return force;
6173
};
6174
force.links = function(x) {
6175
if (!arguments.length) return links;
6176
links = x;
6177
return force;
6178
};
6179
force.size = function(x) {
6180
if (!arguments.length) return size;
6181
size = x;
6182
return force;
6183
};
6184
force.linkDistance = function(x) {
6185
if (!arguments.length) return linkDistance;
6186
linkDistance = typeof x === "function" ? x : +x;
6187
return force;
6188
};
6189
force.distance = force.linkDistance;
6190
force.linkStrength = function(x) {
6191
if (!arguments.length) return linkStrength;
6192
linkStrength = typeof x === "function" ? x : +x;
6193
return force;
6194
};
6195
force.friction = function(x) {
6196
if (!arguments.length) return friction;
6197
friction = +x;
6198
return force;
6199
};
6200
force.charge = function(x) {
6201
if (!arguments.length) return charge;
6202
charge = typeof x === "function" ? x : +x;
6203
return force;
6204
};
6205
force.chargeDistance = function(x) {
6206
if (!arguments.length) return Math.sqrt(chargeDistance2);
6207
chargeDistance2 = x * x;
6208
return force;
6209
};
6210
force.gravity = function(x) {
6211
if (!arguments.length) return gravity;
6212
gravity = +x;
6213
return force;
6214
};
6215
force.theta = function(x) {
6216
if (!arguments.length) return Math.sqrt(theta2);
6217
theta2 = x * x;
6218
return force;
6219
};
6220
force.alpha = function(x) {
6221
if (!arguments.length) return alpha;
6222
x = +x;
6223
if (alpha) {
6224
if (x > 0) alpha = x; else alpha = 0;
6225
} else if (x > 0) {
6226
event.start({
6227
type: "start",
6228
alpha: alpha = x
6229
});
6230
d3.timer(force.tick);
6231
}
6232
return force;
6233
};
6234
force.start = function() {
6235
var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6236
for (i = 0; i < n; ++i) {
6237
(o = nodes[i]).index = i;
6238
o.weight = 0;
6239
}
6240
for (i = 0; i < m; ++i) {
6241
o = links[i];
6242
if (typeof o.source == "number") o.source = nodes[o.source];
6243
if (typeof o.target == "number") o.target = nodes[o.target];
6244
++o.source.weight;
6245
++o.target.weight;
6246
}
6247
for (i = 0; i < n; ++i) {
6248
o = nodes[i];
6249
if (isNaN(o.x)) o.x = position("x", w);
6250
if (isNaN(o.y)) o.y = position("y", h);
6251
if (isNaN(o.px)) o.px = o.x;
6252
if (isNaN(o.py)) o.py = o.y;
6253
}
6254
distances = [];
6255
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;
6256
strengths = [];
6257
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;
6258
charges = [];
6259
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;
6260
function position(dimension, size) {
6261
if (!neighbors) {
6262
neighbors = new Array(n);
6263
for (j = 0; j < n; ++j) {
6264
neighbors[j] = [];
6265
}
6266
for (j = 0; j < m; ++j) {
6267
var o = links[j];
6268
neighbors[o.source.index].push(o.target);
6269
neighbors[o.target.index].push(o.source);
6270
}
6271
}
6272
var candidates = neighbors[i], j = -1, m = candidates.length, x;
6273
while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
6274
return Math.random() * size;
6275
}
6276
return force.resume();
6277
};
6278
force.resume = function() {
6279
return force.alpha(.1);
6280
};
6281
force.stop = function() {
6282
return force.alpha(0);
6283
};
6284
force.drag = function() {
6285
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);
6286
if (!arguments.length) return drag;
6287
this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
6288
};
6289
function dragmove(d) {
6290
d.px = d3.event.x, d.py = d3.event.y;
6291
force.resume();
6292
}
6293
return d3.rebind(force, event, "on");
6294
};
6295
function d3_layout_forceDragstart(d) {
6296
d.fixed |= 2;
6297
}
6298
function d3_layout_forceDragend(d) {
6299
d.fixed &= ~6;
6300
}
6301
function d3_layout_forceMouseover(d) {
6302
d.fixed |= 4;
6303
d.px = d.x, d.py = d.y;
6304
}
6305
function d3_layout_forceMouseout(d) {
6306
d.fixed &= ~4;
6307
}
6308
function d3_layout_forceAccumulate(quad, alpha, charges) {
6309
var cx = 0, cy = 0;
6310
quad.charge = 0;
6311
if (!quad.leaf) {
6312
var nodes = quad.nodes, n = nodes.length, i = -1, c;
6313
while (++i < n) {
6314
c = nodes[i];
6315
if (c == null) continue;
6316
d3_layout_forceAccumulate(c, alpha, charges);
6317
quad.charge += c.charge;
6318
cx += c.charge * c.cx;
6319
cy += c.charge * c.cy;
6320
}
6321
}
6322
if (quad.point) {
6323
if (!quad.leaf) {
6324
quad.point.x += Math.random() - .5;
6325
quad.point.y += Math.random() - .5;
6326
}
6327
var k = alpha * charges[quad.point.index];
6328
quad.charge += quad.pointCharge = k;
6329
cx += k * quad.point.x;
6330
cy += k * quad.point.y;
6331
}
6332
quad.cx = cx / quad.charge;
6333
quad.cy = cy / quad.charge;
6334
}
6335
var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
6336
d3.layout.hierarchy = function() {
6337
var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
6338
function hierarchy(root) {
6339
var stack = [ root ], nodes = [], node;
6340
root.depth = 0;
6341
while ((node = stack.pop()) != null) {
6342
nodes.push(node);
6343
if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
6344
var n, childs, child;
6345
while (--n >= 0) {
6346
stack.push(child = childs[n]);
6347
child.parent = node;
6348
child.depth = node.depth + 1;
6349
}
6350
if (value) node.value = 0;
6351
node.children = childs;
6352
} else {
6353
if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
6354
delete node.children;
6355
}
6356
}
6357
d3_layout_hierarchyVisitAfter(root, function(node) {
6358
var childs, parent;
6359
if (sort && (childs = node.children)) childs.sort(sort);
6360
if (value && (parent = node.parent)) parent.value += node.value;
6361
});
6362
return nodes;
6363
}
6364
hierarchy.sort = function(x) {
6365
if (!arguments.length) return sort;
6366
sort = x;
6367
return hierarchy;
6368
};
6369
hierarchy.children = function(x) {
6370
if (!arguments.length) return children;
6371
children = x;
6372
return hierarchy;
6373
};
6374
hierarchy.value = function(x) {
6375
if (!arguments.length) return value;
6376
value = x;
6377
return hierarchy;
6378
};
6379
hierarchy.revalue = function(root) {
6380
if (value) {
6381
d3_layout_hierarchyVisitBefore(root, function(node) {
6382
if (node.children) node.value = 0;
6383
});
6384
d3_layout_hierarchyVisitAfter(root, function(node) {
6385
var parent;
6386
if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
6387
if (parent = node.parent) parent.value += node.value;
6388
});
6389
}
6390
return root;
6391
};
6392
return hierarchy;
6393
};
6394
function d3_layout_hierarchyRebind(object, hierarchy) {
6395
d3.rebind(object, hierarchy, "sort", "children", "value");
6396
object.nodes = object;
6397
object.links = d3_layout_hierarchyLinks;
6398
return object;
6399
}
6400
function d3_layout_hierarchyVisitBefore(node, callback) {
6401
var nodes = [ node ];
6402
while ((node = nodes.pop()) != null) {
6403
callback(node);
6404
if ((children = node.children) && (n = children.length)) {
6405
var n, children;
6406
while (--n >= 0) nodes.push(children[n]);
6407
}
6408
}
6409
}
6410
function d3_layout_hierarchyVisitAfter(node, callback) {
6411
var nodes = [ node ], nodes2 = [];
6412
while ((node = nodes.pop()) != null) {
6413
nodes2.push(node);
6414
if ((children = node.children) && (n = children.length)) {
6415
var i = -1, n, children;
6416
while (++i < n) nodes.push(children[i]);
6417
}
6418
}
6419
while ((node = nodes2.pop()) != null) {
6420
callback(node);
6421
}
6422
}
6423
function d3_layout_hierarchyChildren(d) {
6424
return d.children;
6425
}
6426
function d3_layout_hierarchyValue(d) {
6427
return d.value;
6428
}
6429
function d3_layout_hierarchySort(a, b) {
6430
return b.value - a.value;
6431
}
6432
function d3_layout_hierarchyLinks(nodes) {
6433
return d3.merge(nodes.map(function(parent) {
6434
return (parent.children || []).map(function(child) {
6435
return {
6436
source: parent,
6437
target: child
6438
};
6439
});
6440
}));
6441
}
6442
d3.layout.partition = function() {
6443
var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
6444
function position(node, x, dx, dy) {
6445
var children = node.children;
6446
node.x = x;
6447
node.y = node.depth * dy;
6448
node.dx = dx;
6449
node.dy = dy;
6450
if (children && (n = children.length)) {
6451
var i = -1, n, c, d;
6452
dx = node.value ? dx / node.value : 0;
6453
while (++i < n) {
6454
position(c = children[i], x, d = c.value * dx, dy);
6455
x += d;
6456
}
6457
}
6458
}
6459
function depth(node) {
6460
var children = node.children, d = 0;
6461
if (children && (n = children.length)) {
6462
var i = -1, n;
6463
while (++i < n) d = Math.max(d, depth(children[i]));
6464
}
6465
return 1 + d;
6466
}
6467
function partition(d, i) {
6468
var nodes = hierarchy.call(this, d, i);
6469
position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
6470
return nodes;
6471
}
6472
partition.size = function(x) {
6473
if (!arguments.length) return size;
6474
size = x;
6475
return partition;
6476
};
6477
return d3_layout_hierarchyRebind(partition, hierarchy);
6478
};
6479
d3.layout.pie = function() {
6480
var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ;
6481
function pie(data) {
6482
var values = data.map(function(d, i) {
6483
return +value.call(pie, d, i);
6484
});
6485
var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
6486
var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values);
6487
var index = d3.range(data.length);
6488
if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
6489
return values[j] - values[i];
6490
} : function(i, j) {
6491
return sort(data[i], data[j]);
6492
});
6493
var arcs = [];
6494
index.forEach(function(i) {
6495
var d;
6496
arcs[i] = {
6497
data: data[i],
6498
value: d = values[i],
6499
startAngle: a,
6500
endAngle: a += d * k
6501
};
6502
});
6503
return arcs;
6504
}
6505
pie.value = function(x) {
6506
if (!arguments.length) return value;
6507
value = x;
6508
return pie;
6509
};
6510
pie.sort = function(x) {
6511
if (!arguments.length) return sort;
6512
sort = x;
6513
return pie;
6514
};
6515
pie.startAngle = function(x) {
6516
if (!arguments.length) return startAngle;
6517
startAngle = x;
6518
return pie;
6519
};
6520
pie.endAngle = function(x) {
6521
if (!arguments.length) return endAngle;
6522
endAngle = x;
6523
return pie;
6524
};
6525
return pie;
6526
};
6527
var d3_layout_pieSortByValue = {};
6528
d3.layout.stack = function() {
6529
var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
6530
function stack(data, index) {
6531
var series = data.map(function(d, i) {
6532
return values.call(stack, d, i);
6533
});
6534
var points = series.map(function(d) {
6535
return d.map(function(v, i) {
6536
return [ x.call(stack, v, i), y.call(stack, v, i) ];
6537
});
6538
});
6539
var orders = order.call(stack, points, index);
6540
series = d3.permute(series, orders);
6541
points = d3.permute(points, orders);
6542
var offsets = offset.call(stack, points, index);
6543
var n = series.length, m = series[0].length, i, j, o;
6544
for (j = 0; j < m; ++j) {
6545
out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
6546
for (i = 1; i < n; ++i) {
6547
out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
6548
}
6549
}
6550
return data;
6551
}
6552
stack.values = function(x) {
6553
if (!arguments.length) return values;
6554
values = x;
6555
return stack;
6556
};
6557
stack.order = function(x) {
6558
if (!arguments.length) return order;
6559
order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
6560
return stack;
6561
};
6562
stack.offset = function(x) {
6563
if (!arguments.length) return offset;
6564
offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
6565
return stack;
6566
};
6567
stack.x = function(z) {
6568
if (!arguments.length) return x;
6569
x = z;
6570
return stack;
6571
};
6572
stack.y = function(z) {
6573
if (!arguments.length) return y;
6574
y = z;
6575
return stack;
6576
};
6577
stack.out = function(z) {
6578
if (!arguments.length) return out;
6579
out = z;
6580
return stack;
6581
};
6582
return stack;
6583
};
6584
function d3_layout_stackX(d) {
6585
return d.x;
6586
}
6587
function d3_layout_stackY(d) {
6588
return d.y;
6589
}
6590
function d3_layout_stackOut(d, y0, y) {
6591
d.y0 = y0;
6592
d.y = y;
6593
}
6594
var d3_layout_stackOrders = d3.map({
6595
"inside-out": function(data) {
6596
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) {
6597
return max[a] - max[b];
6598
}), top = 0, bottom = 0, tops = [], bottoms = [];
6599
for (i = 0; i < n; ++i) {
6600
j = index[i];
6601
if (top < bottom) {
6602
top += sums[j];
6603
tops.push(j);
6604
} else {
6605
bottom += sums[j];
6606
bottoms.push(j);
6607
}
6608
}
6609
return bottoms.reverse().concat(tops);
6610
},
6611
reverse: function(data) {
6612
return d3.range(data.length).reverse();
6613
},
6614
"default": d3_layout_stackOrderDefault
6615
});
6616
var d3_layout_stackOffsets = d3.map({
6617
silhouette: function(data) {
6618
var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
6619
for (j = 0; j < m; ++j) {
6620
for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6621
if (o > max) max = o;
6622
sums.push(o);
6623
}
6624
for (j = 0; j < m; ++j) {
6625
y0[j] = (max - sums[j]) / 2;
6626
}
6627
return y0;
6628
},
6629
wiggle: function(data) {
6630
var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
6631
y0[0] = o = o0 = 0;
6632
for (j = 1; j < m; ++j) {
6633
for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
6634
for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
6635
for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
6636
s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
6637
}
6638
s2 += s3 * data[i][j][1];
6639
}
6640
y0[j] = o -= s1 ? s2 / s1 * dx : 0;
6641
if (o < o0) o0 = o;
6642
}
6643
for (j = 0; j < m; ++j) y0[j] -= o0;
6644
return y0;
6645
},
6646
expand: function(data) {
6647
var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
6648
for (j = 0; j < m; ++j) {
6649
for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6650
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;
6651
}
6652
for (j = 0; j < m; ++j) y0[j] = 0;
6653
return y0;
6654
},
6655
zero: d3_layout_stackOffsetZero
6656
});
6657
function d3_layout_stackOrderDefault(data) {
6658
return d3.range(data.length);
6659
}
6660
function d3_layout_stackOffsetZero(data) {
6661
var j = -1, m = data[0].length, y0 = [];
6662
while (++j < m) y0[j] = 0;
6663
return y0;
6664
}
6665
function d3_layout_stackMaxIndex(array) {
6666
var i = 1, j = 0, v = array[0][1], k, n = array.length;
6667
for (;i < n; ++i) {
6668
if ((k = array[i][1]) > v) {
6669
j = i;
6670
v = k;
6671
}
6672
}
6673
return j;
6674
}
6675
function d3_layout_stackReduceSum(d) {
6676
return d.reduce(d3_layout_stackSum, 0);
6677
}
6678
function d3_layout_stackSum(p, d) {
6679
return p + d[1];
6680
}
6681
d3.layout.histogram = function() {
6682
var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
6683
function histogram(data, i) {
6684
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;
6685
while (++i < m) {
6686
bin = bins[i] = [];
6687
bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
6688
bin.y = 0;
6689
}
6690
if (m > 0) {
6691
i = -1;
6692
while (++i < n) {
6693
x = values[i];
6694
if (x >= range[0] && x <= range[1]) {
6695
bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
6696
bin.y += k;
6697
bin.push(data[i]);
6698
}
6699
}
6700
}
6701
return bins;
6702
}
6703
histogram.value = function(x) {
6704
if (!arguments.length) return valuer;
6705
valuer = x;
6706
return histogram;
6707
};
6708
histogram.range = function(x) {
6709
if (!arguments.length) return ranger;
6710
ranger = d3_functor(x);
6711
return histogram;
6712
};
6713
histogram.bins = function(x) {
6714
if (!arguments.length) return binner;
6715
binner = typeof x === "number" ? function(range) {
6716
return d3_layout_histogramBinFixed(range, x);
6717
} : d3_functor(x);
6718
return histogram;
6719
};
6720
histogram.frequency = function(x) {
6721
if (!arguments.length) return frequency;
6722
frequency = !!x;
6723
return histogram;
6724
};
6725
return histogram;
6726
};
6727
function d3_layout_histogramBinSturges(range, values) {
6728
return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
6729
}
6730
function d3_layout_histogramBinFixed(range, n) {
6731
var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
6732
while (++x <= n) f[x] = m * x + b;
6733
return f;
6734
}
6735
function d3_layout_histogramRange(values) {
6736
return [ d3.min(values), d3.max(values) ];
6737
}
6738
d3.layout.pack = function() {
6739
var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6740
function pack(d, i) {
6741
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() {
6742
return radius;
6743
};
6744
root.x = root.y = 0;
6745
d3_layout_hierarchyVisitAfter(root, function(d) {
6746
d.r = +r(d.value);
6747
});
6748
d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6749
if (padding) {
6750
var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6751
d3_layout_hierarchyVisitAfter(root, function(d) {
6752
d.r += dr;
6753
});
6754
d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6755
d3_layout_hierarchyVisitAfter(root, function(d) {
6756
d.r -= dr;
6757
});
6758
}
6759
d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6760
return nodes;
6761
}
6762
pack.size = function(_) {
6763
if (!arguments.length) return size;
6764
size = _;
6765
return pack;
6766
};
6767
pack.radius = function(_) {
6768
if (!arguments.length) return radius;
6769
radius = _ == null || typeof _ === "function" ? _ : +_;
6770
return pack;
6771
};
6772
pack.padding = function(_) {
6773
if (!arguments.length) return padding;
6774
padding = +_;
6775
return pack;
6776
};
6777
return d3_layout_hierarchyRebind(pack, hierarchy);
6778
};
6779
function d3_layout_packSort(a, b) {
6780
return a.value - b.value;
6781
}
6782
function d3_layout_packInsert(a, b) {
6783
var c = a._pack_next;
6784
a._pack_next = b;
6785
b._pack_prev = a;
6786
b._pack_next = c;
6787
c._pack_prev = b;
6788
}
6789
function d3_layout_packSplice(a, b) {
6790
a._pack_next = b;
6791
b._pack_prev = a;
6792
}
6793
function d3_layout_packIntersects(a, b) {
6794
var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6795
return .999 * dr * dr > dx * dx + dy * dy;
6796
}
6797
function d3_layout_packSiblings(node) {
6798
if (!(nodes = node.children) || !(n = nodes.length)) return;
6799
var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6800
function bound(node) {
6801
xMin = Math.min(node.x - node.r, xMin);
6802
xMax = Math.max(node.x + node.r, xMax);
6803
yMin = Math.min(node.y - node.r, yMin);
6804
yMax = Math.max(node.y + node.r, yMax);
6805
}
6806
nodes.forEach(d3_layout_packLink);
6807
a = nodes[0];
6808
a.x = -a.r;
6809
a.y = 0;
6810
bound(a);
6811
if (n > 1) {
6812
b = nodes[1];
6813
b.x = b.r;
6814
b.y = 0;
6815
bound(b);
6816
if (n > 2) {
6817
c = nodes[2];
6818
d3_layout_packPlace(a, b, c);
6819
bound(c);
6820
d3_layout_packInsert(a, c);
6821
a._pack_prev = c;
6822
d3_layout_packInsert(c, b);
6823
b = a._pack_next;
6824
for (i = 3; i < n; i++) {
6825
d3_layout_packPlace(a, b, c = nodes[i]);
6826
var isect = 0, s1 = 1, s2 = 1;
6827
for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
6828
if (d3_layout_packIntersects(j, c)) {
6829
isect = 1;
6830
break;
6831
}
6832
}
6833
if (isect == 1) {
6834
for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
6835
if (d3_layout_packIntersects(k, c)) {
6836
break;
6837
}
6838
}
6839
}
6840
if (isect) {
6841
if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
6842
i--;
6843
} else {
6844
d3_layout_packInsert(a, c);
6845
b = c;
6846
bound(c);
6847
}
6848
}
6849
}
6850
}
6851
var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
6852
for (i = 0; i < n; i++) {
6853
c = nodes[i];
6854
c.x -= cx;
6855
c.y -= cy;
6856
cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
6857
}
6858
node.r = cr;
6859
nodes.forEach(d3_layout_packUnlink);
6860
}
6861
function d3_layout_packLink(node) {
6862
node._pack_next = node._pack_prev = node;
6863
}
6864
function d3_layout_packUnlink(node) {
6865
delete node._pack_next;
6866
delete node._pack_prev;
6867
}
6868
function d3_layout_packTransform(node, x, y, k) {
6869
var children = node.children;
6870
node.x = x += k * node.x;
6871
node.y = y += k * node.y;
6872
node.r *= k;
6873
if (children) {
6874
var i = -1, n = children.length;
6875
while (++i < n) d3_layout_packTransform(children[i], x, y, k);
6876
}
6877
}
6878
function d3_layout_packPlace(a, b, c) {
6879
var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
6880
if (db && (dx || dy)) {
6881
var da = b.r + c.r, dc = dx * dx + dy * dy;
6882
da *= da;
6883
db *= db;
6884
var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
6885
c.x = a.x + x * dx + y * dy;
6886
c.y = a.y + x * dy - y * dx;
6887
} else {
6888
c.x = a.x + db;
6889
c.y = a.y;
6890
}
6891
}
6892
d3.layout.tree = function() {
6893
var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
6894
function tree(d, i) {
6895
var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
6896
d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
6897
d3_layout_hierarchyVisitBefore(root1, secondWalk);
6898
if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
6899
var left = root0, right = root0, bottom = root0;
6900
d3_layout_hierarchyVisitBefore(root0, function(node) {
6901
if (node.x < left.x) left = node;
6902
if (node.x > right.x) right = node;
6903
if (node.depth > bottom.depth) bottom = node;
6904
});
6905
var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
6906
d3_layout_hierarchyVisitBefore(root0, function(node) {
6907
node.x = (node.x + tx) * kx;
6908
node.y = node.depth * ky;
6909
});
6910
}
6911
return nodes;
6912
}
6913
function wrapTree(root0) {
6914
var root1 = {
6915
A: null,
6916
children: [ root0 ]
6917
}, queue = [ root1 ], node1;
6918
while ((node1 = queue.pop()) != null) {
6919
for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
6920
queue.push((children[i] = child = {
6921
_: children[i],
6922
parent: node1,
6923
children: (child = children[i].children) && child.slice() || [],
6924
A: null,
6925
a: null,
6926
z: 0,
6927
m: 0,
6928
c: 0,
6929
s: 0,
6930
t: null,
6931
i: i
6932
}).a = child);
6933
}
6934
}
6935
return root1.children[0];
6936
}
6937
function firstWalk(v) {
6938
var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
6939
if (children.length) {
6940
d3_layout_treeShift(v);
6941
var midpoint = (children[0].z + children[children.length - 1].z) / 2;
6942
if (w) {
6943
v.z = w.z + separation(v._, w._);
6944
v.m = v.z - midpoint;
6945
} else {
6946
v.z = midpoint;
6947
}
6948
} else if (w) {
6949
v.z = w.z + separation(v._, w._);
6950
}
6951
v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
6952
}
6953
function secondWalk(v) {
6954
v._.x = v.z + v.parent.m;
6955
v.m += v.parent.m;
6956
}
6957
function apportion(v, w, ancestor) {
6958
if (w) {
6959
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;
6960
while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
6961
vom = d3_layout_treeLeft(vom);
6962
vop = d3_layout_treeRight(vop);
6963
vop.a = v;
6964
shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
6965
if (shift > 0) {
6966
d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
6967
sip += shift;
6968
sop += shift;
6969
}
6970
sim += vim.m;
6971
sip += vip.m;
6972
som += vom.m;
6973
sop += vop.m;
6974
}
6975
if (vim && !d3_layout_treeRight(vop)) {
6976
vop.t = vim;
6977
vop.m += sim - sop;
6978
}
6979
if (vip && !d3_layout_treeLeft(vom)) {
6980
vom.t = vip;
6981
vom.m += sip - som;
6982
ancestor = v;
6983
}
6984
}
6985
return ancestor;
6986
}
6987
function sizeNode(node) {
6988
node.x *= size[0];
6989
node.y = node.depth * size[1];
6990
}
6991
tree.separation = function(x) {
6992
if (!arguments.length) return separation;
6993
separation = x;
6994
return tree;
6995
};
6996
tree.size = function(x) {
6997
if (!arguments.length) return nodeSize ? null : size;
6998
nodeSize = (size = x) == null ? sizeNode : null;
6999
return tree;
7000
};
7001
tree.nodeSize = function(x) {
7002
if (!arguments.length) return nodeSize ? size : null;
7003
nodeSize = (size = x) == null ? null : sizeNode;
7004
return tree;
7005
};
7006
return d3_layout_hierarchyRebind(tree, hierarchy);
7007
};
7008
function d3_layout_treeSeparation(a, b) {
7009
return a.parent == b.parent ? 1 : 2;
7010
}
7011
function d3_layout_treeLeft(v) {
7012
var children = v.children;
7013
return children.length ? children[0] : v.t;
7014
}
7015
function d3_layout_treeRight(v) {
7016
var children = v.children, n;
7017
return (n = children.length) ? children[n - 1] : v.t;
7018
}
7019
function d3_layout_treeMove(wm, wp, shift) {
7020
var change = shift / (wp.i - wm.i);
7021
wp.c -= change;
7022
wp.s += shift;
7023
wm.c += change;
7024
wp.z += shift;
7025
wp.m += shift;
7026
}
7027
function d3_layout_treeShift(v) {
7028
var shift = 0, change = 0, children = v.children, i = children.length, w;
7029
while (--i >= 0) {
7030
w = children[i];
7031
w.z += shift;
7032
w.m += shift;
7033
shift += w.s + (change += w.c);
7034
}
7035
}
7036
function d3_layout_treeAncestor(vim, v, ancestor) {
7037
return vim.a.parent === v.parent ? vim.a : ancestor;
7038
}
7039
d3.layout.cluster = function() {
7040
var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
7041
function cluster(d, i) {
7042
var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
7043
d3_layout_hierarchyVisitAfter(root, function(node) {
7044
var children = node.children;
7045
if (children && children.length) {
7046
node.x = d3_layout_clusterX(children);
7047
node.y = d3_layout_clusterY(children);
7048
} else {
7049
node.x = previousNode ? x += separation(node, previousNode) : 0;
7050
node.y = 0;
7051
previousNode = node;
7052
}
7053
});
7054
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;
7055
d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
7056
node.x = (node.x - root.x) * size[0];
7057
node.y = (root.y - node.y) * size[1];
7058
} : function(node) {
7059
node.x = (node.x - x0) / (x1 - x0) * size[0];
7060
node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
7061
});
7062
return nodes;
7063
}
7064
cluster.separation = function(x) {
7065
if (!arguments.length) return separation;
7066
separation = x;
7067
return cluster;
7068
};
7069
cluster.size = function(x) {
7070
if (!arguments.length) return nodeSize ? null : size;
7071
nodeSize = (size = x) == null;
7072
return cluster;
7073
};
7074
cluster.nodeSize = function(x) {
7075
if (!arguments.length) return nodeSize ? size : null;
7076
nodeSize = (size = x) != null;
7077
return cluster;
7078
};
7079
return d3_layout_hierarchyRebind(cluster, hierarchy);
7080
};
7081
function d3_layout_clusterY(children) {
7082
return 1 + d3.max(children, function(child) {
7083
return child.y;
7084
});
7085
}
7086
function d3_layout_clusterX(children) {
7087
return children.reduce(function(x, child) {
7088
return x + child.x;
7089
}, 0) / children.length;
7090
}
7091
function d3_layout_clusterLeft(node) {
7092
var children = node.children;
7093
return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
7094
}
7095
function d3_layout_clusterRight(node) {
7096
var children = node.children, n;
7097
return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
7098
}
7099
d3.layout.treemap = function() {
7100
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));
7101
function scale(children, k) {
7102
var i = -1, n = children.length, child, area;
7103
while (++i < n) {
7104
area = (child = children[i]).value * (k < 0 ? 0 : k);
7105
child.area = isNaN(area) || area <= 0 ? 0 : area;
7106
}
7107
}
7108
function squarify(node) {
7109
var children = node.children;
7110
if (children && children.length) {
7111
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;
7112
scale(remaining, rect.dx * rect.dy / node.value);
7113
row.area = 0;
7114
while ((n = remaining.length) > 0) {
7115
row.push(child = remaining[n - 1]);
7116
row.area += child.area;
7117
if (mode !== "squarify" || (score = worst(row, u)) <= best) {
7118
remaining.pop();
7119
best = score;
7120
} else {
7121
row.area -= row.pop().area;
7122
position(row, u, rect, false);
7123
u = Math.min(rect.dx, rect.dy);
7124
row.length = row.area = 0;
7125
best = Infinity;
7126
}
7127
}
7128
if (row.length) {
7129
position(row, u, rect, true);
7130
row.length = row.area = 0;
7131
}
7132
children.forEach(squarify);
7133
}
7134
}
7135
function stickify(node) {
7136
var children = node.children;
7137
if (children && children.length) {
7138
var rect = pad(node), remaining = children.slice(), child, row = [];
7139
scale(remaining, rect.dx * rect.dy / node.value);
7140
row.area = 0;
7141
while (child = remaining.pop()) {
7142
row.push(child);
7143
row.area += child.area;
7144
if (child.z != null) {
7145
position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
7146
row.length = row.area = 0;
7147
}
7148
}
7149
children.forEach(stickify);
7150
}
7151
}
7152
function worst(row, u) {
7153
var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
7154
while (++i < n) {
7155
if (!(r = row[i].area)) continue;
7156
if (r < rmin) rmin = r;
7157
if (r > rmax) rmax = r;
7158
}
7159
s *= s;
7160
u *= u;
7161
return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
7162
}
7163
function position(row, u, rect, flush) {
7164
var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
7165
if (u == rect.dx) {
7166
if (flush || v > rect.dy) v = rect.dy;
7167
while (++i < n) {
7168
o = row[i];
7169
o.x = x;
7170
o.y = y;
7171
o.dy = v;
7172
x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
7173
}
7174
o.z = true;
7175
o.dx += rect.x + rect.dx - x;
7176
rect.y += v;
7177
rect.dy -= v;
7178
} else {
7179
if (flush || v > rect.dx) v = rect.dx;
7180
while (++i < n) {
7181
o = row[i];
7182
o.x = x;
7183
o.y = y;
7184
o.dx = v;
7185
y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
7186
}
7187
o.z = false;
7188
o.dy += rect.y + rect.dy - y;
7189
rect.x += v;
7190
rect.dx -= v;
7191
}
7192
}
7193
function treemap(d) {
7194
var nodes = stickies || hierarchy(d), root = nodes[0];
7195
root.x = 0;
7196
root.y = 0;
7197
root.dx = size[0];
7198
root.dy = size[1];
7199
if (stickies) hierarchy.revalue(root);
7200
scale([ root ], root.dx * root.dy / root.value);
7201
(stickies ? stickify : squarify)(root);
7202
if (sticky) stickies = nodes;
7203
return nodes;
7204
}
7205
treemap.size = function(x) {
7206
if (!arguments.length) return size;
7207
size = x;
7208
return treemap;
7209
};
7210
treemap.padding = function(x) {
7211
if (!arguments.length) return padding;
7212
function padFunction(node) {
7213
var p = x.call(treemap, node, node.depth);
7214
return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
7215
}
7216
function padConstant(node) {
7217
return d3_layout_treemapPad(node, x);
7218
}
7219
var type;
7220
pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
7221
padConstant) : padConstant;
7222
return treemap;
7223
};
7224
treemap.round = function(x) {
7225
if (!arguments.length) return round != Number;
7226
round = x ? Math.round : Number;
7227
return treemap;
7228
};
7229
treemap.sticky = function(x) {
7230
if (!arguments.length) return sticky;
7231
sticky = x;
7232
stickies = null;
7233
return treemap;
7234
};
7235
treemap.ratio = function(x) {
7236
if (!arguments.length) return ratio;
7237
ratio = x;
7238
return treemap;
7239
};
7240
treemap.mode = function(x) {
7241
if (!arguments.length) return mode;
7242
mode = x + "";
7243
return treemap;
7244
};
7245
return d3_layout_hierarchyRebind(treemap, hierarchy);
7246
};
7247
function d3_layout_treemapPadNull(node) {
7248
return {
7249
x: node.x,
7250
y: node.y,
7251
dx: node.dx,
7252
dy: node.dy
7253
};
7254
}
7255
function d3_layout_treemapPad(node, padding) {
7256
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];
7257
if (dx < 0) {
7258
x += dx / 2;
7259
dx = 0;
7260
}
7261
if (dy < 0) {
7262
y += dy / 2;
7263
dy = 0;
7264
}
7265
return {
7266
x: x,
7267
y: y,
7268
dx: dx,
7269
dy: dy
7270
};
7271
}
7272
d3.random = {
7273
normal: function(µ, σ) {
7274
var n = arguments.length;
7275
if (n < 2) σ = 1;
7276
if (n < 1) µ = 0;
7277
return function() {
7278
var x, y, r;
7279
do {
7280
x = Math.random() * 2 - 1;
7281
y = Math.random() * 2 - 1;
7282
r = x * x + y * y;
7283
} while (!r || r > 1);
7284
return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
7285
};
7286
},
7287
logNormal: function() {
7288
var random = d3.random.normal.apply(d3, arguments);
7289
return function() {
7290
return Math.exp(random());
7291
};
7292
},
7293
bates: function(m) {
7294
var random = d3.random.irwinHall(m);
7295
return function() {
7296
return random() / m;
7297
};
7298
},
7299
irwinHall: function(m) {
7300
return function() {
7301
for (var s = 0, j = 0; j < m; j++) s += Math.random();
7302
return s;
7303
};
7304
}
7305
};
7306
d3.scale = {};
7307
function d3_scaleExtent(domain) {
7308
var start = domain[0], stop = domain[domain.length - 1];
7309
return start < stop ? [ start, stop ] : [ stop, start ];
7310
}
7311
function d3_scaleRange(scale) {
7312
return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
7313
}
7314
function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
7315
var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
7316
return function(x) {
7317
return i(u(x));
7318
};
7319
}
7320
function d3_scale_nice(domain, nice) {
7321
var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
7322
if (x1 < x0) {
7323
dx = i0, i0 = i1, i1 = dx;
7324
dx = x0, x0 = x1, x1 = dx;
7325
}
7326
domain[i0] = nice.floor(x0);
7327
domain[i1] = nice.ceil(x1);
7328
return domain;
7329
}
7330
function d3_scale_niceStep(step) {
7331
return step ? {
7332
floor: function(x) {
7333
return Math.floor(x / step) * step;
7334
},
7335
ceil: function(x) {
7336
return Math.ceil(x / step) * step;
7337
}
7338
} : d3_scale_niceIdentity;
7339
}
7340
var d3_scale_niceIdentity = {
7341
floor: d3_identity,
7342
ceil: d3_identity
7343
};
7344
function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
7345
var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
7346
if (domain[k] < domain[0]) {
7347
domain = domain.slice().reverse();
7348
range = range.slice().reverse();
7349
}
7350
while (++j <= k) {
7351
u.push(uninterpolate(domain[j - 1], domain[j]));
7352
i.push(interpolate(range[j - 1], range[j]));
7353
}
7354
return function(x) {
7355
var j = d3.bisect(domain, x, 1, k) - 1;
7356
return i[j](u[j](x));
7357
};
7358
}
7359
d3.scale.linear = function() {
7360
return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
7361
};
7362
function d3_scale_linear(domain, range, interpolate, clamp) {
7363
var output, input;
7364
function rescale() {
7365
var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
7366
output = linear(domain, range, uninterpolate, interpolate);
7367
input = linear(range, domain, uninterpolate, d3_interpolate);
7368
return scale;
7369
}
7370
function scale(x) {
7371
return output(x);
7372
}
7373
scale.invert = function(y) {
7374
return input(y);
7375
};
7376
scale.domain = function(x) {
7377
if (!arguments.length) return domain;
7378
domain = x.map(Number);
7379
return rescale();
7380
};
7381
scale.range = function(x) {
7382
if (!arguments.length) return range;
7383
range = x;
7384
return rescale();
7385
};
7386
scale.rangeRound = function(x) {
7387
return scale.range(x).interpolate(d3_interpolateRound);
7388
};
7389
scale.clamp = function(x) {
7390
if (!arguments.length) return clamp;
7391
clamp = x;
7392
return rescale();
7393
};
7394
scale.interpolate = function(x) {
7395
if (!arguments.length) return interpolate;
7396
interpolate = x;
7397
return rescale();
7398
};
7399
scale.ticks = function(m) {
7400
return d3_scale_linearTicks(domain, m);
7401
};
7402
scale.tickFormat = function(m, format) {
7403
return d3_scale_linearTickFormat(domain, m, format);
7404
};
7405
scale.nice = function(m) {
7406
d3_scale_linearNice(domain, m);
7407
return rescale();
7408
};
7409
scale.copy = function() {
7410
return d3_scale_linear(domain, range, interpolate, clamp);
7411
};
7412
return rescale();
7413
}
7414
function d3_scale_linearRebind(scale, linear) {
7415
return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7416
}
7417
function d3_scale_linearNice(domain, m) {
7418
return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7419
}
7420
function d3_scale_linearTickRange(domain, m) {
7421
if (m == null) m = 10;
7422
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;
7423
if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
7424
extent[0] = Math.ceil(extent[0] / step) * step;
7425
extent[1] = Math.floor(extent[1] / step) * step + step * .5;
7426
extent[2] = step;
7427
return extent;
7428
}
7429
function d3_scale_linearTicks(domain, m) {
7430
return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
7431
}
7432
function d3_scale_linearTickFormat(domain, m, format) {
7433
var range = d3_scale_linearTickRange(domain, m);
7434
if (format) {
7435
var match = d3_format_re.exec(format);
7436
match.shift();
7437
if (match[8] === "s") {
7438
var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
7439
if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
7440
match[8] = "f";
7441
format = d3.format(match.join(""));
7442
return function(d) {
7443
return format(prefix.scale(d)) + prefix.symbol;
7444
};
7445
}
7446
if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
7447
format = match.join("");
7448
} else {
7449
format = ",." + d3_scale_linearPrecision(range[2]) + "f";
7450
}
7451
return d3.format(format);
7452
}
7453
var d3_scale_linearFormatSignificant = {
7454
s: 1,
7455
g: 1,
7456
p: 1,
7457
r: 1,
7458
e: 1
7459
};
7460
function d3_scale_linearPrecision(value) {
7461
return -Math.floor(Math.log(value) / Math.LN10 + .01);
7462
}
7463
function d3_scale_linearFormatPrecision(type, range) {
7464
var p = d3_scale_linearPrecision(range[2]);
7465
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;
7466
}
7467
d3.scale.log = function() {
7468
return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
7469
};
7470
function d3_scale_log(linear, base, positive, domain) {
7471
function log(x) {
7472
return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
7473
}
7474
function pow(x) {
7475
return positive ? Math.pow(base, x) : -Math.pow(base, -x);
7476
}
7477
function scale(x) {
7478
return linear(log(x));
7479
}
7480
scale.invert = function(x) {
7481
return pow(linear.invert(x));
7482
};
7483
scale.domain = function(x) {
7484
if (!arguments.length) return domain;
7485
positive = x[0] >= 0;
7486
linear.domain((domain = x.map(Number)).map(log));
7487
return scale;
7488
};
7489
scale.base = function(_) {
7490
if (!arguments.length) return base;
7491
base = +_;
7492
linear.domain(domain.map(log));
7493
return scale;
7494
};
7495
scale.nice = function() {
7496
var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
7497
linear.domain(niced);
7498
domain = niced.map(pow);
7499
return scale;
7500
};
7501
scale.ticks = function() {
7502
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;
7503
if (isFinite(j - i)) {
7504
if (positive) {
7505
for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
7506
ticks.push(pow(i));
7507
} else {
7508
ticks.push(pow(i));
7509
for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
7510
}
7511
for (i = 0; ticks[i] < u; i++) {}
7512
for (j = ticks.length; ticks[j - 1] > v; j--) {}
7513
ticks = ticks.slice(i, j);
7514
}
7515
return ticks;
7516
};
7517
scale.tickFormat = function(n, format) {
7518
if (!arguments.length) return d3_scale_logFormat;
7519
if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
7520
var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
7521
Math.floor), e;
7522
return function(d) {
7523
return d / pow(f(log(d) + e)) <= k ? format(d) : "";
7524
};
7525
};
7526
scale.copy = function() {
7527
return d3_scale_log(linear.copy(), base, positive, domain);
7528
};
7529
return d3_scale_linearRebind(scale, linear);
7530
}
7531
var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
7532
floor: function(x) {
7533
return -Math.ceil(-x);
7534
},
7535
ceil: function(x) {
7536
return -Math.floor(-x);
7537
}
7538
};
7539
d3.scale.pow = function() {
7540
return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
7541
};
7542
function d3_scale_pow(linear, exponent, domain) {
7543
var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
7544
function scale(x) {
7545
return linear(powp(x));
7546
}
7547
scale.invert = function(x) {
7548
return powb(linear.invert(x));
7549
};
7550
scale.domain = function(x) {
7551
if (!arguments.length) return domain;
7552
linear.domain((domain = x.map(Number)).map(powp));
7553
return scale;
7554
};
7555
scale.ticks = function(m) {
7556
return d3_scale_linearTicks(domain, m);
7557
};
7558
scale.tickFormat = function(m, format) {
7559
return d3_scale_linearTickFormat(domain, m, format);
7560
};
7561
scale.nice = function(m) {
7562
return scale.domain(d3_scale_linearNice(domain, m));
7563
};
7564
scale.exponent = function(x) {
7565
if (!arguments.length) return exponent;
7566
powp = d3_scale_powPow(exponent = x);
7567
powb = d3_scale_powPow(1 / exponent);
7568
linear.domain(domain.map(powp));
7569
return scale;
7570
};
7571
scale.copy = function() {
7572
return d3_scale_pow(linear.copy(), exponent, domain);
7573
};
7574
return d3_scale_linearRebind(scale, linear);
7575
}
7576
function d3_scale_powPow(e) {
7577
return function(x) {
7578
return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
7579
};
7580
}
7581
d3.scale.sqrt = function() {
7582
return d3.scale.pow().exponent(.5);
7583
};
7584
d3.scale.ordinal = function() {
7585
return d3_scale_ordinal([], {
7586
t: "range",
7587
a: [ [] ]
7588
});
7589
};
7590
function d3_scale_ordinal(domain, ranger) {
7591
var index, range, rangeBand;
7592
function scale(x) {
7593
return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
7594
}
7595
function steps(start, step) {
7596
return d3.range(domain.length).map(function(i) {
7597
return start + step * i;
7598
});
7599
}
7600
scale.domain = function(x) {
7601
if (!arguments.length) return domain;
7602
domain = [];
7603
index = new d3_Map();
7604
var i = -1, n = x.length, xi;
7605
while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
7606
return scale[ranger.t].apply(scale, ranger.a);
7607
};
7608
scale.range = function(x) {
7609
if (!arguments.length) return range;
7610
range = x;
7611
rangeBand = 0;
7612
ranger = {
7613
t: "range",
7614
a: arguments
7615
};
7616
return scale;
7617
};
7618
scale.rangePoints = function(x, padding) {
7619
if (arguments.length < 2) padding = 0;
7620
var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
7621
range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
7622
rangeBand = 0;
7623
ranger = {
7624
t: "rangePoints",
7625
a: arguments
7626
};
7627
return scale;
7628
};
7629
scale.rangeBands = function(x, padding, outerPadding) {
7630
if (arguments.length < 2) padding = 0;
7631
if (arguments.length < 3) outerPadding = padding;
7632
var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
7633
range = steps(start + step * outerPadding, step);
7634
if (reverse) range.reverse();
7635
rangeBand = step * (1 - padding);
7636
ranger = {
7637
t: "rangeBands",
7638
a: arguments
7639
};
7640
return scale;
7641
};
7642
scale.rangeRoundBands = function(x, padding, outerPadding) {
7643
if (arguments.length < 2) padding = 0;
7644
if (arguments.length < 3) outerPadding = padding;
7645
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;
7646
range = steps(start + Math.round(error / 2), step);
7647
if (reverse) range.reverse();
7648
rangeBand = Math.round(step * (1 - padding));
7649
ranger = {
7650
t: "rangeRoundBands",
7651
a: arguments
7652
};
7653
return scale;
7654
};
7655
scale.rangeBand = function() {
7656
return rangeBand;
7657
};
7658
scale.rangeExtent = function() {
7659
return d3_scaleExtent(ranger.a[0]);
7660
};
7661
scale.copy = function() {
7662
return d3_scale_ordinal(domain, ranger);
7663
};
7664
return scale.domain(domain);
7665
}
7666
d3.scale.category10 = function() {
7667
return d3.scale.ordinal().range(d3_category10);
7668
};
7669
d3.scale.category20 = function() {
7670
return d3.scale.ordinal().range(d3_category20);
7671
};
7672
d3.scale.category20b = function() {
7673
return d3.scale.ordinal().range(d3_category20b);
7674
};
7675
d3.scale.category20c = function() {
7676
return d3.scale.ordinal().range(d3_category20c);
7677
};
7678
var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
7679
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);
7680
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);
7681
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);
7682
d3.scale.quantile = function() {
7683
return d3_scale_quantile([], []);
7684
};
7685
function d3_scale_quantile(domain, range) {
7686
var thresholds;
7687
function rescale() {
7688
var k = 0, q = range.length;
7689
thresholds = [];
7690
while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
7691
return scale;
7692
}
7693
function scale(x) {
7694
if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
7695
}
7696
scale.domain = function(x) {
7697
if (!arguments.length) return domain;
7698
domain = x.filter(d3_number).sort(d3_ascending);
7699
return rescale();
7700
};
7701
scale.range = function(x) {
7702
if (!arguments.length) return range;
7703
range = x;
7704
return rescale();
7705
};
7706
scale.quantiles = function() {
7707
return thresholds;
7708
};
7709
scale.invertExtent = function(y) {
7710
y = range.indexOf(y);
7711
return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
7712
};
7713
scale.copy = function() {
7714
return d3_scale_quantile(domain, range);
7715
};
7716
return rescale();
7717
}
7718
d3.scale.quantize = function() {
7719
return d3_scale_quantize(0, 1, [ 0, 1 ]);
7720
};
7721
function d3_scale_quantize(x0, x1, range) {
7722
var kx, i;
7723
function scale(x) {
7724
return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7725
}
7726
function rescale() {
7727
kx = range.length / (x1 - x0);
7728
i = range.length - 1;
7729
return scale;
7730
}
7731
scale.domain = function(x) {
7732
if (!arguments.length) return [ x0, x1 ];
7733
x0 = +x[0];
7734
x1 = +x[x.length - 1];
7735
return rescale();
7736
};
7737
scale.range = function(x) {
7738
if (!arguments.length) return range;
7739
range = x;
7740
return rescale();
7741
};
7742
scale.invertExtent = function(y) {
7743
y = range.indexOf(y);
7744
y = y < 0 ? NaN : y / kx + x0;
7745
return [ y, y + 1 / kx ];
7746
};
7747
scale.copy = function() {
7748
return d3_scale_quantize(x0, x1, range);
7749
};
7750
return rescale();
7751
}
7752
d3.scale.threshold = function() {
7753
return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7754
};
7755
function d3_scale_threshold(domain, range) {
7756
function scale(x) {
7757
if (x <= x) return range[d3.bisect(domain, x)];
7758
}
7759
scale.domain = function(_) {
7760
if (!arguments.length) return domain;
7761
domain = _;
7762
return scale;
7763
};
7764
scale.range = function(_) {
7765
if (!arguments.length) return range;
7766
range = _;
7767
return scale;
7768
};
7769
scale.invertExtent = function(y) {
7770
y = range.indexOf(y);
7771
return [ domain[y - 1], domain[y] ];
7772
};
7773
scale.copy = function() {
7774
return d3_scale_threshold(domain, range);
7775
};
7776
return scale;
7777
}
7778
d3.scale.identity = function() {
7779
return d3_scale_identity([ 0, 1 ]);
7780
};
7781
function d3_scale_identity(domain) {
7782
function identity(x) {
7783
return +x;
7784
}
7785
identity.invert = identity;
7786
identity.domain = identity.range = function(x) {
7787
if (!arguments.length) return domain;
7788
domain = x.map(identity);
7789
return identity;
7790
};
7791
identity.ticks = function(m) {
7792
return d3_scale_linearTicks(domain, m);
7793
};
7794
identity.tickFormat = function(m, format) {
7795
return d3_scale_linearTickFormat(domain, m, format);
7796
};
7797
identity.copy = function() {
7798
return d3_scale_identity(domain);
7799
};
7800
return identity;
7801
}
7802
d3.svg = {};
7803
d3.svg.arc = function() {
7804
var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
7805
function arc() {
7806
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,
7807
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);
7808
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";
7809
}
7810
arc.innerRadius = function(v) {
7811
if (!arguments.length) return innerRadius;
7812
innerRadius = d3_functor(v);
7813
return arc;
7814
};
7815
arc.outerRadius = function(v) {
7816
if (!arguments.length) return outerRadius;
7817
outerRadius = d3_functor(v);
7818
return arc;
7819
};
7820
arc.startAngle = function(v) {
7821
if (!arguments.length) return startAngle;
7822
startAngle = d3_functor(v);
7823
return arc;
7824
};
7825
arc.endAngle = function(v) {
7826
if (!arguments.length) return endAngle;
7827
endAngle = d3_functor(v);
7828
return arc;
7829
};
7830
arc.centroid = function() {
7831
var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
7832
return [ Math.cos(a) * r, Math.sin(a) * r ];
7833
};
7834
return arc;
7835
};
7836
var d3_svg_arcOffset = -halfπ, d3_svg_arcMax = τ - ε;
7837
function d3_svg_arcInnerRadius(d) {
7838
return d.innerRadius;
7839
}
7840
function d3_svg_arcOuterRadius(d) {
7841
return d.outerRadius;
7842
}
7843
function d3_svg_arcStartAngle(d) {
7844
return d.startAngle;
7845
}
7846
function d3_svg_arcEndAngle(d) {
7847
return d.endAngle;
7848
}
7849
function d3_svg_line(projection) {
7850
var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
7851
function line(data) {
7852
var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
7853
function segment() {
7854
segments.push("M", interpolate(projection(points), tension));
7855
}
7856
while (++i < n) {
7857
if (defined.call(this, d = data[i], i)) {
7858
points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
7859
} else if (points.length) {
7860
segment();
7861
points = [];
7862
}
7863
}
7864
if (points.length) segment();
7865
return segments.length ? segments.join("") : null;
7866
}
7867
line.x = function(_) {
7868
if (!arguments.length) return x;
7869
x = _;
7870
return line;
7871
};
7872
line.y = function(_) {
7873
if (!arguments.length) return y;
7874
y = _;
7875
return line;
7876
};
7877
line.defined = function(_) {
7878
if (!arguments.length) return defined;
7879
defined = _;
7880
return line;
7881
};
7882
line.interpolate = function(_) {
7883
if (!arguments.length) return interpolateKey;
7884
if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
7885
return line;
7886
};
7887
line.tension = function(_) {
7888
if (!arguments.length) return tension;
7889
tension = _;
7890
return line;
7891
};
7892
return line;
7893
}
7894
d3.svg.line = function() {
7895
return d3_svg_line(d3_identity);
7896
};
7897
var d3_svg_lineInterpolators = d3.map({
7898
linear: d3_svg_lineLinear,
7899
"linear-closed": d3_svg_lineLinearClosed,
7900
step: d3_svg_lineStep,
7901
"step-before": d3_svg_lineStepBefore,
7902
"step-after": d3_svg_lineStepAfter,
7903
basis: d3_svg_lineBasis,
7904
"basis-open": d3_svg_lineBasisOpen,
7905
"basis-closed": d3_svg_lineBasisClosed,
7906
bundle: d3_svg_lineBundle,
7907
cardinal: d3_svg_lineCardinal,
7908
"cardinal-open": d3_svg_lineCardinalOpen,
7909
"cardinal-closed": d3_svg_lineCardinalClosed,
7910
monotone: d3_svg_lineMonotone
7911
});
7912
d3_svg_lineInterpolators.forEach(function(key, value) {
7913
value.key = key;
7914
value.closed = /-closed$/.test(key);
7915
});
7916
function d3_svg_lineLinear(points) {
7917
return points.join("L");
7918
}
7919
function d3_svg_lineLinearClosed(points) {
7920
return d3_svg_lineLinear(points) + "Z";
7921
}
7922
function d3_svg_lineStep(points) {
7923
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
7924
while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
7925
if (n > 1) path.push("H", p[0]);
7926
return path.join("");
7927
}
7928
function d3_svg_lineStepBefore(points) {
7929
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
7930
while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
7931
return path.join("");
7932
}
7933
function d3_svg_lineStepAfter(points) {
7934
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
7935
while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
7936
return path.join("");
7937
}
7938
function d3_svg_lineCardinalOpen(points, tension) {
7939
return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
7940
}
7941
function d3_svg_lineCardinalClosed(points, tension) {
7942
return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
7943
points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
7944
}
7945
function d3_svg_lineCardinal(points, tension) {
7946
return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
7947
}
7948
function d3_svg_lineHermite(points, tangents) {
7949
if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
7950
return d3_svg_lineLinear(points);
7951
}
7952
var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
7953
if (quad) {
7954
path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
7955
p0 = points[1];
7956
pi = 2;
7957
}
7958
if (tangents.length > 1) {
7959
t = tangents[1];
7960
p = points[pi];
7961
pi++;
7962
path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
7963
for (var i = 2; i < tangents.length; i++, pi++) {
7964
p = points[pi];
7965
t = tangents[i];
7966
path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
7967
}
7968
}
7969
if (quad) {
7970
var lp = points[pi];
7971
path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
7972
}
7973
return path;
7974
}
7975
function d3_svg_lineCardinalTangents(points, tension) {
7976
var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
7977
while (++i < n) {
7978
p0 = p1;
7979
p1 = p2;
7980
p2 = points[i];
7981
tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
7982
}
7983
return tangents;
7984
}
7985
function d3_svg_lineBasis(points) {
7986
if (points.length < 3) return d3_svg_lineLinear(points);
7987
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) ];
7988
points.push(points[n - 1]);
7989
while (++i <= n) {
7990
pi = points[i];
7991
px.shift();
7992
px.push(pi[0]);
7993
py.shift();
7994
py.push(pi[1]);
7995
d3_svg_lineBasisBezier(path, px, py);
7996
}
7997
points.pop();
7998
path.push("L", pi);
7999
return path.join("");
8000
}
8001
function d3_svg_lineBasisOpen(points) {
8002
if (points.length < 4) return d3_svg_lineLinear(points);
8003
var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
8004
while (++i < 3) {
8005
pi = points[i];
8006
px.push(pi[0]);
8007
py.push(pi[1]);
8008
}
8009
path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
8010
--i;
8011
while (++i < n) {
8012
pi = points[i];
8013
px.shift();
8014
px.push(pi[0]);
8015
py.shift();
8016
py.push(pi[1]);
8017
d3_svg_lineBasisBezier(path, px, py);
8018
}
8019
return path.join("");
8020
}
8021
function d3_svg_lineBasisClosed(points) {
8022
var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
8023
while (++i < 4) {
8024
pi = points[i % n];
8025
px.push(pi[0]);
8026
py.push(pi[1]);
8027
}
8028
path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8029
--i;
8030
while (++i < m) {
8031
pi = points[i % n];
8032
px.shift();
8033
px.push(pi[0]);
8034
py.shift();
8035
py.push(pi[1]);
8036
d3_svg_lineBasisBezier(path, px, py);
8037
}
8038
return path.join("");
8039
}
8040
function d3_svg_lineBundle(points, tension) {
8041
var n = points.length - 1;
8042
if (n) {
8043
var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
8044
while (++i <= n) {
8045
p = points[i];
8046
t = i / n;
8047
p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
8048
p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
8049
}
8050
}
8051
return d3_svg_lineBasis(points);
8052
}
8053
function d3_svg_lineDot4(a, b) {
8054
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
8055
}
8056
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 ];
8057
function d3_svg_lineBasisBezier(path, x, y) {
8058
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));
8059
}
8060
function d3_svg_lineSlope(p0, p1) {
8061
return (p1[1] - p0[1]) / (p1[0] - p0[0]);
8062
}
8063
function d3_svg_lineFiniteDifferences(points) {
8064
var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
8065
while (++i < j) {
8066
m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
8067
}
8068
m[i] = d;
8069
return m;
8070
}
8071
function d3_svg_lineMonotoneTangents(points) {
8072
var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
8073
while (++i < j) {
8074
d = d3_svg_lineSlope(points[i], points[i + 1]);
8075
if (abs(d) < ε) {
8076
m[i] = m[i + 1] = 0;
8077
} else {
8078
a = m[i] / d;
8079
b = m[i + 1] / d;
8080
s = a * a + b * b;
8081
if (s > 9) {
8082
s = d * 3 / Math.sqrt(s);
8083
m[i] = s * a;
8084
m[i + 1] = s * b;
8085
}
8086
}
8087
}
8088
i = -1;
8089
while (++i <= j) {
8090
s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
8091
tangents.push([ s || 0, m[i] * s || 0 ]);
8092
}
8093
return tangents;
8094
}
8095
function d3_svg_lineMonotone(points) {
8096
return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
8097
}
8098
d3.svg.line.radial = function() {
8099
var line = d3_svg_line(d3_svg_lineRadial);
8100
line.radius = line.x, delete line.x;
8101
line.angle = line.y, delete line.y;
8102
return line;
8103
};
8104
function d3_svg_lineRadial(points) {
8105
var point, i = -1, n = points.length, r, a;
8106
while (++i < n) {
8107
point = points[i];
8108
r = point[0];
8109
a = point[1] + d3_svg_arcOffset;
8110
point[0] = r * Math.cos(a);
8111
point[1] = r * Math.sin(a);
8112
}
8113
return points;
8114
}
8115
function d3_svg_area(projection) {
8116
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;
8117
function area(data) {
8118
var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
8119
return x;
8120
} : d3_functor(x1), fy1 = y0 === y1 ? function() {
8121
return y;
8122
} : d3_functor(y1), x, y;
8123
function segment() {
8124
segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
8125
}
8126
while (++i < n) {
8127
if (defined.call(this, d = data[i], i)) {
8128
points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
8129
points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
8130
} else if (points0.length) {
8131
segment();
8132
points0 = [];
8133
points1 = [];
8134
}
8135
}
8136
if (points0.length) segment();
8137
return segments.length ? segments.join("") : null;
8138
}
8139
area.x = function(_) {
8140
if (!arguments.length) return x1;
8141
x0 = x1 = _;
8142
return area;
8143
};
8144
area.x0 = function(_) {
8145
if (!arguments.length) return x0;
8146
x0 = _;
8147
return area;
8148
};
8149
area.x1 = function(_) {
8150
if (!arguments.length) return x1;
8151
x1 = _;
8152
return area;
8153
};
8154
area.y = function(_) {
8155
if (!arguments.length) return y1;
8156
y0 = y1 = _;
8157
return area;
8158
};
8159
area.y0 = function(_) {
8160
if (!arguments.length) return y0;
8161
y0 = _;
8162
return area;
8163
};
8164
area.y1 = function(_) {
8165
if (!arguments.length) return y1;
8166
y1 = _;
8167
return area;
8168
};
8169
area.defined = function(_) {
8170
if (!arguments.length) return defined;
8171
defined = _;
8172
return area;
8173
};
8174
area.interpolate = function(_) {
8175
if (!arguments.length) return interpolateKey;
8176
if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8177
interpolateReverse = interpolate.reverse || interpolate;
8178
L = interpolate.closed ? "M" : "L";
8179
return area;
8180
};
8181
area.tension = function(_) {
8182
if (!arguments.length) return tension;
8183
tension = _;
8184
return area;
8185
};
8186
return area;
8187
}
8188
d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
8189
d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
8190
d3.svg.area = function() {
8191
return d3_svg_area(d3_identity);
8192
};
8193
d3.svg.area.radial = function() {
8194
var area = d3_svg_area(d3_svg_lineRadial);
8195
area.radius = area.x, delete area.x;
8196
area.innerRadius = area.x0, delete area.x0;
8197
area.outerRadius = area.x1, delete area.x1;
8198
area.angle = area.y, delete area.y;
8199
area.startAngle = area.y0, delete area.y0;
8200
area.endAngle = area.y1, delete area.y1;
8201
return area;
8202
};
8203
d3.svg.chord = function() {
8204
var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
8205
function chord(d, i) {
8206
var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
8207
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";
8208
}
8209
function subgroup(self, f, d, i) {
8210
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;
8211
return {
8212
r: r,
8213
a0: a0,
8214
a1: a1,
8215
p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
8216
p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
8217
};
8218
}
8219
function equals(a, b) {
8220
return a.a0 == b.a0 && a.a1 == b.a1;
8221
}
8222
function arc(r, p, a) {
8223
return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
8224
}
8225
function curve(r0, p0, r1, p1) {
8226
return "Q 0,0 " + p1;
8227
}
8228
chord.radius = function(v) {
8229
if (!arguments.length) return radius;
8230
radius = d3_functor(v);
8231
return chord;
8232
};
8233
chord.source = function(v) {
8234
if (!arguments.length) return source;
8235
source = d3_functor(v);
8236
return chord;
8237
};
8238
chord.target = function(v) {
8239
if (!arguments.length) return target;
8240
target = d3_functor(v);
8241
return chord;
8242
};
8243
chord.startAngle = function(v) {
8244
if (!arguments.length) return startAngle;
8245
startAngle = d3_functor(v);
8246
return chord;
8247
};
8248
chord.endAngle = function(v) {
8249
if (!arguments.length) return endAngle;
8250
endAngle = d3_functor(v);
8251
return chord;
8252
};
8253
return chord;
8254
};
8255
function d3_svg_chordRadius(d) {
8256
return d.radius;
8257
}
8258
d3.svg.diagonal = function() {
8259
var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
8260
function diagonal(d, i) {
8261
var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
8262
x: p0.x,
8263
y: m
8264
}, {
8265
x: p3.x,
8266
y: m
8267
}, p3 ];
8268
p = p.map(projection);
8269
return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
8270
}
8271
diagonal.source = function(x) {
8272
if (!arguments.length) return source;
8273
source = d3_functor(x);
8274
return diagonal;
8275
};
8276
diagonal.target = function(x) {
8277
if (!arguments.length) return target;
8278
target = d3_functor(x);
8279
return diagonal;
8280
};
8281
diagonal.projection = function(x) {
8282
if (!arguments.length) return projection;
8283
projection = x;
8284
return diagonal;
8285
};
8286
return diagonal;
8287
};
8288
function d3_svg_diagonalProjection(d) {
8289
return [ d.x, d.y ];
8290
}
8291
d3.svg.diagonal.radial = function() {
8292
var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
8293
diagonal.projection = function(x) {
8294
return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
8295
};
8296
return diagonal;
8297
};
8298
function d3_svg_diagonalRadialProjection(projection) {
8299
return function() {
8300
var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
8301
return [ r * Math.cos(a), r * Math.sin(a) ];
8302
};
8303
}
8304
d3.svg.symbol = function() {
8305
var type = d3_svg_symbolType, size = d3_svg_symbolSize;
8306
function symbol(d, i) {
8307
return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
8308
}
8309
symbol.type = function(x) {
8310
if (!arguments.length) return type;
8311
type = d3_functor(x);
8312
return symbol;
8313
};
8314
symbol.size = function(x) {
8315
if (!arguments.length) return size;
8316
size = d3_functor(x);
8317
return symbol;
8318
};
8319
return symbol;
8320
};
8321
function d3_svg_symbolSize() {
8322
return 64;
8323
}
8324
function d3_svg_symbolType() {
8325
return "circle";
8326
}
8327
function d3_svg_symbolCircle(size) {
8328
var r = Math.sqrt(size / π);
8329
return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
8330
}
8331
var d3_svg_symbols = d3.map({
8332
circle: d3_svg_symbolCircle,
8333
cross: function(size) {
8334
var r = Math.sqrt(size / 5) / 2;
8335
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";
8336
},
8337
diamond: function(size) {
8338
var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
8339
return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
8340
},
8341
square: function(size) {
8342
var r = Math.sqrt(size) / 2;
8343
return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
8344
},
8345
"triangle-down": function(size) {
8346
var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8347
return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
8348
},
8349
"triangle-up": function(size) {
8350
var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8351
return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
8352
}
8353
});
8354
d3.svg.symbolTypes = d3_svg_symbols.keys();
8355
var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
8356
function d3_transition(groups, id) {
8357
d3_subclass(groups, d3_transitionPrototype);
8358
groups.id = id;
8359
return groups;
8360
}
8361
var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
8362
d3_transitionPrototype.call = d3_selectionPrototype.call;
8363
d3_transitionPrototype.empty = d3_selectionPrototype.empty;
8364
d3_transitionPrototype.node = d3_selectionPrototype.node;
8365
d3_transitionPrototype.size = d3_selectionPrototype.size;
8366
d3.transition = function(selection) {
8367
return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
8368
};
8369
d3.transition.prototype = d3_transitionPrototype;
8370
d3_transitionPrototype.select = function(selector) {
8371
var id = this.id, subgroups = [], subgroup, subnode, node;
8372
selector = d3_selection_selector(selector);
8373
for (var j = -1, m = this.length; ++j < m; ) {
8374
subgroups.push(subgroup = []);
8375
for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8376
if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
8377
if ("__data__" in node) subnode.__data__ = node.__data__;
8378
d3_transitionNode(subnode, i, id, node.__transition__[id]);
8379
subgroup.push(subnode);
8380
} else {
8381
subgroup.push(null);
8382
}
8383
}
8384
}
8385
return d3_transition(subgroups, id);
8386
};
8387
d3_transitionPrototype.selectAll = function(selector) {
8388
var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
8389
selector = d3_selection_selectorAll(selector);
8390
for (var j = -1, m = this.length; ++j < m; ) {
8391
for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8392
if (node = group[i]) {
8393
transition = node.__transition__[id];
8394
subnodes = selector.call(node, node.__data__, i, j);
8395
subgroups.push(subgroup = []);
8396
for (var k = -1, o = subnodes.length; ++k < o; ) {
8397
if (subnode = subnodes[k]) d3_transitionNode(subnode, k, id, transition);
8398
subgroup.push(subnode);
8399
}
8400
}
8401
}
8402
}
8403
return d3_transition(subgroups, id);
8404
};
8405
d3_transitionPrototype.filter = function(filter) {
8406
var subgroups = [], subgroup, group, node;
8407
if (typeof filter !== "function") filter = d3_selection_filter(filter);
8408
for (var j = 0, m = this.length; j < m; j++) {
8409
subgroups.push(subgroup = []);
8410
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8411
if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
8412
subgroup.push(node);
8413
}
8414
}
8415
}
8416
return d3_transition(subgroups, this.id);
8417
};
8418
d3_transitionPrototype.tween = function(name, tween) {
8419
var id = this.id;
8420
if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
8421
return d3_selection_each(this, tween == null ? function(node) {
8422
node.__transition__[id].tween.remove(name);
8423
} : function(node) {
8424
node.__transition__[id].tween.set(name, tween);
8425
});
8426
};
8427
function d3_transition_tween(groups, name, value, tween) {
8428
var id = groups.id;
8429
return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
8430
node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
8431
} : (value = tween(value), function(node) {
8432
node.__transition__[id].tween.set(name, value);
8433
}));
8434
}
8435
d3_transitionPrototype.attr = function(nameNS, value) {
8436
if (arguments.length < 2) {
8437
for (value in nameNS) this.attr(value, nameNS[value]);
8438
return this;
8439
}
8440
var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
8441
function attrNull() {
8442
this.removeAttribute(name);
8443
}
8444
function attrNullNS() {
8445
this.removeAttributeNS(name.space, name.local);
8446
}
8447
function attrTween(b) {
8448
return b == null ? attrNull : (b += "", function() {
8449
var a = this.getAttribute(name), i;
8450
return a !== b && (i = interpolate(a, b), function(t) {
8451
this.setAttribute(name, i(t));
8452
});
8453
});
8454
}
8455
function attrTweenNS(b) {
8456
return b == null ? attrNullNS : (b += "", function() {
8457
var a = this.getAttributeNS(name.space, name.local), i;
8458
return a !== b && (i = interpolate(a, b), function(t) {
8459
this.setAttributeNS(name.space, name.local, i(t));
8460
});
8461
});
8462
}
8463
return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
8464
};
8465
d3_transitionPrototype.attrTween = function(nameNS, tween) {
8466
var name = d3.ns.qualify(nameNS);
8467
function attrTween(d, i) {
8468
var f = tween.call(this, d, i, this.getAttribute(name));
8469
return f && function(t) {
8470
this.setAttribute(name, f(t));
8471
};
8472
}
8473
function attrTweenNS(d, i) {
8474
var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
8475
return f && function(t) {
8476
this.setAttributeNS(name.space, name.local, f(t));
8477
};
8478
}
8479
return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
8480
};
8481
d3_transitionPrototype.style = function(name, value, priority) {
8482
var n = arguments.length;
8483
if (n < 3) {
8484
if (typeof name !== "string") {
8485
if (n < 2) value = "";
8486
for (priority in name) this.style(priority, name[priority], value);
8487
return this;
8488
}
8489
priority = "";
8490
}
8491
function styleNull() {
8492
this.style.removeProperty(name);
8493
}
8494
function styleString(b) {
8495
return b == null ? styleNull : (b += "", function() {
8496
var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
8497
return a !== b && (i = d3_interpolate(a, b), function(t) {
8498
this.style.setProperty(name, i(t), priority);
8499
});
8500
});
8501
}
8502
return d3_transition_tween(this, "style." + name, value, styleString);
8503
};
8504
d3_transitionPrototype.styleTween = function(name, tween, priority) {
8505
if (arguments.length < 3) priority = "";
8506
function styleTween(d, i) {
8507
var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
8508
return f && function(t) {
8509
this.style.setProperty(name, f(t), priority);
8510
};
8511
}
8512
return this.tween("style." + name, styleTween);
8513
};
8514
d3_transitionPrototype.text = function(value) {
8515
return d3_transition_tween(this, "text", value, d3_transition_text);
8516
};
8517
function d3_transition_text(b) {
8518
if (b == null) b = "";
8519
return function() {
8520
this.textContent = b;
8521
};
8522
}
8523
d3_transitionPrototype.remove = function() {
8524
return this.each("end.transition", function() {
8525
var p;
8526
if (this.__transition__.count < 2 && (p = this.parentNode)) p.removeChild(this);
8527
});
8528
};
8529
d3_transitionPrototype.ease = function(value) {
8530
var id = this.id;
8531
if (arguments.length < 1) return this.node().__transition__[id].ease;
8532
if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
8533
return d3_selection_each(this, function(node) {
8534
node.__transition__[id].ease = value;
8535
});
8536
};
8537
d3_transitionPrototype.delay = function(value) {
8538
var id = this.id;
8539
if (arguments.length < 1) return this.node().__transition__[id].delay;
8540
return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8541
node.__transition__[id].delay = +value.call(node, node.__data__, i, j);
8542
} : (value = +value, function(node) {
8543
node.__transition__[id].delay = value;
8544
}));
8545
};
8546
d3_transitionPrototype.duration = function(value) {
8547
var id = this.id;
8548
if (arguments.length < 1) return this.node().__transition__[id].duration;
8549
return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8550
node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j));
8551
} : (value = Math.max(1, value), function(node) {
8552
node.__transition__[id].duration = value;
8553
}));
8554
};
8555
d3_transitionPrototype.each = function(type, listener) {
8556
var id = this.id;
8557
if (arguments.length < 2) {
8558
var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
8559
d3_transitionInheritId = id;
8560
d3_selection_each(this, function(node, i, j) {
8561
d3_transitionInherit = node.__transition__[id];
8562
type.call(node, node.__data__, i, j);
8563
});
8564
d3_transitionInherit = inherit;
8565
d3_transitionInheritId = inheritId;
8566
} else {
8567
d3_selection_each(this, function(node) {
8568
var transition = node.__transition__[id];
8569
(transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
8570
});
8571
}
8572
return this;
8573
};
8574
d3_transitionPrototype.transition = function() {
8575
var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
8576
for (var j = 0, m = this.length; j < m; j++) {
8577
subgroups.push(subgroup = []);
8578
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8579
if (node = group[i]) {
8580
transition = Object.create(node.__transition__[id0]);
8581
transition.delay += transition.duration;
8582
d3_transitionNode(node, i, id1, transition);
8583
}
8584
subgroup.push(node);
8585
}
8586
}
8587
return d3_transition(subgroups, id1);
8588
};
8589
function d3_transitionNode(node, i, id, inherit) {
8590
var lock = node.__transition__ || (node.__transition__ = {
8591
active: 0,
8592
count: 0
8593
}), transition = lock[id];
8594
if (!transition) {
8595
var time = inherit.time;
8596
transition = lock[id] = {
8597
tween: new d3_Map(),
8598
time: time,
8599
ease: inherit.ease,
8600
delay: inherit.delay,
8601
duration: inherit.duration
8602
};
8603
++lock.count;
8604
d3.timer(function(elapsed) {
8605
var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = [];
8606
timer.t = delay + time;
8607
if (delay <= elapsed) return start(elapsed - delay);
8608
timer.c = start;
8609
function start(elapsed) {
8610
if (lock.active > id) return stop();
8611
lock.active = id;
8612
transition.event && transition.event.start.call(node, d, i);
8613
transition.tween.forEach(function(key, value) {
8614
if (value = value.call(node, d, i)) {
8615
tweened.push(value);
8616
}
8617
});
8618
d3.timer(function() {
8619
timer.c = tick(elapsed || 1) ? d3_true : tick;
8620
return 1;
8621
}, 0, time);
8622
}
8623
function tick(elapsed) {
8624
if (lock.active !== id) return stop();
8625
var t = elapsed / duration, e = ease(t), n = tweened.length;
8626
while (n > 0) {
8627
tweened[--n].call(node, e);
8628
}
8629
if (t >= 1) {
8630
transition.event && transition.event.end.call(node, d, i);
8631
return stop();
8632
}
8633
}
8634
function stop() {
8635
if (--lock.count) delete lock[id]; else delete node.__transition__;
8636
return 1;
8637
}
8638
}, 0, time);
8639
}
8640
}
8641
d3.svg.axis = function() {
8642
var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
8643
function axis(g) {
8644
g.each(function() {
8645
var g = d3.select(this);
8646
var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
8647
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;
8648
var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
8649
d3.transition(path));
8650
tickEnter.append("line");
8651
tickEnter.append("text");
8652
var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
8653
switch (orient) {
8654
case "bottom":
8655
{
8656
tickTransform = d3_svg_axisX;
8657
lineEnter.attr("y2", innerTickSize);
8658
textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding);
8659
lineUpdate.attr("x2", 0).attr("y2", innerTickSize);
8660
textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding);
8661
text.attr("dy", ".71em").style("text-anchor", "middle");
8662
pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize);
8663
break;
8664
}
8665
8666
case "top":
8667
{
8668
tickTransform = d3_svg_axisX;
8669
lineEnter.attr("y2", -innerTickSize);
8670
textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
8671
lineUpdate.attr("x2", 0).attr("y2", -innerTickSize);
8672
textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
8673
text.attr("dy", "0em").style("text-anchor", "middle");
8674
pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize);
8675
break;
8676
}
8677
8678
case "left":
8679
{
8680
tickTransform = d3_svg_axisY;
8681
lineEnter.attr("x2", -innerTickSize);
8682
textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding));
8683
lineUpdate.attr("x2", -innerTickSize).attr("y2", 0);
8684
textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", 0);
8685
text.attr("dy", ".32em").style("text-anchor", "end");
8686
pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize);
8687
break;
8688
}
8689
8690
case "right":
8691
{
8692
tickTransform = d3_svg_axisY;
8693
lineEnter.attr("x2", innerTickSize);
8694
textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding);
8695
lineUpdate.attr("x2", innerTickSize).attr("y2", 0);
8696
textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0);
8697
text.attr("dy", ".32em").style("text-anchor", "start");
8698
pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize);
8699
break;
8700
}
8701
}
8702
if (scale1.rangeBand) {
8703
var x = scale1, dx = x.rangeBand() / 2;
8704
scale0 = scale1 = function(d) {
8705
return x(d) + dx;
8706
};
8707
} else if (scale0.rangeBand) {
8708
scale0 = scale1;
8709
} else {
8710
tickExit.call(tickTransform, scale1);
8711
}
8712
tickEnter.call(tickTransform, scale0);
8713
tickUpdate.call(tickTransform, scale1);
8714
});
8715
}
8716
axis.scale = function(x) {
8717
if (!arguments.length) return scale;
8718
scale = x;
8719
return axis;
8720
};
8721
axis.orient = function(x) {
8722
if (!arguments.length) return orient;
8723
orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
8724
return axis;
8725
};
8726
axis.ticks = function() {
8727
if (!arguments.length) return tickArguments_;
8728
tickArguments_ = arguments;
8729
return axis;
8730
};
8731
axis.tickValues = function(x) {
8732
if (!arguments.length) return tickValues;
8733
tickValues = x;
8734
return axis;
8735
};
8736
axis.tickFormat = function(x) {
8737
if (!arguments.length) return tickFormat_;
8738
tickFormat_ = x;
8739
return axis;
8740
};
8741
axis.tickSize = function(x) {
8742
var n = arguments.length;
8743
if (!n) return innerTickSize;
8744
innerTickSize = +x;
8745
outerTickSize = +arguments[n - 1];
8746
return axis;
8747
};
8748
axis.innerTickSize = function(x) {
8749
if (!arguments.length) return innerTickSize;
8750
innerTickSize = +x;
8751
return axis;
8752
};
8753
axis.outerTickSize = function(x) {
8754
if (!arguments.length) return outerTickSize;
8755
outerTickSize = +x;
8756
return axis;
8757
};
8758
axis.tickPadding = function(x) {
8759
if (!arguments.length) return tickPadding;
8760
tickPadding = +x;
8761
return axis;
8762
};
8763
axis.tickSubdivide = function() {
8764
return arguments.length && axis;
8765
};
8766
return axis;
8767
};
8768
var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
8769
top: 1,
8770
right: 1,
8771
bottom: 1,
8772
left: 1
8773
};
8774
function d3_svg_axisX(selection, x) {
8775
selection.attr("transform", function(d) {
8776
return "translate(" + x(d) + ",0)";
8777
});
8778
}
8779
function d3_svg_axisY(selection, y) {
8780
selection.attr("transform", function(d) {
8781
return "translate(0," + y(d) + ")";
8782
});
8783
}
8784
d3.svg.brush = function() {
8785
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];
8786
function brush(g) {
8787
g.each(function() {
8788
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);
8789
var background = g.selectAll(".background").data([ 0 ]);
8790
background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
8791
g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
8792
var resize = g.selectAll(".resize").data(resizes, d3_identity);
8793
resize.exit().remove();
8794
resize.enter().append("g").attr("class", function(d) {
8795
return "resize " + d;
8796
}).style("cursor", function(d) {
8797
return d3_svg_brushCursor[d];
8798
}).append("rect").attr("x", function(d) {
8799
return /[ew]$/.test(d) ? -3 : null;
8800
}).attr("y", function(d) {
8801
return /^[ns]/.test(d) ? -3 : null;
8802
}).attr("width", 6).attr("height", 6).style("visibility", "hidden");
8803
resize.style("display", brush.empty() ? "none" : null);
8804
var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
8805
if (x) {
8806
range = d3_scaleRange(x);
8807
backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
8808
redrawX(gUpdate);
8809
}
8810
if (y) {
8811
range = d3_scaleRange(y);
8812
backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
8813
redrawY(gUpdate);
8814
}
8815
redraw(gUpdate);
8816
});
8817
}
8818
brush.event = function(g) {
8819
g.each(function() {
8820
var event_ = event.of(this, arguments), extent1 = {
8821
x: xExtent,
8822
y: yExtent,
8823
i: xExtentDomain,
8824
j: yExtentDomain
8825
}, extent0 = this.__chart__ || extent1;
8826
this.__chart__ = extent1;
8827
if (d3_transitionInheritId) {
8828
d3.select(this).transition().each("start.brush", function() {
8829
xExtentDomain = extent0.i;
8830
yExtentDomain = extent0.j;
8831
xExtent = extent0.x;
8832
yExtent = extent0.y;
8833
event_({
8834
type: "brushstart"
8835
});
8836
}).tween("brush:brush", function() {
8837
var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
8838
xExtentDomain = yExtentDomain = null;
8839
return function(t) {
8840
xExtent = extent1.x = xi(t);
8841
yExtent = extent1.y = yi(t);
8842
event_({
8843
type: "brush",
8844
mode: "resize"
8845
});
8846
};
8847
}).each("end.brush", function() {
8848
xExtentDomain = extent1.i;
8849
yExtentDomain = extent1.j;
8850
event_({
8851
type: "brush",
8852
mode: "resize"
8853
});
8854
event_({
8855
type: "brushend"
8856
});
8857
});
8858
} else {
8859
event_({
8860
type: "brushstart"
8861
});
8862
event_({
8863
type: "brush",
8864
mode: "resize"
8865
});
8866
event_({
8867
type: "brushend"
8868
});
8869
}
8870
});
8871
};
8872
function redraw(g) {
8873
g.selectAll(".resize").attr("transform", function(d) {
8874
return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
8875
});
8876
}
8877
function redrawX(g) {
8878
g.select(".extent").attr("x", xExtent[0]);
8879
g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
8880
}
8881
function redrawY(g) {
8882
g.select(".extent").attr("y", yExtent[0]);
8883
g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
8884
}
8885
function brushstart() {
8886
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;
8887
var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
8888
if (d3.event.changedTouches) {
8889
w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
8890
} else {
8891
w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
8892
}
8893
g.interrupt().selectAll("*").interrupt();
8894
if (dragging) {
8895
origin[0] = xExtent[0] - origin[0];
8896
origin[1] = yExtent[0] - origin[1];
8897
} else if (resizing) {
8898
var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
8899
offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
8900
origin[0] = xExtent[ex];
8901
origin[1] = yExtent[ey];
8902
} else if (d3.event.altKey) center = origin.slice();
8903
g.style("pointer-events", "none").selectAll(".resize").style("display", null);
8904
d3.select("body").style("cursor", eventTarget.style("cursor"));
8905
event_({
8906
type: "brushstart"
8907
});
8908
brushmove();
8909
function keydown() {
8910
if (d3.event.keyCode == 32) {
8911
if (!dragging) {
8912
center = null;
8913
origin[0] -= xExtent[1];
8914
origin[1] -= yExtent[1];
8915
dragging = 2;
8916
}
8917
d3_eventPreventDefault();
8918
}
8919
}
8920
function keyup() {
8921
if (d3.event.keyCode == 32 && dragging == 2) {
8922
origin[0] += xExtent[1];
8923
origin[1] += yExtent[1];
8924
dragging = 0;
8925
d3_eventPreventDefault();
8926
}
8927
}
8928
function brushmove() {
8929
var point = d3.mouse(target), moved = false;
8930
if (offset) {
8931
point[0] += offset[0];
8932
point[1] += offset[1];
8933
}
8934
if (!dragging) {
8935
if (d3.event.altKey) {
8936
if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
8937
origin[0] = xExtent[+(point[0] < center[0])];
8938
origin[1] = yExtent[+(point[1] < center[1])];
8939
} else center = null;
8940
}
8941
if (resizingX && move1(point, x, 0)) {
8942
redrawX(g);
8943
moved = true;
8944
}
8945
if (resizingY && move1(point, y, 1)) {
8946
redrawY(g);
8947
moved = true;
8948
}
8949
if (moved) {
8950
redraw(g);
8951
event_({
8952
type: "brush",
8953
mode: dragging ? "move" : "resize"
8954
});
8955
}
8956
}
8957
function move1(point, scale, i) {
8958
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;
8959
if (dragging) {
8960
r0 -= position;
8961
r1 -= size + position;
8962
}
8963
min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
8964
if (dragging) {
8965
max = (min += position) + size;
8966
} else {
8967
if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
8968
if (position < min) {
8969
max = min;
8970
min = position;
8971
} else {
8972
max = position;
8973
}
8974
}
8975
if (extent[0] != min || extent[1] != max) {
8976
if (i) yExtentDomain = null; else xExtentDomain = null;
8977
extent[0] = min;
8978
extent[1] = max;
8979
return true;
8980
}
8981
}
8982
function brushend() {
8983
brushmove();
8984
g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
8985
d3.select("body").style("cursor", null);
8986
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);
8987
dragRestore();
8988
event_({
8989
type: "brushend"
8990
});
8991
}
8992
}
8993
brush.x = function(z) {
8994
if (!arguments.length) return x;
8995
x = z;
8996
resizes = d3_svg_brushResizes[!x << 1 | !y];
8997
return brush;
8998
};
8999
brush.y = function(z) {
9000
if (!arguments.length) return y;
9001
y = z;
9002
resizes = d3_svg_brushResizes[!x << 1 | !y];
9003
return brush;
9004
};
9005
brush.clamp = function(z) {
9006
if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
9007
if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
9008
return brush;
9009
};
9010
brush.extent = function(z) {
9011
var x0, x1, y0, y1, t;
9012
if (!arguments.length) {
9013
if (x) {
9014
if (xExtentDomain) {
9015
x0 = xExtentDomain[0], x1 = xExtentDomain[1];
9016
} else {
9017
x0 = xExtent[0], x1 = xExtent[1];
9018
if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
9019
if (x1 < x0) t = x0, x0 = x1, x1 = t;
9020
}
9021
}
9022
if (y) {
9023
if (yExtentDomain) {
9024
y0 = yExtentDomain[0], y1 = yExtentDomain[1];
9025
} else {
9026
y0 = yExtent[0], y1 = yExtent[1];
9027
if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
9028
if (y1 < y0) t = y0, y0 = y1, y1 = t;
9029
}
9030
}
9031
return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
9032
}
9033
if (x) {
9034
x0 = z[0], x1 = z[1];
9035
if (y) x0 = x0[0], x1 = x1[0];
9036
xExtentDomain = [ x0, x1 ];
9037
if (x.invert) x0 = x(x0), x1 = x(x1);
9038
if (x1 < x0) t = x0, x0 = x1, x1 = t;
9039
if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
9040
}
9041
if (y) {
9042
y0 = z[0], y1 = z[1];
9043
if (x) y0 = y0[1], y1 = y1[1];
9044
yExtentDomain = [ y0, y1 ];
9045
if (y.invert) y0 = y(y0), y1 = y(y1);
9046
if (y1 < y0) t = y0, y0 = y1, y1 = t;
9047
if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
9048
}
9049
return brush;
9050
};
9051
brush.clear = function() {
9052
if (!brush.empty()) {
9053
xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
9054
xExtentDomain = yExtentDomain = null;
9055
}
9056
return brush;
9057
};
9058
brush.empty = function() {
9059
return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
9060
};
9061
return d3.rebind(brush, event, "on");
9062
};
9063
var d3_svg_brushCursor = {
9064
n: "ns-resize",
9065
e: "ew-resize",
9066
s: "ns-resize",
9067
w: "ew-resize",
9068
nw: "nwse-resize",
9069
ne: "nesw-resize",
9070
se: "nwse-resize",
9071
sw: "nesw-resize"
9072
};
9073
var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
9074
var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
9075
var d3_time_formatUtc = d3_time_format.utc;
9076
var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
9077
d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
9078
function d3_time_formatIsoNative(date) {
9079
return date.toISOString();
9080
}
9081
d3_time_formatIsoNative.parse = function(string) {
9082
var date = new Date(string);
9083
return isNaN(date) ? null : date;
9084
};
9085
d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
9086
d3_time.second = d3_time_interval(function(date) {
9087
return new d3_date(Math.floor(date / 1e3) * 1e3);
9088
}, function(date, offset) {
9089
date.setTime(date.getTime() + Math.floor(offset) * 1e3);
9090
}, function(date) {
9091
return date.getSeconds();
9092
});
9093
d3_time.seconds = d3_time.second.range;
9094
d3_time.seconds.utc = d3_time.second.utc.range;
9095
d3_time.minute = d3_time_interval(function(date) {
9096
return new d3_date(Math.floor(date / 6e4) * 6e4);
9097
}, function(date, offset) {
9098
date.setTime(date.getTime() + Math.floor(offset) * 6e4);
9099
}, function(date) {
9100
return date.getMinutes();
9101
});
9102
d3_time.minutes = d3_time.minute.range;
9103
d3_time.minutes.utc = d3_time.minute.utc.range;
9104
d3_time.hour = d3_time_interval(function(date) {
9105
var timezone = date.getTimezoneOffset() / 60;
9106
return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
9107
}, function(date, offset) {
9108
date.setTime(date.getTime() + Math.floor(offset) * 36e5);
9109
}, function(date) {
9110
return date.getHours();
9111
});
9112
d3_time.hours = d3_time.hour.range;
9113
d3_time.hours.utc = d3_time.hour.utc.range;
9114
d3_time.month = d3_time_interval(function(date) {
9115
date = d3_time.day(date);
9116
date.setDate(1);
9117
return date;
9118
}, function(date, offset) {
9119
date.setMonth(date.getMonth() + offset);
9120
}, function(date) {
9121
return date.getMonth();
9122
});
9123
d3_time.months = d3_time.month.range;
9124
d3_time.months.utc = d3_time.month.utc.range;
9125
function d3_time_scale(linear, methods, format) {
9126
function scale(x) {
9127
return linear(x);
9128
}
9129
scale.invert = function(x) {
9130
return d3_time_scaleDate(linear.invert(x));
9131
};
9132
scale.domain = function(x) {
9133
if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
9134
linear.domain(x);
9135
return scale;
9136
};
9137
function tickMethod(extent, count) {
9138
var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
9139
return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
9140
return d / 31536e6;
9141
}), 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];
9142
}
9143
scale.nice = function(interval, skip) {
9144
var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
9145
if (method) interval = method[0], skip = method[1];
9146
function skipped(date) {
9147
return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
9148
}
9149
return scale.domain(d3_scale_nice(domain, skip > 1 ? {
9150
floor: function(date) {
9151
while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
9152
return date;
9153
},
9154
ceil: function(date) {
9155
while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
9156
return date;
9157
}
9158
} : interval));
9159
};
9160
scale.ticks = function(interval, skip) {
9161
var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
9162
range: interval
9163
}, skip ];
9164
if (method) interval = method[0], skip = method[1];
9165
return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
9166
};
9167
scale.tickFormat = function() {
9168
return format;
9169
};
9170
scale.copy = function() {
9171
return d3_time_scale(linear.copy(), methods, format);
9172
};
9173
return d3_scale_linearRebind(scale, linear);
9174
}
9175
function d3_time_scaleDate(t) {
9176
return new Date(t);
9177
}
9178
var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
9179
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 ] ];
9180
var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
9181
return d.getMilliseconds();
9182
} ], [ ":%S", function(d) {
9183
return d.getSeconds();
9184
} ], [ "%I:%M", function(d) {
9185
return d.getMinutes();
9186
} ], [ "%I %p", function(d) {
9187
return d.getHours();
9188
} ], [ "%a %d", function(d) {
9189
return d.getDay() && d.getDate() != 1;
9190
} ], [ "%b %d", function(d) {
9191
return d.getDate() != 1;
9192
} ], [ "%B", function(d) {
9193
return d.getMonth();
9194
} ], [ "%Y", d3_true ] ]);
9195
var d3_time_scaleMilliseconds = {
9196
range: function(start, stop, step) {
9197
return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
9198
},
9199
floor: d3_identity,
9200
ceil: d3_identity
9201
};
9202
d3_time_scaleLocalMethods.year = d3_time.year;
9203
d3_time.scale = function() {
9204
return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
9205
};
9206
var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
9207
return [ m[0].utc, m[1] ];
9208
});
9209
var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
9210
return d.getUTCMilliseconds();
9211
} ], [ ":%S", function(d) {
9212
return d.getUTCSeconds();
9213
} ], [ "%I:%M", function(d) {
9214
return d.getUTCMinutes();
9215
} ], [ "%I %p", function(d) {
9216
return d.getUTCHours();
9217
} ], [ "%a %d", function(d) {
9218
return d.getUTCDay() && d.getUTCDate() != 1;
9219
} ], [ "%b %d", function(d) {
9220
return d.getUTCDate() != 1;
9221
} ], [ "%B", function(d) {
9222
return d.getUTCMonth();
9223
} ], [ "%Y", d3_true ] ]);
9224
d3_time_scaleUtcMethods.year = d3_time.year.utc;
9225
d3_time.scale.utc = function() {
9226
return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
9227
};
9228
d3.text = d3_xhrType(function(request) {
9229
return request.responseText;
9230
});
9231
d3.json = function(url, callback) {
9232
return d3_xhr(url, "application/json", d3_json, callback);
9233
};
9234
function d3_json(request) {
9235
return JSON.parse(request.responseText);
9236
}
9237
d3.html = function(url, callback) {
9238
return d3_xhr(url, "text/html", d3_html, callback);
9239
};
9240
function d3_html(request) {
9241
var range = d3_document.createRange();
9242
range.selectNode(d3_document.body);
9243
return range.createContextualFragment(request.responseText);
9244
}
9245
d3.xml = d3_xhrType(function(request) {
9246
return request.responseXML;
9247
});
9248
if (typeof define === "function" && define.amd) {
9249
define(d3);
9250
} else if (typeof module === "object" && module.exports) {
9251
module.exports = d3;
9252
} else {
9253
this.d3 = d3;
9254
}
9255
}();
9256
9257