tom | 1f60124 | 2014-10-13 11:10:40 -0700 | [diff] [blame] | 1 | !function() { |
| 2 | var d3 = { |
| 3 | version: "3.4.12" |
| 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.slice(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.slice(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.slice(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.slice(i + 1); |
| 420 | type = type.slice(0, i); |
| 421 | } |
| 422 | if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener); |
| 423 | if (arguments.length === 2) { |
| 424 | if (listener == null) for (type in this) { |
| 425 | if (this.hasOwnProperty(type)) this[type].on(name, null); |
| 426 | } |
| 427 | return this; |
| 428 | } |
| 429 | }; |
| 430 | function d3_dispatch_event(dispatch) { |
| 431 | var listeners = [], listenerByName = new d3_Map(); |
| 432 | function event() { |
| 433 | var z = listeners, i = -1, n = z.length, l; |
| 434 | while (++i < n) if (l = z[i].on) l.apply(this, arguments); |
| 435 | return dispatch; |
| 436 | } |
| 437 | event.on = function(name, listener) { |
| 438 | var l = listenerByName.get(name), i; |
| 439 | if (arguments.length < 2) return l && l.on; |
| 440 | if (l) { |
| 441 | l.on = null; |
| 442 | listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1)); |
| 443 | listenerByName.remove(name); |
| 444 | } |
| 445 | if (listener) listeners.push(listenerByName.set(name, { |
| 446 | on: listener |
| 447 | })); |
| 448 | return dispatch; |
| 449 | }; |
| 450 | return event; |
| 451 | } |
| 452 | d3.event = null; |
| 453 | function d3_eventPreventDefault() { |
| 454 | d3.event.preventDefault(); |
| 455 | } |
| 456 | function d3_eventSource() { |
| 457 | var e = d3.event, s; |
| 458 | while (s = e.sourceEvent) e = s; |
| 459 | return e; |
| 460 | } |
| 461 | function d3_eventDispatch(target) { |
| 462 | var dispatch = new d3_dispatch(), i = 0, n = arguments.length; |
| 463 | while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch); |
| 464 | dispatch.of = function(thiz, argumentz) { |
| 465 | return function(e1) { |
| 466 | try { |
| 467 | var e0 = e1.sourceEvent = d3.event; |
| 468 | e1.target = target; |
| 469 | d3.event = e1; |
| 470 | dispatch[e1.type].apply(thiz, argumentz); |
| 471 | } finally { |
| 472 | d3.event = e0; |
| 473 | } |
| 474 | }; |
| 475 | }; |
| 476 | return dispatch; |
| 477 | } |
| 478 | d3.requote = function(s) { |
| 479 | return s.replace(d3_requote_re, "\\$&"); |
| 480 | }; |
| 481 | var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g; |
| 482 | var d3_subclass = {}.__proto__ ? function(object, prototype) { |
| 483 | object.__proto__ = prototype; |
| 484 | } : function(object, prototype) { |
| 485 | for (var property in prototype) object[property] = prototype[property]; |
| 486 | }; |
| 487 | function d3_selection(groups) { |
| 488 | d3_subclass(groups, d3_selectionPrototype); |
| 489 | return groups; |
| 490 | } |
| 491 | var d3_select = function(s, n) { |
| 492 | return n.querySelector(s); |
| 493 | }, d3_selectAll = function(s, n) { |
| 494 | return n.querySelectorAll(s); |
| 495 | }, d3_selectMatcher = d3_documentElement.matches || d3_documentElement[d3_vendorSymbol(d3_documentElement, "matchesSelector")], d3_selectMatches = function(n, s) { |
| 496 | return d3_selectMatcher.call(n, s); |
| 497 | }; |
| 498 | if (typeof Sizzle === "function") { |
| 499 | d3_select = function(s, n) { |
| 500 | return Sizzle(s, n)[0] || null; |
| 501 | }; |
| 502 | d3_selectAll = Sizzle; |
| 503 | d3_selectMatches = Sizzle.matchesSelector; |
| 504 | } |
| 505 | d3.selection = function() { |
| 506 | return d3_selectionRoot; |
| 507 | }; |
| 508 | var d3_selectionPrototype = d3.selection.prototype = []; |
| 509 | d3_selectionPrototype.select = function(selector) { |
| 510 | var subgroups = [], subgroup, subnode, group, node; |
| 511 | selector = d3_selection_selector(selector); |
| 512 | for (var j = -1, m = this.length; ++j < m; ) { |
| 513 | subgroups.push(subgroup = []); |
| 514 | subgroup.parentNode = (group = this[j]).parentNode; |
| 515 | for (var i = -1, n = group.length; ++i < n; ) { |
| 516 | if (node = group[i]) { |
| 517 | subgroup.push(subnode = selector.call(node, node.__data__, i, j)); |
| 518 | if (subnode && "__data__" in node) subnode.__data__ = node.__data__; |
| 519 | } else { |
| 520 | subgroup.push(null); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | return d3_selection(subgroups); |
| 525 | }; |
| 526 | function d3_selection_selector(selector) { |
| 527 | return typeof selector === "function" ? selector : function() { |
| 528 | return d3_select(selector, this); |
| 529 | }; |
| 530 | } |
| 531 | d3_selectionPrototype.selectAll = function(selector) { |
| 532 | var subgroups = [], subgroup, node; |
| 533 | selector = d3_selection_selectorAll(selector); |
| 534 | for (var j = -1, m = this.length; ++j < m; ) { |
| 535 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
| 536 | if (node = group[i]) { |
| 537 | subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j))); |
| 538 | subgroup.parentNode = node; |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | return d3_selection(subgroups); |
| 543 | }; |
| 544 | function d3_selection_selectorAll(selector) { |
| 545 | return typeof selector === "function" ? selector : function() { |
| 546 | return d3_selectAll(selector, this); |
| 547 | }; |
| 548 | } |
| 549 | var d3_nsPrefix = { |
| 550 | svg: "http://www.w3.org/2000/svg", |
| 551 | xhtml: "http://www.w3.org/1999/xhtml", |
| 552 | xlink: "http://www.w3.org/1999/xlink", |
| 553 | xml: "http://www.w3.org/XML/1998/namespace", |
| 554 | xmlns: "http://www.w3.org/2000/xmlns/" |
| 555 | }; |
| 556 | d3.ns = { |
| 557 | prefix: d3_nsPrefix, |
| 558 | qualify: function(name) { |
| 559 | var i = name.indexOf(":"), prefix = name; |
| 560 | if (i >= 0) { |
| 561 | prefix = name.slice(0, i); |
| 562 | name = name.slice(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 | d3_selection_each(this, 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.slice(0, i); |
| 1012 | var filter = d3_selection_onFilters.get(type); |
| 1013 | if (filter) type = filter, wrap = d3_selection_onFilter; |
| 1014 | function onRemove() { |
| 1015 | var l = this[name]; |
| 1016 | if (l) { |
| 1017 | this.removeEventListener(type, l, l.$); |
| 1018 | delete this[name]; |
| 1019 | } |
| 1020 | } |
| 1021 | function onAdd() { |
| 1022 | var l = wrap(listener, d3_array(arguments)); |
| 1023 | onRemove.call(this); |
| 1024 | this.addEventListener(type, this[name] = l, l.$ = capture); |
| 1025 | l._ = listener; |
| 1026 | } |
| 1027 | function removeAll() { |
| 1028 | var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match; |
| 1029 | for (var name in this) { |
| 1030 | if (match = name.match(re)) { |
| 1031 | var l = this[name]; |
| 1032 | this.removeEventListener(match[1], l, l.$); |
| 1033 | delete this[name]; |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll; |
| 1038 | } |
| 1039 | var d3_selection_onFilters = d3.map({ |
| 1040 | mouseenter: "mouseover", |
| 1041 | mouseleave: "mouseout" |
| 1042 | }); |
| 1043 | d3_selection_onFilters.forEach(function(k) { |
| 1044 | if ("on" + k in d3_document) d3_selection_onFilters.remove(k); |
| 1045 | }); |
| 1046 | function d3_selection_onListener(listener, argumentz) { |
| 1047 | return function(e) { |
| 1048 | var o = d3.event; |
| 1049 | d3.event = e; |
| 1050 | argumentz[0] = this.__data__; |
| 1051 | try { |
| 1052 | listener.apply(this, argumentz); |
| 1053 | } finally { |
| 1054 | d3.event = o; |
| 1055 | } |
| 1056 | }; |
| 1057 | } |
| 1058 | function d3_selection_onFilter(listener, argumentz) { |
| 1059 | var l = d3_selection_onListener(listener, argumentz); |
| 1060 | return function(e) { |
| 1061 | var target = this, related = e.relatedTarget; |
| 1062 | if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) { |
| 1063 | l.call(target, e); |
| 1064 | } |
| 1065 | }; |
| 1066 | } |
| 1067 | var d3_event_dragSelect = "onselectstart" in d3_document ? null : d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0; |
| 1068 | function d3_event_dragSuppress() { |
| 1069 | var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault); |
| 1070 | if (d3_event_dragSelect) { |
| 1071 | var style = d3_documentElement.style, select = style[d3_event_dragSelect]; |
| 1072 | style[d3_event_dragSelect] = "none"; |
| 1073 | } |
| 1074 | return function(suppressClick) { |
| 1075 | w.on(name, null); |
| 1076 | if (d3_event_dragSelect) style[d3_event_dragSelect] = select; |
| 1077 | if (suppressClick) { |
| 1078 | function off() { |
| 1079 | w.on(click, null); |
| 1080 | } |
| 1081 | w.on(click, function() { |
| 1082 | d3_eventPreventDefault(); |
| 1083 | off(); |
| 1084 | }, true); |
| 1085 | setTimeout(off, 0); |
| 1086 | } |
| 1087 | }; |
| 1088 | } |
| 1089 | d3.mouse = function(container) { |
| 1090 | return d3_mousePoint(container, d3_eventSource()); |
| 1091 | }; |
| 1092 | var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0; |
| 1093 | function d3_mousePoint(container, e) { |
| 1094 | if (e.changedTouches) e = e.changedTouches[0]; |
| 1095 | var svg = container.ownerSVGElement || container; |
| 1096 | if (svg.createSVGPoint) { |
| 1097 | var point = svg.createSVGPoint(); |
| 1098 | if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) { |
| 1099 | svg = d3.select("body").append("svg").style({ |
| 1100 | position: "absolute", |
| 1101 | top: 0, |
| 1102 | left: 0, |
| 1103 | margin: 0, |
| 1104 | padding: 0, |
| 1105 | border: "none" |
| 1106 | }, "important"); |
| 1107 | var ctm = svg[0][0].getScreenCTM(); |
| 1108 | d3_mouse_bug44083 = !(ctm.f || ctm.e); |
| 1109 | svg.remove(); |
| 1110 | } |
| 1111 | if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX, |
| 1112 | point.y = e.clientY; |
| 1113 | point = point.matrixTransform(container.getScreenCTM().inverse()); |
| 1114 | return [ point.x, point.y ]; |
| 1115 | } |
| 1116 | var rect = container.getBoundingClientRect(); |
| 1117 | return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ]; |
| 1118 | } |
| 1119 | d3.touch = function(container, touches, identifier) { |
| 1120 | if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches; |
| 1121 | if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) { |
| 1122 | if ((touch = touches[i]).identifier === identifier) { |
| 1123 | return d3_mousePoint(container, touch); |
| 1124 | } |
| 1125 | } |
| 1126 | }; |
| 1127 | d3.behavior.drag = function() { |
| 1128 | var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_behavior_dragMouseSubject, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_behavior_dragTouchSubject, "touchmove", "touchend"); |
| 1129 | function drag() { |
| 1130 | this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart); |
| 1131 | } |
| 1132 | function dragstart(id, position, subject, move, end) { |
| 1133 | return function() { |
| 1134 | var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject()).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(), position0 = position(parent, dragId); |
| 1135 | if (origin) { |
| 1136 | dragOffset = origin.apply(that, arguments); |
| 1137 | dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ]; |
| 1138 | } else { |
| 1139 | dragOffset = [ 0, 0 ]; |
| 1140 | } |
| 1141 | dispatch({ |
| 1142 | type: "dragstart" |
| 1143 | }); |
| 1144 | function moved() { |
| 1145 | var position1 = position(parent, dragId), dx, dy; |
| 1146 | if (!position1) return; |
| 1147 | dx = position1[0] - position0[0]; |
| 1148 | dy = position1[1] - position0[1]; |
| 1149 | dragged |= dx | dy; |
| 1150 | position0 = position1; |
| 1151 | dispatch({ |
| 1152 | type: "drag", |
| 1153 | x: position1[0] + dragOffset[0], |
| 1154 | y: position1[1] + dragOffset[1], |
| 1155 | dx: dx, |
| 1156 | dy: dy |
| 1157 | }); |
| 1158 | } |
| 1159 | function ended() { |
| 1160 | if (!position(parent, dragId)) return; |
| 1161 | dragSubject.on(move + dragName, null).on(end + dragName, null); |
| 1162 | dragRestore(dragged && d3.event.target === target); |
| 1163 | dispatch({ |
| 1164 | type: "dragend" |
| 1165 | }); |
| 1166 | } |
| 1167 | }; |
| 1168 | } |
| 1169 | drag.origin = function(x) { |
| 1170 | if (!arguments.length) return origin; |
| 1171 | origin = x; |
| 1172 | return drag; |
| 1173 | }; |
| 1174 | return d3.rebind(drag, event, "on"); |
| 1175 | }; |
| 1176 | function d3_behavior_dragTouchId() { |
| 1177 | return d3.event.changedTouches[0].identifier; |
| 1178 | } |
| 1179 | function d3_behavior_dragTouchSubject() { |
| 1180 | return d3.event.target; |
| 1181 | } |
| 1182 | function d3_behavior_dragMouseSubject() { |
| 1183 | return d3_window; |
| 1184 | } |
| 1185 | d3.touches = function(container, touches) { |
| 1186 | if (arguments.length < 2) touches = d3_eventSource().touches; |
| 1187 | return touches ? d3_array(touches).map(function(touch) { |
| 1188 | var point = d3_mousePoint(container, touch); |
| 1189 | point.identifier = touch.identifier; |
| 1190 | return point; |
| 1191 | }) : []; |
| 1192 | }; |
| 1193 | var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π; |
| 1194 | function d3_sgn(x) { |
| 1195 | return x > 0 ? 1 : x < 0 ? -1 : 0; |
| 1196 | } |
| 1197 | function d3_cross2d(a, b, c) { |
| 1198 | return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]); |
| 1199 | } |
| 1200 | function d3_acos(x) { |
| 1201 | return x > 1 ? 0 : x < -1 ? π : Math.acos(x); |
| 1202 | } |
| 1203 | function d3_asin(x) { |
| 1204 | return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x); |
| 1205 | } |
| 1206 | function d3_sinh(x) { |
| 1207 | return ((x = Math.exp(x)) - 1 / x) / 2; |
| 1208 | } |
| 1209 | function d3_cosh(x) { |
| 1210 | return ((x = Math.exp(x)) + 1 / x) / 2; |
| 1211 | } |
| 1212 | function d3_tanh(x) { |
| 1213 | return ((x = Math.exp(2 * x)) - 1) / (x + 1); |
| 1214 | } |
| 1215 | function d3_haversin(x) { |
| 1216 | return (x = Math.sin(x / 2)) * x; |
| 1217 | } |
| 1218 | var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4; |
| 1219 | d3.interpolateZoom = function(p0, p1) { |
| 1220 | var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2]; |
| 1221 | 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)) / ρ; |
| 1222 | function interpolate(t) { |
| 1223 | var s = t * S; |
| 1224 | if (dr) { |
| 1225 | var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0)); |
| 1226 | return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ]; |
| 1227 | } |
| 1228 | return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ]; |
| 1229 | } |
| 1230 | interpolate.duration = S * 1e3; |
| 1231 | return interpolate; |
| 1232 | }; |
| 1233 | d3.behavior.zoom = function() { |
| 1234 | var view = { |
| 1235 | x: 0, |
| 1236 | y: 0, |
| 1237 | k: 1 |
| 1238 | }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1; |
| 1239 | function zoom(g) { |
| 1240 | g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted); |
| 1241 | } |
| 1242 | zoom.event = function(g) { |
| 1243 | g.each(function() { |
| 1244 | var dispatch = event.of(this, arguments), view1 = view; |
| 1245 | if (d3_transitionInheritId) { |
| 1246 | d3.select(this).transition().each("start.zoom", function() { |
| 1247 | view = this.__chart__ || { |
| 1248 | x: 0, |
| 1249 | y: 0, |
| 1250 | k: 1 |
| 1251 | }; |
| 1252 | zoomstarted(dispatch); |
| 1253 | }).tween("zoom:zoom", function() { |
| 1254 | 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 ]); |
| 1255 | return function(t) { |
| 1256 | var l = i(t), k = dx / l[2]; |
| 1257 | this.__chart__ = view = { |
| 1258 | x: cx - l[0] * k, |
| 1259 | y: cy - l[1] * k, |
| 1260 | k: k |
| 1261 | }; |
| 1262 | zoomed(dispatch); |
| 1263 | }; |
| 1264 | }).each("end.zoom", function() { |
| 1265 | zoomended(dispatch); |
| 1266 | }); |
| 1267 | } else { |
| 1268 | this.__chart__ = view; |
| 1269 | zoomstarted(dispatch); |
| 1270 | zoomed(dispatch); |
| 1271 | zoomended(dispatch); |
| 1272 | } |
| 1273 | }); |
| 1274 | }; |
| 1275 | zoom.translate = function(_) { |
| 1276 | if (!arguments.length) return [ view.x, view.y ]; |
| 1277 | view = { |
| 1278 | x: +_[0], |
| 1279 | y: +_[1], |
| 1280 | k: view.k |
| 1281 | }; |
| 1282 | rescale(); |
| 1283 | return zoom; |
| 1284 | }; |
| 1285 | zoom.scale = function(_) { |
| 1286 | if (!arguments.length) return view.k; |
| 1287 | view = { |
| 1288 | x: view.x, |
| 1289 | y: view.y, |
| 1290 | k: +_ |
| 1291 | }; |
| 1292 | rescale(); |
| 1293 | return zoom; |
| 1294 | }; |
| 1295 | zoom.scaleExtent = function(_) { |
| 1296 | if (!arguments.length) return scaleExtent; |
| 1297 | scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ]; |
| 1298 | return zoom; |
| 1299 | }; |
| 1300 | zoom.center = function(_) { |
| 1301 | if (!arguments.length) return center; |
| 1302 | center = _ && [ +_[0], +_[1] ]; |
| 1303 | return zoom; |
| 1304 | }; |
| 1305 | zoom.size = function(_) { |
| 1306 | if (!arguments.length) return size; |
| 1307 | size = _ && [ +_[0], +_[1] ]; |
| 1308 | return zoom; |
| 1309 | }; |
| 1310 | zoom.x = function(z) { |
| 1311 | if (!arguments.length) return x1; |
| 1312 | x1 = z; |
| 1313 | x0 = z.copy(); |
| 1314 | view = { |
| 1315 | x: 0, |
| 1316 | y: 0, |
| 1317 | k: 1 |
| 1318 | }; |
| 1319 | return zoom; |
| 1320 | }; |
| 1321 | zoom.y = function(z) { |
| 1322 | if (!arguments.length) return y1; |
| 1323 | y1 = z; |
| 1324 | y0 = z.copy(); |
| 1325 | view = { |
| 1326 | x: 0, |
| 1327 | y: 0, |
| 1328 | k: 1 |
| 1329 | }; |
| 1330 | return zoom; |
| 1331 | }; |
| 1332 | function location(p) { |
| 1333 | return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ]; |
| 1334 | } |
| 1335 | function point(l) { |
| 1336 | return [ l[0] * view.k + view.x, l[1] * view.k + view.y ]; |
| 1337 | } |
| 1338 | function scaleTo(s) { |
| 1339 | view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s)); |
| 1340 | } |
| 1341 | function translateTo(p, l) { |
| 1342 | l = point(l); |
| 1343 | view.x += p[0] - l[0]; |
| 1344 | view.y += p[1] - l[1]; |
| 1345 | } |
| 1346 | function rescale() { |
| 1347 | if (x1) x1.domain(x0.range().map(function(x) { |
| 1348 | return (x - view.x) / view.k; |
| 1349 | }).map(x0.invert)); |
| 1350 | if (y1) y1.domain(y0.range().map(function(y) { |
| 1351 | return (y - view.y) / view.k; |
| 1352 | }).map(y0.invert)); |
| 1353 | } |
| 1354 | function zoomstarted(dispatch) { |
| 1355 | dispatch({ |
| 1356 | type: "zoomstart" |
| 1357 | }); |
| 1358 | } |
| 1359 | function zoomed(dispatch) { |
| 1360 | rescale(); |
| 1361 | dispatch({ |
| 1362 | type: "zoom", |
| 1363 | scale: view.k, |
| 1364 | translate: [ view.x, view.y ] |
| 1365 | }); |
| 1366 | } |
| 1367 | function zoomended(dispatch) { |
| 1368 | dispatch({ |
| 1369 | type: "zoomend" |
| 1370 | }); |
| 1371 | } |
| 1372 | function mousedowned() { |
| 1373 | 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(); |
| 1374 | d3_selection_interrupt.call(that); |
| 1375 | zoomstarted(dispatch); |
| 1376 | function moved() { |
| 1377 | dragged = 1; |
| 1378 | translateTo(d3.mouse(that), location0); |
| 1379 | zoomed(dispatch); |
| 1380 | } |
| 1381 | function ended() { |
| 1382 | subject.on(mousemove, null).on(mouseup, null); |
| 1383 | dragRestore(dragged && d3.event.target === target); |
| 1384 | zoomended(dispatch); |
| 1385 | } |
| 1386 | } |
| 1387 | function touchstarted() { |
| 1388 | var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(); |
| 1389 | d3_selection_interrupt.call(that); |
| 1390 | started(); |
| 1391 | zoomstarted(dispatch); |
| 1392 | subject.on(mousedown, null).on(touchstart, started); |
| 1393 | function relocate() { |
| 1394 | var touches = d3.touches(that); |
| 1395 | scale0 = view.k; |
| 1396 | touches.forEach(function(t) { |
| 1397 | if (t.identifier in locations0) locations0[t.identifier] = location(t); |
| 1398 | }); |
| 1399 | return touches; |
| 1400 | } |
| 1401 | function started() { |
| 1402 | var target = d3.event.target; |
| 1403 | d3.select(target).on(touchmove, moved).on(touchend, ended); |
| 1404 | targets.push(target); |
| 1405 | var changed = d3.event.changedTouches; |
| 1406 | for (var i = 0, n = changed.length; i < n; ++i) { |
| 1407 | locations0[changed[i].identifier] = null; |
| 1408 | } |
| 1409 | var touches = relocate(), now = Date.now(); |
| 1410 | if (touches.length === 1) { |
| 1411 | if (now - touchtime < 500) { |
| 1412 | var p = touches[0], l = locations0[p.identifier]; |
| 1413 | scaleTo(view.k * 2); |
| 1414 | translateTo(p, l); |
| 1415 | d3_eventPreventDefault(); |
| 1416 | zoomed(dispatch); |
| 1417 | } |
| 1418 | touchtime = now; |
| 1419 | } else if (touches.length > 1) { |
| 1420 | var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1]; |
| 1421 | distance0 = dx * dx + dy * dy; |
| 1422 | } |
| 1423 | } |
| 1424 | function moved() { |
| 1425 | var touches = d3.touches(that), p0, l0, p1, l1; |
| 1426 | for (var i = 0, n = touches.length; i < n; ++i, l1 = null) { |
| 1427 | p1 = touches[i]; |
| 1428 | if (l1 = locations0[p1.identifier]) { |
| 1429 | if (l0) break; |
| 1430 | p0 = p1, l0 = l1; |
| 1431 | } |
| 1432 | } |
| 1433 | if (l1) { |
| 1434 | var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0); |
| 1435 | p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ]; |
| 1436 | l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ]; |
| 1437 | scaleTo(scale1 * scale0); |
| 1438 | } |
| 1439 | touchtime = null; |
| 1440 | translateTo(p0, l0); |
| 1441 | zoomed(dispatch); |
| 1442 | } |
| 1443 | function ended() { |
| 1444 | if (d3.event.touches.length) { |
| 1445 | var changed = d3.event.changedTouches; |
| 1446 | for (var i = 0, n = changed.length; i < n; ++i) { |
| 1447 | delete locations0[changed[i].identifier]; |
| 1448 | } |
| 1449 | for (var identifier in locations0) { |
| 1450 | return void relocate(); |
| 1451 | } |
| 1452 | } |
| 1453 | d3.selectAll(targets).on(zoomName, null); |
| 1454 | subject.on(mousedown, mousedowned).on(touchstart, touchstarted); |
| 1455 | dragRestore(); |
| 1456 | zoomended(dispatch); |
| 1457 | } |
| 1458 | } |
| 1459 | function mousewheeled() { |
| 1460 | var dispatch = event.of(this, arguments); |
| 1461 | if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)), |
| 1462 | d3_selection_interrupt.call(this), zoomstarted(dispatch); |
| 1463 | mousewheelTimer = setTimeout(function() { |
| 1464 | mousewheelTimer = null; |
| 1465 | zoomended(dispatch); |
| 1466 | }, 50); |
| 1467 | d3_eventPreventDefault(); |
| 1468 | scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k); |
| 1469 | translateTo(center0, translate0); |
| 1470 | zoomed(dispatch); |
| 1471 | } |
| 1472 | function dblclicked() { |
| 1473 | var dispatch = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2; |
| 1474 | zoomstarted(dispatch); |
| 1475 | scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1)); |
| 1476 | translateTo(p, l); |
| 1477 | zoomed(dispatch); |
| 1478 | zoomended(dispatch); |
| 1479 | } |
| 1480 | return d3.rebind(zoom, event, "on"); |
| 1481 | }; |
| 1482 | var d3_behavior_zoomInfinity = [ 0, Infinity ]; |
| 1483 | var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() { |
| 1484 | return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1); |
| 1485 | }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() { |
| 1486 | return d3.event.wheelDelta; |
| 1487 | }, "mousewheel") : (d3_behavior_zoomDelta = function() { |
| 1488 | return -d3.event.detail; |
| 1489 | }, "MozMousePixelScroll"); |
| 1490 | d3.color = d3_color; |
| 1491 | function d3_color() {} |
| 1492 | d3_color.prototype.toString = function() { |
| 1493 | return this.rgb() + ""; |
| 1494 | }; |
| 1495 | d3.hsl = d3_hsl; |
| 1496 | function d3_hsl(h, s, l) { |
| 1497 | return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l); |
| 1498 | } |
| 1499 | var d3_hslPrototype = d3_hsl.prototype = new d3_color(); |
| 1500 | d3_hslPrototype.brighter = function(k) { |
| 1501 | k = Math.pow(.7, arguments.length ? k : 1); |
| 1502 | return new d3_hsl(this.h, this.s, this.l / k); |
| 1503 | }; |
| 1504 | d3_hslPrototype.darker = function(k) { |
| 1505 | k = Math.pow(.7, arguments.length ? k : 1); |
| 1506 | return new d3_hsl(this.h, this.s, k * this.l); |
| 1507 | }; |
| 1508 | d3_hslPrototype.rgb = function() { |
| 1509 | return d3_hsl_rgb(this.h, this.s, this.l); |
| 1510 | }; |
| 1511 | function d3_hsl_rgb(h, s, l) { |
| 1512 | var m1, m2; |
| 1513 | h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h; |
| 1514 | s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s; |
| 1515 | l = l < 0 ? 0 : l > 1 ? 1 : l; |
| 1516 | m2 = l <= .5 ? l * (1 + s) : l + s - l * s; |
| 1517 | m1 = 2 * l - m2; |
| 1518 | function v(h) { |
| 1519 | if (h > 360) h -= 360; else if (h < 0) h += 360; |
| 1520 | if (h < 60) return m1 + (m2 - m1) * h / 60; |
| 1521 | if (h < 180) return m2; |
| 1522 | if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60; |
| 1523 | return m1; |
| 1524 | } |
| 1525 | function vv(h) { |
| 1526 | return Math.round(v(h) * 255); |
| 1527 | } |
| 1528 | return new d3_rgb(vv(h + 120), vv(h), vv(h - 120)); |
| 1529 | } |
| 1530 | d3.hcl = d3_hcl; |
| 1531 | function d3_hcl(h, c, l) { |
| 1532 | return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l); |
| 1533 | } |
| 1534 | var d3_hclPrototype = d3_hcl.prototype = new d3_color(); |
| 1535 | d3_hclPrototype.brighter = function(k) { |
| 1536 | return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1))); |
| 1537 | }; |
| 1538 | d3_hclPrototype.darker = function(k) { |
| 1539 | return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1))); |
| 1540 | }; |
| 1541 | d3_hclPrototype.rgb = function() { |
| 1542 | return d3_hcl_lab(this.h, this.c, this.l).rgb(); |
| 1543 | }; |
| 1544 | function d3_hcl_lab(h, c, l) { |
| 1545 | if (isNaN(h)) h = 0; |
| 1546 | if (isNaN(c)) c = 0; |
| 1547 | return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c); |
| 1548 | } |
| 1549 | d3.lab = d3_lab; |
| 1550 | function d3_lab(l, a, b) { |
| 1551 | return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b); |
| 1552 | } |
| 1553 | var d3_lab_K = 18; |
| 1554 | var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883; |
| 1555 | var d3_labPrototype = d3_lab.prototype = new d3_color(); |
| 1556 | d3_labPrototype.brighter = function(k) { |
| 1557 | return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b); |
| 1558 | }; |
| 1559 | d3_labPrototype.darker = function(k) { |
| 1560 | return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b); |
| 1561 | }; |
| 1562 | d3_labPrototype.rgb = function() { |
| 1563 | return d3_lab_rgb(this.l, this.a, this.b); |
| 1564 | }; |
| 1565 | function d3_lab_rgb(l, a, b) { |
| 1566 | var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200; |
| 1567 | x = d3_lab_xyz(x) * d3_lab_X; |
| 1568 | y = d3_lab_xyz(y) * d3_lab_Y; |
| 1569 | z = d3_lab_xyz(z) * d3_lab_Z; |
| 1570 | return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z)); |
| 1571 | } |
| 1572 | function d3_lab_hcl(l, a, b) { |
| 1573 | return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l); |
| 1574 | } |
| 1575 | function d3_lab_xyz(x) { |
| 1576 | return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037; |
| 1577 | } |
| 1578 | function d3_xyz_lab(x) { |
| 1579 | return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29; |
| 1580 | } |
| 1581 | function d3_xyz_rgb(r) { |
| 1582 | return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055)); |
| 1583 | } |
| 1584 | d3.rgb = d3_rgb; |
| 1585 | function d3_rgb(r, g, b) { |
| 1586 | return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b); |
| 1587 | } |
| 1588 | function d3_rgbNumber(value) { |
| 1589 | return new d3_rgb(value >> 16, value >> 8 & 255, value & 255); |
| 1590 | } |
| 1591 | function d3_rgbString(value) { |
| 1592 | return d3_rgbNumber(value) + ""; |
| 1593 | } |
| 1594 | var d3_rgbPrototype = d3_rgb.prototype = new d3_color(); |
| 1595 | d3_rgbPrototype.brighter = function(k) { |
| 1596 | k = Math.pow(.7, arguments.length ? k : 1); |
| 1597 | var r = this.r, g = this.g, b = this.b, i = 30; |
| 1598 | if (!r && !g && !b) return new d3_rgb(i, i, i); |
| 1599 | if (r && r < i) r = i; |
| 1600 | if (g && g < i) g = i; |
| 1601 | if (b && b < i) b = i; |
| 1602 | return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k)); |
| 1603 | }; |
| 1604 | d3_rgbPrototype.darker = function(k) { |
| 1605 | k = Math.pow(.7, arguments.length ? k : 1); |
| 1606 | return new d3_rgb(k * this.r, k * this.g, k * this.b); |
| 1607 | }; |
| 1608 | d3_rgbPrototype.hsl = function() { |
| 1609 | return d3_rgb_hsl(this.r, this.g, this.b); |
| 1610 | }; |
| 1611 | d3_rgbPrototype.toString = function() { |
| 1612 | return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b); |
| 1613 | }; |
| 1614 | function d3_rgb_hex(v) { |
| 1615 | return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16); |
| 1616 | } |
| 1617 | function d3_rgb_parse(format, rgb, hsl) { |
| 1618 | var r = 0, g = 0, b = 0, m1, m2, color; |
| 1619 | m1 = /([a-z]+)\((.*)\)/i.exec(format); |
| 1620 | if (m1) { |
| 1621 | m2 = m1[2].split(","); |
| 1622 | switch (m1[1]) { |
| 1623 | case "hsl": |
| 1624 | { |
| 1625 | return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100); |
| 1626 | } |
| 1627 | |
| 1628 | case "rgb": |
| 1629 | { |
| 1630 | return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2])); |
| 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b); |
| 1635 | if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) { |
| 1636 | if (format.length === 4) { |
| 1637 | r = (color & 3840) >> 4; |
| 1638 | r = r >> 4 | r; |
| 1639 | g = color & 240; |
| 1640 | g = g >> 4 | g; |
| 1641 | b = color & 15; |
| 1642 | b = b << 4 | b; |
| 1643 | } else if (format.length === 7) { |
| 1644 | r = (color & 16711680) >> 16; |
| 1645 | g = (color & 65280) >> 8; |
| 1646 | b = color & 255; |
| 1647 | } |
| 1648 | } |
| 1649 | return rgb(r, g, b); |
| 1650 | } |
| 1651 | function d3_rgb_hsl(r, g, b) { |
| 1652 | 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; |
| 1653 | if (d) { |
| 1654 | s = l < .5 ? d / (max + min) : d / (2 - max - min); |
| 1655 | 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; |
| 1656 | h *= 60; |
| 1657 | } else { |
| 1658 | h = NaN; |
| 1659 | s = l > 0 && l < 1 ? 0 : h; |
| 1660 | } |
| 1661 | return new d3_hsl(h, s, l); |
| 1662 | } |
| 1663 | function d3_rgb_lab(r, g, b) { |
| 1664 | r = d3_rgb_xyz(r); |
| 1665 | g = d3_rgb_xyz(g); |
| 1666 | b = d3_rgb_xyz(b); |
| 1667 | 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); |
| 1668 | return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z)); |
| 1669 | } |
| 1670 | function d3_rgb_xyz(r) { |
| 1671 | return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4); |
| 1672 | } |
| 1673 | function d3_rgb_parseNumber(c) { |
| 1674 | var f = parseFloat(c); |
| 1675 | return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f; |
| 1676 | } |
| 1677 | var d3_rgb_names = d3.map({ |
| 1678 | aliceblue: 15792383, |
| 1679 | antiquewhite: 16444375, |
| 1680 | aqua: 65535, |
| 1681 | aquamarine: 8388564, |
| 1682 | azure: 15794175, |
| 1683 | beige: 16119260, |
| 1684 | bisque: 16770244, |
| 1685 | black: 0, |
| 1686 | blanchedalmond: 16772045, |
| 1687 | blue: 255, |
| 1688 | blueviolet: 9055202, |
| 1689 | brown: 10824234, |
| 1690 | burlywood: 14596231, |
| 1691 | cadetblue: 6266528, |
| 1692 | chartreuse: 8388352, |
| 1693 | chocolate: 13789470, |
| 1694 | coral: 16744272, |
| 1695 | cornflowerblue: 6591981, |
| 1696 | cornsilk: 16775388, |
| 1697 | crimson: 14423100, |
| 1698 | cyan: 65535, |
| 1699 | darkblue: 139, |
| 1700 | darkcyan: 35723, |
| 1701 | darkgoldenrod: 12092939, |
| 1702 | darkgray: 11119017, |
| 1703 | darkgreen: 25600, |
| 1704 | darkgrey: 11119017, |
| 1705 | darkkhaki: 12433259, |
| 1706 | darkmagenta: 9109643, |
| 1707 | darkolivegreen: 5597999, |
| 1708 | darkorange: 16747520, |
| 1709 | darkorchid: 10040012, |
| 1710 | darkred: 9109504, |
| 1711 | darksalmon: 15308410, |
| 1712 | darkseagreen: 9419919, |
| 1713 | darkslateblue: 4734347, |
| 1714 | darkslategray: 3100495, |
| 1715 | darkslategrey: 3100495, |
| 1716 | darkturquoise: 52945, |
| 1717 | darkviolet: 9699539, |
| 1718 | deeppink: 16716947, |
| 1719 | deepskyblue: 49151, |
| 1720 | dimgray: 6908265, |
| 1721 | dimgrey: 6908265, |
| 1722 | dodgerblue: 2003199, |
| 1723 | firebrick: 11674146, |
| 1724 | floralwhite: 16775920, |
| 1725 | forestgreen: 2263842, |
| 1726 | fuchsia: 16711935, |
| 1727 | gainsboro: 14474460, |
| 1728 | ghostwhite: 16316671, |
| 1729 | gold: 16766720, |
| 1730 | goldenrod: 14329120, |
| 1731 | gray: 8421504, |
| 1732 | green: 32768, |
| 1733 | greenyellow: 11403055, |
| 1734 | grey: 8421504, |
| 1735 | honeydew: 15794160, |
| 1736 | hotpink: 16738740, |
| 1737 | indianred: 13458524, |
| 1738 | indigo: 4915330, |
| 1739 | ivory: 16777200, |
| 1740 | khaki: 15787660, |
| 1741 | lavender: 15132410, |
| 1742 | lavenderblush: 16773365, |
| 1743 | lawngreen: 8190976, |
| 1744 | lemonchiffon: 16775885, |
| 1745 | lightblue: 11393254, |
| 1746 | lightcoral: 15761536, |
| 1747 | lightcyan: 14745599, |
| 1748 | lightgoldenrodyellow: 16448210, |
| 1749 | lightgray: 13882323, |
| 1750 | lightgreen: 9498256, |
| 1751 | lightgrey: 13882323, |
| 1752 | lightpink: 16758465, |
| 1753 | lightsalmon: 16752762, |
| 1754 | lightseagreen: 2142890, |
| 1755 | lightskyblue: 8900346, |
| 1756 | lightslategray: 7833753, |
| 1757 | lightslategrey: 7833753, |
| 1758 | lightsteelblue: 11584734, |
| 1759 | lightyellow: 16777184, |
| 1760 | lime: 65280, |
| 1761 | limegreen: 3329330, |
| 1762 | linen: 16445670, |
| 1763 | magenta: 16711935, |
| 1764 | maroon: 8388608, |
| 1765 | mediumaquamarine: 6737322, |
| 1766 | mediumblue: 205, |
| 1767 | mediumorchid: 12211667, |
| 1768 | mediumpurple: 9662683, |
| 1769 | mediumseagreen: 3978097, |
| 1770 | mediumslateblue: 8087790, |
| 1771 | mediumspringgreen: 64154, |
| 1772 | mediumturquoise: 4772300, |
| 1773 | mediumvioletred: 13047173, |
| 1774 | midnightblue: 1644912, |
| 1775 | mintcream: 16121850, |
| 1776 | mistyrose: 16770273, |
| 1777 | moccasin: 16770229, |
| 1778 | navajowhite: 16768685, |
| 1779 | navy: 128, |
| 1780 | oldlace: 16643558, |
| 1781 | olive: 8421376, |
| 1782 | olivedrab: 7048739, |
| 1783 | orange: 16753920, |
| 1784 | orangered: 16729344, |
| 1785 | orchid: 14315734, |
| 1786 | palegoldenrod: 15657130, |
| 1787 | palegreen: 10025880, |
| 1788 | paleturquoise: 11529966, |
| 1789 | palevioletred: 14381203, |
| 1790 | papayawhip: 16773077, |
| 1791 | peachpuff: 16767673, |
| 1792 | peru: 13468991, |
| 1793 | pink: 16761035, |
| 1794 | plum: 14524637, |
| 1795 | powderblue: 11591910, |
| 1796 | purple: 8388736, |
| 1797 | red: 16711680, |
| 1798 | rosybrown: 12357519, |
| 1799 | royalblue: 4286945, |
| 1800 | saddlebrown: 9127187, |
| 1801 | salmon: 16416882, |
| 1802 | sandybrown: 16032864, |
| 1803 | seagreen: 3050327, |
| 1804 | seashell: 16774638, |
| 1805 | sienna: 10506797, |
| 1806 | silver: 12632256, |
| 1807 | skyblue: 8900331, |
| 1808 | slateblue: 6970061, |
| 1809 | slategray: 7372944, |
| 1810 | slategrey: 7372944, |
| 1811 | snow: 16775930, |
| 1812 | springgreen: 65407, |
| 1813 | steelblue: 4620980, |
| 1814 | tan: 13808780, |
| 1815 | teal: 32896, |
| 1816 | thistle: 14204888, |
| 1817 | tomato: 16737095, |
| 1818 | turquoise: 4251856, |
| 1819 | violet: 15631086, |
| 1820 | wheat: 16113331, |
| 1821 | white: 16777215, |
| 1822 | whitesmoke: 16119285, |
| 1823 | yellow: 16776960, |
| 1824 | yellowgreen: 10145074 |
| 1825 | }); |
| 1826 | d3_rgb_names.forEach(function(key, value) { |
| 1827 | d3_rgb_names.set(key, d3_rgbNumber(value)); |
| 1828 | }); |
| 1829 | function d3_functor(v) { |
| 1830 | return typeof v === "function" ? v : function() { |
| 1831 | return v; |
| 1832 | }; |
| 1833 | } |
| 1834 | d3.functor = d3_functor; |
| 1835 | function d3_identity(d) { |
| 1836 | return d; |
| 1837 | } |
| 1838 | d3.xhr = d3_xhrType(d3_identity); |
| 1839 | function d3_xhrType(response) { |
| 1840 | return function(url, mimeType, callback) { |
| 1841 | if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType, |
| 1842 | mimeType = null; |
| 1843 | return d3_xhr(url, mimeType, response, callback); |
| 1844 | }; |
| 1845 | } |
| 1846 | function d3_xhr(url, mimeType, response, callback) { |
| 1847 | var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null; |
| 1848 | if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest(); |
| 1849 | "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() { |
| 1850 | request.readyState > 3 && respond(); |
| 1851 | }; |
| 1852 | function respond() { |
| 1853 | var status = request.status, result; |
| 1854 | if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) { |
| 1855 | try { |
| 1856 | result = response.call(xhr, request); |
| 1857 | } catch (e) { |
| 1858 | dispatch.error.call(xhr, e); |
| 1859 | return; |
| 1860 | } |
| 1861 | dispatch.load.call(xhr, result); |
| 1862 | } else { |
| 1863 | dispatch.error.call(xhr, request); |
| 1864 | } |
| 1865 | } |
| 1866 | request.onprogress = function(event) { |
| 1867 | var o = d3.event; |
| 1868 | d3.event = event; |
| 1869 | try { |
| 1870 | dispatch.progress.call(xhr, request); |
| 1871 | } finally { |
| 1872 | d3.event = o; |
| 1873 | } |
| 1874 | }; |
| 1875 | xhr.header = function(name, value) { |
| 1876 | name = (name + "").toLowerCase(); |
| 1877 | if (arguments.length < 2) return headers[name]; |
| 1878 | if (value == null) delete headers[name]; else headers[name] = value + ""; |
| 1879 | return xhr; |
| 1880 | }; |
| 1881 | xhr.mimeType = function(value) { |
| 1882 | if (!arguments.length) return mimeType; |
| 1883 | mimeType = value == null ? null : value + ""; |
| 1884 | return xhr; |
| 1885 | }; |
| 1886 | xhr.responseType = function(value) { |
| 1887 | if (!arguments.length) return responseType; |
| 1888 | responseType = value; |
| 1889 | return xhr; |
| 1890 | }; |
| 1891 | xhr.response = function(value) { |
| 1892 | response = value; |
| 1893 | return xhr; |
| 1894 | }; |
| 1895 | [ "get", "post" ].forEach(function(method) { |
| 1896 | xhr[method] = function() { |
| 1897 | return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments))); |
| 1898 | }; |
| 1899 | }); |
| 1900 | xhr.send = function(method, data, callback) { |
| 1901 | if (arguments.length === 2 && typeof data === "function") callback = data, data = null; |
| 1902 | request.open(method, url, true); |
| 1903 | if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*"; |
| 1904 | if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]); |
| 1905 | if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType); |
| 1906 | if (responseType != null) request.responseType = responseType; |
| 1907 | if (callback != null) xhr.on("error", callback).on("load", function(request) { |
| 1908 | callback(null, request); |
| 1909 | }); |
| 1910 | dispatch.beforesend.call(xhr, request); |
| 1911 | request.send(data == null ? null : data); |
| 1912 | return xhr; |
| 1913 | }; |
| 1914 | xhr.abort = function() { |
| 1915 | request.abort(); |
| 1916 | return xhr; |
| 1917 | }; |
| 1918 | d3.rebind(xhr, dispatch, "on"); |
| 1919 | return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback)); |
| 1920 | } |
| 1921 | function d3_xhr_fixCallback(callback) { |
| 1922 | return callback.length === 1 ? function(error, request) { |
| 1923 | callback(error == null ? request : null); |
| 1924 | } : callback; |
| 1925 | } |
| 1926 | function d3_xhrHasResponse(request) { |
| 1927 | var type = request.responseType; |
| 1928 | return type && type !== "text" ? request.response : request.responseText; |
| 1929 | } |
| 1930 | d3.dsv = function(delimiter, mimeType) { |
| 1931 | var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0); |
| 1932 | function dsv(url, row, callback) { |
| 1933 | if (arguments.length < 3) callback = row, row = null; |
| 1934 | var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback); |
| 1935 | xhr.row = function(_) { |
| 1936 | return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row; |
| 1937 | }; |
| 1938 | return xhr; |
| 1939 | } |
| 1940 | function response(request) { |
| 1941 | return dsv.parse(request.responseText); |
| 1942 | } |
| 1943 | function typedResponse(f) { |
| 1944 | return function(request) { |
| 1945 | return dsv.parse(request.responseText, f); |
| 1946 | }; |
| 1947 | } |
| 1948 | dsv.parse = function(text, f) { |
| 1949 | var o; |
| 1950 | return dsv.parseRows(text, function(row, i) { |
| 1951 | if (o) return o(row, i - 1); |
| 1952 | var a = new Function("d", "return {" + row.map(function(name, i) { |
| 1953 | return JSON.stringify(name) + ": d[" + i + "]"; |
| 1954 | }).join(",") + "}"); |
| 1955 | o = f ? function(row, i) { |
| 1956 | return f(a(row), i); |
| 1957 | } : a; |
| 1958 | }); |
| 1959 | }; |
| 1960 | dsv.parseRows = function(text, f) { |
| 1961 | var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol; |
| 1962 | function token() { |
| 1963 | if (I >= N) return EOF; |
| 1964 | if (eol) return eol = false, EOL; |
| 1965 | var j = I; |
| 1966 | if (text.charCodeAt(j) === 34) { |
| 1967 | var i = j; |
| 1968 | while (i++ < N) { |
| 1969 | if (text.charCodeAt(i) === 34) { |
| 1970 | if (text.charCodeAt(i + 1) !== 34) break; |
| 1971 | ++i; |
| 1972 | } |
| 1973 | } |
| 1974 | I = i + 2; |
| 1975 | var c = text.charCodeAt(i + 1); |
| 1976 | if (c === 13) { |
| 1977 | eol = true; |
| 1978 | if (text.charCodeAt(i + 2) === 10) ++I; |
| 1979 | } else if (c === 10) { |
| 1980 | eol = true; |
| 1981 | } |
| 1982 | return text.slice(j + 1, i).replace(/""/g, '"'); |
| 1983 | } |
| 1984 | while (I < N) { |
| 1985 | var c = text.charCodeAt(I++), k = 1; |
| 1986 | if (c === 10) eol = true; else if (c === 13) { |
| 1987 | eol = true; |
| 1988 | if (text.charCodeAt(I) === 10) ++I, ++k; |
| 1989 | } else if (c !== delimiterCode) continue; |
| 1990 | return text.slice(j, I - k); |
| 1991 | } |
| 1992 | return text.slice(j); |
| 1993 | } |
| 1994 | while ((t = token()) !== EOF) { |
| 1995 | var a = []; |
| 1996 | while (t !== EOL && t !== EOF) { |
| 1997 | a.push(t); |
| 1998 | t = token(); |
| 1999 | } |
| 2000 | if (f && !(a = f(a, n++))) continue; |
| 2001 | rows.push(a); |
| 2002 | } |
| 2003 | return rows; |
| 2004 | }; |
| 2005 | dsv.format = function(rows) { |
| 2006 | if (Array.isArray(rows[0])) return dsv.formatRows(rows); |
| 2007 | var fieldSet = new d3_Set(), fields = []; |
| 2008 | rows.forEach(function(row) { |
| 2009 | for (var field in row) { |
| 2010 | if (!fieldSet.has(field)) { |
| 2011 | fields.push(fieldSet.add(field)); |
| 2012 | } |
| 2013 | } |
| 2014 | }); |
| 2015 | return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) { |
| 2016 | return fields.map(function(field) { |
| 2017 | return formatValue(row[field]); |
| 2018 | }).join(delimiter); |
| 2019 | })).join("\n"); |
| 2020 | }; |
| 2021 | dsv.formatRows = function(rows) { |
| 2022 | return rows.map(formatRow).join("\n"); |
| 2023 | }; |
| 2024 | function formatRow(row) { |
| 2025 | return row.map(formatValue).join(delimiter); |
| 2026 | } |
| 2027 | function formatValue(text) { |
| 2028 | return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text; |
| 2029 | } |
| 2030 | return dsv; |
| 2031 | }; |
| 2032 | d3.csv = d3.dsv(",", "text/csv"); |
| 2033 | d3.tsv = d3.dsv(" ", "text/tab-separated-values"); |
| 2034 | 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) { |
| 2035 | setTimeout(callback, 17); |
| 2036 | }; |
| 2037 | d3.timer = function(callback, delay, then) { |
| 2038 | var n = arguments.length; |
| 2039 | if (n < 2) delay = 0; |
| 2040 | if (n < 3) then = Date.now(); |
| 2041 | var time = then + delay, timer = { |
| 2042 | c: callback, |
| 2043 | t: time, |
| 2044 | f: false, |
| 2045 | n: null |
| 2046 | }; |
| 2047 | if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer; |
| 2048 | d3_timer_queueTail = timer; |
| 2049 | if (!d3_timer_interval) { |
| 2050 | d3_timer_timeout = clearTimeout(d3_timer_timeout); |
| 2051 | d3_timer_interval = 1; |
| 2052 | d3_timer_frame(d3_timer_step); |
| 2053 | } |
| 2054 | }; |
| 2055 | function d3_timer_step() { |
| 2056 | var now = d3_timer_mark(), delay = d3_timer_sweep() - now; |
| 2057 | if (delay > 24) { |
| 2058 | if (isFinite(delay)) { |
| 2059 | clearTimeout(d3_timer_timeout); |
| 2060 | d3_timer_timeout = setTimeout(d3_timer_step, delay); |
| 2061 | } |
| 2062 | d3_timer_interval = 0; |
| 2063 | } else { |
| 2064 | d3_timer_interval = 1; |
| 2065 | d3_timer_frame(d3_timer_step); |
| 2066 | } |
| 2067 | } |
| 2068 | d3.timer.flush = function() { |
| 2069 | d3_timer_mark(); |
| 2070 | d3_timer_sweep(); |
| 2071 | }; |
| 2072 | function d3_timer_mark() { |
| 2073 | var now = Date.now(); |
| 2074 | d3_timer_active = d3_timer_queueHead; |
| 2075 | while (d3_timer_active) { |
| 2076 | if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t); |
| 2077 | d3_timer_active = d3_timer_active.n; |
| 2078 | } |
| 2079 | return now; |
| 2080 | } |
| 2081 | function d3_timer_sweep() { |
| 2082 | var t0, t1 = d3_timer_queueHead, time = Infinity; |
| 2083 | while (t1) { |
| 2084 | if (t1.f) { |
| 2085 | t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n; |
| 2086 | } else { |
| 2087 | if (t1.t < time) time = t1.t; |
| 2088 | t1 = (t0 = t1).n; |
| 2089 | } |
| 2090 | } |
| 2091 | d3_timer_queueTail = t0; |
| 2092 | return time; |
| 2093 | } |
| 2094 | function d3_format_precision(x, p) { |
| 2095 | return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1); |
| 2096 | } |
| 2097 | d3.round = function(x, n) { |
| 2098 | return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x); |
| 2099 | }; |
| 2100 | var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix); |
| 2101 | d3.formatPrefix = function(value, precision) { |
| 2102 | var i = 0; |
| 2103 | if (value) { |
| 2104 | if (value < 0) value *= -1; |
| 2105 | if (precision) value = d3.round(value, d3_format_precision(value, precision)); |
| 2106 | i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10); |
| 2107 | i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3)); |
| 2108 | } |
| 2109 | return d3_formatPrefixes[8 + i / 3]; |
| 2110 | }; |
| 2111 | function d3_formatPrefix(d, i) { |
| 2112 | var k = Math.pow(10, abs(8 - i) * 3); |
| 2113 | return { |
| 2114 | scale: i > 8 ? function(d) { |
| 2115 | return d / k; |
| 2116 | } : function(d) { |
| 2117 | return d * k; |
| 2118 | }, |
| 2119 | symbol: d |
| 2120 | }; |
| 2121 | } |
| 2122 | function d3_locale_numberFormat(locale) { |
| 2123 | var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping ? function(value) { |
| 2124 | var i = value.length, t = [], j = 0, g = locale_grouping[0]; |
| 2125 | while (g > 0 && i > 0) { |
| 2126 | t.push(value.substring(i -= g, i + g)); |
| 2127 | g = locale_grouping[j = (j + 1) % locale_grouping.length]; |
| 2128 | } |
| 2129 | return t.reverse().join(locale_thousands); |
| 2130 | } : d3_identity; |
| 2131 | return function(specifier) { |
| 2132 | 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; |
| 2133 | if (precision) precision = +precision.substring(1); |
| 2134 | if (zfill || fill === "0" && align === "=") { |
| 2135 | zfill = fill = "0"; |
| 2136 | align = "="; |
| 2137 | if (comma) width -= Math.floor((width - 1) / 4); |
| 2138 | } |
| 2139 | switch (type) { |
| 2140 | case "n": |
| 2141 | comma = true; |
| 2142 | type = "g"; |
| 2143 | break; |
| 2144 | |
| 2145 | case "%": |
| 2146 | scale = 100; |
| 2147 | suffix = "%"; |
| 2148 | type = "f"; |
| 2149 | break; |
| 2150 | |
| 2151 | case "p": |
| 2152 | scale = 100; |
| 2153 | suffix = "%"; |
| 2154 | type = "r"; |
| 2155 | break; |
| 2156 | |
| 2157 | case "b": |
| 2158 | case "o": |
| 2159 | case "x": |
| 2160 | case "X": |
| 2161 | if (symbol === "#") prefix = "0" + type.toLowerCase(); |
| 2162 | |
| 2163 | case "c": |
| 2164 | case "d": |
| 2165 | integer = true; |
| 2166 | precision = 0; |
| 2167 | break; |
| 2168 | |
| 2169 | case "s": |
| 2170 | scale = -1; |
| 2171 | type = "r"; |
| 2172 | break; |
| 2173 | } |
| 2174 | if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1]; |
| 2175 | if (type == "r" && !precision) type = "g"; |
| 2176 | if (precision != null) { |
| 2177 | 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)); |
| 2178 | } |
| 2179 | type = d3_format_types.get(type) || d3_format_typeDefault; |
| 2180 | var zcomma = zfill && comma; |
| 2181 | return function(value) { |
| 2182 | var fullSuffix = suffix; |
| 2183 | if (integer && value % 1) return ""; |
| 2184 | var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign; |
| 2185 | if (scale < 0) { |
| 2186 | var unit = d3.formatPrefix(value, precision); |
| 2187 | value = unit.scale(value); |
| 2188 | fullSuffix = unit.symbol + suffix; |
| 2189 | } else { |
| 2190 | value *= scale; |
| 2191 | } |
| 2192 | value = type(value, precision); |
| 2193 | var i = value.lastIndexOf("."), before = i < 0 ? value : value.substring(0, i), after = i < 0 ? "" : locale_decimal + value.substring(i + 1); |
| 2194 | if (!zfill && comma) before = formatGroup(before); |
| 2195 | var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : ""; |
| 2196 | if (zcomma) before = formatGroup(padding + before); |
| 2197 | negative += prefix; |
| 2198 | value = before + after; |
| 2199 | 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; |
| 2200 | }; |
| 2201 | }; |
| 2202 | } |
| 2203 | var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i; |
| 2204 | var d3_format_types = d3.map({ |
| 2205 | b: function(x) { |
| 2206 | return x.toString(2); |
| 2207 | }, |
| 2208 | c: function(x) { |
| 2209 | return String.fromCharCode(x); |
| 2210 | }, |
| 2211 | o: function(x) { |
| 2212 | return x.toString(8); |
| 2213 | }, |
| 2214 | x: function(x) { |
| 2215 | return x.toString(16); |
| 2216 | }, |
| 2217 | X: function(x) { |
| 2218 | return x.toString(16).toUpperCase(); |
| 2219 | }, |
| 2220 | g: function(x, p) { |
| 2221 | return x.toPrecision(p); |
| 2222 | }, |
| 2223 | e: function(x, p) { |
| 2224 | return x.toExponential(p); |
| 2225 | }, |
| 2226 | f: function(x, p) { |
| 2227 | return x.toFixed(p); |
| 2228 | }, |
| 2229 | r: function(x, p) { |
| 2230 | 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)))); |
| 2231 | } |
| 2232 | }); |
| 2233 | function d3_format_typeDefault(x) { |
| 2234 | return x + ""; |
| 2235 | } |
| 2236 | var d3_time = d3.time = {}, d3_date = Date; |
| 2237 | function d3_date_utc() { |
| 2238 | this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]); |
| 2239 | } |
| 2240 | d3_date_utc.prototype = { |
| 2241 | getDate: function() { |
| 2242 | return this._.getUTCDate(); |
| 2243 | }, |
| 2244 | getDay: function() { |
| 2245 | return this._.getUTCDay(); |
| 2246 | }, |
| 2247 | getFullYear: function() { |
| 2248 | return this._.getUTCFullYear(); |
| 2249 | }, |
| 2250 | getHours: function() { |
| 2251 | return this._.getUTCHours(); |
| 2252 | }, |
| 2253 | getMilliseconds: function() { |
| 2254 | return this._.getUTCMilliseconds(); |
| 2255 | }, |
| 2256 | getMinutes: function() { |
| 2257 | return this._.getUTCMinutes(); |
| 2258 | }, |
| 2259 | getMonth: function() { |
| 2260 | return this._.getUTCMonth(); |
| 2261 | }, |
| 2262 | getSeconds: function() { |
| 2263 | return this._.getUTCSeconds(); |
| 2264 | }, |
| 2265 | getTime: function() { |
| 2266 | return this._.getTime(); |
| 2267 | }, |
| 2268 | getTimezoneOffset: function() { |
| 2269 | return 0; |
| 2270 | }, |
| 2271 | valueOf: function() { |
| 2272 | return this._.valueOf(); |
| 2273 | }, |
| 2274 | setDate: function() { |
| 2275 | d3_time_prototype.setUTCDate.apply(this._, arguments); |
| 2276 | }, |
| 2277 | setDay: function() { |
| 2278 | d3_time_prototype.setUTCDay.apply(this._, arguments); |
| 2279 | }, |
| 2280 | setFullYear: function() { |
| 2281 | d3_time_prototype.setUTCFullYear.apply(this._, arguments); |
| 2282 | }, |
| 2283 | setHours: function() { |
| 2284 | d3_time_prototype.setUTCHours.apply(this._, arguments); |
| 2285 | }, |
| 2286 | setMilliseconds: function() { |
| 2287 | d3_time_prototype.setUTCMilliseconds.apply(this._, arguments); |
| 2288 | }, |
| 2289 | setMinutes: function() { |
| 2290 | d3_time_prototype.setUTCMinutes.apply(this._, arguments); |
| 2291 | }, |
| 2292 | setMonth: function() { |
| 2293 | d3_time_prototype.setUTCMonth.apply(this._, arguments); |
| 2294 | }, |
| 2295 | setSeconds: function() { |
| 2296 | d3_time_prototype.setUTCSeconds.apply(this._, arguments); |
| 2297 | }, |
| 2298 | setTime: function() { |
| 2299 | d3_time_prototype.setTime.apply(this._, arguments); |
| 2300 | } |
| 2301 | }; |
| 2302 | var d3_time_prototype = Date.prototype; |
| 2303 | function d3_time_interval(local, step, number) { |
| 2304 | function round(date) { |
| 2305 | var d0 = local(date), d1 = offset(d0, 1); |
| 2306 | return date - d0 < d1 - date ? d0 : d1; |
| 2307 | } |
| 2308 | function ceil(date) { |
| 2309 | step(date = local(new d3_date(date - 1)), 1); |
| 2310 | return date; |
| 2311 | } |
| 2312 | function offset(date, k) { |
| 2313 | step(date = new d3_date(+date), k); |
| 2314 | return date; |
| 2315 | } |
| 2316 | function range(t0, t1, dt) { |
| 2317 | var time = ceil(t0), times = []; |
| 2318 | if (dt > 1) { |
| 2319 | while (time < t1) { |
| 2320 | if (!(number(time) % dt)) times.push(new Date(+time)); |
| 2321 | step(time, 1); |
| 2322 | } |
| 2323 | } else { |
| 2324 | while (time < t1) times.push(new Date(+time)), step(time, 1); |
| 2325 | } |
| 2326 | return times; |
| 2327 | } |
| 2328 | function range_utc(t0, t1, dt) { |
| 2329 | try { |
| 2330 | d3_date = d3_date_utc; |
| 2331 | var utc = new d3_date_utc(); |
| 2332 | utc._ = t0; |
| 2333 | return range(utc, t1, dt); |
| 2334 | } finally { |
| 2335 | d3_date = Date; |
| 2336 | } |
| 2337 | } |
| 2338 | local.floor = local; |
| 2339 | local.round = round; |
| 2340 | local.ceil = ceil; |
| 2341 | local.offset = offset; |
| 2342 | local.range = range; |
| 2343 | var utc = local.utc = d3_time_interval_utc(local); |
| 2344 | utc.floor = utc; |
| 2345 | utc.round = d3_time_interval_utc(round); |
| 2346 | utc.ceil = d3_time_interval_utc(ceil); |
| 2347 | utc.offset = d3_time_interval_utc(offset); |
| 2348 | utc.range = range_utc; |
| 2349 | return local; |
| 2350 | } |
| 2351 | function d3_time_interval_utc(method) { |
| 2352 | return function(date, k) { |
| 2353 | try { |
| 2354 | d3_date = d3_date_utc; |
| 2355 | var utc = new d3_date_utc(); |
| 2356 | utc._ = date; |
| 2357 | return method(utc, k)._; |
| 2358 | } finally { |
| 2359 | d3_date = Date; |
| 2360 | } |
| 2361 | }; |
| 2362 | } |
| 2363 | d3_time.year = d3_time_interval(function(date) { |
| 2364 | date = d3_time.day(date); |
| 2365 | date.setMonth(0, 1); |
| 2366 | return date; |
| 2367 | }, function(date, offset) { |
| 2368 | date.setFullYear(date.getFullYear() + offset); |
| 2369 | }, function(date) { |
| 2370 | return date.getFullYear(); |
| 2371 | }); |
| 2372 | d3_time.years = d3_time.year.range; |
| 2373 | d3_time.years.utc = d3_time.year.utc.range; |
| 2374 | d3_time.day = d3_time_interval(function(date) { |
| 2375 | var day = new d3_date(2e3, 0); |
| 2376 | day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate()); |
| 2377 | return day; |
| 2378 | }, function(date, offset) { |
| 2379 | date.setDate(date.getDate() + offset); |
| 2380 | }, function(date) { |
| 2381 | return date.getDate() - 1; |
| 2382 | }); |
| 2383 | d3_time.days = d3_time.day.range; |
| 2384 | d3_time.days.utc = d3_time.day.utc.range; |
| 2385 | d3_time.dayOfYear = function(date) { |
| 2386 | var year = d3_time.year(date); |
| 2387 | return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5); |
| 2388 | }; |
| 2389 | [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) { |
| 2390 | i = 7 - i; |
| 2391 | var interval = d3_time[day] = d3_time_interval(function(date) { |
| 2392 | (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7); |
| 2393 | return date; |
| 2394 | }, function(date, offset) { |
| 2395 | date.setDate(date.getDate() + Math.floor(offset) * 7); |
| 2396 | }, function(date) { |
| 2397 | var day = d3_time.year(date).getDay(); |
| 2398 | return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i); |
| 2399 | }); |
| 2400 | d3_time[day + "s"] = interval.range; |
| 2401 | d3_time[day + "s"].utc = interval.utc.range; |
| 2402 | d3_time[day + "OfYear"] = function(date) { |
| 2403 | var day = d3_time.year(date).getDay(); |
| 2404 | return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7); |
| 2405 | }; |
| 2406 | }); |
| 2407 | d3_time.week = d3_time.sunday; |
| 2408 | d3_time.weeks = d3_time.sunday.range; |
| 2409 | d3_time.weeks.utc = d3_time.sunday.utc.range; |
| 2410 | d3_time.weekOfYear = d3_time.sundayOfYear; |
| 2411 | function d3_locale_timeFormat(locale) { |
| 2412 | 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; |
| 2413 | function d3_time_format(template) { |
| 2414 | var n = template.length; |
| 2415 | function format(date) { |
| 2416 | var string = [], i = -1, j = 0, c, p, f; |
| 2417 | while (++i < n) { |
| 2418 | if (template.charCodeAt(i) === 37) { |
| 2419 | string.push(template.slice(j, i)); |
| 2420 | if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i); |
| 2421 | if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p); |
| 2422 | string.push(c); |
| 2423 | j = i + 1; |
| 2424 | } |
| 2425 | } |
| 2426 | string.push(template.slice(j, i)); |
| 2427 | return string.join(""); |
| 2428 | } |
| 2429 | format.parse = function(string) { |
| 2430 | var d = { |
| 2431 | y: 1900, |
| 2432 | m: 0, |
| 2433 | d: 1, |
| 2434 | H: 0, |
| 2435 | M: 0, |
| 2436 | S: 0, |
| 2437 | L: 0, |
| 2438 | Z: null |
| 2439 | }, i = d3_time_parse(d, template, string, 0); |
| 2440 | if (i != string.length) return null; |
| 2441 | if ("p" in d) d.H = d.H % 12 + d.p * 12; |
| 2442 | var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)(); |
| 2443 | if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) { |
| 2444 | date.setFullYear(d.y, 0, 1); |
| 2445 | 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); |
| 2446 | } else date.setFullYear(d.y, d.m, d.d); |
| 2447 | date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L); |
| 2448 | return localZ ? date._ : date; |
| 2449 | }; |
| 2450 | format.toString = function() { |
| 2451 | return template; |
| 2452 | }; |
| 2453 | return format; |
| 2454 | } |
| 2455 | function d3_time_parse(date, template, string, j) { |
| 2456 | var c, p, t, i = 0, n = template.length, m = string.length; |
| 2457 | while (i < n) { |
| 2458 | if (j >= m) return -1; |
| 2459 | c = template.charCodeAt(i++); |
| 2460 | if (c === 37) { |
| 2461 | t = template.charAt(i++); |
| 2462 | p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t]; |
| 2463 | if (!p || (j = p(date, string, j)) < 0) return -1; |
| 2464 | } else if (c != string.charCodeAt(j++)) { |
| 2465 | return -1; |
| 2466 | } |
| 2467 | } |
| 2468 | return j; |
| 2469 | } |
| 2470 | d3_time_format.utc = function(template) { |
| 2471 | var local = d3_time_format(template); |
| 2472 | function format(date) { |
| 2473 | try { |
| 2474 | d3_date = d3_date_utc; |
| 2475 | var utc = new d3_date(); |
| 2476 | utc._ = date; |
| 2477 | return local(utc); |
| 2478 | } finally { |
| 2479 | d3_date = Date; |
| 2480 | } |
| 2481 | } |
| 2482 | format.parse = function(string) { |
| 2483 | try { |
| 2484 | d3_date = d3_date_utc; |
| 2485 | var date = local.parse(string); |
| 2486 | return date && date._; |
| 2487 | } finally { |
| 2488 | d3_date = Date; |
| 2489 | } |
| 2490 | }; |
| 2491 | format.toString = local.toString; |
| 2492 | return format; |
| 2493 | }; |
| 2494 | d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti; |
| 2495 | 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); |
| 2496 | locale_periods.forEach(function(p, i) { |
| 2497 | d3_time_periodLookup.set(p.toLowerCase(), i); |
| 2498 | }); |
| 2499 | var d3_time_formats = { |
| 2500 | a: function(d) { |
| 2501 | return locale_shortDays[d.getDay()]; |
| 2502 | }, |
| 2503 | A: function(d) { |
| 2504 | return locale_days[d.getDay()]; |
| 2505 | }, |
| 2506 | b: function(d) { |
| 2507 | return locale_shortMonths[d.getMonth()]; |
| 2508 | }, |
| 2509 | B: function(d) { |
| 2510 | return locale_months[d.getMonth()]; |
| 2511 | }, |
| 2512 | c: d3_time_format(locale_dateTime), |
| 2513 | d: function(d, p) { |
| 2514 | return d3_time_formatPad(d.getDate(), p, 2); |
| 2515 | }, |
| 2516 | e: function(d, p) { |
| 2517 | return d3_time_formatPad(d.getDate(), p, 2); |
| 2518 | }, |
| 2519 | H: function(d, p) { |
| 2520 | return d3_time_formatPad(d.getHours(), p, 2); |
| 2521 | }, |
| 2522 | I: function(d, p) { |
| 2523 | return d3_time_formatPad(d.getHours() % 12 || 12, p, 2); |
| 2524 | }, |
| 2525 | j: function(d, p) { |
| 2526 | return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3); |
| 2527 | }, |
| 2528 | L: function(d, p) { |
| 2529 | return d3_time_formatPad(d.getMilliseconds(), p, 3); |
| 2530 | }, |
| 2531 | m: function(d, p) { |
| 2532 | return d3_time_formatPad(d.getMonth() + 1, p, 2); |
| 2533 | }, |
| 2534 | M: function(d, p) { |
| 2535 | return d3_time_formatPad(d.getMinutes(), p, 2); |
| 2536 | }, |
| 2537 | p: function(d) { |
| 2538 | return locale_periods[+(d.getHours() >= 12)]; |
| 2539 | }, |
| 2540 | S: function(d, p) { |
| 2541 | return d3_time_formatPad(d.getSeconds(), p, 2); |
| 2542 | }, |
| 2543 | U: function(d, p) { |
| 2544 | return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2); |
| 2545 | }, |
| 2546 | w: function(d) { |
| 2547 | return d.getDay(); |
| 2548 | }, |
| 2549 | W: function(d, p) { |
| 2550 | return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2); |
| 2551 | }, |
| 2552 | x: d3_time_format(locale_date), |
| 2553 | X: d3_time_format(locale_time), |
| 2554 | y: function(d, p) { |
| 2555 | return d3_time_formatPad(d.getFullYear() % 100, p, 2); |
| 2556 | }, |
| 2557 | Y: function(d, p) { |
| 2558 | return d3_time_formatPad(d.getFullYear() % 1e4, p, 4); |
| 2559 | }, |
| 2560 | Z: d3_time_zone, |
| 2561 | "%": function() { |
| 2562 | return "%"; |
| 2563 | } |
| 2564 | }; |
| 2565 | var d3_time_parsers = { |
| 2566 | a: d3_time_parseWeekdayAbbrev, |
| 2567 | A: d3_time_parseWeekday, |
| 2568 | b: d3_time_parseMonthAbbrev, |
| 2569 | B: d3_time_parseMonth, |
| 2570 | c: d3_time_parseLocaleFull, |
| 2571 | d: d3_time_parseDay, |
| 2572 | e: d3_time_parseDay, |
| 2573 | H: d3_time_parseHour24, |
| 2574 | I: d3_time_parseHour24, |
| 2575 | j: d3_time_parseDayOfYear, |
| 2576 | L: d3_time_parseMilliseconds, |
| 2577 | m: d3_time_parseMonthNumber, |
| 2578 | M: d3_time_parseMinutes, |
| 2579 | p: d3_time_parseAmPm, |
| 2580 | S: d3_time_parseSeconds, |
| 2581 | U: d3_time_parseWeekNumberSunday, |
| 2582 | w: d3_time_parseWeekdayNumber, |
| 2583 | W: d3_time_parseWeekNumberMonday, |
| 2584 | x: d3_time_parseLocaleDate, |
| 2585 | X: d3_time_parseLocaleTime, |
| 2586 | y: d3_time_parseYear, |
| 2587 | Y: d3_time_parseFullYear, |
| 2588 | Z: d3_time_parseZone, |
| 2589 | "%": d3_time_parseLiteralPercent |
| 2590 | }; |
| 2591 | function d3_time_parseWeekdayAbbrev(date, string, i) { |
| 2592 | d3_time_dayAbbrevRe.lastIndex = 0; |
| 2593 | var n = d3_time_dayAbbrevRe.exec(string.slice(i)); |
| 2594 | return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 2595 | } |
| 2596 | function d3_time_parseWeekday(date, string, i) { |
| 2597 | d3_time_dayRe.lastIndex = 0; |
| 2598 | var n = d3_time_dayRe.exec(string.slice(i)); |
| 2599 | return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 2600 | } |
| 2601 | function d3_time_parseMonthAbbrev(date, string, i) { |
| 2602 | d3_time_monthAbbrevRe.lastIndex = 0; |
| 2603 | var n = d3_time_monthAbbrevRe.exec(string.slice(i)); |
| 2604 | return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 2605 | } |
| 2606 | function d3_time_parseMonth(date, string, i) { |
| 2607 | d3_time_monthRe.lastIndex = 0; |
| 2608 | var n = d3_time_monthRe.exec(string.slice(i)); |
| 2609 | return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 2610 | } |
| 2611 | function d3_time_parseLocaleFull(date, string, i) { |
| 2612 | return d3_time_parse(date, d3_time_formats.c.toString(), string, i); |
| 2613 | } |
| 2614 | function d3_time_parseLocaleDate(date, string, i) { |
| 2615 | return d3_time_parse(date, d3_time_formats.x.toString(), string, i); |
| 2616 | } |
| 2617 | function d3_time_parseLocaleTime(date, string, i) { |
| 2618 | return d3_time_parse(date, d3_time_formats.X.toString(), string, i); |
| 2619 | } |
| 2620 | function d3_time_parseAmPm(date, string, i) { |
| 2621 | var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase()); |
| 2622 | return n == null ? -1 : (date.p = n, i); |
| 2623 | } |
| 2624 | return d3_time_format; |
| 2625 | } |
| 2626 | var d3_time_formatPads = { |
| 2627 | "-": "", |
| 2628 | _: " ", |
| 2629 | "0": "0" |
| 2630 | }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/; |
| 2631 | function d3_time_formatPad(value, fill, width) { |
| 2632 | var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length; |
| 2633 | return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string); |
| 2634 | } |
| 2635 | function d3_time_formatRe(names) { |
| 2636 | return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i"); |
| 2637 | } |
| 2638 | function d3_time_formatLookup(names) { |
| 2639 | var map = new d3_Map(), i = -1, n = names.length; |
| 2640 | while (++i < n) map.set(names[i].toLowerCase(), i); |
| 2641 | return map; |
| 2642 | } |
| 2643 | function d3_time_parseWeekdayNumber(date, string, i) { |
| 2644 | d3_time_numberRe.lastIndex = 0; |
| 2645 | var n = d3_time_numberRe.exec(string.slice(i, i + 1)); |
| 2646 | return n ? (date.w = +n[0], i + n[0].length) : -1; |
| 2647 | } |
| 2648 | function d3_time_parseWeekNumberSunday(date, string, i) { |
| 2649 | d3_time_numberRe.lastIndex = 0; |
| 2650 | var n = d3_time_numberRe.exec(string.slice(i)); |
| 2651 | return n ? (date.U = +n[0], i + n[0].length) : -1; |
| 2652 | } |
| 2653 | function d3_time_parseWeekNumberMonday(date, string, i) { |
| 2654 | d3_time_numberRe.lastIndex = 0; |
| 2655 | var n = d3_time_numberRe.exec(string.slice(i)); |
| 2656 | return n ? (date.W = +n[0], i + n[0].length) : -1; |
| 2657 | } |
| 2658 | function d3_time_parseFullYear(date, string, i) { |
| 2659 | d3_time_numberRe.lastIndex = 0; |
| 2660 | var n = d3_time_numberRe.exec(string.slice(i, i + 4)); |
| 2661 | return n ? (date.y = +n[0], i + n[0].length) : -1; |
| 2662 | } |
| 2663 | function d3_time_parseYear(date, string, i) { |
| 2664 | d3_time_numberRe.lastIndex = 0; |
| 2665 | var n = d3_time_numberRe.exec(string.slice(i, i + 2)); |
| 2666 | return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1; |
| 2667 | } |
| 2668 | function d3_time_parseZone(date, string, i) { |
| 2669 | return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string, |
| 2670 | i + 5) : -1; |
| 2671 | } |
| 2672 | function d3_time_expandYear(d) { |
| 2673 | return d + (d > 68 ? 1900 : 2e3); |
| 2674 | } |
| 2675 | function d3_time_parseMonthNumber(date, string, i) { |
| 2676 | d3_time_numberRe.lastIndex = 0; |
| 2677 | var n = d3_time_numberRe.exec(string.slice(i, i + 2)); |
| 2678 | return n ? (date.m = n[0] - 1, i + n[0].length) : -1; |
| 2679 | } |
| 2680 | function d3_time_parseDay(date, string, i) { |
| 2681 | d3_time_numberRe.lastIndex = 0; |
| 2682 | var n = d3_time_numberRe.exec(string.slice(i, i + 2)); |
| 2683 | return n ? (date.d = +n[0], i + n[0].length) : -1; |
| 2684 | } |
| 2685 | function d3_time_parseDayOfYear(date, string, i) { |
| 2686 | d3_time_numberRe.lastIndex = 0; |
| 2687 | var n = d3_time_numberRe.exec(string.slice(i, i + 3)); |
| 2688 | return n ? (date.j = +n[0], i + n[0].length) : -1; |
| 2689 | } |
| 2690 | function d3_time_parseHour24(date, string, i) { |
| 2691 | d3_time_numberRe.lastIndex = 0; |
| 2692 | var n = d3_time_numberRe.exec(string.slice(i, i + 2)); |
| 2693 | return n ? (date.H = +n[0], i + n[0].length) : -1; |
| 2694 | } |
| 2695 | function d3_time_parseMinutes(date, string, i) { |
| 2696 | d3_time_numberRe.lastIndex = 0; |
| 2697 | var n = d3_time_numberRe.exec(string.slice(i, i + 2)); |
| 2698 | return n ? (date.M = +n[0], i + n[0].length) : -1; |
| 2699 | } |
| 2700 | function d3_time_parseSeconds(date, string, i) { |
| 2701 | d3_time_numberRe.lastIndex = 0; |
| 2702 | var n = d3_time_numberRe.exec(string.slice(i, i + 2)); |
| 2703 | return n ? (date.S = +n[0], i + n[0].length) : -1; |
| 2704 | } |
| 2705 | function d3_time_parseMilliseconds(date, string, i) { |
| 2706 | d3_time_numberRe.lastIndex = 0; |
| 2707 | var n = d3_time_numberRe.exec(string.slice(i, i + 3)); |
| 2708 | return n ? (date.L = +n[0], i + n[0].length) : -1; |
| 2709 | } |
| 2710 | function d3_time_zone(d) { |
| 2711 | var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60; |
| 2712 | return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2); |
| 2713 | } |
| 2714 | function d3_time_parseLiteralPercent(date, string, i) { |
| 2715 | d3_time_percentRe.lastIndex = 0; |
| 2716 | var n = d3_time_percentRe.exec(string.slice(i, i + 1)); |
| 2717 | return n ? i + n[0].length : -1; |
| 2718 | } |
| 2719 | function d3_time_formatMulti(formats) { |
| 2720 | var n = formats.length, i = -1; |
| 2721 | while (++i < n) formats[i][0] = this(formats[i][0]); |
| 2722 | return function(date) { |
| 2723 | var i = 0, f = formats[i]; |
| 2724 | while (!f[1](date)) f = formats[++i]; |
| 2725 | return f[0](date); |
| 2726 | }; |
| 2727 | } |
| 2728 | d3.locale = function(locale) { |
| 2729 | return { |
| 2730 | numberFormat: d3_locale_numberFormat(locale), |
| 2731 | timeFormat: d3_locale_timeFormat(locale) |
| 2732 | }; |
| 2733 | }; |
| 2734 | var d3_locale_enUS = d3.locale({ |
| 2735 | decimal: ".", |
| 2736 | thousands: ",", |
| 2737 | grouping: [ 3 ], |
| 2738 | currency: [ "$", "" ], |
| 2739 | dateTime: "%a %b %e %X %Y", |
| 2740 | date: "%m/%d/%Y", |
| 2741 | time: "%H:%M:%S", |
| 2742 | periods: [ "AM", "PM" ], |
| 2743 | days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], |
| 2744 | shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], |
| 2745 | months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], |
| 2746 | shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ] |
| 2747 | }); |
| 2748 | d3.format = d3_locale_enUS.numberFormat; |
| 2749 | d3.geo = {}; |
| 2750 | function d3_adder() {} |
| 2751 | d3_adder.prototype = { |
| 2752 | s: 0, |
| 2753 | t: 0, |
| 2754 | add: function(y) { |
| 2755 | d3_adderSum(y, this.t, d3_adderTemp); |
| 2756 | d3_adderSum(d3_adderTemp.s, this.s, this); |
| 2757 | if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t; |
| 2758 | }, |
| 2759 | reset: function() { |
| 2760 | this.s = this.t = 0; |
| 2761 | }, |
| 2762 | valueOf: function() { |
| 2763 | return this.s; |
| 2764 | } |
| 2765 | }; |
| 2766 | var d3_adderTemp = new d3_adder(); |
| 2767 | function d3_adderSum(a, b, o) { |
| 2768 | var x = o.s = a + b, bv = x - a, av = x - bv; |
| 2769 | o.t = a - av + (b - bv); |
| 2770 | } |
| 2771 | d3.geo.stream = function(object, listener) { |
| 2772 | if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) { |
| 2773 | d3_geo_streamObjectType[object.type](object, listener); |
| 2774 | } else { |
| 2775 | d3_geo_streamGeometry(object, listener); |
| 2776 | } |
| 2777 | }; |
| 2778 | function d3_geo_streamGeometry(geometry, listener) { |
| 2779 | if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) { |
| 2780 | d3_geo_streamGeometryType[geometry.type](geometry, listener); |
| 2781 | } |
| 2782 | } |
| 2783 | var d3_geo_streamObjectType = { |
| 2784 | Feature: function(feature, listener) { |
| 2785 | d3_geo_streamGeometry(feature.geometry, listener); |
| 2786 | }, |
| 2787 | FeatureCollection: function(object, listener) { |
| 2788 | var features = object.features, i = -1, n = features.length; |
| 2789 | while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener); |
| 2790 | } |
| 2791 | }; |
| 2792 | var d3_geo_streamGeometryType = { |
| 2793 | Sphere: function(object, listener) { |
| 2794 | listener.sphere(); |
| 2795 | }, |
| 2796 | Point: function(object, listener) { |
| 2797 | object = object.coordinates; |
| 2798 | listener.point(object[0], object[1], object[2]); |
| 2799 | }, |
| 2800 | MultiPoint: function(object, listener) { |
| 2801 | var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 2802 | while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]); |
| 2803 | }, |
| 2804 | LineString: function(object, listener) { |
| 2805 | d3_geo_streamLine(object.coordinates, listener, 0); |
| 2806 | }, |
| 2807 | MultiLineString: function(object, listener) { |
| 2808 | var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 2809 | while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0); |
| 2810 | }, |
| 2811 | Polygon: function(object, listener) { |
| 2812 | d3_geo_streamPolygon(object.coordinates, listener); |
| 2813 | }, |
| 2814 | MultiPolygon: function(object, listener) { |
| 2815 | var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 2816 | while (++i < n) d3_geo_streamPolygon(coordinates[i], listener); |
| 2817 | }, |
| 2818 | GeometryCollection: function(object, listener) { |
| 2819 | var geometries = object.geometries, i = -1, n = geometries.length; |
| 2820 | while (++i < n) d3_geo_streamGeometry(geometries[i], listener); |
| 2821 | } |
| 2822 | }; |
| 2823 | function d3_geo_streamLine(coordinates, listener, closed) { |
| 2824 | var i = -1, n = coordinates.length - closed, coordinate; |
| 2825 | listener.lineStart(); |
| 2826 | while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]); |
| 2827 | listener.lineEnd(); |
| 2828 | } |
| 2829 | function d3_geo_streamPolygon(coordinates, listener) { |
| 2830 | var i = -1, n = coordinates.length; |
| 2831 | listener.polygonStart(); |
| 2832 | while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1); |
| 2833 | listener.polygonEnd(); |
| 2834 | } |
| 2835 | d3.geo.area = function(object) { |
| 2836 | d3_geo_areaSum = 0; |
| 2837 | d3.geo.stream(object, d3_geo_area); |
| 2838 | return d3_geo_areaSum; |
| 2839 | }; |
| 2840 | var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder(); |
| 2841 | var d3_geo_area = { |
| 2842 | sphere: function() { |
| 2843 | d3_geo_areaSum += 4 * π; |
| 2844 | }, |
| 2845 | point: d3_noop, |
| 2846 | lineStart: d3_noop, |
| 2847 | lineEnd: d3_noop, |
| 2848 | polygonStart: function() { |
| 2849 | d3_geo_areaRingSum.reset(); |
| 2850 | d3_geo_area.lineStart = d3_geo_areaRingStart; |
| 2851 | }, |
| 2852 | polygonEnd: function() { |
| 2853 | var area = 2 * d3_geo_areaRingSum; |
| 2854 | d3_geo_areaSum += area < 0 ? 4 * π + area : area; |
| 2855 | d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop; |
| 2856 | } |
| 2857 | }; |
| 2858 | function d3_geo_areaRingStart() { |
| 2859 | var λ00, φ00, λ0, cosφ0, sinφ0; |
| 2860 | d3_geo_area.point = function(λ, φ) { |
| 2861 | d3_geo_area.point = nextPoint; |
| 2862 | λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4), |
| 2863 | sinφ0 = Math.sin(φ); |
| 2864 | }; |
| 2865 | function nextPoint(λ, φ) { |
| 2866 | λ *= d3_radians; |
| 2867 | φ = φ * d3_radians / 2 + π / 4; |
| 2868 | var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ); |
| 2869 | d3_geo_areaRingSum.add(Math.atan2(v, u)); |
| 2870 | λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ; |
| 2871 | } |
| 2872 | d3_geo_area.lineEnd = function() { |
| 2873 | nextPoint(λ00, φ00); |
| 2874 | }; |
| 2875 | } |
| 2876 | function d3_geo_cartesian(spherical) { |
| 2877 | var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ); |
| 2878 | return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ]; |
| 2879 | } |
| 2880 | function d3_geo_cartesianDot(a, b) { |
| 2881 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; |
| 2882 | } |
| 2883 | function d3_geo_cartesianCross(a, b) { |
| 2884 | 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] ]; |
| 2885 | } |
| 2886 | function d3_geo_cartesianAdd(a, b) { |
| 2887 | a[0] += b[0]; |
| 2888 | a[1] += b[1]; |
| 2889 | a[2] += b[2]; |
| 2890 | } |
| 2891 | function d3_geo_cartesianScale(vector, k) { |
| 2892 | return [ vector[0] * k, vector[1] * k, vector[2] * k ]; |
| 2893 | } |
| 2894 | function d3_geo_cartesianNormalize(d) { |
| 2895 | var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); |
| 2896 | d[0] /= l; |
| 2897 | d[1] /= l; |
| 2898 | d[2] /= l; |
| 2899 | } |
| 2900 | function d3_geo_spherical(cartesian) { |
| 2901 | return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ]; |
| 2902 | } |
| 2903 | function d3_geo_sphericalEqual(a, b) { |
| 2904 | return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε; |
| 2905 | } |
| 2906 | d3.geo.bounds = function() { |
| 2907 | var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range; |
| 2908 | var bound = { |
| 2909 | point: point, |
| 2910 | lineStart: lineStart, |
| 2911 | lineEnd: lineEnd, |
| 2912 | polygonStart: function() { |
| 2913 | bound.point = ringPoint; |
| 2914 | bound.lineStart = ringStart; |
| 2915 | bound.lineEnd = ringEnd; |
| 2916 | dλSum = 0; |
| 2917 | d3_geo_area.polygonStart(); |
| 2918 | }, |
| 2919 | polygonEnd: function() { |
| 2920 | d3_geo_area.polygonEnd(); |
| 2921 | bound.point = point; |
| 2922 | bound.lineStart = lineStart; |
| 2923 | bound.lineEnd = lineEnd; |
| 2924 | if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90; |
| 2925 | range[0] = λ0, range[1] = λ1; |
| 2926 | } |
| 2927 | }; |
| 2928 | function point(λ, φ) { |
| 2929 | ranges.push(range = [ λ0 = λ, λ1 = λ ]); |
| 2930 | if (φ < φ0) φ0 = φ; |
| 2931 | if (φ > φ1) φ1 = φ; |
| 2932 | } |
| 2933 | function linePoint(λ, φ) { |
| 2934 | var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]); |
| 2935 | if (p0) { |
| 2936 | var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal); |
| 2937 | d3_geo_cartesianNormalize(inflection); |
| 2938 | inflection = d3_geo_spherical(inflection); |
| 2939 | var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180; |
| 2940 | if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) { |
| 2941 | var φi = inflection[1] * d3_degrees; |
| 2942 | if (φi > φ1) φ1 = φi; |
| 2943 | } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) { |
| 2944 | var φi = -inflection[1] * d3_degrees; |
| 2945 | if (φi < φ0) φ0 = φi; |
| 2946 | } else { |
| 2947 | if (φ < φ0) φ0 = φ; |
| 2948 | if (φ > φ1) φ1 = φ; |
| 2949 | } |
| 2950 | if (antimeridian) { |
| 2951 | if (λ < λ_) { |
| 2952 | if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ; |
| 2953 | } else { |
| 2954 | if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ; |
| 2955 | } |
| 2956 | } else { |
| 2957 | if (λ1 >= λ0) { |
| 2958 | if (λ < λ0) λ0 = λ; |
| 2959 | if (λ > λ1) λ1 = λ; |
| 2960 | } else { |
| 2961 | if (λ > λ_) { |
| 2962 | if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ; |
| 2963 | } else { |
| 2964 | if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ; |
| 2965 | } |
| 2966 | } |
| 2967 | } |
| 2968 | } else { |
| 2969 | point(λ, φ); |
| 2970 | } |
| 2971 | p0 = p, λ_ = λ; |
| 2972 | } |
| 2973 | function lineStart() { |
| 2974 | bound.point = linePoint; |
| 2975 | } |
| 2976 | function lineEnd() { |
| 2977 | range[0] = λ0, range[1] = λ1; |
| 2978 | bound.point = point; |
| 2979 | p0 = null; |
| 2980 | } |
| 2981 | function ringPoint(λ, φ) { |
| 2982 | if (p0) { |
| 2983 | var dλ = λ - λ_; |
| 2984 | dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ; |
| 2985 | } else λ__ = λ, φ__ = φ; |
| 2986 | d3_geo_area.point(λ, φ); |
| 2987 | linePoint(λ, φ); |
| 2988 | } |
| 2989 | function ringStart() { |
| 2990 | d3_geo_area.lineStart(); |
| 2991 | } |
| 2992 | function ringEnd() { |
| 2993 | ringPoint(λ__, φ__); |
| 2994 | d3_geo_area.lineEnd(); |
| 2995 | if (abs(dλSum) > ε) λ0 = -(λ1 = 180); |
| 2996 | range[0] = λ0, range[1] = λ1; |
| 2997 | p0 = null; |
| 2998 | } |
| 2999 | function angle(λ0, λ1) { |
| 3000 | return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1; |
| 3001 | } |
| 3002 | function compareRanges(a, b) { |
| 3003 | return a[0] - b[0]; |
| 3004 | } |
| 3005 | function withinRange(x, range) { |
| 3006 | return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x; |
| 3007 | } |
| 3008 | return function(feature) { |
| 3009 | φ1 = λ1 = -(λ0 = φ0 = Infinity); |
| 3010 | ranges = []; |
| 3011 | d3.geo.stream(feature, bound); |
| 3012 | var n = ranges.length; |
| 3013 | if (n) { |
| 3014 | ranges.sort(compareRanges); |
| 3015 | for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) { |
| 3016 | b = ranges[i]; |
| 3017 | if (withinRange(b[0], a) || withinRange(b[1], a)) { |
| 3018 | if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1]; |
| 3019 | if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0]; |
| 3020 | } else { |
| 3021 | merged.push(a = b); |
| 3022 | } |
| 3023 | } |
| 3024 | var best = -Infinity, dλ; |
| 3025 | for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) { |
| 3026 | b = merged[i]; |
| 3027 | if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1]; |
| 3028 | } |
| 3029 | } |
| 3030 | ranges = range = null; |
| 3031 | return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ]; |
| 3032 | }; |
| 3033 | }(); |
| 3034 | d3.geo.centroid = function(object) { |
| 3035 | 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; |
| 3036 | d3.geo.stream(object, d3_geo_centroid); |
| 3037 | var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z; |
| 3038 | if (m < ε2) { |
| 3039 | x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1; |
| 3040 | if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0; |
| 3041 | m = x * x + y * y + z * z; |
| 3042 | if (m < ε2) return [ NaN, NaN ]; |
| 3043 | } |
| 3044 | return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ]; |
| 3045 | }; |
| 3046 | 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; |
| 3047 | var d3_geo_centroid = { |
| 3048 | sphere: d3_noop, |
| 3049 | point: d3_geo_centroidPoint, |
| 3050 | lineStart: d3_geo_centroidLineStart, |
| 3051 | lineEnd: d3_geo_centroidLineEnd, |
| 3052 | polygonStart: function() { |
| 3053 | d3_geo_centroid.lineStart = d3_geo_centroidRingStart; |
| 3054 | }, |
| 3055 | polygonEnd: function() { |
| 3056 | d3_geo_centroid.lineStart = d3_geo_centroidLineStart; |
| 3057 | } |
| 3058 | }; |
| 3059 | function d3_geo_centroidPoint(λ, φ) { |
| 3060 | λ *= d3_radians; |
| 3061 | var cosφ = Math.cos(φ *= d3_radians); |
| 3062 | d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ)); |
| 3063 | } |
| 3064 | function d3_geo_centroidPointXYZ(x, y, z) { |
| 3065 | ++d3_geo_centroidW0; |
| 3066 | d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0; |
| 3067 | d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0; |
| 3068 | d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0; |
| 3069 | } |
| 3070 | function d3_geo_centroidLineStart() { |
| 3071 | var x0, y0, z0; |
| 3072 | d3_geo_centroid.point = function(λ, φ) { |
| 3073 | λ *= d3_radians; |
| 3074 | var cosφ = Math.cos(φ *= d3_radians); |
| 3075 | x0 = cosφ * Math.cos(λ); |
| 3076 | y0 = cosφ * Math.sin(λ); |
| 3077 | z0 = Math.sin(φ); |
| 3078 | d3_geo_centroid.point = nextPoint; |
| 3079 | d3_geo_centroidPointXYZ(x0, y0, z0); |
| 3080 | }; |
| 3081 | function nextPoint(λ, φ) { |
| 3082 | λ *= d3_radians; |
| 3083 | 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); |
| 3084 | d3_geo_centroidW1 += w; |
| 3085 | d3_geo_centroidX1 += w * (x0 + (x0 = x)); |
| 3086 | d3_geo_centroidY1 += w * (y0 + (y0 = y)); |
| 3087 | d3_geo_centroidZ1 += w * (z0 + (z0 = z)); |
| 3088 | d3_geo_centroidPointXYZ(x0, y0, z0); |
| 3089 | } |
| 3090 | } |
| 3091 | function d3_geo_centroidLineEnd() { |
| 3092 | d3_geo_centroid.point = d3_geo_centroidPoint; |
| 3093 | } |
| 3094 | function d3_geo_centroidRingStart() { |
| 3095 | var λ00, φ00, x0, y0, z0; |
| 3096 | d3_geo_centroid.point = function(λ, φ) { |
| 3097 | λ00 = λ, φ00 = φ; |
| 3098 | d3_geo_centroid.point = nextPoint; |
| 3099 | λ *= d3_radians; |
| 3100 | var cosφ = Math.cos(φ *= d3_radians); |
| 3101 | x0 = cosφ * Math.cos(λ); |
| 3102 | y0 = cosφ * Math.sin(λ); |
| 3103 | z0 = Math.sin(φ); |
| 3104 | d3_geo_centroidPointXYZ(x0, y0, z0); |
| 3105 | }; |
| 3106 | d3_geo_centroid.lineEnd = function() { |
| 3107 | nextPoint(λ00, φ00); |
| 3108 | d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd; |
| 3109 | d3_geo_centroid.point = d3_geo_centroidPoint; |
| 3110 | }; |
| 3111 | function nextPoint(λ, φ) { |
| 3112 | λ *= d3_radians; |
| 3113 | 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); |
| 3114 | d3_geo_centroidX2 += v * cx; |
| 3115 | d3_geo_centroidY2 += v * cy; |
| 3116 | d3_geo_centroidZ2 += v * cz; |
| 3117 | d3_geo_centroidW1 += w; |
| 3118 | d3_geo_centroidX1 += w * (x0 + (x0 = x)); |
| 3119 | d3_geo_centroidY1 += w * (y0 + (y0 = y)); |
| 3120 | d3_geo_centroidZ1 += w * (z0 + (z0 = z)); |
| 3121 | d3_geo_centroidPointXYZ(x0, y0, z0); |
| 3122 | } |
| 3123 | } |
| 3124 | function d3_true() { |
| 3125 | return true; |
| 3126 | } |
| 3127 | function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) { |
| 3128 | var subject = [], clip = []; |
| 3129 | segments.forEach(function(segment) { |
| 3130 | if ((n = segment.length - 1) <= 0) return; |
| 3131 | var n, p0 = segment[0], p1 = segment[n]; |
| 3132 | if (d3_geo_sphericalEqual(p0, p1)) { |
| 3133 | listener.lineStart(); |
| 3134 | for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]); |
| 3135 | listener.lineEnd(); |
| 3136 | return; |
| 3137 | } |
| 3138 | var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false); |
| 3139 | a.o = b; |
| 3140 | subject.push(a); |
| 3141 | clip.push(b); |
| 3142 | a = new d3_geo_clipPolygonIntersection(p1, segment, null, false); |
| 3143 | b = new d3_geo_clipPolygonIntersection(p1, null, a, true); |
| 3144 | a.o = b; |
| 3145 | subject.push(a); |
| 3146 | clip.push(b); |
| 3147 | }); |
| 3148 | clip.sort(compare); |
| 3149 | d3_geo_clipPolygonLinkCircular(subject); |
| 3150 | d3_geo_clipPolygonLinkCircular(clip); |
| 3151 | if (!subject.length) return; |
| 3152 | for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) { |
| 3153 | clip[i].e = entry = !entry; |
| 3154 | } |
| 3155 | var start = subject[0], points, point; |
| 3156 | while (1) { |
| 3157 | var current = start, isSubject = true; |
| 3158 | while (current.v) if ((current = current.n) === start) return; |
| 3159 | points = current.z; |
| 3160 | listener.lineStart(); |
| 3161 | do { |
| 3162 | current.v = current.o.v = true; |
| 3163 | if (current.e) { |
| 3164 | if (isSubject) { |
| 3165 | for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]); |
| 3166 | } else { |
| 3167 | interpolate(current.x, current.n.x, 1, listener); |
| 3168 | } |
| 3169 | current = current.n; |
| 3170 | } else { |
| 3171 | if (isSubject) { |
| 3172 | points = current.p.z; |
| 3173 | for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]); |
| 3174 | } else { |
| 3175 | interpolate(current.x, current.p.x, -1, listener); |
| 3176 | } |
| 3177 | current = current.p; |
| 3178 | } |
| 3179 | current = current.o; |
| 3180 | points = current.z; |
| 3181 | isSubject = !isSubject; |
| 3182 | } while (!current.v); |
| 3183 | listener.lineEnd(); |
| 3184 | } |
| 3185 | } |
| 3186 | function d3_geo_clipPolygonLinkCircular(array) { |
| 3187 | if (!(n = array.length)) return; |
| 3188 | var n, i = 0, a = array[0], b; |
| 3189 | while (++i < n) { |
| 3190 | a.n = b = array[i]; |
| 3191 | b.p = a; |
| 3192 | a = b; |
| 3193 | } |
| 3194 | a.n = b = array[0]; |
| 3195 | b.p = a; |
| 3196 | } |
| 3197 | function d3_geo_clipPolygonIntersection(point, points, other, entry) { |
| 3198 | this.x = point; |
| 3199 | this.z = points; |
| 3200 | this.o = other; |
| 3201 | this.e = entry; |
| 3202 | this.v = false; |
| 3203 | this.n = this.p = null; |
| 3204 | } |
| 3205 | function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) { |
| 3206 | return function(rotate, listener) { |
| 3207 | var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]); |
| 3208 | var clip = { |
| 3209 | point: point, |
| 3210 | lineStart: lineStart, |
| 3211 | lineEnd: lineEnd, |
| 3212 | polygonStart: function() { |
| 3213 | clip.point = pointRing; |
| 3214 | clip.lineStart = ringStart; |
| 3215 | clip.lineEnd = ringEnd; |
| 3216 | segments = []; |
| 3217 | polygon = []; |
| 3218 | }, |
| 3219 | polygonEnd: function() { |
| 3220 | clip.point = point; |
| 3221 | clip.lineStart = lineStart; |
| 3222 | clip.lineEnd = lineEnd; |
| 3223 | segments = d3.merge(segments); |
| 3224 | var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon); |
| 3225 | if (segments.length) { |
| 3226 | if (!polygonStarted) listener.polygonStart(), polygonStarted = true; |
| 3227 | d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener); |
| 3228 | } else if (clipStartInside) { |
| 3229 | if (!polygonStarted) listener.polygonStart(), polygonStarted = true; |
| 3230 | listener.lineStart(); |
| 3231 | interpolate(null, null, 1, listener); |
| 3232 | listener.lineEnd(); |
| 3233 | } |
| 3234 | if (polygonStarted) listener.polygonEnd(), polygonStarted = false; |
| 3235 | segments = polygon = null; |
| 3236 | }, |
| 3237 | sphere: function() { |
| 3238 | listener.polygonStart(); |
| 3239 | listener.lineStart(); |
| 3240 | interpolate(null, null, 1, listener); |
| 3241 | listener.lineEnd(); |
| 3242 | listener.polygonEnd(); |
| 3243 | } |
| 3244 | }; |
| 3245 | function point(λ, φ) { |
| 3246 | var point = rotate(λ, φ); |
| 3247 | if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ); |
| 3248 | } |
| 3249 | function pointLine(λ, φ) { |
| 3250 | var point = rotate(λ, φ); |
| 3251 | line.point(point[0], point[1]); |
| 3252 | } |
| 3253 | function lineStart() { |
| 3254 | clip.point = pointLine; |
| 3255 | line.lineStart(); |
| 3256 | } |
| 3257 | function lineEnd() { |
| 3258 | clip.point = point; |
| 3259 | line.lineEnd(); |
| 3260 | } |
| 3261 | var segments; |
| 3262 | var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring; |
| 3263 | function pointRing(λ, φ) { |
| 3264 | ring.push([ λ, φ ]); |
| 3265 | var point = rotate(λ, φ); |
| 3266 | ringListener.point(point[0], point[1]); |
| 3267 | } |
| 3268 | function ringStart() { |
| 3269 | ringListener.lineStart(); |
| 3270 | ring = []; |
| 3271 | } |
| 3272 | function ringEnd() { |
| 3273 | pointRing(ring[0][0], ring[0][1]); |
| 3274 | ringListener.lineEnd(); |
| 3275 | var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length; |
| 3276 | ring.pop(); |
| 3277 | polygon.push(ring); |
| 3278 | ring = null; |
| 3279 | if (!n) return; |
| 3280 | if (clean & 1) { |
| 3281 | segment = ringSegments[0]; |
| 3282 | var n = segment.length - 1, i = -1, point; |
| 3283 | if (n > 0) { |
| 3284 | if (!polygonStarted) listener.polygonStart(), polygonStarted = true; |
| 3285 | listener.lineStart(); |
| 3286 | while (++i < n) listener.point((point = segment[i])[0], point[1]); |
| 3287 | listener.lineEnd(); |
| 3288 | } |
| 3289 | return; |
| 3290 | } |
| 3291 | if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift())); |
| 3292 | segments.push(ringSegments.filter(d3_geo_clipSegmentLength1)); |
| 3293 | } |
| 3294 | return clip; |
| 3295 | }; |
| 3296 | } |
| 3297 | function d3_geo_clipSegmentLength1(segment) { |
| 3298 | return segment.length > 1; |
| 3299 | } |
| 3300 | function d3_geo_clipBufferListener() { |
| 3301 | var lines = [], line; |
| 3302 | return { |
| 3303 | lineStart: function() { |
| 3304 | lines.push(line = []); |
| 3305 | }, |
| 3306 | point: function(λ, φ) { |
| 3307 | line.push([ λ, φ ]); |
| 3308 | }, |
| 3309 | lineEnd: d3_noop, |
| 3310 | buffer: function() { |
| 3311 | var buffer = lines; |
| 3312 | lines = []; |
| 3313 | line = null; |
| 3314 | return buffer; |
| 3315 | }, |
| 3316 | rejoin: function() { |
| 3317 | if (lines.length > 1) lines.push(lines.pop().concat(lines.shift())); |
| 3318 | } |
| 3319 | }; |
| 3320 | } |
| 3321 | function d3_geo_clipSort(a, b) { |
| 3322 | return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]); |
| 3323 | } |
| 3324 | var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]); |
| 3325 | function d3_geo_clipAntimeridianLine(listener) { |
| 3326 | var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean; |
| 3327 | return { |
| 3328 | lineStart: function() { |
| 3329 | listener.lineStart(); |
| 3330 | clean = 1; |
| 3331 | }, |
| 3332 | point: function(λ1, φ1) { |
| 3333 | var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0); |
| 3334 | if (abs(dλ - π) < ε) { |
| 3335 | listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ); |
| 3336 | listener.point(sλ0, φ0); |
| 3337 | listener.lineEnd(); |
| 3338 | listener.lineStart(); |
| 3339 | listener.point(sλ1, φ0); |
| 3340 | listener.point(λ1, φ0); |
| 3341 | clean = 0; |
| 3342 | } else if (sλ0 !== sλ1 && dλ >= π) { |
| 3343 | if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε; |
| 3344 | if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε; |
| 3345 | φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1); |
| 3346 | listener.point(sλ0, φ0); |
| 3347 | listener.lineEnd(); |
| 3348 | listener.lineStart(); |
| 3349 | listener.point(sλ1, φ0); |
| 3350 | clean = 0; |
| 3351 | } |
| 3352 | listener.point(λ0 = λ1, φ0 = φ1); |
| 3353 | sλ0 = sλ1; |
| 3354 | }, |
| 3355 | lineEnd: function() { |
| 3356 | listener.lineEnd(); |
| 3357 | λ0 = φ0 = NaN; |
| 3358 | }, |
| 3359 | clean: function() { |
| 3360 | return 2 - clean; |
| 3361 | } |
| 3362 | }; |
| 3363 | } |
| 3364 | function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) { |
| 3365 | var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1); |
| 3366 | 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; |
| 3367 | } |
| 3368 | function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) { |
| 3369 | var φ; |
| 3370 | if (from == null) { |
| 3371 | φ = direction * halfπ; |
| 3372 | listener.point(-π, φ); |
| 3373 | listener.point(0, φ); |
| 3374 | listener.point(π, φ); |
| 3375 | listener.point(π, 0); |
| 3376 | listener.point(π, -φ); |
| 3377 | listener.point(0, -φ); |
| 3378 | listener.point(-π, -φ); |
| 3379 | listener.point(-π, 0); |
| 3380 | listener.point(-π, φ); |
| 3381 | } else if (abs(from[0] - to[0]) > ε) { |
| 3382 | var s = from[0] < to[0] ? π : -π; |
| 3383 | φ = direction * s / 2; |
| 3384 | listener.point(-s, φ); |
| 3385 | listener.point(0, φ); |
| 3386 | listener.point(s, φ); |
| 3387 | } else { |
| 3388 | listener.point(to[0], to[1]); |
| 3389 | } |
| 3390 | } |
| 3391 | function d3_geo_pointInPolygon(point, polygon) { |
| 3392 | var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0; |
| 3393 | d3_geo_areaRingSum.reset(); |
| 3394 | for (var i = 0, n = polygon.length; i < n; ++i) { |
| 3395 | var ring = polygon[i], m = ring.length; |
| 3396 | if (!m) continue; |
| 3397 | var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1; |
| 3398 | while (true) { |
| 3399 | if (j === m) j = 0; |
| 3400 | point = ring[j]; |
| 3401 | var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ; |
| 3402 | d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ))); |
| 3403 | polarAngle += antimeridian ? dλ + sdλ * τ : dλ; |
| 3404 | if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) { |
| 3405 | var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point)); |
| 3406 | d3_geo_cartesianNormalize(arc); |
| 3407 | var intersection = d3_geo_cartesianCross(meridianNormal, arc); |
| 3408 | d3_geo_cartesianNormalize(intersection); |
| 3409 | var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]); |
| 3410 | if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) { |
| 3411 | winding += antimeridian ^ dλ >= 0 ? 1 : -1; |
| 3412 | } |
| 3413 | } |
| 3414 | if (!j++) break; |
| 3415 | λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point; |
| 3416 | } |
| 3417 | } |
| 3418 | return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1; |
| 3419 | } |
| 3420 | function d3_geo_clipCircle(radius) { |
| 3421 | var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians); |
| 3422 | return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]); |
| 3423 | function visible(λ, φ) { |
| 3424 | return Math.cos(λ) * Math.cos(φ) > cr; |
| 3425 | } |
| 3426 | function clipLine(listener) { |
| 3427 | var point0, c0, v0, v00, clean; |
| 3428 | return { |
| 3429 | lineStart: function() { |
| 3430 | v00 = v0 = false; |
| 3431 | clean = 1; |
| 3432 | }, |
| 3433 | point: function(λ, φ) { |
| 3434 | var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0; |
| 3435 | if (!point0 && (v00 = v0 = v)) listener.lineStart(); |
| 3436 | if (v !== v0) { |
| 3437 | point2 = intersect(point0, point1); |
| 3438 | if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) { |
| 3439 | point1[0] += ε; |
| 3440 | point1[1] += ε; |
| 3441 | v = visible(point1[0], point1[1]); |
| 3442 | } |
| 3443 | } |
| 3444 | if (v !== v0) { |
| 3445 | clean = 0; |
| 3446 | if (v) { |
| 3447 | listener.lineStart(); |
| 3448 | point2 = intersect(point1, point0); |
| 3449 | listener.point(point2[0], point2[1]); |
| 3450 | } else { |
| 3451 | point2 = intersect(point0, point1); |
| 3452 | listener.point(point2[0], point2[1]); |
| 3453 | listener.lineEnd(); |
| 3454 | } |
| 3455 | point0 = point2; |
| 3456 | } else if (notHemisphere && point0 && smallRadius ^ v) { |
| 3457 | var t; |
| 3458 | if (!(c & c0) && (t = intersect(point1, point0, true))) { |
| 3459 | clean = 0; |
| 3460 | if (smallRadius) { |
| 3461 | listener.lineStart(); |
| 3462 | listener.point(t[0][0], t[0][1]); |
| 3463 | listener.point(t[1][0], t[1][1]); |
| 3464 | listener.lineEnd(); |
| 3465 | } else { |
| 3466 | listener.point(t[1][0], t[1][1]); |
| 3467 | listener.lineEnd(); |
| 3468 | listener.lineStart(); |
| 3469 | listener.point(t[0][0], t[0][1]); |
| 3470 | } |
| 3471 | } |
| 3472 | } |
| 3473 | if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) { |
| 3474 | listener.point(point1[0], point1[1]); |
| 3475 | } |
| 3476 | point0 = point1, v0 = v, c0 = c; |
| 3477 | }, |
| 3478 | lineEnd: function() { |
| 3479 | if (v0) listener.lineEnd(); |
| 3480 | point0 = null; |
| 3481 | }, |
| 3482 | clean: function() { |
| 3483 | return clean | (v00 && v0) << 1; |
| 3484 | } |
| 3485 | }; |
| 3486 | } |
| 3487 | function intersect(a, b, two) { |
| 3488 | var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b); |
| 3489 | var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2; |
| 3490 | if (!determinant) return !two && a; |
| 3491 | 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); |
| 3492 | d3_geo_cartesianAdd(A, B); |
| 3493 | 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); |
| 3494 | if (t2 < 0) return; |
| 3495 | var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu); |
| 3496 | d3_geo_cartesianAdd(q, A); |
| 3497 | q = d3_geo_spherical(q); |
| 3498 | if (!two) return q; |
| 3499 | var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z; |
| 3500 | if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z; |
| 3501 | var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε; |
| 3502 | if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z; |
| 3503 | 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)) { |
| 3504 | var q1 = d3_geo_cartesianScale(u, (-w + t) / uu); |
| 3505 | d3_geo_cartesianAdd(q1, A); |
| 3506 | return [ q, d3_geo_spherical(q1) ]; |
| 3507 | } |
| 3508 | } |
| 3509 | function code(λ, φ) { |
| 3510 | var r = smallRadius ? radius : π - radius, code = 0; |
| 3511 | if (λ < -r) code |= 1; else if (λ > r) code |= 2; |
| 3512 | if (φ < -r) code |= 4; else if (φ > r) code |= 8; |
| 3513 | return code; |
| 3514 | } |
| 3515 | } |
| 3516 | function d3_geom_clipLine(x0, y0, x1, y1) { |
| 3517 | return function(line) { |
| 3518 | 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; |
| 3519 | r = x0 - ax; |
| 3520 | if (!dx && r > 0) return; |
| 3521 | r /= dx; |
| 3522 | if (dx < 0) { |
| 3523 | if (r < t0) return; |
| 3524 | if (r < t1) t1 = r; |
| 3525 | } else if (dx > 0) { |
| 3526 | if (r > t1) return; |
| 3527 | if (r > t0) t0 = r; |
| 3528 | } |
| 3529 | r = x1 - ax; |
| 3530 | if (!dx && r < 0) return; |
| 3531 | r /= dx; |
| 3532 | if (dx < 0) { |
| 3533 | if (r > t1) return; |
| 3534 | if (r > t0) t0 = r; |
| 3535 | } else if (dx > 0) { |
| 3536 | if (r < t0) return; |
| 3537 | if (r < t1) t1 = r; |
| 3538 | } |
| 3539 | r = y0 - ay; |
| 3540 | if (!dy && r > 0) return; |
| 3541 | r /= dy; |
| 3542 | if (dy < 0) { |
| 3543 | if (r < t0) return; |
| 3544 | if (r < t1) t1 = r; |
| 3545 | } else if (dy > 0) { |
| 3546 | if (r > t1) return; |
| 3547 | if (r > t0) t0 = r; |
| 3548 | } |
| 3549 | r = y1 - ay; |
| 3550 | if (!dy && r < 0) return; |
| 3551 | r /= dy; |
| 3552 | if (dy < 0) { |
| 3553 | if (r > t1) return; |
| 3554 | if (r > t0) t0 = r; |
| 3555 | } else if (dy > 0) { |
| 3556 | if (r < t0) return; |
| 3557 | if (r < t1) t1 = r; |
| 3558 | } |
| 3559 | if (t0 > 0) line.a = { |
| 3560 | x: ax + t0 * dx, |
| 3561 | y: ay + t0 * dy |
| 3562 | }; |
| 3563 | if (t1 < 1) line.b = { |
| 3564 | x: ax + t1 * dx, |
| 3565 | y: ay + t1 * dy |
| 3566 | }; |
| 3567 | return line; |
| 3568 | }; |
| 3569 | } |
| 3570 | var d3_geo_clipExtentMAX = 1e9; |
| 3571 | d3.geo.clipExtent = function() { |
| 3572 | var x0, y0, x1, y1, stream, clip, clipExtent = { |
| 3573 | stream: function(output) { |
| 3574 | if (stream) stream.valid = false; |
| 3575 | stream = clip(output); |
| 3576 | stream.valid = true; |
| 3577 | return stream; |
| 3578 | }, |
| 3579 | extent: function(_) { |
| 3580 | if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ]; |
| 3581 | clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]); |
| 3582 | if (stream) stream.valid = false, stream = null; |
| 3583 | return clipExtent; |
| 3584 | } |
| 3585 | }; |
| 3586 | return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]); |
| 3587 | }; |
| 3588 | function d3_geo_clipExtent(x0, y0, x1, y1) { |
| 3589 | return function(listener) { |
| 3590 | var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring; |
| 3591 | var clip = { |
| 3592 | point: point, |
| 3593 | lineStart: lineStart, |
| 3594 | lineEnd: lineEnd, |
| 3595 | polygonStart: function() { |
| 3596 | listener = bufferListener; |
| 3597 | segments = []; |
| 3598 | polygon = []; |
| 3599 | clean = true; |
| 3600 | }, |
| 3601 | polygonEnd: function() { |
| 3602 | listener = listener_; |
| 3603 | segments = d3.merge(segments); |
| 3604 | var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length; |
| 3605 | if (inside || visible) { |
| 3606 | listener.polygonStart(); |
| 3607 | if (inside) { |
| 3608 | listener.lineStart(); |
| 3609 | interpolate(null, null, 1, listener); |
| 3610 | listener.lineEnd(); |
| 3611 | } |
| 3612 | if (visible) { |
| 3613 | d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener); |
| 3614 | } |
| 3615 | listener.polygonEnd(); |
| 3616 | } |
| 3617 | segments = polygon = ring = null; |
| 3618 | } |
| 3619 | }; |
| 3620 | function insidePolygon(p) { |
| 3621 | var wn = 0, n = polygon.length, y = p[1]; |
| 3622 | for (var i = 0; i < n; ++i) { |
| 3623 | for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) { |
| 3624 | b = v[j]; |
| 3625 | if (a[1] <= y) { |
| 3626 | if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn; |
| 3627 | } else { |
| 3628 | if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn; |
| 3629 | } |
| 3630 | a = b; |
| 3631 | } |
| 3632 | } |
| 3633 | return wn !== 0; |
| 3634 | } |
| 3635 | function interpolate(from, to, direction, listener) { |
| 3636 | var a = 0, a1 = 0; |
| 3637 | if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) { |
| 3638 | do { |
| 3639 | listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0); |
| 3640 | } while ((a = (a + direction + 4) % 4) !== a1); |
| 3641 | } else { |
| 3642 | listener.point(to[0], to[1]); |
| 3643 | } |
| 3644 | } |
| 3645 | function pointVisible(x, y) { |
| 3646 | return x0 <= x && x <= x1 && y0 <= y && y <= y1; |
| 3647 | } |
| 3648 | function point(x, y) { |
| 3649 | if (pointVisible(x, y)) listener.point(x, y); |
| 3650 | } |
| 3651 | var x__, y__, v__, x_, y_, v_, first, clean; |
| 3652 | function lineStart() { |
| 3653 | clip.point = linePoint; |
| 3654 | if (polygon) polygon.push(ring = []); |
| 3655 | first = true; |
| 3656 | v_ = false; |
| 3657 | x_ = y_ = NaN; |
| 3658 | } |
| 3659 | function lineEnd() { |
| 3660 | if (segments) { |
| 3661 | linePoint(x__, y__); |
| 3662 | if (v__ && v_) bufferListener.rejoin(); |
| 3663 | segments.push(bufferListener.buffer()); |
| 3664 | } |
| 3665 | clip.point = point; |
| 3666 | if (v_) listener.lineEnd(); |
| 3667 | } |
| 3668 | function linePoint(x, y) { |
| 3669 | x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x)); |
| 3670 | y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y)); |
| 3671 | var v = pointVisible(x, y); |
| 3672 | if (polygon) ring.push([ x, y ]); |
| 3673 | if (first) { |
| 3674 | x__ = x, y__ = y, v__ = v; |
| 3675 | first = false; |
| 3676 | if (v) { |
| 3677 | listener.lineStart(); |
| 3678 | listener.point(x, y); |
| 3679 | } |
| 3680 | } else { |
| 3681 | if (v && v_) listener.point(x, y); else { |
| 3682 | var l = { |
| 3683 | a: { |
| 3684 | x: x_, |
| 3685 | y: y_ |
| 3686 | }, |
| 3687 | b: { |
| 3688 | x: x, |
| 3689 | y: y |
| 3690 | } |
| 3691 | }; |
| 3692 | if (clipLine(l)) { |
| 3693 | if (!v_) { |
| 3694 | listener.lineStart(); |
| 3695 | listener.point(l.a.x, l.a.y); |
| 3696 | } |
| 3697 | listener.point(l.b.x, l.b.y); |
| 3698 | if (!v) listener.lineEnd(); |
| 3699 | clean = false; |
| 3700 | } else if (v) { |
| 3701 | listener.lineStart(); |
| 3702 | listener.point(x, y); |
| 3703 | clean = false; |
| 3704 | } |
| 3705 | } |
| 3706 | } |
| 3707 | x_ = x, y_ = y, v_ = v; |
| 3708 | } |
| 3709 | return clip; |
| 3710 | }; |
| 3711 | function corner(p, direction) { |
| 3712 | 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; |
| 3713 | } |
| 3714 | function compare(a, b) { |
| 3715 | return comparePoints(a.x, b.x); |
| 3716 | } |
| 3717 | function comparePoints(a, b) { |
| 3718 | var ca = corner(a, 1), cb = corner(b, 1); |
| 3719 | 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]; |
| 3720 | } |
| 3721 | } |
| 3722 | function d3_geo_compose(a, b) { |
| 3723 | function compose(x, y) { |
| 3724 | return x = a(x, y), b(x[0], x[1]); |
| 3725 | } |
| 3726 | if (a.invert && b.invert) compose.invert = function(x, y) { |
| 3727 | return x = b.invert(x, y), x && a.invert(x[0], x[1]); |
| 3728 | }; |
| 3729 | return compose; |
| 3730 | } |
| 3731 | function d3_geo_conic(projectAt) { |
| 3732 | var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1); |
| 3733 | p.parallels = function(_) { |
| 3734 | if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ]; |
| 3735 | return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180); |
| 3736 | }; |
| 3737 | return p; |
| 3738 | } |
| 3739 | function d3_geo_conicEqualArea(φ0, φ1) { |
| 3740 | 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; |
| 3741 | function forward(λ, φ) { |
| 3742 | var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n; |
| 3743 | return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ]; |
| 3744 | } |
| 3745 | forward.invert = function(x, y) { |
| 3746 | var ρ0_y = ρ0 - y; |
| 3747 | return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ]; |
| 3748 | }; |
| 3749 | return forward; |
| 3750 | } |
| 3751 | (d3.geo.conicEqualArea = function() { |
| 3752 | return d3_geo_conic(d3_geo_conicEqualArea); |
| 3753 | }).raw = d3_geo_conicEqualArea; |
| 3754 | d3.geo.albers = function() { |
| 3755 | return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070); |
| 3756 | }; |
| 3757 | d3.geo.albersUsa = function() { |
| 3758 | var lower48 = d3.geo.albers(); |
| 3759 | var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]); |
| 3760 | var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]); |
| 3761 | var point, pointStream = { |
| 3762 | point: function(x, y) { |
| 3763 | point = [ x, y ]; |
| 3764 | } |
| 3765 | }, lower48Point, alaskaPoint, hawaiiPoint; |
| 3766 | function albersUsa(coordinates) { |
| 3767 | var x = coordinates[0], y = coordinates[1]; |
| 3768 | point = null; |
| 3769 | (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y); |
| 3770 | return point; |
| 3771 | } |
| 3772 | albersUsa.invert = function(coordinates) { |
| 3773 | var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k; |
| 3774 | return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates); |
| 3775 | }; |
| 3776 | albersUsa.stream = function(stream) { |
| 3777 | var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream); |
| 3778 | return { |
| 3779 | point: function(x, y) { |
| 3780 | lower48Stream.point(x, y); |
| 3781 | alaskaStream.point(x, y); |
| 3782 | hawaiiStream.point(x, y); |
| 3783 | }, |
| 3784 | sphere: function() { |
| 3785 | lower48Stream.sphere(); |
| 3786 | alaskaStream.sphere(); |
| 3787 | hawaiiStream.sphere(); |
| 3788 | }, |
| 3789 | lineStart: function() { |
| 3790 | lower48Stream.lineStart(); |
| 3791 | alaskaStream.lineStart(); |
| 3792 | hawaiiStream.lineStart(); |
| 3793 | }, |
| 3794 | lineEnd: function() { |
| 3795 | lower48Stream.lineEnd(); |
| 3796 | alaskaStream.lineEnd(); |
| 3797 | hawaiiStream.lineEnd(); |
| 3798 | }, |
| 3799 | polygonStart: function() { |
| 3800 | lower48Stream.polygonStart(); |
| 3801 | alaskaStream.polygonStart(); |
| 3802 | hawaiiStream.polygonStart(); |
| 3803 | }, |
| 3804 | polygonEnd: function() { |
| 3805 | lower48Stream.polygonEnd(); |
| 3806 | alaskaStream.polygonEnd(); |
| 3807 | hawaiiStream.polygonEnd(); |
| 3808 | } |
| 3809 | }; |
| 3810 | }; |
| 3811 | albersUsa.precision = function(_) { |
| 3812 | if (!arguments.length) return lower48.precision(); |
| 3813 | lower48.precision(_); |
| 3814 | alaska.precision(_); |
| 3815 | hawaii.precision(_); |
| 3816 | return albersUsa; |
| 3817 | }; |
| 3818 | albersUsa.scale = function(_) { |
| 3819 | if (!arguments.length) return lower48.scale(); |
| 3820 | lower48.scale(_); |
| 3821 | alaska.scale(_ * .35); |
| 3822 | hawaii.scale(_); |
| 3823 | return albersUsa.translate(lower48.translate()); |
| 3824 | }; |
| 3825 | albersUsa.translate = function(_) { |
| 3826 | if (!arguments.length) return lower48.translate(); |
| 3827 | var k = lower48.scale(), x = +_[0], y = +_[1]; |
| 3828 | lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point; |
| 3829 | 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; |
| 3830 | 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; |
| 3831 | return albersUsa; |
| 3832 | }; |
| 3833 | return albersUsa.scale(1070); |
| 3834 | }; |
| 3835 | var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = { |
| 3836 | point: d3_noop, |
| 3837 | lineStart: d3_noop, |
| 3838 | lineEnd: d3_noop, |
| 3839 | polygonStart: function() { |
| 3840 | d3_geo_pathAreaPolygon = 0; |
| 3841 | d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart; |
| 3842 | }, |
| 3843 | polygonEnd: function() { |
| 3844 | d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop; |
| 3845 | d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2); |
| 3846 | } |
| 3847 | }; |
| 3848 | function d3_geo_pathAreaRingStart() { |
| 3849 | var x00, y00, x0, y0; |
| 3850 | d3_geo_pathArea.point = function(x, y) { |
| 3851 | d3_geo_pathArea.point = nextPoint; |
| 3852 | x00 = x0 = x, y00 = y0 = y; |
| 3853 | }; |
| 3854 | function nextPoint(x, y) { |
| 3855 | d3_geo_pathAreaPolygon += y0 * x - x0 * y; |
| 3856 | x0 = x, y0 = y; |
| 3857 | } |
| 3858 | d3_geo_pathArea.lineEnd = function() { |
| 3859 | nextPoint(x00, y00); |
| 3860 | }; |
| 3861 | } |
| 3862 | var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1; |
| 3863 | var d3_geo_pathBounds = { |
| 3864 | point: d3_geo_pathBoundsPoint, |
| 3865 | lineStart: d3_noop, |
| 3866 | lineEnd: d3_noop, |
| 3867 | polygonStart: d3_noop, |
| 3868 | polygonEnd: d3_noop |
| 3869 | }; |
| 3870 | function d3_geo_pathBoundsPoint(x, y) { |
| 3871 | if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x; |
| 3872 | if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x; |
| 3873 | if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y; |
| 3874 | if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y; |
| 3875 | } |
| 3876 | function d3_geo_pathBuffer() { |
| 3877 | var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = []; |
| 3878 | var stream = { |
| 3879 | point: point, |
| 3880 | lineStart: function() { |
| 3881 | stream.point = pointLineStart; |
| 3882 | }, |
| 3883 | lineEnd: lineEnd, |
| 3884 | polygonStart: function() { |
| 3885 | stream.lineEnd = lineEndPolygon; |
| 3886 | }, |
| 3887 | polygonEnd: function() { |
| 3888 | stream.lineEnd = lineEnd; |
| 3889 | stream.point = point; |
| 3890 | }, |
| 3891 | pointRadius: function(_) { |
| 3892 | pointCircle = d3_geo_pathBufferCircle(_); |
| 3893 | return stream; |
| 3894 | }, |
| 3895 | result: function() { |
| 3896 | if (buffer.length) { |
| 3897 | var result = buffer.join(""); |
| 3898 | buffer = []; |
| 3899 | return result; |
| 3900 | } |
| 3901 | } |
| 3902 | }; |
| 3903 | function point(x, y) { |
| 3904 | buffer.push("M", x, ",", y, pointCircle); |
| 3905 | } |
| 3906 | function pointLineStart(x, y) { |
| 3907 | buffer.push("M", x, ",", y); |
| 3908 | stream.point = pointLine; |
| 3909 | } |
| 3910 | function pointLine(x, y) { |
| 3911 | buffer.push("L", x, ",", y); |
| 3912 | } |
| 3913 | function lineEnd() { |
| 3914 | stream.point = point; |
| 3915 | } |
| 3916 | function lineEndPolygon() { |
| 3917 | buffer.push("Z"); |
| 3918 | } |
| 3919 | return stream; |
| 3920 | } |
| 3921 | function d3_geo_pathBufferCircle(radius) { |
| 3922 | return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z"; |
| 3923 | } |
| 3924 | var d3_geo_pathCentroid = { |
| 3925 | point: d3_geo_pathCentroidPoint, |
| 3926 | lineStart: d3_geo_pathCentroidLineStart, |
| 3927 | lineEnd: d3_geo_pathCentroidLineEnd, |
| 3928 | polygonStart: function() { |
| 3929 | d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart; |
| 3930 | }, |
| 3931 | polygonEnd: function() { |
| 3932 | d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint; |
| 3933 | d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart; |
| 3934 | d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd; |
| 3935 | } |
| 3936 | }; |
| 3937 | function d3_geo_pathCentroidPoint(x, y) { |
| 3938 | d3_geo_centroidX0 += x; |
| 3939 | d3_geo_centroidY0 += y; |
| 3940 | ++d3_geo_centroidZ0; |
| 3941 | } |
| 3942 | function d3_geo_pathCentroidLineStart() { |
| 3943 | var x0, y0; |
| 3944 | d3_geo_pathCentroid.point = function(x, y) { |
| 3945 | d3_geo_pathCentroid.point = nextPoint; |
| 3946 | d3_geo_pathCentroidPoint(x0 = x, y0 = y); |
| 3947 | }; |
| 3948 | function nextPoint(x, y) { |
| 3949 | var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy); |
| 3950 | d3_geo_centroidX1 += z * (x0 + x) / 2; |
| 3951 | d3_geo_centroidY1 += z * (y0 + y) / 2; |
| 3952 | d3_geo_centroidZ1 += z; |
| 3953 | d3_geo_pathCentroidPoint(x0 = x, y0 = y); |
| 3954 | } |
| 3955 | } |
| 3956 | function d3_geo_pathCentroidLineEnd() { |
| 3957 | d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint; |
| 3958 | } |
| 3959 | function d3_geo_pathCentroidRingStart() { |
| 3960 | var x00, y00, x0, y0; |
| 3961 | d3_geo_pathCentroid.point = function(x, y) { |
| 3962 | d3_geo_pathCentroid.point = nextPoint; |
| 3963 | d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y); |
| 3964 | }; |
| 3965 | function nextPoint(x, y) { |
| 3966 | var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy); |
| 3967 | d3_geo_centroidX1 += z * (x0 + x) / 2; |
| 3968 | d3_geo_centroidY1 += z * (y0 + y) / 2; |
| 3969 | d3_geo_centroidZ1 += z; |
| 3970 | z = y0 * x - x0 * y; |
| 3971 | d3_geo_centroidX2 += z * (x0 + x); |
| 3972 | d3_geo_centroidY2 += z * (y0 + y); |
| 3973 | d3_geo_centroidZ2 += z * 3; |
| 3974 | d3_geo_pathCentroidPoint(x0 = x, y0 = y); |
| 3975 | } |
| 3976 | d3_geo_pathCentroid.lineEnd = function() { |
| 3977 | nextPoint(x00, y00); |
| 3978 | }; |
| 3979 | } |
| 3980 | function d3_geo_pathContext(context) { |
| 3981 | var pointRadius = 4.5; |
| 3982 | var stream = { |
| 3983 | point: point, |
| 3984 | lineStart: function() { |
| 3985 | stream.point = pointLineStart; |
| 3986 | }, |
| 3987 | lineEnd: lineEnd, |
| 3988 | polygonStart: function() { |
| 3989 | stream.lineEnd = lineEndPolygon; |
| 3990 | }, |
| 3991 | polygonEnd: function() { |
| 3992 | stream.lineEnd = lineEnd; |
| 3993 | stream.point = point; |
| 3994 | }, |
| 3995 | pointRadius: function(_) { |
| 3996 | pointRadius = _; |
| 3997 | return stream; |
| 3998 | }, |
| 3999 | result: d3_noop |
| 4000 | }; |
| 4001 | function point(x, y) { |
| 4002 | context.moveTo(x, y); |
| 4003 | context.arc(x, y, pointRadius, 0, τ); |
| 4004 | } |
| 4005 | function pointLineStart(x, y) { |
| 4006 | context.moveTo(x, y); |
| 4007 | stream.point = pointLine; |
| 4008 | } |
| 4009 | function pointLine(x, y) { |
| 4010 | context.lineTo(x, y); |
| 4011 | } |
| 4012 | function lineEnd() { |
| 4013 | stream.point = point; |
| 4014 | } |
| 4015 | function lineEndPolygon() { |
| 4016 | context.closePath(); |
| 4017 | } |
| 4018 | return stream; |
| 4019 | } |
| 4020 | function d3_geo_resample(project) { |
| 4021 | var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16; |
| 4022 | function resample(stream) { |
| 4023 | return (maxDepth ? resampleRecursive : resampleNone)(stream); |
| 4024 | } |
| 4025 | function resampleNone(stream) { |
| 4026 | return d3_geo_transformPoint(stream, function(x, y) { |
| 4027 | x = project(x, y); |
| 4028 | stream.point(x[0], x[1]); |
| 4029 | }); |
| 4030 | } |
| 4031 | function resampleRecursive(stream) { |
| 4032 | var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0; |
| 4033 | var resample = { |
| 4034 | point: point, |
| 4035 | lineStart: lineStart, |
| 4036 | lineEnd: lineEnd, |
| 4037 | polygonStart: function() { |
| 4038 | stream.polygonStart(); |
| 4039 | resample.lineStart = ringStart; |
| 4040 | }, |
| 4041 | polygonEnd: function() { |
| 4042 | stream.polygonEnd(); |
| 4043 | resample.lineStart = lineStart; |
| 4044 | } |
| 4045 | }; |
| 4046 | function point(x, y) { |
| 4047 | x = project(x, y); |
| 4048 | stream.point(x[0], x[1]); |
| 4049 | } |
| 4050 | function lineStart() { |
| 4051 | x0 = NaN; |
| 4052 | resample.point = linePoint; |
| 4053 | stream.lineStart(); |
| 4054 | } |
| 4055 | function linePoint(λ, φ) { |
| 4056 | var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ); |
| 4057 | 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); |
| 4058 | stream.point(x0, y0); |
| 4059 | } |
| 4060 | function lineEnd() { |
| 4061 | resample.point = point; |
| 4062 | stream.lineEnd(); |
| 4063 | } |
| 4064 | function ringStart() { |
| 4065 | lineStart(); |
| 4066 | resample.point = ringPoint; |
| 4067 | resample.lineEnd = ringEnd; |
| 4068 | } |
| 4069 | function ringPoint(λ, φ) { |
| 4070 | linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0; |
| 4071 | resample.point = linePoint; |
| 4072 | } |
| 4073 | function ringEnd() { |
| 4074 | resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream); |
| 4075 | resample.lineEnd = lineEnd; |
| 4076 | lineEnd(); |
| 4077 | } |
| 4078 | return resample; |
| 4079 | } |
| 4080 | function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) { |
| 4081 | var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy; |
| 4082 | if (d2 > 4 * δ2 && depth--) { |
| 4083 | 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; |
| 4084 | if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { |
| 4085 | resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream); |
| 4086 | stream.point(x2, y2); |
| 4087 | resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream); |
| 4088 | } |
| 4089 | } |
| 4090 | } |
| 4091 | resample.precision = function(_) { |
| 4092 | if (!arguments.length) return Math.sqrt(δ2); |
| 4093 | maxDepth = (δ2 = _ * _) > 0 && 16; |
| 4094 | return resample; |
| 4095 | }; |
| 4096 | return resample; |
| 4097 | } |
| 4098 | d3.geo.path = function() { |
| 4099 | var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream; |
| 4100 | function path(object) { |
| 4101 | if (object) { |
| 4102 | if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments)); |
| 4103 | if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream); |
| 4104 | d3.geo.stream(object, cacheStream); |
| 4105 | } |
| 4106 | return contextStream.result(); |
| 4107 | } |
| 4108 | path.area = function(object) { |
| 4109 | d3_geo_pathAreaSum = 0; |
| 4110 | d3.geo.stream(object, projectStream(d3_geo_pathArea)); |
| 4111 | return d3_geo_pathAreaSum; |
| 4112 | }; |
| 4113 | path.centroid = function(object) { |
| 4114 | 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; |
| 4115 | d3.geo.stream(object, projectStream(d3_geo_pathCentroid)); |
| 4116 | 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 ]; |
| 4117 | }; |
| 4118 | path.bounds = function(object) { |
| 4119 | d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity); |
| 4120 | d3.geo.stream(object, projectStream(d3_geo_pathBounds)); |
| 4121 | return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ]; |
| 4122 | }; |
| 4123 | path.projection = function(_) { |
| 4124 | if (!arguments.length) return projection; |
| 4125 | projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity; |
| 4126 | return reset(); |
| 4127 | }; |
| 4128 | path.context = function(_) { |
| 4129 | if (!arguments.length) return context; |
| 4130 | contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_); |
| 4131 | if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius); |
| 4132 | return reset(); |
| 4133 | }; |
| 4134 | path.pointRadius = function(_) { |
| 4135 | if (!arguments.length) return pointRadius; |
| 4136 | pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_); |
| 4137 | return path; |
| 4138 | }; |
| 4139 | function reset() { |
| 4140 | cacheStream = null; |
| 4141 | return path; |
| 4142 | } |
| 4143 | return path.projection(d3.geo.albersUsa()).context(null); |
| 4144 | }; |
| 4145 | function d3_geo_pathProjectStream(project) { |
| 4146 | var resample = d3_geo_resample(function(x, y) { |
| 4147 | return project([ x * d3_degrees, y * d3_degrees ]); |
| 4148 | }); |
| 4149 | return function(stream) { |
| 4150 | return d3_geo_projectionRadians(resample(stream)); |
| 4151 | }; |
| 4152 | } |
| 4153 | d3.geo.transform = function(methods) { |
| 4154 | return { |
| 4155 | stream: function(stream) { |
| 4156 | var transform = new d3_geo_transform(stream); |
| 4157 | for (var k in methods) transform[k] = methods[k]; |
| 4158 | return transform; |
| 4159 | } |
| 4160 | }; |
| 4161 | }; |
| 4162 | function d3_geo_transform(stream) { |
| 4163 | this.stream = stream; |
| 4164 | } |
| 4165 | d3_geo_transform.prototype = { |
| 4166 | point: function(x, y) { |
| 4167 | this.stream.point(x, y); |
| 4168 | }, |
| 4169 | sphere: function() { |
| 4170 | this.stream.sphere(); |
| 4171 | }, |
| 4172 | lineStart: function() { |
| 4173 | this.stream.lineStart(); |
| 4174 | }, |
| 4175 | lineEnd: function() { |
| 4176 | this.stream.lineEnd(); |
| 4177 | }, |
| 4178 | polygonStart: function() { |
| 4179 | this.stream.polygonStart(); |
| 4180 | }, |
| 4181 | polygonEnd: function() { |
| 4182 | this.stream.polygonEnd(); |
| 4183 | } |
| 4184 | }; |
| 4185 | function d3_geo_transformPoint(stream, point) { |
| 4186 | return { |
| 4187 | point: point, |
| 4188 | sphere: function() { |
| 4189 | stream.sphere(); |
| 4190 | }, |
| 4191 | lineStart: function() { |
| 4192 | stream.lineStart(); |
| 4193 | }, |
| 4194 | lineEnd: function() { |
| 4195 | stream.lineEnd(); |
| 4196 | }, |
| 4197 | polygonStart: function() { |
| 4198 | stream.polygonStart(); |
| 4199 | }, |
| 4200 | polygonEnd: function() { |
| 4201 | stream.polygonEnd(); |
| 4202 | } |
| 4203 | }; |
| 4204 | } |
| 4205 | d3.geo.projection = d3_geo_projection; |
| 4206 | d3.geo.projectionMutator = d3_geo_projectionMutator; |
| 4207 | function d3_geo_projection(project) { |
| 4208 | return d3_geo_projectionMutator(function() { |
| 4209 | return project; |
| 4210 | })(); |
| 4211 | } |
| 4212 | function d3_geo_projectionMutator(projectAt) { |
| 4213 | var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) { |
| 4214 | x = project(x, y); |
| 4215 | return [ x[0] * k + δx, δy - x[1] * k ]; |
| 4216 | }), 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; |
| 4217 | function projection(point) { |
| 4218 | point = projectRotate(point[0] * d3_radians, point[1] * d3_radians); |
| 4219 | return [ point[0] * k + δx, δy - point[1] * k ]; |
| 4220 | } |
| 4221 | function invert(point) { |
| 4222 | point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k); |
| 4223 | return point && [ point[0] * d3_degrees, point[1] * d3_degrees ]; |
| 4224 | } |
| 4225 | projection.stream = function(output) { |
| 4226 | if (stream) stream.valid = false; |
| 4227 | stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output)))); |
| 4228 | stream.valid = true; |
| 4229 | return stream; |
| 4230 | }; |
| 4231 | projection.clipAngle = function(_) { |
| 4232 | if (!arguments.length) return clipAngle; |
| 4233 | preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians); |
| 4234 | return invalidate(); |
| 4235 | }; |
| 4236 | projection.clipExtent = function(_) { |
| 4237 | if (!arguments.length) return clipExtent; |
| 4238 | clipExtent = _; |
| 4239 | postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity; |
| 4240 | return invalidate(); |
| 4241 | }; |
| 4242 | projection.scale = function(_) { |
| 4243 | if (!arguments.length) return k; |
| 4244 | k = +_; |
| 4245 | return reset(); |
| 4246 | }; |
| 4247 | projection.translate = function(_) { |
| 4248 | if (!arguments.length) return [ x, y ]; |
| 4249 | x = +_[0]; |
| 4250 | y = +_[1]; |
| 4251 | return reset(); |
| 4252 | }; |
| 4253 | projection.center = function(_) { |
| 4254 | if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ]; |
| 4255 | λ = _[0] % 360 * d3_radians; |
| 4256 | φ = _[1] % 360 * d3_radians; |
| 4257 | return reset(); |
| 4258 | }; |
| 4259 | projection.rotate = function(_) { |
| 4260 | if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ]; |
| 4261 | δλ = _[0] % 360 * d3_radians; |
| 4262 | δφ = _[1] % 360 * d3_radians; |
| 4263 | δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0; |
| 4264 | return reset(); |
| 4265 | }; |
| 4266 | d3.rebind(projection, projectResample, "precision"); |
| 4267 | function reset() { |
| 4268 | projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project); |
| 4269 | var center = project(λ, φ); |
| 4270 | δx = x - center[0] * k; |
| 4271 | δy = y + center[1] * k; |
| 4272 | return invalidate(); |
| 4273 | } |
| 4274 | function invalidate() { |
| 4275 | if (stream) stream.valid = false, stream = null; |
| 4276 | return projection; |
| 4277 | } |
| 4278 | return function() { |
| 4279 | project = projectAt.apply(this, arguments); |
| 4280 | projection.invert = project.invert && invert; |
| 4281 | return reset(); |
| 4282 | }; |
| 4283 | } |
| 4284 | function d3_geo_projectionRadians(stream) { |
| 4285 | return d3_geo_transformPoint(stream, function(x, y) { |
| 4286 | stream.point(x * d3_radians, y * d3_radians); |
| 4287 | }); |
| 4288 | } |
| 4289 | function d3_geo_equirectangular(λ, φ) { |
| 4290 | return [ λ, φ ]; |
| 4291 | } |
| 4292 | (d3.geo.equirectangular = function() { |
| 4293 | return d3_geo_projection(d3_geo_equirectangular); |
| 4294 | }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular; |
| 4295 | d3.geo.rotation = function(rotate) { |
| 4296 | rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0); |
| 4297 | function forward(coordinates) { |
| 4298 | coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians); |
| 4299 | return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates; |
| 4300 | } |
| 4301 | forward.invert = function(coordinates) { |
| 4302 | coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians); |
| 4303 | return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates; |
| 4304 | }; |
| 4305 | return forward; |
| 4306 | }; |
| 4307 | function d3_geo_identityRotation(λ, φ) { |
| 4308 | return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ]; |
| 4309 | } |
| 4310 | d3_geo_identityRotation.invert = d3_geo_equirectangular; |
| 4311 | function d3_geo_rotation(δλ, δφ, δγ) { |
| 4312 | return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation; |
| 4313 | } |
| 4314 | function d3_geo_forwardRotationλ(δλ) { |
| 4315 | return function(λ, φ) { |
| 4316 | return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ]; |
| 4317 | }; |
| 4318 | } |
| 4319 | function d3_geo_rotationλ(δλ) { |
| 4320 | var rotation = d3_geo_forwardRotationλ(δλ); |
| 4321 | rotation.invert = d3_geo_forwardRotationλ(-δλ); |
| 4322 | return rotation; |
| 4323 | } |
| 4324 | function d3_geo_rotationφγ(δφ, δγ) { |
| 4325 | var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ); |
| 4326 | function rotation(λ, φ) { |
| 4327 | var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ; |
| 4328 | return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ]; |
| 4329 | } |
| 4330 | rotation.invert = function(λ, φ) { |
| 4331 | var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ; |
| 4332 | return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ]; |
| 4333 | }; |
| 4334 | return rotation; |
| 4335 | } |
| 4336 | d3.geo.circle = function() { |
| 4337 | var origin = [ 0, 0 ], angle, precision = 6, interpolate; |
| 4338 | function circle() { |
| 4339 | 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 = []; |
| 4340 | interpolate(null, null, 1, { |
| 4341 | point: function(x, y) { |
| 4342 | ring.push(x = rotate(x, y)); |
| 4343 | x[0] *= d3_degrees, x[1] *= d3_degrees; |
| 4344 | } |
| 4345 | }); |
| 4346 | return { |
| 4347 | type: "Polygon", |
| 4348 | coordinates: [ ring ] |
| 4349 | }; |
| 4350 | } |
| 4351 | circle.origin = function(x) { |
| 4352 | if (!arguments.length) return origin; |
| 4353 | origin = x; |
| 4354 | return circle; |
| 4355 | }; |
| 4356 | circle.angle = function(x) { |
| 4357 | if (!arguments.length) return angle; |
| 4358 | interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians); |
| 4359 | return circle; |
| 4360 | }; |
| 4361 | circle.precision = function(_) { |
| 4362 | if (!arguments.length) return precision; |
| 4363 | interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians); |
| 4364 | return circle; |
| 4365 | }; |
| 4366 | return circle.angle(90); |
| 4367 | }; |
| 4368 | function d3_geo_circleInterpolate(radius, precision) { |
| 4369 | var cr = Math.cos(radius), sr = Math.sin(radius); |
| 4370 | return function(from, to, direction, listener) { |
| 4371 | var step = direction * precision; |
| 4372 | if (from != null) { |
| 4373 | from = d3_geo_circleAngle(cr, from); |
| 4374 | to = d3_geo_circleAngle(cr, to); |
| 4375 | if (direction > 0 ? from < to : from > to) from += direction * τ; |
| 4376 | } else { |
| 4377 | from = radius + direction * τ; |
| 4378 | to = radius - .5 * step; |
| 4379 | } |
| 4380 | for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) { |
| 4381 | listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]); |
| 4382 | } |
| 4383 | }; |
| 4384 | } |
| 4385 | function d3_geo_circleAngle(cr, point) { |
| 4386 | var a = d3_geo_cartesian(point); |
| 4387 | a[0] -= cr; |
| 4388 | d3_geo_cartesianNormalize(a); |
| 4389 | var angle = d3_acos(-a[1]); |
| 4390 | return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI); |
| 4391 | } |
| 4392 | d3.geo.distance = function(a, b) { |
| 4393 | 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; |
| 4394 | 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Δλ); |
| 4395 | }; |
| 4396 | d3.geo.graticule = function() { |
| 4397 | var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5; |
| 4398 | function graticule() { |
| 4399 | return { |
| 4400 | type: "MultiLineString", |
| 4401 | coordinates: lines() |
| 4402 | }; |
| 4403 | } |
| 4404 | function lines() { |
| 4405 | 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) { |
| 4406 | return abs(x % DX) > ε; |
| 4407 | }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) { |
| 4408 | return abs(y % DY) > ε; |
| 4409 | }).map(y)); |
| 4410 | } |
| 4411 | graticule.lines = function() { |
| 4412 | return lines().map(function(coordinates) { |
| 4413 | return { |
| 4414 | type: "LineString", |
| 4415 | coordinates: coordinates |
| 4416 | }; |
| 4417 | }); |
| 4418 | }; |
| 4419 | graticule.outline = function() { |
| 4420 | return { |
| 4421 | type: "Polygon", |
| 4422 | coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ] |
| 4423 | }; |
| 4424 | }; |
| 4425 | graticule.extent = function(_) { |
| 4426 | if (!arguments.length) return graticule.minorExtent(); |
| 4427 | return graticule.majorExtent(_).minorExtent(_); |
| 4428 | }; |
| 4429 | graticule.majorExtent = function(_) { |
| 4430 | if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ]; |
| 4431 | X0 = +_[0][0], X1 = +_[1][0]; |
| 4432 | Y0 = +_[0][1], Y1 = +_[1][1]; |
| 4433 | if (X0 > X1) _ = X0, X0 = X1, X1 = _; |
| 4434 | if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _; |
| 4435 | return graticule.precision(precision); |
| 4436 | }; |
| 4437 | graticule.minorExtent = function(_) { |
| 4438 | if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ]; |
| 4439 | x0 = +_[0][0], x1 = +_[1][0]; |
| 4440 | y0 = +_[0][1], y1 = +_[1][1]; |
| 4441 | if (x0 > x1) _ = x0, x0 = x1, x1 = _; |
| 4442 | if (y0 > y1) _ = y0, y0 = y1, y1 = _; |
| 4443 | return graticule.precision(precision); |
| 4444 | }; |
| 4445 | graticule.step = function(_) { |
| 4446 | if (!arguments.length) return graticule.minorStep(); |
| 4447 | return graticule.majorStep(_).minorStep(_); |
| 4448 | }; |
| 4449 | graticule.majorStep = function(_) { |
| 4450 | if (!arguments.length) return [ DX, DY ]; |
| 4451 | DX = +_[0], DY = +_[1]; |
| 4452 | return graticule; |
| 4453 | }; |
| 4454 | graticule.minorStep = function(_) { |
| 4455 | if (!arguments.length) return [ dx, dy ]; |
| 4456 | dx = +_[0], dy = +_[1]; |
| 4457 | return graticule; |
| 4458 | }; |
| 4459 | graticule.precision = function(_) { |
| 4460 | if (!arguments.length) return precision; |
| 4461 | precision = +_; |
| 4462 | x = d3_geo_graticuleX(y0, y1, 90); |
| 4463 | y = d3_geo_graticuleY(x0, x1, precision); |
| 4464 | X = d3_geo_graticuleX(Y0, Y1, 90); |
| 4465 | Y = d3_geo_graticuleY(X0, X1, precision); |
| 4466 | return graticule; |
| 4467 | }; |
| 4468 | return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]); |
| 4469 | }; |
| 4470 | function d3_geo_graticuleX(y0, y1, dy) { |
| 4471 | var y = d3.range(y0, y1 - ε, dy).concat(y1); |
| 4472 | return function(x) { |
| 4473 | return y.map(function(y) { |
| 4474 | return [ x, y ]; |
| 4475 | }); |
| 4476 | }; |
| 4477 | } |
| 4478 | function d3_geo_graticuleY(x0, x1, dx) { |
| 4479 | var x = d3.range(x0, x1 - ε, dx).concat(x1); |
| 4480 | return function(y) { |
| 4481 | return x.map(function(x) { |
| 4482 | return [ x, y ]; |
| 4483 | }); |
| 4484 | }; |
| 4485 | } |
| 4486 | function d3_source(d) { |
| 4487 | return d.source; |
| 4488 | } |
| 4489 | function d3_target(d) { |
| 4490 | return d.target; |
| 4491 | } |
| 4492 | d3.geo.greatArc = function() { |
| 4493 | var source = d3_source, source_, target = d3_target, target_; |
| 4494 | function greatArc() { |
| 4495 | return { |
| 4496 | type: "LineString", |
| 4497 | coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ] |
| 4498 | }; |
| 4499 | } |
| 4500 | greatArc.distance = function() { |
| 4501 | return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments)); |
| 4502 | }; |
| 4503 | greatArc.source = function(_) { |
| 4504 | if (!arguments.length) return source; |
| 4505 | source = _, source_ = typeof _ === "function" ? null : _; |
| 4506 | return greatArc; |
| 4507 | }; |
| 4508 | greatArc.target = function(_) { |
| 4509 | if (!arguments.length) return target; |
| 4510 | target = _, target_ = typeof _ === "function" ? null : _; |
| 4511 | return greatArc; |
| 4512 | }; |
| 4513 | greatArc.precision = function() { |
| 4514 | return arguments.length ? greatArc : 0; |
| 4515 | }; |
| 4516 | return greatArc; |
| 4517 | }; |
| 4518 | d3.geo.interpolate = function(source, target) { |
| 4519 | return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians); |
| 4520 | }; |
| 4521 | function d3_geo_interpolate(x0, y0, x1, y1) { |
| 4522 | 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); |
| 4523 | var interpolate = d ? function(t) { |
| 4524 | 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; |
| 4525 | return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ]; |
| 4526 | } : function() { |
| 4527 | return [ x0 * d3_degrees, y0 * d3_degrees ]; |
| 4528 | }; |
| 4529 | interpolate.distance = d; |
| 4530 | return interpolate; |
| 4531 | } |
| 4532 | d3.geo.length = function(object) { |
| 4533 | d3_geo_lengthSum = 0; |
| 4534 | d3.geo.stream(object, d3_geo_length); |
| 4535 | return d3_geo_lengthSum; |
| 4536 | }; |
| 4537 | var d3_geo_lengthSum; |
| 4538 | var d3_geo_length = { |
| 4539 | sphere: d3_noop, |
| 4540 | point: d3_noop, |
| 4541 | lineStart: d3_geo_lengthLineStart, |
| 4542 | lineEnd: d3_noop, |
| 4543 | polygonStart: d3_noop, |
| 4544 | polygonEnd: d3_noop |
| 4545 | }; |
| 4546 | function d3_geo_lengthLineStart() { |
| 4547 | var λ0, sinφ0, cosφ0; |
| 4548 | d3_geo_length.point = function(λ, φ) { |
| 4549 | λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ); |
| 4550 | d3_geo_length.point = nextPoint; |
| 4551 | }; |
| 4552 | d3_geo_length.lineEnd = function() { |
| 4553 | d3_geo_length.point = d3_geo_length.lineEnd = d3_noop; |
| 4554 | }; |
| 4555 | function nextPoint(λ, φ) { |
| 4556 | var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t); |
| 4557 | 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Δλ); |
| 4558 | λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ; |
| 4559 | } |
| 4560 | } |
| 4561 | function d3_geo_azimuthal(scale, angle) { |
| 4562 | function azimuthal(λ, φ) { |
| 4563 | var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ); |
| 4564 | return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ]; |
| 4565 | } |
| 4566 | azimuthal.invert = function(x, y) { |
| 4567 | var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c); |
| 4568 | return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ]; |
| 4569 | }; |
| 4570 | return azimuthal; |
| 4571 | } |
| 4572 | var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) { |
| 4573 | return Math.sqrt(2 / (1 + cosλcosφ)); |
| 4574 | }, function(ρ) { |
| 4575 | return 2 * Math.asin(ρ / 2); |
| 4576 | }); |
| 4577 | (d3.geo.azimuthalEqualArea = function() { |
| 4578 | return d3_geo_projection(d3_geo_azimuthalEqualArea); |
| 4579 | }).raw = d3_geo_azimuthalEqualArea; |
| 4580 | var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) { |
| 4581 | var c = Math.acos(cosλcosφ); |
| 4582 | return c && c / Math.sin(c); |
| 4583 | }, d3_identity); |
| 4584 | (d3.geo.azimuthalEquidistant = function() { |
| 4585 | return d3_geo_projection(d3_geo_azimuthalEquidistant); |
| 4586 | }).raw = d3_geo_azimuthalEquidistant; |
| 4587 | function d3_geo_conicConformal(φ0, φ1) { |
| 4588 | var cosφ0 = Math.cos(φ0), t = function(φ) { |
| 4589 | return Math.tan(π / 4 + φ / 2); |
| 4590 | }, 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; |
| 4591 | if (!n) return d3_geo_mercator; |
| 4592 | function forward(λ, φ) { |
| 4593 | if (F > 0) { |
| 4594 | if (φ < -halfπ + ε) φ = -halfπ + ε; |
| 4595 | } else { |
| 4596 | if (φ > halfπ - ε) φ = halfπ - ε; |
| 4597 | } |
| 4598 | var ρ = F / Math.pow(t(φ), n); |
| 4599 | return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ]; |
| 4600 | } |
| 4601 | forward.invert = function(x, y) { |
| 4602 | var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y); |
| 4603 | return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ]; |
| 4604 | }; |
| 4605 | return forward; |
| 4606 | } |
| 4607 | (d3.geo.conicConformal = function() { |
| 4608 | return d3_geo_conic(d3_geo_conicConformal); |
| 4609 | }).raw = d3_geo_conicConformal; |
| 4610 | function d3_geo_conicEquidistant(φ0, φ1) { |
| 4611 | var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0; |
| 4612 | if (abs(n) < ε) return d3_geo_equirectangular; |
| 4613 | function forward(λ, φ) { |
| 4614 | var ρ = G - φ; |
| 4615 | return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ]; |
| 4616 | } |
| 4617 | forward.invert = function(x, y) { |
| 4618 | var ρ0_y = G - y; |
| 4619 | return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ]; |
| 4620 | }; |
| 4621 | return forward; |
| 4622 | } |
| 4623 | (d3.geo.conicEquidistant = function() { |
| 4624 | return d3_geo_conic(d3_geo_conicEquidistant); |
| 4625 | }).raw = d3_geo_conicEquidistant; |
| 4626 | var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) { |
| 4627 | return 1 / cosλcosφ; |
| 4628 | }, Math.atan); |
| 4629 | (d3.geo.gnomonic = function() { |
| 4630 | return d3_geo_projection(d3_geo_gnomonic); |
| 4631 | }).raw = d3_geo_gnomonic; |
| 4632 | function d3_geo_mercator(λ, φ) { |
| 4633 | return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ]; |
| 4634 | } |
| 4635 | d3_geo_mercator.invert = function(x, y) { |
| 4636 | return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ]; |
| 4637 | }; |
| 4638 | function d3_geo_mercatorProjection(project) { |
| 4639 | var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto; |
| 4640 | m.scale = function() { |
| 4641 | var v = scale.apply(m, arguments); |
| 4642 | return v === m ? clipAuto ? m.clipExtent(null) : m : v; |
| 4643 | }; |
| 4644 | m.translate = function() { |
| 4645 | var v = translate.apply(m, arguments); |
| 4646 | return v === m ? clipAuto ? m.clipExtent(null) : m : v; |
| 4647 | }; |
| 4648 | m.clipExtent = function(_) { |
| 4649 | var v = clipExtent.apply(m, arguments); |
| 4650 | if (v === m) { |
| 4651 | if (clipAuto = _ == null) { |
| 4652 | var k = π * scale(), t = translate(); |
| 4653 | clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]); |
| 4654 | } |
| 4655 | } else if (clipAuto) { |
| 4656 | v = null; |
| 4657 | } |
| 4658 | return v; |
| 4659 | }; |
| 4660 | return m.clipExtent(null); |
| 4661 | } |
| 4662 | (d3.geo.mercator = function() { |
| 4663 | return d3_geo_mercatorProjection(d3_geo_mercator); |
| 4664 | }).raw = d3_geo_mercator; |
| 4665 | var d3_geo_orthographic = d3_geo_azimuthal(function() { |
| 4666 | return 1; |
| 4667 | }, Math.asin); |
| 4668 | (d3.geo.orthographic = function() { |
| 4669 | return d3_geo_projection(d3_geo_orthographic); |
| 4670 | }).raw = d3_geo_orthographic; |
| 4671 | var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) { |
| 4672 | return 1 / (1 + cosλcosφ); |
| 4673 | }, function(ρ) { |
| 4674 | return 2 * Math.atan(ρ); |
| 4675 | }); |
| 4676 | (d3.geo.stereographic = function() { |
| 4677 | return d3_geo_projection(d3_geo_stereographic); |
| 4678 | }).raw = d3_geo_stereographic; |
| 4679 | function d3_geo_transverseMercator(λ, φ) { |
| 4680 | return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ]; |
| 4681 | } |
| 4682 | d3_geo_transverseMercator.invert = function(x, y) { |
| 4683 | return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ]; |
| 4684 | }; |
| 4685 | (d3.geo.transverseMercator = function() { |
| 4686 | var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate; |
| 4687 | projection.center = function(_) { |
| 4688 | return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]); |
| 4689 | }; |
| 4690 | projection.rotate = function(_) { |
| 4691 | return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(), |
| 4692 | [ _[0], _[1], _[2] - 90 ]); |
| 4693 | }; |
| 4694 | return rotate([ 0, 0, 90 ]); |
| 4695 | }).raw = d3_geo_transverseMercator; |
| 4696 | d3.geom = {}; |
| 4697 | function d3_geom_pointX(d) { |
| 4698 | return d[0]; |
| 4699 | } |
| 4700 | function d3_geom_pointY(d) { |
| 4701 | return d[1]; |
| 4702 | } |
| 4703 | d3.geom.hull = function(vertices) { |
| 4704 | var x = d3_geom_pointX, y = d3_geom_pointY; |
| 4705 | if (arguments.length) return hull(vertices); |
| 4706 | function hull(data) { |
| 4707 | if (data.length < 3) return []; |
| 4708 | var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = []; |
| 4709 | for (i = 0; i < n; i++) { |
| 4710 | points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]); |
| 4711 | } |
| 4712 | points.sort(d3_geom_hullOrder); |
| 4713 | for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]); |
| 4714 | var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints); |
| 4715 | var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = []; |
| 4716 | for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]); |
| 4717 | for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]); |
| 4718 | return polygon; |
| 4719 | } |
| 4720 | hull.x = function(_) { |
| 4721 | return arguments.length ? (x = _, hull) : x; |
| 4722 | }; |
| 4723 | hull.y = function(_) { |
| 4724 | return arguments.length ? (y = _, hull) : y; |
| 4725 | }; |
| 4726 | return hull; |
| 4727 | }; |
| 4728 | function d3_geom_hullUpper(points) { |
| 4729 | var n = points.length, hull = [ 0, 1 ], hs = 2; |
| 4730 | for (var i = 2; i < n; i++) { |
| 4731 | while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs; |
| 4732 | hull[hs++] = i; |
| 4733 | } |
| 4734 | return hull.slice(0, hs); |
| 4735 | } |
| 4736 | function d3_geom_hullOrder(a, b) { |
| 4737 | return a[0] - b[0] || a[1] - b[1]; |
| 4738 | } |
| 4739 | d3.geom.polygon = function(coordinates) { |
| 4740 | d3_subclass(coordinates, d3_geom_polygonPrototype); |
| 4741 | return coordinates; |
| 4742 | }; |
| 4743 | var d3_geom_polygonPrototype = d3.geom.polygon.prototype = []; |
| 4744 | d3_geom_polygonPrototype.area = function() { |
| 4745 | var i = -1, n = this.length, a, b = this[n - 1], area = 0; |
| 4746 | while (++i < n) { |
| 4747 | a = b; |
| 4748 | b = this[i]; |
| 4749 | area += a[1] * b[0] - a[0] * b[1]; |
| 4750 | } |
| 4751 | return area * .5; |
| 4752 | }; |
| 4753 | d3_geom_polygonPrototype.centroid = function(k) { |
| 4754 | var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c; |
| 4755 | if (!arguments.length) k = -1 / (6 * this.area()); |
| 4756 | while (++i < n) { |
| 4757 | a = b; |
| 4758 | b = this[i]; |
| 4759 | c = a[0] * b[1] - b[0] * a[1]; |
| 4760 | x += (a[0] + b[0]) * c; |
| 4761 | y += (a[1] + b[1]) * c; |
| 4762 | } |
| 4763 | return [ x * k, y * k ]; |
| 4764 | }; |
| 4765 | d3_geom_polygonPrototype.clip = function(subject) { |
| 4766 | 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; |
| 4767 | while (++i < n) { |
| 4768 | input = subject.slice(); |
| 4769 | subject.length = 0; |
| 4770 | b = this[i]; |
| 4771 | c = input[(m = input.length - closed) - 1]; |
| 4772 | j = -1; |
| 4773 | while (++j < m) { |
| 4774 | d = input[j]; |
| 4775 | if (d3_geom_polygonInside(d, a, b)) { |
| 4776 | if (!d3_geom_polygonInside(c, a, b)) { |
| 4777 | subject.push(d3_geom_polygonIntersect(c, d, a, b)); |
| 4778 | } |
| 4779 | subject.push(d); |
| 4780 | } else if (d3_geom_polygonInside(c, a, b)) { |
| 4781 | subject.push(d3_geom_polygonIntersect(c, d, a, b)); |
| 4782 | } |
| 4783 | c = d; |
| 4784 | } |
| 4785 | if (closed) subject.push(subject[0]); |
| 4786 | a = b; |
| 4787 | } |
| 4788 | return subject; |
| 4789 | }; |
| 4790 | function d3_geom_polygonInside(p, a, b) { |
| 4791 | return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]); |
| 4792 | } |
| 4793 | function d3_geom_polygonIntersect(c, d, a, b) { |
| 4794 | 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); |
| 4795 | return [ x1 + ua * x21, y1 + ua * y21 ]; |
| 4796 | } |
| 4797 | function d3_geom_polygonClosed(coordinates) { |
| 4798 | var a = coordinates[0], b = coordinates[coordinates.length - 1]; |
| 4799 | return !(a[0] - b[0] || a[1] - b[1]); |
| 4800 | } |
| 4801 | var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = []; |
| 4802 | function d3_geom_voronoiBeach() { |
| 4803 | d3_geom_voronoiRedBlackNode(this); |
| 4804 | this.edge = this.site = this.circle = null; |
| 4805 | } |
| 4806 | function d3_geom_voronoiCreateBeach(site) { |
| 4807 | var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach(); |
| 4808 | beach.site = site; |
| 4809 | return beach; |
| 4810 | } |
| 4811 | function d3_geom_voronoiDetachBeach(beach) { |
| 4812 | d3_geom_voronoiDetachCircle(beach); |
| 4813 | d3_geom_voronoiBeaches.remove(beach); |
| 4814 | d3_geom_voronoiBeachPool.push(beach); |
| 4815 | d3_geom_voronoiRedBlackNode(beach); |
| 4816 | } |
| 4817 | function d3_geom_voronoiRemoveBeach(beach) { |
| 4818 | var circle = beach.circle, x = circle.x, y = circle.cy, vertex = { |
| 4819 | x: x, |
| 4820 | y: y |
| 4821 | }, previous = beach.P, next = beach.N, disappearing = [ beach ]; |
| 4822 | d3_geom_voronoiDetachBeach(beach); |
| 4823 | var lArc = previous; |
| 4824 | while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) { |
| 4825 | previous = lArc.P; |
| 4826 | disappearing.unshift(lArc); |
| 4827 | d3_geom_voronoiDetachBeach(lArc); |
| 4828 | lArc = previous; |
| 4829 | } |
| 4830 | disappearing.unshift(lArc); |
| 4831 | d3_geom_voronoiDetachCircle(lArc); |
| 4832 | var rArc = next; |
| 4833 | while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) { |
| 4834 | next = rArc.N; |
| 4835 | disappearing.push(rArc); |
| 4836 | d3_geom_voronoiDetachBeach(rArc); |
| 4837 | rArc = next; |
| 4838 | } |
| 4839 | disappearing.push(rArc); |
| 4840 | d3_geom_voronoiDetachCircle(rArc); |
| 4841 | var nArcs = disappearing.length, iArc; |
| 4842 | for (iArc = 1; iArc < nArcs; ++iArc) { |
| 4843 | rArc = disappearing[iArc]; |
| 4844 | lArc = disappearing[iArc - 1]; |
| 4845 | d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex); |
| 4846 | } |
| 4847 | lArc = disappearing[0]; |
| 4848 | rArc = disappearing[nArcs - 1]; |
| 4849 | rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex); |
| 4850 | d3_geom_voronoiAttachCircle(lArc); |
| 4851 | d3_geom_voronoiAttachCircle(rArc); |
| 4852 | } |
| 4853 | function d3_geom_voronoiAddBeach(site) { |
| 4854 | var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._; |
| 4855 | while (node) { |
| 4856 | dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x; |
| 4857 | if (dxl > ε) node = node.L; else { |
| 4858 | dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix); |
| 4859 | if (dxr > ε) { |
| 4860 | if (!node.R) { |
| 4861 | lArc = node; |
| 4862 | break; |
| 4863 | } |
| 4864 | node = node.R; |
| 4865 | } else { |
| 4866 | if (dxl > -ε) { |
| 4867 | lArc = node.P; |
| 4868 | rArc = node; |
| 4869 | } else if (dxr > -ε) { |
| 4870 | lArc = node; |
| 4871 | rArc = node.N; |
| 4872 | } else { |
| 4873 | lArc = rArc = node; |
| 4874 | } |
| 4875 | break; |
| 4876 | } |
| 4877 | } |
| 4878 | } |
| 4879 | var newArc = d3_geom_voronoiCreateBeach(site); |
| 4880 | d3_geom_voronoiBeaches.insert(lArc, newArc); |
| 4881 | if (!lArc && !rArc) return; |
| 4882 | if (lArc === rArc) { |
| 4883 | d3_geom_voronoiDetachCircle(lArc); |
| 4884 | rArc = d3_geom_voronoiCreateBeach(lArc.site); |
| 4885 | d3_geom_voronoiBeaches.insert(newArc, rArc); |
| 4886 | newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); |
| 4887 | d3_geom_voronoiAttachCircle(lArc); |
| 4888 | d3_geom_voronoiAttachCircle(rArc); |
| 4889 | return; |
| 4890 | } |
| 4891 | if (!rArc) { |
| 4892 | newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); |
| 4893 | return; |
| 4894 | } |
| 4895 | d3_geom_voronoiDetachCircle(lArc); |
| 4896 | d3_geom_voronoiDetachCircle(rArc); |
| 4897 | 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 = { |
| 4898 | x: (cy * hb - by * hc) / d + ax, |
| 4899 | y: (bx * hc - cx * hb) / d + ay |
| 4900 | }; |
| 4901 | d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex); |
| 4902 | newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex); |
| 4903 | rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex); |
| 4904 | d3_geom_voronoiAttachCircle(lArc); |
| 4905 | d3_geom_voronoiAttachCircle(rArc); |
| 4906 | } |
| 4907 | function d3_geom_voronoiLeftBreakPoint(arc, directrix) { |
| 4908 | var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix; |
| 4909 | if (!pby2) return rfocx; |
| 4910 | var lArc = arc.P; |
| 4911 | if (!lArc) return -Infinity; |
| 4912 | site = lArc.site; |
| 4913 | var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix; |
| 4914 | if (!plby2) return lfocx; |
| 4915 | var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2; |
| 4916 | if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx; |
| 4917 | return (rfocx + lfocx) / 2; |
| 4918 | } |
| 4919 | function d3_geom_voronoiRightBreakPoint(arc, directrix) { |
| 4920 | var rArc = arc.N; |
| 4921 | if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix); |
| 4922 | var site = arc.site; |
| 4923 | return site.y === directrix ? site.x : Infinity; |
| 4924 | } |
| 4925 | function d3_geom_voronoiCell(site) { |
| 4926 | this.site = site; |
| 4927 | this.edges = []; |
| 4928 | } |
| 4929 | d3_geom_voronoiCell.prototype.prepare = function() { |
| 4930 | var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge; |
| 4931 | while (iHalfEdge--) { |
| 4932 | edge = halfEdges[iHalfEdge].edge; |
| 4933 | if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1); |
| 4934 | } |
| 4935 | halfEdges.sort(d3_geom_voronoiHalfEdgeOrder); |
| 4936 | return halfEdges.length; |
| 4937 | }; |
| 4938 | function d3_geom_voronoiCloseCells(extent) { |
| 4939 | 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; |
| 4940 | while (iCell--) { |
| 4941 | cell = cells[iCell]; |
| 4942 | if (!cell || !cell.prepare()) continue; |
| 4943 | halfEdges = cell.edges; |
| 4944 | nHalfEdges = halfEdges.length; |
| 4945 | iHalfEdge = 0; |
| 4946 | while (iHalfEdge < nHalfEdges) { |
| 4947 | end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y; |
| 4948 | start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y; |
| 4949 | if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) { |
| 4950 | halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? { |
| 4951 | x: x0, |
| 4952 | y: abs(x2 - x0) < ε ? y2 : y1 |
| 4953 | } : abs(y3 - y1) < ε && x1 - x3 > ε ? { |
| 4954 | x: abs(y2 - y1) < ε ? x2 : x1, |
| 4955 | y: y1 |
| 4956 | } : abs(x3 - x1) < ε && y3 - y0 > ε ? { |
| 4957 | x: x1, |
| 4958 | y: abs(x2 - x1) < ε ? y2 : y0 |
| 4959 | } : abs(y3 - y0) < ε && x3 - x0 > ε ? { |
| 4960 | x: abs(y2 - y0) < ε ? x2 : x0, |
| 4961 | y: y0 |
| 4962 | } : null), cell.site, null)); |
| 4963 | ++nHalfEdges; |
| 4964 | } |
| 4965 | } |
| 4966 | } |
| 4967 | } |
| 4968 | function d3_geom_voronoiHalfEdgeOrder(a, b) { |
| 4969 | return b.angle - a.angle; |
| 4970 | } |
| 4971 | function d3_geom_voronoiCircle() { |
| 4972 | d3_geom_voronoiRedBlackNode(this); |
| 4973 | this.x = this.y = this.arc = this.site = this.cy = null; |
| 4974 | } |
| 4975 | function d3_geom_voronoiAttachCircle(arc) { |
| 4976 | var lArc = arc.P, rArc = arc.N; |
| 4977 | if (!lArc || !rArc) return; |
| 4978 | var lSite = lArc.site, cSite = arc.site, rSite = rArc.site; |
| 4979 | if (lSite === rSite) return; |
| 4980 | var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by; |
| 4981 | var d = 2 * (ax * cy - ay * cx); |
| 4982 | if (d >= -ε2) return; |
| 4983 | 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; |
| 4984 | var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle(); |
| 4985 | circle.arc = arc; |
| 4986 | circle.site = cSite; |
| 4987 | circle.x = x + bx; |
| 4988 | circle.y = cy + Math.sqrt(x * x + y * y); |
| 4989 | circle.cy = cy; |
| 4990 | arc.circle = circle; |
| 4991 | var before = null, node = d3_geom_voronoiCircles._; |
| 4992 | while (node) { |
| 4993 | if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) { |
| 4994 | if (node.L) node = node.L; else { |
| 4995 | before = node.P; |
| 4996 | break; |
| 4997 | } |
| 4998 | } else { |
| 4999 | if (node.R) node = node.R; else { |
| 5000 | before = node; |
| 5001 | break; |
| 5002 | } |
| 5003 | } |
| 5004 | } |
| 5005 | d3_geom_voronoiCircles.insert(before, circle); |
| 5006 | if (!before) d3_geom_voronoiFirstCircle = circle; |
| 5007 | } |
| 5008 | function d3_geom_voronoiDetachCircle(arc) { |
| 5009 | var circle = arc.circle; |
| 5010 | if (circle) { |
| 5011 | if (!circle.P) d3_geom_voronoiFirstCircle = circle.N; |
| 5012 | d3_geom_voronoiCircles.remove(circle); |
| 5013 | d3_geom_voronoiCirclePool.push(circle); |
| 5014 | d3_geom_voronoiRedBlackNode(circle); |
| 5015 | arc.circle = null; |
| 5016 | } |
| 5017 | } |
| 5018 | function d3_geom_voronoiClipEdges(extent) { |
| 5019 | 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; |
| 5020 | while (i--) { |
| 5021 | e = edges[i]; |
| 5022 | if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) { |
| 5023 | e.a = e.b = null; |
| 5024 | edges.splice(i, 1); |
| 5025 | } |
| 5026 | } |
| 5027 | } |
| 5028 | function d3_geom_voronoiConnectEdge(edge, extent) { |
| 5029 | var vb = edge.b; |
| 5030 | if (vb) return true; |
| 5031 | 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; |
| 5032 | if (ry === ly) { |
| 5033 | if (fx < x0 || fx >= x1) return; |
| 5034 | if (lx > rx) { |
| 5035 | if (!va) va = { |
| 5036 | x: fx, |
| 5037 | y: y0 |
| 5038 | }; else if (va.y >= y1) return; |
| 5039 | vb = { |
| 5040 | x: fx, |
| 5041 | y: y1 |
| 5042 | }; |
| 5043 | } else { |
| 5044 | if (!va) va = { |
| 5045 | x: fx, |
| 5046 | y: y1 |
| 5047 | }; else if (va.y < y0) return; |
| 5048 | vb = { |
| 5049 | x: fx, |
| 5050 | y: y0 |
| 5051 | }; |
| 5052 | } |
| 5053 | } else { |
| 5054 | fm = (lx - rx) / (ry - ly); |
| 5055 | fb = fy - fm * fx; |
| 5056 | if (fm < -1 || fm > 1) { |
| 5057 | if (lx > rx) { |
| 5058 | if (!va) va = { |
| 5059 | x: (y0 - fb) / fm, |
| 5060 | y: y0 |
| 5061 | }; else if (va.y >= y1) return; |
| 5062 | vb = { |
| 5063 | x: (y1 - fb) / fm, |
| 5064 | y: y1 |
| 5065 | }; |
| 5066 | } else { |
| 5067 | if (!va) va = { |
| 5068 | x: (y1 - fb) / fm, |
| 5069 | y: y1 |
| 5070 | }; else if (va.y < y0) return; |
| 5071 | vb = { |
| 5072 | x: (y0 - fb) / fm, |
| 5073 | y: y0 |
| 5074 | }; |
| 5075 | } |
| 5076 | } else { |
| 5077 | if (ly < ry) { |
| 5078 | if (!va) va = { |
| 5079 | x: x0, |
| 5080 | y: fm * x0 + fb |
| 5081 | }; else if (va.x >= x1) return; |
| 5082 | vb = { |
| 5083 | x: x1, |
| 5084 | y: fm * x1 + fb |
| 5085 | }; |
| 5086 | } else { |
| 5087 | if (!va) va = { |
| 5088 | x: x1, |
| 5089 | y: fm * x1 + fb |
| 5090 | }; else if (va.x < x0) return; |
| 5091 | vb = { |
| 5092 | x: x0, |
| 5093 | y: fm * x0 + fb |
| 5094 | }; |
| 5095 | } |
| 5096 | } |
| 5097 | } |
| 5098 | edge.a = va; |
| 5099 | edge.b = vb; |
| 5100 | return true; |
| 5101 | } |
| 5102 | function d3_geom_voronoiEdge(lSite, rSite) { |
| 5103 | this.l = lSite; |
| 5104 | this.r = rSite; |
| 5105 | this.a = this.b = null; |
| 5106 | } |
| 5107 | function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) { |
| 5108 | var edge = new d3_geom_voronoiEdge(lSite, rSite); |
| 5109 | d3_geom_voronoiEdges.push(edge); |
| 5110 | if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va); |
| 5111 | if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb); |
| 5112 | d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite)); |
| 5113 | d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite)); |
| 5114 | return edge; |
| 5115 | } |
| 5116 | function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) { |
| 5117 | var edge = new d3_geom_voronoiEdge(lSite, null); |
| 5118 | edge.a = va; |
| 5119 | edge.b = vb; |
| 5120 | d3_geom_voronoiEdges.push(edge); |
| 5121 | return edge; |
| 5122 | } |
| 5123 | function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) { |
| 5124 | if (!edge.a && !edge.b) { |
| 5125 | edge.a = vertex; |
| 5126 | edge.l = lSite; |
| 5127 | edge.r = rSite; |
| 5128 | } else if (edge.l === rSite) { |
| 5129 | edge.b = vertex; |
| 5130 | } else { |
| 5131 | edge.a = vertex; |
| 5132 | } |
| 5133 | } |
| 5134 | function d3_geom_voronoiHalfEdge(edge, lSite, rSite) { |
| 5135 | var va = edge.a, vb = edge.b; |
| 5136 | this.edge = edge; |
| 5137 | this.site = lSite; |
| 5138 | 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); |
| 5139 | } |
| 5140 | d3_geom_voronoiHalfEdge.prototype = { |
| 5141 | start: function() { |
| 5142 | return this.edge.l === this.site ? this.edge.a : this.edge.b; |
| 5143 | }, |
| 5144 | end: function() { |
| 5145 | return this.edge.l === this.site ? this.edge.b : this.edge.a; |
| 5146 | } |
| 5147 | }; |
| 5148 | function d3_geom_voronoiRedBlackTree() { |
| 5149 | this._ = null; |
| 5150 | } |
| 5151 | function d3_geom_voronoiRedBlackNode(node) { |
| 5152 | node.U = node.C = node.L = node.R = node.P = node.N = null; |
| 5153 | } |
| 5154 | d3_geom_voronoiRedBlackTree.prototype = { |
| 5155 | insert: function(after, node) { |
| 5156 | var parent, grandpa, uncle; |
| 5157 | if (after) { |
| 5158 | node.P = after; |
| 5159 | node.N = after.N; |
| 5160 | if (after.N) after.N.P = node; |
| 5161 | after.N = node; |
| 5162 | if (after.R) { |
| 5163 | after = after.R; |
| 5164 | while (after.L) after = after.L; |
| 5165 | after.L = node; |
| 5166 | } else { |
| 5167 | after.R = node; |
| 5168 | } |
| 5169 | parent = after; |
| 5170 | } else if (this._) { |
| 5171 | after = d3_geom_voronoiRedBlackFirst(this._); |
| 5172 | node.P = null; |
| 5173 | node.N = after; |
| 5174 | after.P = after.L = node; |
| 5175 | parent = after; |
| 5176 | } else { |
| 5177 | node.P = node.N = null; |
| 5178 | this._ = node; |
| 5179 | parent = null; |
| 5180 | } |
| 5181 | node.L = node.R = null; |
| 5182 | node.U = parent; |
| 5183 | node.C = true; |
| 5184 | after = node; |
| 5185 | while (parent && parent.C) { |
| 5186 | grandpa = parent.U; |
| 5187 | if (parent === grandpa.L) { |
| 5188 | uncle = grandpa.R; |
| 5189 | if (uncle && uncle.C) { |
| 5190 | parent.C = uncle.C = false; |
| 5191 | grandpa.C = true; |
| 5192 | after = grandpa; |
| 5193 | } else { |
| 5194 | if (after === parent.R) { |
| 5195 | d3_geom_voronoiRedBlackRotateLeft(this, parent); |
| 5196 | after = parent; |
| 5197 | parent = after.U; |
| 5198 | } |
| 5199 | parent.C = false; |
| 5200 | grandpa.C = true; |
| 5201 | d3_geom_voronoiRedBlackRotateRight(this, grandpa); |
| 5202 | } |
| 5203 | } else { |
| 5204 | uncle = grandpa.L; |
| 5205 | if (uncle && uncle.C) { |
| 5206 | parent.C = uncle.C = false; |
| 5207 | grandpa.C = true; |
| 5208 | after = grandpa; |
| 5209 | } else { |
| 5210 | if (after === parent.L) { |
| 5211 | d3_geom_voronoiRedBlackRotateRight(this, parent); |
| 5212 | after = parent; |
| 5213 | parent = after.U; |
| 5214 | } |
| 5215 | parent.C = false; |
| 5216 | grandpa.C = true; |
| 5217 | d3_geom_voronoiRedBlackRotateLeft(this, grandpa); |
| 5218 | } |
| 5219 | } |
| 5220 | parent = after.U; |
| 5221 | } |
| 5222 | this._.C = false; |
| 5223 | }, |
| 5224 | remove: function(node) { |
| 5225 | if (node.N) node.N.P = node.P; |
| 5226 | if (node.P) node.P.N = node.N; |
| 5227 | node.N = node.P = null; |
| 5228 | var parent = node.U, sibling, left = node.L, right = node.R, next, red; |
| 5229 | if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right); |
| 5230 | if (parent) { |
| 5231 | if (parent.L === node) parent.L = next; else parent.R = next; |
| 5232 | } else { |
| 5233 | this._ = next; |
| 5234 | } |
| 5235 | if (left && right) { |
| 5236 | red = next.C; |
| 5237 | next.C = node.C; |
| 5238 | next.L = left; |
| 5239 | left.U = next; |
| 5240 | if (next !== right) { |
| 5241 | parent = next.U; |
| 5242 | next.U = node.U; |
| 5243 | node = next.R; |
| 5244 | parent.L = node; |
| 5245 | next.R = right; |
| 5246 | right.U = next; |
| 5247 | } else { |
| 5248 | next.U = parent; |
| 5249 | parent = next; |
| 5250 | node = next.R; |
| 5251 | } |
| 5252 | } else { |
| 5253 | red = node.C; |
| 5254 | node = next; |
| 5255 | } |
| 5256 | if (node) node.U = parent; |
| 5257 | if (red) return; |
| 5258 | if (node && node.C) { |
| 5259 | node.C = false; |
| 5260 | return; |
| 5261 | } |
| 5262 | do { |
| 5263 | if (node === this._) break; |
| 5264 | if (node === parent.L) { |
| 5265 | sibling = parent.R; |
| 5266 | if (sibling.C) { |
| 5267 | sibling.C = false; |
| 5268 | parent.C = true; |
| 5269 | d3_geom_voronoiRedBlackRotateLeft(this, parent); |
| 5270 | sibling = parent.R; |
| 5271 | } |
| 5272 | if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) { |
| 5273 | if (!sibling.R || !sibling.R.C) { |
| 5274 | sibling.L.C = false; |
| 5275 | sibling.C = true; |
| 5276 | d3_geom_voronoiRedBlackRotateRight(this, sibling); |
| 5277 | sibling = parent.R; |
| 5278 | } |
| 5279 | sibling.C = parent.C; |
| 5280 | parent.C = sibling.R.C = false; |
| 5281 | d3_geom_voronoiRedBlackRotateLeft(this, parent); |
| 5282 | node = this._; |
| 5283 | break; |
| 5284 | } |
| 5285 | } else { |
| 5286 | sibling = parent.L; |
| 5287 | if (sibling.C) { |
| 5288 | sibling.C = false; |
| 5289 | parent.C = true; |
| 5290 | d3_geom_voronoiRedBlackRotateRight(this, parent); |
| 5291 | sibling = parent.L; |
| 5292 | } |
| 5293 | if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) { |
| 5294 | if (!sibling.L || !sibling.L.C) { |
| 5295 | sibling.R.C = false; |
| 5296 | sibling.C = true; |
| 5297 | d3_geom_voronoiRedBlackRotateLeft(this, sibling); |
| 5298 | sibling = parent.L; |
| 5299 | } |
| 5300 | sibling.C = parent.C; |
| 5301 | parent.C = sibling.L.C = false; |
| 5302 | d3_geom_voronoiRedBlackRotateRight(this, parent); |
| 5303 | node = this._; |
| 5304 | break; |
| 5305 | } |
| 5306 | } |
| 5307 | sibling.C = true; |
| 5308 | node = parent; |
| 5309 | parent = parent.U; |
| 5310 | } while (!node.C); |
| 5311 | if (node) node.C = false; |
| 5312 | } |
| 5313 | }; |
| 5314 | function d3_geom_voronoiRedBlackRotateLeft(tree, node) { |
| 5315 | var p = node, q = node.R, parent = p.U; |
| 5316 | if (parent) { |
| 5317 | if (parent.L === p) parent.L = q; else parent.R = q; |
| 5318 | } else { |
| 5319 | tree._ = q; |
| 5320 | } |
| 5321 | q.U = parent; |
| 5322 | p.U = q; |
| 5323 | p.R = q.L; |
| 5324 | if (p.R) p.R.U = p; |
| 5325 | q.L = p; |
| 5326 | } |
| 5327 | function d3_geom_voronoiRedBlackRotateRight(tree, node) { |
| 5328 | var p = node, q = node.L, parent = p.U; |
| 5329 | if (parent) { |
| 5330 | if (parent.L === p) parent.L = q; else parent.R = q; |
| 5331 | } else { |
| 5332 | tree._ = q; |
| 5333 | } |
| 5334 | q.U = parent; |
| 5335 | p.U = q; |
| 5336 | p.L = q.R; |
| 5337 | if (p.L) p.L.U = p; |
| 5338 | q.R = p; |
| 5339 | } |
| 5340 | function d3_geom_voronoiRedBlackFirst(node) { |
| 5341 | while (node.L) node = node.L; |
| 5342 | return node; |
| 5343 | } |
| 5344 | function d3_geom_voronoi(sites, bbox) { |
| 5345 | var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle; |
| 5346 | d3_geom_voronoiEdges = []; |
| 5347 | d3_geom_voronoiCells = new Array(sites.length); |
| 5348 | d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree(); |
| 5349 | d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree(); |
| 5350 | while (true) { |
| 5351 | circle = d3_geom_voronoiFirstCircle; |
| 5352 | if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) { |
| 5353 | if (site.x !== x0 || site.y !== y0) { |
| 5354 | d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site); |
| 5355 | d3_geom_voronoiAddBeach(site); |
| 5356 | x0 = site.x, y0 = site.y; |
| 5357 | } |
| 5358 | site = sites.pop(); |
| 5359 | } else if (circle) { |
| 5360 | d3_geom_voronoiRemoveBeach(circle.arc); |
| 5361 | } else { |
| 5362 | break; |
| 5363 | } |
| 5364 | } |
| 5365 | if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox); |
| 5366 | var diagram = { |
| 5367 | cells: d3_geom_voronoiCells, |
| 5368 | edges: d3_geom_voronoiEdges |
| 5369 | }; |
| 5370 | d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null; |
| 5371 | return diagram; |
| 5372 | } |
| 5373 | function d3_geom_voronoiVertexOrder(a, b) { |
| 5374 | return b.y - a.y || b.x - a.x; |
| 5375 | } |
| 5376 | d3.geom.voronoi = function(points) { |
| 5377 | var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent; |
| 5378 | if (points) return voronoi(points); |
| 5379 | function voronoi(data) { |
| 5380 | var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1]; |
| 5381 | d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) { |
| 5382 | var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) { |
| 5383 | var s = e.start(); |
| 5384 | return [ s.x, s.y ]; |
| 5385 | }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : []; |
| 5386 | polygon.point = data[i]; |
| 5387 | }); |
| 5388 | return polygons; |
| 5389 | } |
| 5390 | function sites(data) { |
| 5391 | return data.map(function(d, i) { |
| 5392 | return { |
| 5393 | x: Math.round(fx(d, i) / ε) * ε, |
| 5394 | y: Math.round(fy(d, i) / ε) * ε, |
| 5395 | i: i |
| 5396 | }; |
| 5397 | }); |
| 5398 | } |
| 5399 | voronoi.links = function(data) { |
| 5400 | return d3_geom_voronoi(sites(data)).edges.filter(function(edge) { |
| 5401 | return edge.l && edge.r; |
| 5402 | }).map(function(edge) { |
| 5403 | return { |
| 5404 | source: data[edge.l.i], |
| 5405 | target: data[edge.r.i] |
| 5406 | }; |
| 5407 | }); |
| 5408 | }; |
| 5409 | voronoi.triangles = function(data) { |
| 5410 | var triangles = []; |
| 5411 | d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) { |
| 5412 | 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; |
| 5413 | while (++j < m) { |
| 5414 | e0 = e1; |
| 5415 | s0 = s1; |
| 5416 | e1 = edges[j].edge; |
| 5417 | s1 = e1.l === site ? e1.r : e1.l; |
| 5418 | if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) { |
| 5419 | triangles.push([ data[i], data[s0.i], data[s1.i] ]); |
| 5420 | } |
| 5421 | } |
| 5422 | }); |
| 5423 | return triangles; |
| 5424 | }; |
| 5425 | voronoi.x = function(_) { |
| 5426 | return arguments.length ? (fx = d3_functor(x = _), voronoi) : x; |
| 5427 | }; |
| 5428 | voronoi.y = function(_) { |
| 5429 | return arguments.length ? (fy = d3_functor(y = _), voronoi) : y; |
| 5430 | }; |
| 5431 | voronoi.clipExtent = function(_) { |
| 5432 | if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent; |
| 5433 | clipExtent = _ == null ? d3_geom_voronoiClipExtent : _; |
| 5434 | return voronoi; |
| 5435 | }; |
| 5436 | voronoi.size = function(_) { |
| 5437 | if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1]; |
| 5438 | return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]); |
| 5439 | }; |
| 5440 | return voronoi; |
| 5441 | }; |
| 5442 | var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ]; |
| 5443 | function d3_geom_voronoiTriangleArea(a, b, c) { |
| 5444 | return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y); |
| 5445 | } |
| 5446 | d3.geom.delaunay = function(vertices) { |
| 5447 | return d3.geom.voronoi().triangles(vertices); |
| 5448 | }; |
| 5449 | d3.geom.quadtree = function(points, x1, y1, x2, y2) { |
| 5450 | var x = d3_geom_pointX, y = d3_geom_pointY, compat; |
| 5451 | if (compat = arguments.length) { |
| 5452 | x = d3_geom_quadtreeCompatX; |
| 5453 | y = d3_geom_quadtreeCompatY; |
| 5454 | if (compat === 3) { |
| 5455 | y2 = y1; |
| 5456 | x2 = x1; |
| 5457 | y1 = x1 = 0; |
| 5458 | } |
| 5459 | return quadtree(points); |
| 5460 | } |
| 5461 | function quadtree(data) { |
| 5462 | var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_; |
| 5463 | if (x1 != null) { |
| 5464 | x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2; |
| 5465 | } else { |
| 5466 | x2_ = y2_ = -(x1_ = y1_ = Infinity); |
| 5467 | xs = [], ys = []; |
| 5468 | n = data.length; |
| 5469 | if (compat) for (i = 0; i < n; ++i) { |
| 5470 | d = data[i]; |
| 5471 | if (d.x < x1_) x1_ = d.x; |
| 5472 | if (d.y < y1_) y1_ = d.y; |
| 5473 | if (d.x > x2_) x2_ = d.x; |
| 5474 | if (d.y > y2_) y2_ = d.y; |
| 5475 | xs.push(d.x); |
| 5476 | ys.push(d.y); |
| 5477 | } else for (i = 0; i < n; ++i) { |
| 5478 | var x_ = +fx(d = data[i], i), y_ = +fy(d, i); |
| 5479 | if (x_ < x1_) x1_ = x_; |
| 5480 | if (y_ < y1_) y1_ = y_; |
| 5481 | if (x_ > x2_) x2_ = x_; |
| 5482 | if (y_ > y2_) y2_ = y_; |
| 5483 | xs.push(x_); |
| 5484 | ys.push(y_); |
| 5485 | } |
| 5486 | } |
| 5487 | var dx = x2_ - x1_, dy = y2_ - y1_; |
| 5488 | if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy; |
| 5489 | function insert(n, d, x, y, x1, y1, x2, y2) { |
| 5490 | if (isNaN(x) || isNaN(y)) return; |
| 5491 | if (n.leaf) { |
| 5492 | var nx = n.x, ny = n.y; |
| 5493 | if (nx != null) { |
| 5494 | if (abs(nx - x) + abs(ny - y) < .01) { |
| 5495 | insertChild(n, d, x, y, x1, y1, x2, y2); |
| 5496 | } else { |
| 5497 | var nPoint = n.point; |
| 5498 | n.x = n.y = n.point = null; |
| 5499 | insertChild(n, nPoint, nx, ny, x1, y1, x2, y2); |
| 5500 | insertChild(n, d, x, y, x1, y1, x2, y2); |
| 5501 | } |
| 5502 | } else { |
| 5503 | n.x = x, n.y = y, n.point = d; |
| 5504 | } |
| 5505 | } else { |
| 5506 | insertChild(n, d, x, y, x1, y1, x2, y2); |
| 5507 | } |
| 5508 | } |
| 5509 | function insertChild(n, d, x, y, x1, y1, x2, y2) { |
| 5510 | var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right; |
| 5511 | n.leaf = false; |
| 5512 | n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode()); |
| 5513 | if (right) x1 = sx; else x2 = sx; |
| 5514 | if (bottom) y1 = sy; else y2 = sy; |
| 5515 | insert(n, d, x, y, x1, y1, x2, y2); |
| 5516 | } |
| 5517 | var root = d3_geom_quadtreeNode(); |
| 5518 | root.add = function(d) { |
| 5519 | insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_); |
| 5520 | }; |
| 5521 | root.visit = function(f) { |
| 5522 | d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_); |
| 5523 | }; |
| 5524 | i = -1; |
| 5525 | if (x1 == null) { |
| 5526 | while (++i < n) { |
| 5527 | insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_); |
| 5528 | } |
| 5529 | --i; |
| 5530 | } else data.forEach(root.add); |
| 5531 | xs = ys = data = d = null; |
| 5532 | return root; |
| 5533 | } |
| 5534 | quadtree.x = function(_) { |
| 5535 | return arguments.length ? (x = _, quadtree) : x; |
| 5536 | }; |
| 5537 | quadtree.y = function(_) { |
| 5538 | return arguments.length ? (y = _, quadtree) : y; |
| 5539 | }; |
| 5540 | quadtree.extent = function(_) { |
| 5541 | if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ]; |
| 5542 | if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], |
| 5543 | y2 = +_[1][1]; |
| 5544 | return quadtree; |
| 5545 | }; |
| 5546 | quadtree.size = function(_) { |
| 5547 | if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ]; |
| 5548 | if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1]; |
| 5549 | return quadtree; |
| 5550 | }; |
| 5551 | return quadtree; |
| 5552 | }; |
| 5553 | function d3_geom_quadtreeCompatX(d) { |
| 5554 | return d.x; |
| 5555 | } |
| 5556 | function d3_geom_quadtreeCompatY(d) { |
| 5557 | return d.y; |
| 5558 | } |
| 5559 | function d3_geom_quadtreeNode() { |
| 5560 | return { |
| 5561 | leaf: true, |
| 5562 | nodes: [], |
| 5563 | point: null, |
| 5564 | x: null, |
| 5565 | y: null |
| 5566 | }; |
| 5567 | } |
| 5568 | function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) { |
| 5569 | if (!f(node, x1, y1, x2, y2)) { |
| 5570 | var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes; |
| 5571 | if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy); |
| 5572 | if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy); |
| 5573 | if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2); |
| 5574 | if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2); |
| 5575 | } |
| 5576 | } |
| 5577 | d3.interpolateRgb = d3_interpolateRgb; |
| 5578 | function d3_interpolateRgb(a, b) { |
| 5579 | a = d3.rgb(a); |
| 5580 | b = d3.rgb(b); |
| 5581 | var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab; |
| 5582 | return function(t) { |
| 5583 | 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)); |
| 5584 | }; |
| 5585 | } |
| 5586 | d3.interpolateObject = d3_interpolateObject; |
| 5587 | function d3_interpolateObject(a, b) { |
| 5588 | var i = {}, c = {}, k; |
| 5589 | for (k in a) { |
| 5590 | if (k in b) { |
| 5591 | i[k] = d3_interpolate(a[k], b[k]); |
| 5592 | } else { |
| 5593 | c[k] = a[k]; |
| 5594 | } |
| 5595 | } |
| 5596 | for (k in b) { |
| 5597 | if (!(k in a)) { |
| 5598 | c[k] = b[k]; |
| 5599 | } |
| 5600 | } |
| 5601 | return function(t) { |
| 5602 | for (k in i) c[k] = i[k](t); |
| 5603 | return c; |
| 5604 | }; |
| 5605 | } |
| 5606 | d3.interpolateNumber = d3_interpolateNumber; |
| 5607 | function d3_interpolateNumber(a, b) { |
| 5608 | b -= a = +a; |
| 5609 | return function(t) { |
| 5610 | return a + b * t; |
| 5611 | }; |
| 5612 | } |
| 5613 | d3.interpolateString = d3_interpolateString; |
| 5614 | function d3_interpolateString(a, b) { |
| 5615 | var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = []; |
| 5616 | a = a + "", b = b + ""; |
| 5617 | while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) { |
| 5618 | if ((bs = bm.index) > bi) { |
| 5619 | bs = b.slice(bi, bs); |
| 5620 | if (s[i]) s[i] += bs; else s[++i] = bs; |
| 5621 | } |
| 5622 | if ((am = am[0]) === (bm = bm[0])) { |
| 5623 | if (s[i]) s[i] += bm; else s[++i] = bm; |
| 5624 | } else { |
| 5625 | s[++i] = null; |
| 5626 | q.push({ |
| 5627 | i: i, |
| 5628 | x: d3_interpolateNumber(am, bm) |
| 5629 | }); |
| 5630 | } |
| 5631 | bi = d3_interpolate_numberB.lastIndex; |
| 5632 | } |
| 5633 | if (bi < b.length) { |
| 5634 | bs = b.slice(bi); |
| 5635 | if (s[i]) s[i] += bs; else s[++i] = bs; |
| 5636 | } |
| 5637 | return s.length < 2 ? q[0] ? (b = q[0].x, function(t) { |
| 5638 | return b(t) + ""; |
| 5639 | }) : function() { |
| 5640 | return b; |
| 5641 | } : (b = q.length, function(t) { |
| 5642 | for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t); |
| 5643 | return s.join(""); |
| 5644 | }); |
| 5645 | } |
| 5646 | var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g"); |
| 5647 | d3.interpolate = d3_interpolate; |
| 5648 | function d3_interpolate(a, b) { |
| 5649 | var i = d3.interpolators.length, f; |
| 5650 | while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ; |
| 5651 | return f; |
| 5652 | } |
| 5653 | d3.interpolators = [ function(a, b) { |
| 5654 | var t = typeof b; |
| 5655 | 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); |
| 5656 | } ]; |
| 5657 | d3.interpolateArray = d3_interpolateArray; |
| 5658 | function d3_interpolateArray(a, b) { |
| 5659 | var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i; |
| 5660 | for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i])); |
| 5661 | for (;i < na; ++i) c[i] = a[i]; |
| 5662 | for (;i < nb; ++i) c[i] = b[i]; |
| 5663 | return function(t) { |
| 5664 | for (i = 0; i < n0; ++i) c[i] = x[i](t); |
| 5665 | return c; |
| 5666 | }; |
| 5667 | } |
| 5668 | var d3_ease_default = function() { |
| 5669 | return d3_identity; |
| 5670 | }; |
| 5671 | var d3_ease = d3.map({ |
| 5672 | linear: d3_ease_default, |
| 5673 | poly: d3_ease_poly, |
| 5674 | quad: function() { |
| 5675 | return d3_ease_quad; |
| 5676 | }, |
| 5677 | cubic: function() { |
| 5678 | return d3_ease_cubic; |
| 5679 | }, |
| 5680 | sin: function() { |
| 5681 | return d3_ease_sin; |
| 5682 | }, |
| 5683 | exp: function() { |
| 5684 | return d3_ease_exp; |
| 5685 | }, |
| 5686 | circle: function() { |
| 5687 | return d3_ease_circle; |
| 5688 | }, |
| 5689 | elastic: d3_ease_elastic, |
| 5690 | back: d3_ease_back, |
| 5691 | bounce: function() { |
| 5692 | return d3_ease_bounce; |
| 5693 | } |
| 5694 | }); |
| 5695 | var d3_ease_mode = d3.map({ |
| 5696 | "in": d3_identity, |
| 5697 | out: d3_ease_reverse, |
| 5698 | "in-out": d3_ease_reflect, |
| 5699 | "out-in": function(f) { |
| 5700 | return d3_ease_reflect(d3_ease_reverse(f)); |
| 5701 | } |
| 5702 | }); |
| 5703 | d3.ease = function(name) { |
| 5704 | var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in"; |
| 5705 | t = d3_ease.get(t) || d3_ease_default; |
| 5706 | m = d3_ease_mode.get(m) || d3_identity; |
| 5707 | return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1)))); |
| 5708 | }; |
| 5709 | function d3_ease_clamp(f) { |
| 5710 | return function(t) { |
| 5711 | return t <= 0 ? 0 : t >= 1 ? 1 : f(t); |
| 5712 | }; |
| 5713 | } |
| 5714 | function d3_ease_reverse(f) { |
| 5715 | return function(t) { |
| 5716 | return 1 - f(1 - t); |
| 5717 | }; |
| 5718 | } |
| 5719 | function d3_ease_reflect(f) { |
| 5720 | return function(t) { |
| 5721 | return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t)); |
| 5722 | }; |
| 5723 | } |
| 5724 | function d3_ease_quad(t) { |
| 5725 | return t * t; |
| 5726 | } |
| 5727 | function d3_ease_cubic(t) { |
| 5728 | return t * t * t; |
| 5729 | } |
| 5730 | function d3_ease_cubicInOut(t) { |
| 5731 | if (t <= 0) return 0; |
| 5732 | if (t >= 1) return 1; |
| 5733 | var t2 = t * t, t3 = t2 * t; |
| 5734 | return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75); |
| 5735 | } |
| 5736 | function d3_ease_poly(e) { |
| 5737 | return function(t) { |
| 5738 | return Math.pow(t, e); |
| 5739 | }; |
| 5740 | } |
| 5741 | function d3_ease_sin(t) { |
| 5742 | return 1 - Math.cos(t * halfπ); |
| 5743 | } |
| 5744 | function d3_ease_exp(t) { |
| 5745 | return Math.pow(2, 10 * (t - 1)); |
| 5746 | } |
| 5747 | function d3_ease_circle(t) { |
| 5748 | return 1 - Math.sqrt(1 - t * t); |
| 5749 | } |
| 5750 | function d3_ease_elastic(a, p) { |
| 5751 | var s; |
| 5752 | if (arguments.length < 2) p = .45; |
| 5753 | if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4; |
| 5754 | return function(t) { |
| 5755 | return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p); |
| 5756 | }; |
| 5757 | } |
| 5758 | function d3_ease_back(s) { |
| 5759 | if (!s) s = 1.70158; |
| 5760 | return function(t) { |
| 5761 | return t * t * ((s + 1) * t - s); |
| 5762 | }; |
| 5763 | } |
| 5764 | function d3_ease_bounce(t) { |
| 5765 | 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; |
| 5766 | } |
| 5767 | d3.interpolateHcl = d3_interpolateHcl; |
| 5768 | function d3_interpolateHcl(a, b) { |
| 5769 | a = d3.hcl(a); |
| 5770 | b = d3.hcl(b); |
| 5771 | var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al; |
| 5772 | if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac; |
| 5773 | if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; |
| 5774 | return function(t) { |
| 5775 | return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + ""; |
| 5776 | }; |
| 5777 | } |
| 5778 | d3.interpolateHsl = d3_interpolateHsl; |
| 5779 | function d3_interpolateHsl(a, b) { |
| 5780 | a = d3.hsl(a); |
| 5781 | b = d3.hsl(b); |
| 5782 | var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al; |
| 5783 | if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as; |
| 5784 | if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; |
| 5785 | return function(t) { |
| 5786 | return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + ""; |
| 5787 | }; |
| 5788 | } |
| 5789 | d3.interpolateLab = d3_interpolateLab; |
| 5790 | function d3_interpolateLab(a, b) { |
| 5791 | a = d3.lab(a); |
| 5792 | b = d3.lab(b); |
| 5793 | var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab; |
| 5794 | return function(t) { |
| 5795 | return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + ""; |
| 5796 | }; |
| 5797 | } |
| 5798 | d3.interpolateRound = d3_interpolateRound; |
| 5799 | function d3_interpolateRound(a, b) { |
| 5800 | b -= a; |
| 5801 | return function(t) { |
| 5802 | return Math.round(a + b * t); |
| 5803 | }; |
| 5804 | } |
| 5805 | d3.transform = function(string) { |
| 5806 | var g = d3_document.createElementNS(d3.ns.prefix.svg, "g"); |
| 5807 | return (d3.transform = function(string) { |
| 5808 | if (string != null) { |
| 5809 | g.setAttribute("transform", string); |
| 5810 | var t = g.transform.baseVal.consolidate(); |
| 5811 | } |
| 5812 | return new d3_transform(t ? t.matrix : d3_transformIdentity); |
| 5813 | })(string); |
| 5814 | }; |
| 5815 | function d3_transform(m) { |
| 5816 | 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; |
| 5817 | if (r0[0] * r1[1] < r1[0] * r0[1]) { |
| 5818 | r0[0] *= -1; |
| 5819 | r0[1] *= -1; |
| 5820 | kx *= -1; |
| 5821 | kz *= -1; |
| 5822 | } |
| 5823 | this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees; |
| 5824 | this.translate = [ m.e, m.f ]; |
| 5825 | this.scale = [ kx, ky ]; |
| 5826 | this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0; |
| 5827 | } |
| 5828 | d3_transform.prototype.toString = function() { |
| 5829 | return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")"; |
| 5830 | }; |
| 5831 | function d3_transformDot(a, b) { |
| 5832 | return a[0] * b[0] + a[1] * b[1]; |
| 5833 | } |
| 5834 | function d3_transformNormalize(a) { |
| 5835 | var k = Math.sqrt(d3_transformDot(a, a)); |
| 5836 | if (k) { |
| 5837 | a[0] /= k; |
| 5838 | a[1] /= k; |
| 5839 | } |
| 5840 | return k; |
| 5841 | } |
| 5842 | function d3_transformCombine(a, b, k) { |
| 5843 | a[0] += k * b[0]; |
| 5844 | a[1] += k * b[1]; |
| 5845 | return a; |
| 5846 | } |
| 5847 | var d3_transformIdentity = { |
| 5848 | a: 1, |
| 5849 | b: 0, |
| 5850 | c: 0, |
| 5851 | d: 1, |
| 5852 | e: 0, |
| 5853 | f: 0 |
| 5854 | }; |
| 5855 | d3.interpolateTransform = d3_interpolateTransform; |
| 5856 | function d3_interpolateTransform(a, b) { |
| 5857 | 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; |
| 5858 | if (ta[0] != tb[0] || ta[1] != tb[1]) { |
| 5859 | s.push("translate(", null, ",", null, ")"); |
| 5860 | q.push({ |
| 5861 | i: 1, |
| 5862 | x: d3_interpolateNumber(ta[0], tb[0]) |
| 5863 | }, { |
| 5864 | i: 3, |
| 5865 | x: d3_interpolateNumber(ta[1], tb[1]) |
| 5866 | }); |
| 5867 | } else if (tb[0] || tb[1]) { |
| 5868 | s.push("translate(" + tb + ")"); |
| 5869 | } else { |
| 5870 | s.push(""); |
| 5871 | } |
| 5872 | if (ra != rb) { |
| 5873 | if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; |
| 5874 | q.push({ |
| 5875 | i: s.push(s.pop() + "rotate(", null, ")") - 2, |
| 5876 | x: d3_interpolateNumber(ra, rb) |
| 5877 | }); |
| 5878 | } else if (rb) { |
| 5879 | s.push(s.pop() + "rotate(" + rb + ")"); |
| 5880 | } |
| 5881 | if (wa != wb) { |
| 5882 | q.push({ |
| 5883 | i: s.push(s.pop() + "skewX(", null, ")") - 2, |
| 5884 | x: d3_interpolateNumber(wa, wb) |
| 5885 | }); |
| 5886 | } else if (wb) { |
| 5887 | s.push(s.pop() + "skewX(" + wb + ")"); |
| 5888 | } |
| 5889 | if (ka[0] != kb[0] || ka[1] != kb[1]) { |
| 5890 | n = s.push(s.pop() + "scale(", null, ",", null, ")"); |
| 5891 | q.push({ |
| 5892 | i: n - 4, |
| 5893 | x: d3_interpolateNumber(ka[0], kb[0]) |
| 5894 | }, { |
| 5895 | i: n - 2, |
| 5896 | x: d3_interpolateNumber(ka[1], kb[1]) |
| 5897 | }); |
| 5898 | } else if (kb[0] != 1 || kb[1] != 1) { |
| 5899 | s.push(s.pop() + "scale(" + kb + ")"); |
| 5900 | } |
| 5901 | n = q.length; |
| 5902 | return function(t) { |
| 5903 | var i = -1, o; |
| 5904 | while (++i < n) s[(o = q[i]).i] = o.x(t); |
| 5905 | return s.join(""); |
| 5906 | }; |
| 5907 | } |
| 5908 | function d3_uninterpolateNumber(a, b) { |
| 5909 | b = b - (a = +a) ? 1 / (b - a) : 0; |
| 5910 | return function(x) { |
| 5911 | return (x - a) * b; |
| 5912 | }; |
| 5913 | } |
| 5914 | function d3_uninterpolateClamp(a, b) { |
| 5915 | b = b - (a = +a) ? 1 / (b - a) : 0; |
| 5916 | return function(x) { |
| 5917 | return Math.max(0, Math.min(1, (x - a) * b)); |
| 5918 | }; |
| 5919 | } |
| 5920 | d3.layout = {}; |
| 5921 | d3.layout.bundle = function() { |
| 5922 | return function(links) { |
| 5923 | var paths = [], i = -1, n = links.length; |
| 5924 | while (++i < n) paths.push(d3_layout_bundlePath(links[i])); |
| 5925 | return paths; |
| 5926 | }; |
| 5927 | }; |
| 5928 | function d3_layout_bundlePath(link) { |
| 5929 | var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ]; |
| 5930 | while (start !== lca) { |
| 5931 | start = start.parent; |
| 5932 | points.push(start); |
| 5933 | } |
| 5934 | var k = points.length; |
| 5935 | while (end !== lca) { |
| 5936 | points.splice(k, 0, end); |
| 5937 | end = end.parent; |
| 5938 | } |
| 5939 | return points; |
| 5940 | } |
| 5941 | function d3_layout_bundleAncestors(node) { |
| 5942 | var ancestors = [], parent = node.parent; |
| 5943 | while (parent != null) { |
| 5944 | ancestors.push(node); |
| 5945 | node = parent; |
| 5946 | parent = parent.parent; |
| 5947 | } |
| 5948 | ancestors.push(node); |
| 5949 | return ancestors; |
| 5950 | } |
| 5951 | function d3_layout_bundleLeastCommonAncestor(a, b) { |
| 5952 | if (a === b) return a; |
| 5953 | var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null; |
| 5954 | while (aNode === bNode) { |
| 5955 | sharedNode = aNode; |
| 5956 | aNode = aNodes.pop(); |
| 5957 | bNode = bNodes.pop(); |
| 5958 | } |
| 5959 | return sharedNode; |
| 5960 | } |
| 5961 | d3.layout.chord = function() { |
| 5962 | var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords; |
| 5963 | function relayout() { |
| 5964 | var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j; |
| 5965 | chords = []; |
| 5966 | groups = []; |
| 5967 | k = 0, i = -1; |
| 5968 | while (++i < n) { |
| 5969 | x = 0, j = -1; |
| 5970 | while (++j < n) { |
| 5971 | x += matrix[i][j]; |
| 5972 | } |
| 5973 | groupSums.push(x); |
| 5974 | subgroupIndex.push(d3.range(n)); |
| 5975 | k += x; |
| 5976 | } |
| 5977 | if (sortGroups) { |
| 5978 | groupIndex.sort(function(a, b) { |
| 5979 | return sortGroups(groupSums[a], groupSums[b]); |
| 5980 | }); |
| 5981 | } |
| 5982 | if (sortSubgroups) { |
| 5983 | subgroupIndex.forEach(function(d, i) { |
| 5984 | d.sort(function(a, b) { |
| 5985 | return sortSubgroups(matrix[i][a], matrix[i][b]); |
| 5986 | }); |
| 5987 | }); |
| 5988 | } |
| 5989 | k = (τ - padding * n) / k; |
| 5990 | x = 0, i = -1; |
| 5991 | while (++i < n) { |
| 5992 | x0 = x, j = -1; |
| 5993 | while (++j < n) { |
| 5994 | var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k; |
| 5995 | subgroups[di + "-" + dj] = { |
| 5996 | index: di, |
| 5997 | subindex: dj, |
| 5998 | startAngle: a0, |
| 5999 | endAngle: a1, |
| 6000 | value: v |
| 6001 | }; |
| 6002 | } |
| 6003 | groups[di] = { |
| 6004 | index: di, |
| 6005 | startAngle: x0, |
| 6006 | endAngle: x, |
| 6007 | value: (x - x0) / k |
| 6008 | }; |
| 6009 | x += padding; |
| 6010 | } |
| 6011 | i = -1; |
| 6012 | while (++i < n) { |
| 6013 | j = i - 1; |
| 6014 | while (++j < n) { |
| 6015 | var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i]; |
| 6016 | if (source.value || target.value) { |
| 6017 | chords.push(source.value < target.value ? { |
| 6018 | source: target, |
| 6019 | target: source |
| 6020 | } : { |
| 6021 | source: source, |
| 6022 | target: target |
| 6023 | }); |
| 6024 | } |
| 6025 | } |
| 6026 | } |
| 6027 | if (sortChords) resort(); |
| 6028 | } |
| 6029 | function resort() { |
| 6030 | chords.sort(function(a, b) { |
| 6031 | return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2); |
| 6032 | }); |
| 6033 | } |
| 6034 | chord.matrix = function(x) { |
| 6035 | if (!arguments.length) return matrix; |
| 6036 | n = (matrix = x) && matrix.length; |
| 6037 | chords = groups = null; |
| 6038 | return chord; |
| 6039 | }; |
| 6040 | chord.padding = function(x) { |
| 6041 | if (!arguments.length) return padding; |
| 6042 | padding = x; |
| 6043 | chords = groups = null; |
| 6044 | return chord; |
| 6045 | }; |
| 6046 | chord.sortGroups = function(x) { |
| 6047 | if (!arguments.length) return sortGroups; |
| 6048 | sortGroups = x; |
| 6049 | chords = groups = null; |
| 6050 | return chord; |
| 6051 | }; |
| 6052 | chord.sortSubgroups = function(x) { |
| 6053 | if (!arguments.length) return sortSubgroups; |
| 6054 | sortSubgroups = x; |
| 6055 | chords = null; |
| 6056 | return chord; |
| 6057 | }; |
| 6058 | chord.sortChords = function(x) { |
| 6059 | if (!arguments.length) return sortChords; |
| 6060 | sortChords = x; |
| 6061 | if (chords) resort(); |
| 6062 | return chord; |
| 6063 | }; |
| 6064 | chord.chords = function() { |
| 6065 | if (!chords) relayout(); |
| 6066 | return chords; |
| 6067 | }; |
| 6068 | chord.groups = function() { |
| 6069 | if (!groups) relayout(); |
| 6070 | return groups; |
| 6071 | }; |
| 6072 | return chord; |
| 6073 | }; |
| 6074 | d3.layout.force = function() { |
| 6075 | 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; |
| 6076 | function repulse(node) { |
| 6077 | return function(quad, x1, _, x2) { |
| 6078 | if (quad.point !== node) { |
| 6079 | var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy; |
| 6080 | if (dw * dw / theta2 < dn) { |
| 6081 | if (dn < chargeDistance2) { |
| 6082 | var k = quad.charge / dn; |
| 6083 | node.px -= dx * k; |
| 6084 | node.py -= dy * k; |
| 6085 | } |
| 6086 | return true; |
| 6087 | } |
| 6088 | if (quad.point && dn && dn < chargeDistance2) { |
| 6089 | var k = quad.pointCharge / dn; |
| 6090 | node.px -= dx * k; |
| 6091 | node.py -= dy * k; |
| 6092 | } |
| 6093 | } |
| 6094 | return !quad.charge; |
| 6095 | }; |
| 6096 | } |
| 6097 | force.tick = function() { |
| 6098 | if ((alpha *= .99) < .005) { |
| 6099 | event.end({ |
| 6100 | type: "end", |
| 6101 | alpha: alpha = 0 |
| 6102 | }); |
| 6103 | return true; |
| 6104 | } |
| 6105 | var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y; |
| 6106 | for (i = 0; i < m; ++i) { |
| 6107 | o = links[i]; |
| 6108 | s = o.source; |
| 6109 | t = o.target; |
| 6110 | x = t.x - s.x; |
| 6111 | y = t.y - s.y; |
| 6112 | if (l = x * x + y * y) { |
| 6113 | l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l; |
| 6114 | x *= l; |
| 6115 | y *= l; |
| 6116 | t.x -= x * (k = s.weight / (t.weight + s.weight)); |
| 6117 | t.y -= y * k; |
| 6118 | s.x += x * (k = 1 - k); |
| 6119 | s.y += y * k; |
| 6120 | } |
| 6121 | } |
| 6122 | if (k = alpha * gravity) { |
| 6123 | x = size[0] / 2; |
| 6124 | y = size[1] / 2; |
| 6125 | i = -1; |
| 6126 | if (k) while (++i < n) { |
| 6127 | o = nodes[i]; |
| 6128 | o.x += (x - o.x) * k; |
| 6129 | o.y += (y - o.y) * k; |
| 6130 | } |
| 6131 | } |
| 6132 | if (charge) { |
| 6133 | d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges); |
| 6134 | i = -1; |
| 6135 | while (++i < n) { |
| 6136 | if (!(o = nodes[i]).fixed) { |
| 6137 | q.visit(repulse(o)); |
| 6138 | } |
| 6139 | } |
| 6140 | } |
| 6141 | i = -1; |
| 6142 | while (++i < n) { |
| 6143 | o = nodes[i]; |
| 6144 | if (o.fixed) { |
| 6145 | o.x = o.px; |
| 6146 | o.y = o.py; |
| 6147 | } else { |
| 6148 | o.x -= (o.px - (o.px = o.x)) * friction; |
| 6149 | o.y -= (o.py - (o.py = o.y)) * friction; |
| 6150 | } |
| 6151 | } |
| 6152 | event.tick({ |
| 6153 | type: "tick", |
| 6154 | alpha: alpha |
| 6155 | }); |
| 6156 | }; |
| 6157 | force.nodes = function(x) { |
| 6158 | if (!arguments.length) return nodes; |
| 6159 | nodes = x; |
| 6160 | return force; |
| 6161 | }; |
| 6162 | force.links = function(x) { |
| 6163 | if (!arguments.length) return links; |
| 6164 | links = x; |
| 6165 | return force; |
| 6166 | }; |
| 6167 | force.size = function(x) { |
| 6168 | if (!arguments.length) return size; |
| 6169 | size = x; |
| 6170 | return force; |
| 6171 | }; |
| 6172 | force.linkDistance = function(x) { |
| 6173 | if (!arguments.length) return linkDistance; |
| 6174 | linkDistance = typeof x === "function" ? x : +x; |
| 6175 | return force; |
| 6176 | }; |
| 6177 | force.distance = force.linkDistance; |
| 6178 | force.linkStrength = function(x) { |
| 6179 | if (!arguments.length) return linkStrength; |
| 6180 | linkStrength = typeof x === "function" ? x : +x; |
| 6181 | return force; |
| 6182 | }; |
| 6183 | force.friction = function(x) { |
| 6184 | if (!arguments.length) return friction; |
| 6185 | friction = +x; |
| 6186 | return force; |
| 6187 | }; |
| 6188 | force.charge = function(x) { |
| 6189 | if (!arguments.length) return charge; |
| 6190 | charge = typeof x === "function" ? x : +x; |
| 6191 | return force; |
| 6192 | }; |
| 6193 | force.chargeDistance = function(x) { |
| 6194 | if (!arguments.length) return Math.sqrt(chargeDistance2); |
| 6195 | chargeDistance2 = x * x; |
| 6196 | return force; |
| 6197 | }; |
| 6198 | force.gravity = function(x) { |
| 6199 | if (!arguments.length) return gravity; |
| 6200 | gravity = +x; |
| 6201 | return force; |
| 6202 | }; |
| 6203 | force.theta = function(x) { |
| 6204 | if (!arguments.length) return Math.sqrt(theta2); |
| 6205 | theta2 = x * x; |
| 6206 | return force; |
| 6207 | }; |
| 6208 | force.alpha = function(x) { |
| 6209 | if (!arguments.length) return alpha; |
| 6210 | x = +x; |
| 6211 | if (alpha) { |
| 6212 | if (x > 0) alpha = x; else alpha = 0; |
| 6213 | } else if (x > 0) { |
| 6214 | event.start({ |
| 6215 | type: "start", |
| 6216 | alpha: alpha = x |
| 6217 | }); |
Thomas Vachuska | c2f7d0a | 2015-06-09 19:38:38 -0700 | [diff] [blame^] | 6218 | //d3.timer(force.tick); |
| 6219 | setTimeout(function tick(){ |
| 6220 | force.tick(); |
| 6221 | if(alpha >= .005); |
| 6222 | setTimeout(tick, 0); |
| 6223 | }, 0); |
tom | 1f60124 | 2014-10-13 11:10:40 -0700 | [diff] [blame] | 6224 | } |
| 6225 | return force; |
| 6226 | }; |
| 6227 | force.start = function() { |
| 6228 | var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o; |
| 6229 | for (i = 0; i < n; ++i) { |
| 6230 | (o = nodes[i]).index = i; |
| 6231 | o.weight = 0; |
| 6232 | } |
| 6233 | for (i = 0; i < m; ++i) { |
| 6234 | o = links[i]; |
| 6235 | if (typeof o.source == "number") o.source = nodes[o.source]; |
| 6236 | if (typeof o.target == "number") o.target = nodes[o.target]; |
| 6237 | ++o.source.weight; |
| 6238 | ++o.target.weight; |
| 6239 | } |
| 6240 | for (i = 0; i < n; ++i) { |
| 6241 | o = nodes[i]; |
| 6242 | if (isNaN(o.x)) o.x = position("x", w); |
| 6243 | if (isNaN(o.y)) o.y = position("y", h); |
| 6244 | if (isNaN(o.px)) o.px = o.x; |
| 6245 | if (isNaN(o.py)) o.py = o.y; |
| 6246 | } |
| 6247 | distances = []; |
| 6248 | 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; |
| 6249 | strengths = []; |
| 6250 | 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; |
| 6251 | charges = []; |
| 6252 | 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; |
| 6253 | function position(dimension, size) { |
| 6254 | if (!neighbors) { |
| 6255 | neighbors = new Array(n); |
| 6256 | for (j = 0; j < n; ++j) { |
| 6257 | neighbors[j] = []; |
| 6258 | } |
| 6259 | for (j = 0; j < m; ++j) { |
| 6260 | var o = links[j]; |
| 6261 | neighbors[o.source.index].push(o.target); |
| 6262 | neighbors[o.target.index].push(o.source); |
| 6263 | } |
| 6264 | } |
| 6265 | var candidates = neighbors[i], j = -1, m = candidates.length, x; |
| 6266 | while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x; |
| 6267 | return Math.random() * size; |
| 6268 | } |
| 6269 | return force.resume(); |
| 6270 | }; |
| 6271 | force.resume = function() { |
| 6272 | return force.alpha(.1); |
| 6273 | }; |
| 6274 | force.stop = function() { |
| 6275 | return force.alpha(0); |
| 6276 | }; |
| 6277 | force.drag = function() { |
| 6278 | 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); |
| 6279 | if (!arguments.length) return drag; |
| 6280 | this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag); |
| 6281 | }; |
| 6282 | function dragmove(d) { |
| 6283 | d.px = d3.event.x, d.py = d3.event.y; |
| 6284 | force.resume(); |
| 6285 | } |
| 6286 | return d3.rebind(force, event, "on"); |
| 6287 | }; |
| 6288 | function d3_layout_forceDragstart(d) { |
| 6289 | d.fixed |= 2; |
| 6290 | } |
| 6291 | function d3_layout_forceDragend(d) { |
| 6292 | d.fixed &= ~6; |
| 6293 | } |
| 6294 | function d3_layout_forceMouseover(d) { |
| 6295 | d.fixed |= 4; |
| 6296 | d.px = d.x, d.py = d.y; |
| 6297 | } |
| 6298 | function d3_layout_forceMouseout(d) { |
| 6299 | d.fixed &= ~4; |
| 6300 | } |
| 6301 | function d3_layout_forceAccumulate(quad, alpha, charges) { |
| 6302 | var cx = 0, cy = 0; |
| 6303 | quad.charge = 0; |
| 6304 | if (!quad.leaf) { |
| 6305 | var nodes = quad.nodes, n = nodes.length, i = -1, c; |
| 6306 | while (++i < n) { |
| 6307 | c = nodes[i]; |
| 6308 | if (c == null) continue; |
| 6309 | d3_layout_forceAccumulate(c, alpha, charges); |
| 6310 | quad.charge += c.charge; |
| 6311 | cx += c.charge * c.cx; |
| 6312 | cy += c.charge * c.cy; |
| 6313 | } |
| 6314 | } |
| 6315 | if (quad.point) { |
| 6316 | if (!quad.leaf) { |
| 6317 | quad.point.x += Math.random() - .5; |
| 6318 | quad.point.y += Math.random() - .5; |
| 6319 | } |
| 6320 | var k = alpha * charges[quad.point.index]; |
| 6321 | quad.charge += quad.pointCharge = k; |
| 6322 | cx += k * quad.point.x; |
| 6323 | cy += k * quad.point.y; |
| 6324 | } |
| 6325 | quad.cx = cx / quad.charge; |
| 6326 | quad.cy = cy / quad.charge; |
| 6327 | } |
| 6328 | var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity; |
| 6329 | d3.layout.hierarchy = function() { |
| 6330 | var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue; |
| 6331 | function hierarchy(root) { |
| 6332 | var stack = [ root ], nodes = [], node; |
| 6333 | root.depth = 0; |
| 6334 | while ((node = stack.pop()) != null) { |
| 6335 | nodes.push(node); |
| 6336 | if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) { |
| 6337 | var n, childs, child; |
| 6338 | while (--n >= 0) { |
| 6339 | stack.push(child = childs[n]); |
| 6340 | child.parent = node; |
| 6341 | child.depth = node.depth + 1; |
| 6342 | } |
| 6343 | if (value) node.value = 0; |
| 6344 | node.children = childs; |
| 6345 | } else { |
| 6346 | if (value) node.value = +value.call(hierarchy, node, node.depth) || 0; |
| 6347 | delete node.children; |
| 6348 | } |
| 6349 | } |
| 6350 | d3_layout_hierarchyVisitAfter(root, function(node) { |
| 6351 | var childs, parent; |
| 6352 | if (sort && (childs = node.children)) childs.sort(sort); |
| 6353 | if (value && (parent = node.parent)) parent.value += node.value; |
| 6354 | }); |
| 6355 | return nodes; |
| 6356 | } |
| 6357 | hierarchy.sort = function(x) { |
| 6358 | if (!arguments.length) return sort; |
| 6359 | sort = x; |
| 6360 | return hierarchy; |
| 6361 | }; |
| 6362 | hierarchy.children = function(x) { |
| 6363 | if (!arguments.length) return children; |
| 6364 | children = x; |
| 6365 | return hierarchy; |
| 6366 | }; |
| 6367 | hierarchy.value = function(x) { |
| 6368 | if (!arguments.length) return value; |
| 6369 | value = x; |
| 6370 | return hierarchy; |
| 6371 | }; |
| 6372 | hierarchy.revalue = function(root) { |
| 6373 | if (value) { |
| 6374 | d3_layout_hierarchyVisitBefore(root, function(node) { |
| 6375 | if (node.children) node.value = 0; |
| 6376 | }); |
| 6377 | d3_layout_hierarchyVisitAfter(root, function(node) { |
| 6378 | var parent; |
| 6379 | if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0; |
| 6380 | if (parent = node.parent) parent.value += node.value; |
| 6381 | }); |
| 6382 | } |
| 6383 | return root; |
| 6384 | }; |
| 6385 | return hierarchy; |
| 6386 | }; |
| 6387 | function d3_layout_hierarchyRebind(object, hierarchy) { |
| 6388 | d3.rebind(object, hierarchy, "sort", "children", "value"); |
| 6389 | object.nodes = object; |
| 6390 | object.links = d3_layout_hierarchyLinks; |
| 6391 | return object; |
| 6392 | } |
| 6393 | function d3_layout_hierarchyVisitBefore(node, callback) { |
| 6394 | var nodes = [ node ]; |
| 6395 | while ((node = nodes.pop()) != null) { |
| 6396 | callback(node); |
| 6397 | if ((children = node.children) && (n = children.length)) { |
| 6398 | var n, children; |
| 6399 | while (--n >= 0) nodes.push(children[n]); |
| 6400 | } |
| 6401 | } |
| 6402 | } |
| 6403 | function d3_layout_hierarchyVisitAfter(node, callback) { |
| 6404 | var nodes = [ node ], nodes2 = []; |
| 6405 | while ((node = nodes.pop()) != null) { |
| 6406 | nodes2.push(node); |
| 6407 | if ((children = node.children) && (n = children.length)) { |
| 6408 | var i = -1, n, children; |
| 6409 | while (++i < n) nodes.push(children[i]); |
| 6410 | } |
| 6411 | } |
| 6412 | while ((node = nodes2.pop()) != null) { |
| 6413 | callback(node); |
| 6414 | } |
| 6415 | } |
| 6416 | function d3_layout_hierarchyChildren(d) { |
| 6417 | return d.children; |
| 6418 | } |
| 6419 | function d3_layout_hierarchyValue(d) { |
| 6420 | return d.value; |
| 6421 | } |
| 6422 | function d3_layout_hierarchySort(a, b) { |
| 6423 | return b.value - a.value; |
| 6424 | } |
| 6425 | function d3_layout_hierarchyLinks(nodes) { |
| 6426 | return d3.merge(nodes.map(function(parent) { |
| 6427 | return (parent.children || []).map(function(child) { |
| 6428 | return { |
| 6429 | source: parent, |
| 6430 | target: child |
| 6431 | }; |
| 6432 | }); |
| 6433 | })); |
| 6434 | } |
| 6435 | d3.layout.partition = function() { |
| 6436 | var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ]; |
| 6437 | function position(node, x, dx, dy) { |
| 6438 | var children = node.children; |
| 6439 | node.x = x; |
| 6440 | node.y = node.depth * dy; |
| 6441 | node.dx = dx; |
| 6442 | node.dy = dy; |
| 6443 | if (children && (n = children.length)) { |
| 6444 | var i = -1, n, c, d; |
| 6445 | dx = node.value ? dx / node.value : 0; |
| 6446 | while (++i < n) { |
| 6447 | position(c = children[i], x, d = c.value * dx, dy); |
| 6448 | x += d; |
| 6449 | } |
| 6450 | } |
| 6451 | } |
| 6452 | function depth(node) { |
| 6453 | var children = node.children, d = 0; |
| 6454 | if (children && (n = children.length)) { |
| 6455 | var i = -1, n; |
| 6456 | while (++i < n) d = Math.max(d, depth(children[i])); |
| 6457 | } |
| 6458 | return 1 + d; |
| 6459 | } |
| 6460 | function partition(d, i) { |
| 6461 | var nodes = hierarchy.call(this, d, i); |
| 6462 | position(nodes[0], 0, size[0], size[1] / depth(nodes[0])); |
| 6463 | return nodes; |
| 6464 | } |
| 6465 | partition.size = function(x) { |
| 6466 | if (!arguments.length) return size; |
| 6467 | size = x; |
| 6468 | return partition; |
| 6469 | }; |
| 6470 | return d3_layout_hierarchyRebind(partition, hierarchy); |
| 6471 | }; |
| 6472 | d3.layout.pie = function() { |
| 6473 | var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ; |
| 6474 | function pie(data) { |
| 6475 | var values = data.map(function(d, i) { |
| 6476 | return +value.call(pie, d, i); |
| 6477 | }); |
| 6478 | var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle); |
| 6479 | var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values); |
| 6480 | var index = d3.range(data.length); |
| 6481 | if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) { |
| 6482 | return values[j] - values[i]; |
| 6483 | } : function(i, j) { |
| 6484 | return sort(data[i], data[j]); |
| 6485 | }); |
| 6486 | var arcs = []; |
| 6487 | index.forEach(function(i) { |
| 6488 | var d; |
| 6489 | arcs[i] = { |
| 6490 | data: data[i], |
| 6491 | value: d = values[i], |
| 6492 | startAngle: a, |
| 6493 | endAngle: a += d * k |
| 6494 | }; |
| 6495 | }); |
| 6496 | return arcs; |
| 6497 | } |
| 6498 | pie.value = function(x) { |
| 6499 | if (!arguments.length) return value; |
| 6500 | value = x; |
| 6501 | return pie; |
| 6502 | }; |
| 6503 | pie.sort = function(x) { |
| 6504 | if (!arguments.length) return sort; |
| 6505 | sort = x; |
| 6506 | return pie; |
| 6507 | }; |
| 6508 | pie.startAngle = function(x) { |
| 6509 | if (!arguments.length) return startAngle; |
| 6510 | startAngle = x; |
| 6511 | return pie; |
| 6512 | }; |
| 6513 | pie.endAngle = function(x) { |
| 6514 | if (!arguments.length) return endAngle; |
| 6515 | endAngle = x; |
| 6516 | return pie; |
| 6517 | }; |
| 6518 | return pie; |
| 6519 | }; |
| 6520 | var d3_layout_pieSortByValue = {}; |
| 6521 | d3.layout.stack = function() { |
| 6522 | var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY; |
| 6523 | function stack(data, index) { |
| 6524 | var series = data.map(function(d, i) { |
| 6525 | return values.call(stack, d, i); |
| 6526 | }); |
| 6527 | var points = series.map(function(d) { |
| 6528 | return d.map(function(v, i) { |
| 6529 | return [ x.call(stack, v, i), y.call(stack, v, i) ]; |
| 6530 | }); |
| 6531 | }); |
| 6532 | var orders = order.call(stack, points, index); |
| 6533 | series = d3.permute(series, orders); |
| 6534 | points = d3.permute(points, orders); |
| 6535 | var offsets = offset.call(stack, points, index); |
| 6536 | var n = series.length, m = series[0].length, i, j, o; |
| 6537 | for (j = 0; j < m; ++j) { |
| 6538 | out.call(stack, series[0][j], o = offsets[j], points[0][j][1]); |
| 6539 | for (i = 1; i < n; ++i) { |
| 6540 | out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]); |
| 6541 | } |
| 6542 | } |
| 6543 | return data; |
| 6544 | } |
| 6545 | stack.values = function(x) { |
| 6546 | if (!arguments.length) return values; |
| 6547 | values = x; |
| 6548 | return stack; |
| 6549 | }; |
| 6550 | stack.order = function(x) { |
| 6551 | if (!arguments.length) return order; |
| 6552 | order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault; |
| 6553 | return stack; |
| 6554 | }; |
| 6555 | stack.offset = function(x) { |
| 6556 | if (!arguments.length) return offset; |
| 6557 | offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero; |
| 6558 | return stack; |
| 6559 | }; |
| 6560 | stack.x = function(z) { |
| 6561 | if (!arguments.length) return x; |
| 6562 | x = z; |
| 6563 | return stack; |
| 6564 | }; |
| 6565 | stack.y = function(z) { |
| 6566 | if (!arguments.length) return y; |
| 6567 | y = z; |
| 6568 | return stack; |
| 6569 | }; |
| 6570 | stack.out = function(z) { |
| 6571 | if (!arguments.length) return out; |
| 6572 | out = z; |
| 6573 | return stack; |
| 6574 | }; |
| 6575 | return stack; |
| 6576 | }; |
| 6577 | function d3_layout_stackX(d) { |
| 6578 | return d.x; |
| 6579 | } |
| 6580 | function d3_layout_stackY(d) { |
| 6581 | return d.y; |
| 6582 | } |
| 6583 | function d3_layout_stackOut(d, y0, y) { |
| 6584 | d.y0 = y0; |
| 6585 | d.y = y; |
| 6586 | } |
| 6587 | var d3_layout_stackOrders = d3.map({ |
| 6588 | "inside-out": function(data) { |
| 6589 | 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) { |
| 6590 | return max[a] - max[b]; |
| 6591 | }), top = 0, bottom = 0, tops = [], bottoms = []; |
| 6592 | for (i = 0; i < n; ++i) { |
| 6593 | j = index[i]; |
| 6594 | if (top < bottom) { |
| 6595 | top += sums[j]; |
| 6596 | tops.push(j); |
| 6597 | } else { |
| 6598 | bottom += sums[j]; |
| 6599 | bottoms.push(j); |
| 6600 | } |
| 6601 | } |
| 6602 | return bottoms.reverse().concat(tops); |
| 6603 | }, |
| 6604 | reverse: function(data) { |
| 6605 | return d3.range(data.length).reverse(); |
| 6606 | }, |
| 6607 | "default": d3_layout_stackOrderDefault |
| 6608 | }); |
| 6609 | var d3_layout_stackOffsets = d3.map({ |
| 6610 | silhouette: function(data) { |
| 6611 | var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = []; |
| 6612 | for (j = 0; j < m; ++j) { |
| 6613 | for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; |
| 6614 | if (o > max) max = o; |
| 6615 | sums.push(o); |
| 6616 | } |
| 6617 | for (j = 0; j < m; ++j) { |
| 6618 | y0[j] = (max - sums[j]) / 2; |
| 6619 | } |
| 6620 | return y0; |
| 6621 | }, |
| 6622 | wiggle: function(data) { |
| 6623 | var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = []; |
| 6624 | y0[0] = o = o0 = 0; |
| 6625 | for (j = 1; j < m; ++j) { |
| 6626 | for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1]; |
| 6627 | for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) { |
| 6628 | for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) { |
| 6629 | s3 += (data[k][j][1] - data[k][j - 1][1]) / dx; |
| 6630 | } |
| 6631 | s2 += s3 * data[i][j][1]; |
| 6632 | } |
| 6633 | y0[j] = o -= s1 ? s2 / s1 * dx : 0; |
| 6634 | if (o < o0) o0 = o; |
| 6635 | } |
| 6636 | for (j = 0; j < m; ++j) y0[j] -= o0; |
| 6637 | return y0; |
| 6638 | }, |
| 6639 | expand: function(data) { |
| 6640 | var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = []; |
| 6641 | for (j = 0; j < m; ++j) { |
| 6642 | for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; |
| 6643 | 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; |
| 6644 | } |
| 6645 | for (j = 0; j < m; ++j) y0[j] = 0; |
| 6646 | return y0; |
| 6647 | }, |
| 6648 | zero: d3_layout_stackOffsetZero |
| 6649 | }); |
| 6650 | function d3_layout_stackOrderDefault(data) { |
| 6651 | return d3.range(data.length); |
| 6652 | } |
| 6653 | function d3_layout_stackOffsetZero(data) { |
| 6654 | var j = -1, m = data[0].length, y0 = []; |
| 6655 | while (++j < m) y0[j] = 0; |
| 6656 | return y0; |
| 6657 | } |
| 6658 | function d3_layout_stackMaxIndex(array) { |
| 6659 | var i = 1, j = 0, v = array[0][1], k, n = array.length; |
| 6660 | for (;i < n; ++i) { |
| 6661 | if ((k = array[i][1]) > v) { |
| 6662 | j = i; |
| 6663 | v = k; |
| 6664 | } |
| 6665 | } |
| 6666 | return j; |
| 6667 | } |
| 6668 | function d3_layout_stackReduceSum(d) { |
| 6669 | return d.reduce(d3_layout_stackSum, 0); |
| 6670 | } |
| 6671 | function d3_layout_stackSum(p, d) { |
| 6672 | return p + d[1]; |
| 6673 | } |
| 6674 | d3.layout.histogram = function() { |
| 6675 | var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges; |
| 6676 | function histogram(data, i) { |
| 6677 | 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; |
| 6678 | while (++i < m) { |
| 6679 | bin = bins[i] = []; |
| 6680 | bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]); |
| 6681 | bin.y = 0; |
| 6682 | } |
| 6683 | if (m > 0) { |
| 6684 | i = -1; |
| 6685 | while (++i < n) { |
| 6686 | x = values[i]; |
| 6687 | if (x >= range[0] && x <= range[1]) { |
| 6688 | bin = bins[d3.bisect(thresholds, x, 1, m) - 1]; |
| 6689 | bin.y += k; |
| 6690 | bin.push(data[i]); |
| 6691 | } |
| 6692 | } |
| 6693 | } |
| 6694 | return bins; |
| 6695 | } |
| 6696 | histogram.value = function(x) { |
| 6697 | if (!arguments.length) return valuer; |
| 6698 | valuer = x; |
| 6699 | return histogram; |
| 6700 | }; |
| 6701 | histogram.range = function(x) { |
| 6702 | if (!arguments.length) return ranger; |
| 6703 | ranger = d3_functor(x); |
| 6704 | return histogram; |
| 6705 | }; |
| 6706 | histogram.bins = function(x) { |
| 6707 | if (!arguments.length) return binner; |
| 6708 | binner = typeof x === "number" ? function(range) { |
| 6709 | return d3_layout_histogramBinFixed(range, x); |
| 6710 | } : d3_functor(x); |
| 6711 | return histogram; |
| 6712 | }; |
| 6713 | histogram.frequency = function(x) { |
| 6714 | if (!arguments.length) return frequency; |
| 6715 | frequency = !!x; |
| 6716 | return histogram; |
| 6717 | }; |
| 6718 | return histogram; |
| 6719 | }; |
| 6720 | function d3_layout_histogramBinSturges(range, values) { |
| 6721 | return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1)); |
| 6722 | } |
| 6723 | function d3_layout_histogramBinFixed(range, n) { |
| 6724 | var x = -1, b = +range[0], m = (range[1] - b) / n, f = []; |
| 6725 | while (++x <= n) f[x] = m * x + b; |
| 6726 | return f; |
| 6727 | } |
| 6728 | function d3_layout_histogramRange(values) { |
| 6729 | return [ d3.min(values), d3.max(values) ]; |
| 6730 | } |
| 6731 | d3.layout.pack = function() { |
| 6732 | var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius; |
| 6733 | function pack(d, i) { |
| 6734 | 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() { |
| 6735 | return radius; |
| 6736 | }; |
| 6737 | root.x = root.y = 0; |
| 6738 | d3_layout_hierarchyVisitAfter(root, function(d) { |
| 6739 | d.r = +r(d.value); |
| 6740 | }); |
| 6741 | d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); |
| 6742 | if (padding) { |
| 6743 | var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2; |
| 6744 | d3_layout_hierarchyVisitAfter(root, function(d) { |
| 6745 | d.r += dr; |
| 6746 | }); |
| 6747 | d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); |
| 6748 | d3_layout_hierarchyVisitAfter(root, function(d) { |
| 6749 | d.r -= dr; |
| 6750 | }); |
| 6751 | } |
| 6752 | d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h)); |
| 6753 | return nodes; |
| 6754 | } |
| 6755 | pack.size = function(_) { |
| 6756 | if (!arguments.length) return size; |
| 6757 | size = _; |
| 6758 | return pack; |
| 6759 | }; |
| 6760 | pack.radius = function(_) { |
| 6761 | if (!arguments.length) return radius; |
| 6762 | radius = _ == null || typeof _ === "function" ? _ : +_; |
| 6763 | return pack; |
| 6764 | }; |
| 6765 | pack.padding = function(_) { |
| 6766 | if (!arguments.length) return padding; |
| 6767 | padding = +_; |
| 6768 | return pack; |
| 6769 | }; |
| 6770 | return d3_layout_hierarchyRebind(pack, hierarchy); |
| 6771 | }; |
| 6772 | function d3_layout_packSort(a, b) { |
| 6773 | return a.value - b.value; |
| 6774 | } |
| 6775 | function d3_layout_packInsert(a, b) { |
| 6776 | var c = a._pack_next; |
| 6777 | a._pack_next = b; |
| 6778 | b._pack_prev = a; |
| 6779 | b._pack_next = c; |
| 6780 | c._pack_prev = b; |
| 6781 | } |
| 6782 | function d3_layout_packSplice(a, b) { |
| 6783 | a._pack_next = b; |
| 6784 | b._pack_prev = a; |
| 6785 | } |
| 6786 | function d3_layout_packIntersects(a, b) { |
| 6787 | var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r; |
| 6788 | return .999 * dr * dr > dx * dx + dy * dy; |
| 6789 | } |
| 6790 | function d3_layout_packSiblings(node) { |
| 6791 | if (!(nodes = node.children) || !(n = nodes.length)) return; |
| 6792 | var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n; |
| 6793 | function bound(node) { |
| 6794 | xMin = Math.min(node.x - node.r, xMin); |
| 6795 | xMax = Math.max(node.x + node.r, xMax); |
| 6796 | yMin = Math.min(node.y - node.r, yMin); |
| 6797 | yMax = Math.max(node.y + node.r, yMax); |
| 6798 | } |
| 6799 | nodes.forEach(d3_layout_packLink); |
| 6800 | a = nodes[0]; |
| 6801 | a.x = -a.r; |
| 6802 | a.y = 0; |
| 6803 | bound(a); |
| 6804 | if (n > 1) { |
| 6805 | b = nodes[1]; |
| 6806 | b.x = b.r; |
| 6807 | b.y = 0; |
| 6808 | bound(b); |
| 6809 | if (n > 2) { |
| 6810 | c = nodes[2]; |
| 6811 | d3_layout_packPlace(a, b, c); |
| 6812 | bound(c); |
| 6813 | d3_layout_packInsert(a, c); |
| 6814 | a._pack_prev = c; |
| 6815 | d3_layout_packInsert(c, b); |
| 6816 | b = a._pack_next; |
| 6817 | for (i = 3; i < n; i++) { |
| 6818 | d3_layout_packPlace(a, b, c = nodes[i]); |
| 6819 | var isect = 0, s1 = 1, s2 = 1; |
| 6820 | for (j = b._pack_next; j !== b; j = j._pack_next, s1++) { |
| 6821 | if (d3_layout_packIntersects(j, c)) { |
| 6822 | isect = 1; |
| 6823 | break; |
| 6824 | } |
| 6825 | } |
| 6826 | if (isect == 1) { |
| 6827 | for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) { |
| 6828 | if (d3_layout_packIntersects(k, c)) { |
| 6829 | break; |
| 6830 | } |
| 6831 | } |
| 6832 | } |
| 6833 | if (isect) { |
| 6834 | if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b); |
| 6835 | i--; |
| 6836 | } else { |
| 6837 | d3_layout_packInsert(a, c); |
| 6838 | b = c; |
| 6839 | bound(c); |
| 6840 | } |
| 6841 | } |
| 6842 | } |
| 6843 | } |
| 6844 | var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0; |
| 6845 | for (i = 0; i < n; i++) { |
| 6846 | c = nodes[i]; |
| 6847 | c.x -= cx; |
| 6848 | c.y -= cy; |
| 6849 | cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y)); |
| 6850 | } |
| 6851 | node.r = cr; |
| 6852 | nodes.forEach(d3_layout_packUnlink); |
| 6853 | } |
| 6854 | function d3_layout_packLink(node) { |
| 6855 | node._pack_next = node._pack_prev = node; |
| 6856 | } |
| 6857 | function d3_layout_packUnlink(node) { |
| 6858 | delete node._pack_next; |
| 6859 | delete node._pack_prev; |
| 6860 | } |
| 6861 | function d3_layout_packTransform(node, x, y, k) { |
| 6862 | var children = node.children; |
| 6863 | node.x = x += k * node.x; |
| 6864 | node.y = y += k * node.y; |
| 6865 | node.r *= k; |
| 6866 | if (children) { |
| 6867 | var i = -1, n = children.length; |
| 6868 | while (++i < n) d3_layout_packTransform(children[i], x, y, k); |
| 6869 | } |
| 6870 | } |
| 6871 | function d3_layout_packPlace(a, b, c) { |
| 6872 | var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y; |
| 6873 | if (db && (dx || dy)) { |
| 6874 | var da = b.r + c.r, dc = dx * dx + dy * dy; |
| 6875 | da *= da; |
| 6876 | db *= db; |
| 6877 | var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc); |
| 6878 | c.x = a.x + x * dx + y * dy; |
| 6879 | c.y = a.y + x * dy - y * dx; |
| 6880 | } else { |
| 6881 | c.x = a.x + db; |
| 6882 | c.y = a.y; |
| 6883 | } |
| 6884 | } |
| 6885 | d3.layout.tree = function() { |
| 6886 | var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null; |
| 6887 | function tree(d, i) { |
| 6888 | var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0); |
| 6889 | d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z; |
| 6890 | d3_layout_hierarchyVisitBefore(root1, secondWalk); |
| 6891 | if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else { |
| 6892 | var left = root0, right = root0, bottom = root0; |
| 6893 | d3_layout_hierarchyVisitBefore(root0, function(node) { |
| 6894 | if (node.x < left.x) left = node; |
| 6895 | if (node.x > right.x) right = node; |
| 6896 | if (node.depth > bottom.depth) bottom = node; |
| 6897 | }); |
| 6898 | var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1); |
| 6899 | d3_layout_hierarchyVisitBefore(root0, function(node) { |
| 6900 | node.x = (node.x + tx) * kx; |
| 6901 | node.y = node.depth * ky; |
| 6902 | }); |
| 6903 | } |
| 6904 | return nodes; |
| 6905 | } |
| 6906 | function wrapTree(root0) { |
| 6907 | var root1 = { |
| 6908 | A: null, |
| 6909 | children: [ root0 ] |
| 6910 | }, queue = [ root1 ], node1; |
| 6911 | while ((node1 = queue.pop()) != null) { |
| 6912 | for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) { |
| 6913 | queue.push((children[i] = child = { |
| 6914 | _: children[i], |
| 6915 | parent: node1, |
| 6916 | children: (child = children[i].children) && child.slice() || [], |
| 6917 | A: null, |
| 6918 | a: null, |
| 6919 | z: 0, |
| 6920 | m: 0, |
| 6921 | c: 0, |
| 6922 | s: 0, |
| 6923 | t: null, |
| 6924 | i: i |
| 6925 | }).a = child); |
| 6926 | } |
| 6927 | } |
| 6928 | return root1.children[0]; |
| 6929 | } |
| 6930 | function firstWalk(v) { |
| 6931 | var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null; |
| 6932 | if (children.length) { |
| 6933 | d3_layout_treeShift(v); |
| 6934 | var midpoint = (children[0].z + children[children.length - 1].z) / 2; |
| 6935 | if (w) { |
| 6936 | v.z = w.z + separation(v._, w._); |
| 6937 | v.m = v.z - midpoint; |
| 6938 | } else { |
| 6939 | v.z = midpoint; |
| 6940 | } |
| 6941 | } else if (w) { |
| 6942 | v.z = w.z + separation(v._, w._); |
| 6943 | } |
| 6944 | v.parent.A = apportion(v, w, v.parent.A || siblings[0]); |
| 6945 | } |
| 6946 | function secondWalk(v) { |
| 6947 | v._.x = v.z + v.parent.m; |
| 6948 | v.m += v.parent.m; |
| 6949 | } |
| 6950 | function apportion(v, w, ancestor) { |
| 6951 | if (w) { |
| 6952 | 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; |
| 6953 | while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) { |
| 6954 | vom = d3_layout_treeLeft(vom); |
| 6955 | vop = d3_layout_treeRight(vop); |
| 6956 | vop.a = v; |
| 6957 | shift = vim.z + sim - vip.z - sip + separation(vim._, vip._); |
| 6958 | if (shift > 0) { |
| 6959 | d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift); |
| 6960 | sip += shift; |
| 6961 | sop += shift; |
| 6962 | } |
| 6963 | sim += vim.m; |
| 6964 | sip += vip.m; |
| 6965 | som += vom.m; |
| 6966 | sop += vop.m; |
| 6967 | } |
| 6968 | if (vim && !d3_layout_treeRight(vop)) { |
| 6969 | vop.t = vim; |
| 6970 | vop.m += sim - sop; |
| 6971 | } |
| 6972 | if (vip && !d3_layout_treeLeft(vom)) { |
| 6973 | vom.t = vip; |
| 6974 | vom.m += sip - som; |
| 6975 | ancestor = v; |
| 6976 | } |
| 6977 | } |
| 6978 | return ancestor; |
| 6979 | } |
| 6980 | function sizeNode(node) { |
| 6981 | node.x *= size[0]; |
| 6982 | node.y = node.depth * size[1]; |
| 6983 | } |
| 6984 | tree.separation = function(x) { |
| 6985 | if (!arguments.length) return separation; |
| 6986 | separation = x; |
| 6987 | return tree; |
| 6988 | }; |
| 6989 | tree.size = function(x) { |
| 6990 | if (!arguments.length) return nodeSize ? null : size; |
| 6991 | nodeSize = (size = x) == null ? sizeNode : null; |
| 6992 | return tree; |
| 6993 | }; |
| 6994 | tree.nodeSize = function(x) { |
| 6995 | if (!arguments.length) return nodeSize ? size : null; |
| 6996 | nodeSize = (size = x) == null ? null : sizeNode; |
| 6997 | return tree; |
| 6998 | }; |
| 6999 | return d3_layout_hierarchyRebind(tree, hierarchy); |
| 7000 | }; |
| 7001 | function d3_layout_treeSeparation(a, b) { |
| 7002 | return a.parent == b.parent ? 1 : 2; |
| 7003 | } |
| 7004 | function d3_layout_treeLeft(v) { |
| 7005 | var children = v.children; |
| 7006 | return children.length ? children[0] : v.t; |
| 7007 | } |
| 7008 | function d3_layout_treeRight(v) { |
| 7009 | var children = v.children, n; |
| 7010 | return (n = children.length) ? children[n - 1] : v.t; |
| 7011 | } |
| 7012 | function d3_layout_treeMove(wm, wp, shift) { |
| 7013 | var change = shift / (wp.i - wm.i); |
| 7014 | wp.c -= change; |
| 7015 | wp.s += shift; |
| 7016 | wm.c += change; |
| 7017 | wp.z += shift; |
| 7018 | wp.m += shift; |
| 7019 | } |
| 7020 | function d3_layout_treeShift(v) { |
| 7021 | var shift = 0, change = 0, children = v.children, i = children.length, w; |
| 7022 | while (--i >= 0) { |
| 7023 | w = children[i]; |
| 7024 | w.z += shift; |
| 7025 | w.m += shift; |
| 7026 | shift += w.s + (change += w.c); |
| 7027 | } |
| 7028 | } |
| 7029 | function d3_layout_treeAncestor(vim, v, ancestor) { |
| 7030 | return vim.a.parent === v.parent ? vim.a : ancestor; |
| 7031 | } |
| 7032 | d3.layout.cluster = function() { |
| 7033 | var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false; |
| 7034 | function cluster(d, i) { |
| 7035 | var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0; |
| 7036 | d3_layout_hierarchyVisitAfter(root, function(node) { |
| 7037 | var children = node.children; |
| 7038 | if (children && children.length) { |
| 7039 | node.x = d3_layout_clusterX(children); |
| 7040 | node.y = d3_layout_clusterY(children); |
| 7041 | } else { |
| 7042 | node.x = previousNode ? x += separation(node, previousNode) : 0; |
| 7043 | node.y = 0; |
| 7044 | previousNode = node; |
| 7045 | } |
| 7046 | }); |
| 7047 | 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; |
| 7048 | d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) { |
| 7049 | node.x = (node.x - root.x) * size[0]; |
| 7050 | node.y = (root.y - node.y) * size[1]; |
| 7051 | } : function(node) { |
| 7052 | node.x = (node.x - x0) / (x1 - x0) * size[0]; |
| 7053 | node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1]; |
| 7054 | }); |
| 7055 | return nodes; |
| 7056 | } |
| 7057 | cluster.separation = function(x) { |
| 7058 | if (!arguments.length) return separation; |
| 7059 | separation = x; |
| 7060 | return cluster; |
| 7061 | }; |
| 7062 | cluster.size = function(x) { |
| 7063 | if (!arguments.length) return nodeSize ? null : size; |
| 7064 | nodeSize = (size = x) == null; |
| 7065 | return cluster; |
| 7066 | }; |
| 7067 | cluster.nodeSize = function(x) { |
| 7068 | if (!arguments.length) return nodeSize ? size : null; |
| 7069 | nodeSize = (size = x) != null; |
| 7070 | return cluster; |
| 7071 | }; |
| 7072 | return d3_layout_hierarchyRebind(cluster, hierarchy); |
| 7073 | }; |
| 7074 | function d3_layout_clusterY(children) { |
| 7075 | return 1 + d3.max(children, function(child) { |
| 7076 | return child.y; |
| 7077 | }); |
| 7078 | } |
| 7079 | function d3_layout_clusterX(children) { |
| 7080 | return children.reduce(function(x, child) { |
| 7081 | return x + child.x; |
| 7082 | }, 0) / children.length; |
| 7083 | } |
| 7084 | function d3_layout_clusterLeft(node) { |
| 7085 | var children = node.children; |
| 7086 | return children && children.length ? d3_layout_clusterLeft(children[0]) : node; |
| 7087 | } |
| 7088 | function d3_layout_clusterRight(node) { |
| 7089 | var children = node.children, n; |
| 7090 | return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node; |
| 7091 | } |
| 7092 | d3.layout.treemap = function() { |
| 7093 | 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)); |
| 7094 | function scale(children, k) { |
| 7095 | var i = -1, n = children.length, child, area; |
| 7096 | while (++i < n) { |
| 7097 | area = (child = children[i]).value * (k < 0 ? 0 : k); |
| 7098 | child.area = isNaN(area) || area <= 0 ? 0 : area; |
| 7099 | } |
| 7100 | } |
| 7101 | function squarify(node) { |
| 7102 | var children = node.children; |
| 7103 | if (children && children.length) { |
| 7104 | 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; |
| 7105 | scale(remaining, rect.dx * rect.dy / node.value); |
| 7106 | row.area = 0; |
| 7107 | while ((n = remaining.length) > 0) { |
| 7108 | row.push(child = remaining[n - 1]); |
| 7109 | row.area += child.area; |
| 7110 | if (mode !== "squarify" || (score = worst(row, u)) <= best) { |
| 7111 | remaining.pop(); |
| 7112 | best = score; |
| 7113 | } else { |
| 7114 | row.area -= row.pop().area; |
| 7115 | position(row, u, rect, false); |
| 7116 | u = Math.min(rect.dx, rect.dy); |
| 7117 | row.length = row.area = 0; |
| 7118 | best = Infinity; |
| 7119 | } |
| 7120 | } |
| 7121 | if (row.length) { |
| 7122 | position(row, u, rect, true); |
| 7123 | row.length = row.area = 0; |
| 7124 | } |
| 7125 | children.forEach(squarify); |
| 7126 | } |
| 7127 | } |
| 7128 | function stickify(node) { |
| 7129 | var children = node.children; |
| 7130 | if (children && children.length) { |
| 7131 | var rect = pad(node), remaining = children.slice(), child, row = []; |
| 7132 | scale(remaining, rect.dx * rect.dy / node.value); |
| 7133 | row.area = 0; |
| 7134 | while (child = remaining.pop()) { |
| 7135 | row.push(child); |
| 7136 | row.area += child.area; |
| 7137 | if (child.z != null) { |
| 7138 | position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length); |
| 7139 | row.length = row.area = 0; |
| 7140 | } |
| 7141 | } |
| 7142 | children.forEach(stickify); |
| 7143 | } |
| 7144 | } |
| 7145 | function worst(row, u) { |
| 7146 | var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length; |
| 7147 | while (++i < n) { |
| 7148 | if (!(r = row[i].area)) continue; |
| 7149 | if (r < rmin) rmin = r; |
| 7150 | if (r > rmax) rmax = r; |
| 7151 | } |
| 7152 | s *= s; |
| 7153 | u *= u; |
| 7154 | return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity; |
| 7155 | } |
| 7156 | function position(row, u, rect, flush) { |
| 7157 | var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o; |
| 7158 | if (u == rect.dx) { |
| 7159 | if (flush || v > rect.dy) v = rect.dy; |
| 7160 | while (++i < n) { |
| 7161 | o = row[i]; |
| 7162 | o.x = x; |
| 7163 | o.y = y; |
| 7164 | o.dy = v; |
| 7165 | x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0); |
| 7166 | } |
| 7167 | o.z = true; |
| 7168 | o.dx += rect.x + rect.dx - x; |
| 7169 | rect.y += v; |
| 7170 | rect.dy -= v; |
| 7171 | } else { |
| 7172 | if (flush || v > rect.dx) v = rect.dx; |
| 7173 | while (++i < n) { |
| 7174 | o = row[i]; |
| 7175 | o.x = x; |
| 7176 | o.y = y; |
| 7177 | o.dx = v; |
| 7178 | y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0); |
| 7179 | } |
| 7180 | o.z = false; |
| 7181 | o.dy += rect.y + rect.dy - y; |
| 7182 | rect.x += v; |
| 7183 | rect.dx -= v; |
| 7184 | } |
| 7185 | } |
| 7186 | function treemap(d) { |
| 7187 | var nodes = stickies || hierarchy(d), root = nodes[0]; |
| 7188 | root.x = 0; |
| 7189 | root.y = 0; |
| 7190 | root.dx = size[0]; |
| 7191 | root.dy = size[1]; |
| 7192 | if (stickies) hierarchy.revalue(root); |
| 7193 | scale([ root ], root.dx * root.dy / root.value); |
| 7194 | (stickies ? stickify : squarify)(root); |
| 7195 | if (sticky) stickies = nodes; |
| 7196 | return nodes; |
| 7197 | } |
| 7198 | treemap.size = function(x) { |
| 7199 | if (!arguments.length) return size; |
| 7200 | size = x; |
| 7201 | return treemap; |
| 7202 | }; |
| 7203 | treemap.padding = function(x) { |
| 7204 | if (!arguments.length) return padding; |
| 7205 | function padFunction(node) { |
| 7206 | var p = x.call(treemap, node, node.depth); |
| 7207 | return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p); |
| 7208 | } |
| 7209 | function padConstant(node) { |
| 7210 | return d3_layout_treemapPad(node, x); |
| 7211 | } |
| 7212 | var type; |
| 7213 | pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ], |
| 7214 | padConstant) : padConstant; |
| 7215 | return treemap; |
| 7216 | }; |
| 7217 | treemap.round = function(x) { |
| 7218 | if (!arguments.length) return round != Number; |
| 7219 | round = x ? Math.round : Number; |
| 7220 | return treemap; |
| 7221 | }; |
| 7222 | treemap.sticky = function(x) { |
| 7223 | if (!arguments.length) return sticky; |
| 7224 | sticky = x; |
| 7225 | stickies = null; |
| 7226 | return treemap; |
| 7227 | }; |
| 7228 | treemap.ratio = function(x) { |
| 7229 | if (!arguments.length) return ratio; |
| 7230 | ratio = x; |
| 7231 | return treemap; |
| 7232 | }; |
| 7233 | treemap.mode = function(x) { |
| 7234 | if (!arguments.length) return mode; |
| 7235 | mode = x + ""; |
| 7236 | return treemap; |
| 7237 | }; |
| 7238 | return d3_layout_hierarchyRebind(treemap, hierarchy); |
| 7239 | }; |
| 7240 | function d3_layout_treemapPadNull(node) { |
| 7241 | return { |
| 7242 | x: node.x, |
| 7243 | y: node.y, |
| 7244 | dx: node.dx, |
| 7245 | dy: node.dy |
| 7246 | }; |
| 7247 | } |
| 7248 | function d3_layout_treemapPad(node, padding) { |
| 7249 | 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]; |
| 7250 | if (dx < 0) { |
| 7251 | x += dx / 2; |
| 7252 | dx = 0; |
| 7253 | } |
| 7254 | if (dy < 0) { |
| 7255 | y += dy / 2; |
| 7256 | dy = 0; |
| 7257 | } |
| 7258 | return { |
| 7259 | x: x, |
| 7260 | y: y, |
| 7261 | dx: dx, |
| 7262 | dy: dy |
| 7263 | }; |
| 7264 | } |
| 7265 | d3.random = { |
| 7266 | normal: function(µ, σ) { |
| 7267 | var n = arguments.length; |
| 7268 | if (n < 2) σ = 1; |
| 7269 | if (n < 1) µ = 0; |
| 7270 | return function() { |
| 7271 | var x, y, r; |
| 7272 | do { |
| 7273 | x = Math.random() * 2 - 1; |
| 7274 | y = Math.random() * 2 - 1; |
| 7275 | r = x * x + y * y; |
| 7276 | } while (!r || r > 1); |
| 7277 | return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r); |
| 7278 | }; |
| 7279 | }, |
| 7280 | logNormal: function() { |
| 7281 | var random = d3.random.normal.apply(d3, arguments); |
| 7282 | return function() { |
| 7283 | return Math.exp(random()); |
| 7284 | }; |
| 7285 | }, |
| 7286 | bates: function(m) { |
| 7287 | var random = d3.random.irwinHall(m); |
| 7288 | return function() { |
| 7289 | return random() / m; |
| 7290 | }; |
| 7291 | }, |
| 7292 | irwinHall: function(m) { |
| 7293 | return function() { |
| 7294 | for (var s = 0, j = 0; j < m; j++) s += Math.random(); |
| 7295 | return s; |
| 7296 | }; |
| 7297 | } |
| 7298 | }; |
| 7299 | d3.scale = {}; |
| 7300 | function d3_scaleExtent(domain) { |
| 7301 | var start = domain[0], stop = domain[domain.length - 1]; |
| 7302 | return start < stop ? [ start, stop ] : [ stop, start ]; |
| 7303 | } |
| 7304 | function d3_scaleRange(scale) { |
| 7305 | return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range()); |
| 7306 | } |
| 7307 | function d3_scale_bilinear(domain, range, uninterpolate, interpolate) { |
| 7308 | var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]); |
| 7309 | return function(x) { |
| 7310 | return i(u(x)); |
| 7311 | }; |
| 7312 | } |
| 7313 | function d3_scale_nice(domain, nice) { |
| 7314 | var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx; |
| 7315 | if (x1 < x0) { |
| 7316 | dx = i0, i0 = i1, i1 = dx; |
| 7317 | dx = x0, x0 = x1, x1 = dx; |
| 7318 | } |
| 7319 | domain[i0] = nice.floor(x0); |
| 7320 | domain[i1] = nice.ceil(x1); |
| 7321 | return domain; |
| 7322 | } |
| 7323 | function d3_scale_niceStep(step) { |
| 7324 | return step ? { |
| 7325 | floor: function(x) { |
| 7326 | return Math.floor(x / step) * step; |
| 7327 | }, |
| 7328 | ceil: function(x) { |
| 7329 | return Math.ceil(x / step) * step; |
| 7330 | } |
| 7331 | } : d3_scale_niceIdentity; |
| 7332 | } |
| 7333 | var d3_scale_niceIdentity = { |
| 7334 | floor: d3_identity, |
| 7335 | ceil: d3_identity |
| 7336 | }; |
| 7337 | function d3_scale_polylinear(domain, range, uninterpolate, interpolate) { |
| 7338 | var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1; |
| 7339 | if (domain[k] < domain[0]) { |
| 7340 | domain = domain.slice().reverse(); |
| 7341 | range = range.slice().reverse(); |
| 7342 | } |
| 7343 | while (++j <= k) { |
| 7344 | u.push(uninterpolate(domain[j - 1], domain[j])); |
| 7345 | i.push(interpolate(range[j - 1], range[j])); |
| 7346 | } |
| 7347 | return function(x) { |
| 7348 | var j = d3.bisect(domain, x, 1, k) - 1; |
| 7349 | return i[j](u[j](x)); |
| 7350 | }; |
| 7351 | } |
| 7352 | d3.scale.linear = function() { |
| 7353 | return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false); |
| 7354 | }; |
| 7355 | function d3_scale_linear(domain, range, interpolate, clamp) { |
| 7356 | var output, input; |
| 7357 | function rescale() { |
| 7358 | var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber; |
| 7359 | output = linear(domain, range, uninterpolate, interpolate); |
| 7360 | input = linear(range, domain, uninterpolate, d3_interpolate); |
| 7361 | return scale; |
| 7362 | } |
| 7363 | function scale(x) { |
| 7364 | return output(x); |
| 7365 | } |
| 7366 | scale.invert = function(y) { |
| 7367 | return input(y); |
| 7368 | }; |
| 7369 | scale.domain = function(x) { |
| 7370 | if (!arguments.length) return domain; |
| 7371 | domain = x.map(Number); |
| 7372 | return rescale(); |
| 7373 | }; |
| 7374 | scale.range = function(x) { |
| 7375 | if (!arguments.length) return range; |
| 7376 | range = x; |
| 7377 | return rescale(); |
| 7378 | }; |
| 7379 | scale.rangeRound = function(x) { |
| 7380 | return scale.range(x).interpolate(d3_interpolateRound); |
| 7381 | }; |
| 7382 | scale.clamp = function(x) { |
| 7383 | if (!arguments.length) return clamp; |
| 7384 | clamp = x; |
| 7385 | return rescale(); |
| 7386 | }; |
| 7387 | scale.interpolate = function(x) { |
| 7388 | if (!arguments.length) return interpolate; |
| 7389 | interpolate = x; |
| 7390 | return rescale(); |
| 7391 | }; |
| 7392 | scale.ticks = function(m) { |
| 7393 | return d3_scale_linearTicks(domain, m); |
| 7394 | }; |
| 7395 | scale.tickFormat = function(m, format) { |
| 7396 | return d3_scale_linearTickFormat(domain, m, format); |
| 7397 | }; |
| 7398 | scale.nice = function(m) { |
| 7399 | d3_scale_linearNice(domain, m); |
| 7400 | return rescale(); |
| 7401 | }; |
| 7402 | scale.copy = function() { |
| 7403 | return d3_scale_linear(domain, range, interpolate, clamp); |
| 7404 | }; |
| 7405 | return rescale(); |
| 7406 | } |
| 7407 | function d3_scale_linearRebind(scale, linear) { |
| 7408 | return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp"); |
| 7409 | } |
| 7410 | function d3_scale_linearNice(domain, m) { |
| 7411 | return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2])); |
| 7412 | } |
| 7413 | function d3_scale_linearTickRange(domain, m) { |
| 7414 | if (m == null) m = 10; |
| 7415 | 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; |
| 7416 | if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2; |
| 7417 | extent[0] = Math.ceil(extent[0] / step) * step; |
| 7418 | extent[1] = Math.floor(extent[1] / step) * step + step * .5; |
| 7419 | extent[2] = step; |
| 7420 | return extent; |
| 7421 | } |
| 7422 | function d3_scale_linearTicks(domain, m) { |
| 7423 | return d3.range.apply(d3, d3_scale_linearTickRange(domain, m)); |
| 7424 | } |
| 7425 | function d3_scale_linearTickFormat(domain, m, format) { |
| 7426 | var range = d3_scale_linearTickRange(domain, m); |
| 7427 | if (format) { |
| 7428 | var match = d3_format_re.exec(format); |
| 7429 | match.shift(); |
| 7430 | if (match[8] === "s") { |
| 7431 | var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1]))); |
| 7432 | if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2])); |
| 7433 | match[8] = "f"; |
| 7434 | format = d3.format(match.join("")); |
| 7435 | return function(d) { |
| 7436 | return format(prefix.scale(d)) + prefix.symbol; |
| 7437 | }; |
| 7438 | } |
| 7439 | if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range); |
| 7440 | format = match.join(""); |
| 7441 | } else { |
| 7442 | format = ",." + d3_scale_linearPrecision(range[2]) + "f"; |
| 7443 | } |
| 7444 | return d3.format(format); |
| 7445 | } |
| 7446 | var d3_scale_linearFormatSignificant = { |
| 7447 | s: 1, |
| 7448 | g: 1, |
| 7449 | p: 1, |
| 7450 | r: 1, |
| 7451 | e: 1 |
| 7452 | }; |
| 7453 | function d3_scale_linearPrecision(value) { |
| 7454 | return -Math.floor(Math.log(value) / Math.LN10 + .01); |
| 7455 | } |
| 7456 | function d3_scale_linearFormatPrecision(type, range) { |
| 7457 | var p = d3_scale_linearPrecision(range[2]); |
| 7458 | 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; |
| 7459 | } |
| 7460 | d3.scale.log = function() { |
| 7461 | return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]); |
| 7462 | }; |
| 7463 | function d3_scale_log(linear, base, positive, domain) { |
| 7464 | function log(x) { |
| 7465 | return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base); |
| 7466 | } |
| 7467 | function pow(x) { |
| 7468 | return positive ? Math.pow(base, x) : -Math.pow(base, -x); |
| 7469 | } |
| 7470 | function scale(x) { |
| 7471 | return linear(log(x)); |
| 7472 | } |
| 7473 | scale.invert = function(x) { |
| 7474 | return pow(linear.invert(x)); |
| 7475 | }; |
| 7476 | scale.domain = function(x) { |
| 7477 | if (!arguments.length) return domain; |
| 7478 | positive = x[0] >= 0; |
| 7479 | linear.domain((domain = x.map(Number)).map(log)); |
| 7480 | return scale; |
| 7481 | }; |
| 7482 | scale.base = function(_) { |
| 7483 | if (!arguments.length) return base; |
| 7484 | base = +_; |
| 7485 | linear.domain(domain.map(log)); |
| 7486 | return scale; |
| 7487 | }; |
| 7488 | scale.nice = function() { |
| 7489 | var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative); |
| 7490 | linear.domain(niced); |
| 7491 | domain = niced.map(pow); |
| 7492 | return scale; |
| 7493 | }; |
| 7494 | scale.ticks = function() { |
| 7495 | 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; |
| 7496 | if (isFinite(j - i)) { |
| 7497 | if (positive) { |
| 7498 | for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k); |
| 7499 | ticks.push(pow(i)); |
| 7500 | } else { |
| 7501 | ticks.push(pow(i)); |
| 7502 | for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k); |
| 7503 | } |
| 7504 | for (i = 0; ticks[i] < u; i++) {} |
| 7505 | for (j = ticks.length; ticks[j - 1] > v; j--) {} |
| 7506 | ticks = ticks.slice(i, j); |
| 7507 | } |
| 7508 | return ticks; |
| 7509 | }; |
| 7510 | scale.tickFormat = function(n, format) { |
| 7511 | if (!arguments.length) return d3_scale_logFormat; |
| 7512 | if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format); |
| 7513 | var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12, |
| 7514 | Math.floor), e; |
| 7515 | return function(d) { |
| 7516 | return d / pow(f(log(d) + e)) <= k ? format(d) : ""; |
| 7517 | }; |
| 7518 | }; |
| 7519 | scale.copy = function() { |
| 7520 | return d3_scale_log(linear.copy(), base, positive, domain); |
| 7521 | }; |
| 7522 | return d3_scale_linearRebind(scale, linear); |
| 7523 | } |
| 7524 | var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = { |
| 7525 | floor: function(x) { |
| 7526 | return -Math.ceil(-x); |
| 7527 | }, |
| 7528 | ceil: function(x) { |
| 7529 | return -Math.floor(-x); |
| 7530 | } |
| 7531 | }; |
| 7532 | d3.scale.pow = function() { |
| 7533 | return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]); |
| 7534 | }; |
| 7535 | function d3_scale_pow(linear, exponent, domain) { |
| 7536 | var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent); |
| 7537 | function scale(x) { |
| 7538 | return linear(powp(x)); |
| 7539 | } |
| 7540 | scale.invert = function(x) { |
| 7541 | return powb(linear.invert(x)); |
| 7542 | }; |
| 7543 | scale.domain = function(x) { |
| 7544 | if (!arguments.length) return domain; |
| 7545 | linear.domain((domain = x.map(Number)).map(powp)); |
| 7546 | return scale; |
| 7547 | }; |
| 7548 | scale.ticks = function(m) { |
| 7549 | return d3_scale_linearTicks(domain, m); |
| 7550 | }; |
| 7551 | scale.tickFormat = function(m, format) { |
| 7552 | return d3_scale_linearTickFormat(domain, m, format); |
| 7553 | }; |
| 7554 | scale.nice = function(m) { |
| 7555 | return scale.domain(d3_scale_linearNice(domain, m)); |
| 7556 | }; |
| 7557 | scale.exponent = function(x) { |
| 7558 | if (!arguments.length) return exponent; |
| 7559 | powp = d3_scale_powPow(exponent = x); |
| 7560 | powb = d3_scale_powPow(1 / exponent); |
| 7561 | linear.domain(domain.map(powp)); |
| 7562 | return scale; |
| 7563 | }; |
| 7564 | scale.copy = function() { |
| 7565 | return d3_scale_pow(linear.copy(), exponent, domain); |
| 7566 | }; |
| 7567 | return d3_scale_linearRebind(scale, linear); |
| 7568 | } |
| 7569 | function d3_scale_powPow(e) { |
| 7570 | return function(x) { |
| 7571 | return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e); |
| 7572 | }; |
| 7573 | } |
| 7574 | d3.scale.sqrt = function() { |
| 7575 | return d3.scale.pow().exponent(.5); |
| 7576 | }; |
| 7577 | d3.scale.ordinal = function() { |
| 7578 | return d3_scale_ordinal([], { |
| 7579 | t: "range", |
| 7580 | a: [ [] ] |
| 7581 | }); |
| 7582 | }; |
| 7583 | function d3_scale_ordinal(domain, ranger) { |
| 7584 | var index, range, rangeBand; |
| 7585 | function scale(x) { |
| 7586 | return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length]; |
| 7587 | } |
| 7588 | function steps(start, step) { |
| 7589 | return d3.range(domain.length).map(function(i) { |
| 7590 | return start + step * i; |
| 7591 | }); |
| 7592 | } |
| 7593 | scale.domain = function(x) { |
| 7594 | if (!arguments.length) return domain; |
| 7595 | domain = []; |
| 7596 | index = new d3_Map(); |
| 7597 | var i = -1, n = x.length, xi; |
| 7598 | while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi)); |
| 7599 | return scale[ranger.t].apply(scale, ranger.a); |
| 7600 | }; |
| 7601 | scale.range = function(x) { |
| 7602 | if (!arguments.length) return range; |
| 7603 | range = x; |
| 7604 | rangeBand = 0; |
| 7605 | ranger = { |
| 7606 | t: "range", |
| 7607 | a: arguments |
| 7608 | }; |
| 7609 | return scale; |
| 7610 | }; |
| 7611 | scale.rangePoints = function(x, padding) { |
| 7612 | if (arguments.length < 2) padding = 0; |
| 7613 | var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding); |
| 7614 | range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step); |
| 7615 | rangeBand = 0; |
| 7616 | ranger = { |
| 7617 | t: "rangePoints", |
| 7618 | a: arguments |
| 7619 | }; |
| 7620 | return scale; |
| 7621 | }; |
| 7622 | scale.rangeBands = function(x, padding, outerPadding) { |
| 7623 | if (arguments.length < 2) padding = 0; |
| 7624 | if (arguments.length < 3) outerPadding = padding; |
| 7625 | var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding); |
| 7626 | range = steps(start + step * outerPadding, step); |
| 7627 | if (reverse) range.reverse(); |
| 7628 | rangeBand = step * (1 - padding); |
| 7629 | ranger = { |
| 7630 | t: "rangeBands", |
| 7631 | a: arguments |
| 7632 | }; |
| 7633 | return scale; |
| 7634 | }; |
| 7635 | scale.rangeRoundBands = function(x, padding, outerPadding) { |
| 7636 | if (arguments.length < 2) padding = 0; |
| 7637 | if (arguments.length < 3) outerPadding = padding; |
| 7638 | 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; |
| 7639 | range = steps(start + Math.round(error / 2), step); |
| 7640 | if (reverse) range.reverse(); |
| 7641 | rangeBand = Math.round(step * (1 - padding)); |
| 7642 | ranger = { |
| 7643 | t: "rangeRoundBands", |
| 7644 | a: arguments |
| 7645 | }; |
| 7646 | return scale; |
| 7647 | }; |
| 7648 | scale.rangeBand = function() { |
| 7649 | return rangeBand; |
| 7650 | }; |
| 7651 | scale.rangeExtent = function() { |
| 7652 | return d3_scaleExtent(ranger.a[0]); |
| 7653 | }; |
| 7654 | scale.copy = function() { |
| 7655 | return d3_scale_ordinal(domain, ranger); |
| 7656 | }; |
| 7657 | return scale.domain(domain); |
| 7658 | } |
| 7659 | d3.scale.category10 = function() { |
| 7660 | return d3.scale.ordinal().range(d3_category10); |
| 7661 | }; |
| 7662 | d3.scale.category20 = function() { |
| 7663 | return d3.scale.ordinal().range(d3_category20); |
| 7664 | }; |
| 7665 | d3.scale.category20b = function() { |
| 7666 | return d3.scale.ordinal().range(d3_category20b); |
| 7667 | }; |
| 7668 | d3.scale.category20c = function() { |
| 7669 | return d3.scale.ordinal().range(d3_category20c); |
| 7670 | }; |
| 7671 | var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString); |
| 7672 | 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); |
| 7673 | 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); |
| 7674 | 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); |
| 7675 | d3.scale.quantile = function() { |
| 7676 | return d3_scale_quantile([], []); |
| 7677 | }; |
| 7678 | function d3_scale_quantile(domain, range) { |
| 7679 | var thresholds; |
| 7680 | function rescale() { |
| 7681 | var k = 0, q = range.length; |
| 7682 | thresholds = []; |
| 7683 | while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q); |
| 7684 | return scale; |
| 7685 | } |
| 7686 | function scale(x) { |
| 7687 | if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)]; |
| 7688 | } |
| 7689 | scale.domain = function(x) { |
| 7690 | if (!arguments.length) return domain; |
| 7691 | domain = x.filter(d3_number).sort(d3_ascending); |
| 7692 | return rescale(); |
| 7693 | }; |
| 7694 | scale.range = function(x) { |
| 7695 | if (!arguments.length) return range; |
| 7696 | range = x; |
| 7697 | return rescale(); |
| 7698 | }; |
| 7699 | scale.quantiles = function() { |
| 7700 | return thresholds; |
| 7701 | }; |
| 7702 | scale.invertExtent = function(y) { |
| 7703 | y = range.indexOf(y); |
| 7704 | return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ]; |
| 7705 | }; |
| 7706 | scale.copy = function() { |
| 7707 | return d3_scale_quantile(domain, range); |
| 7708 | }; |
| 7709 | return rescale(); |
| 7710 | } |
| 7711 | d3.scale.quantize = function() { |
| 7712 | return d3_scale_quantize(0, 1, [ 0, 1 ]); |
| 7713 | }; |
| 7714 | function d3_scale_quantize(x0, x1, range) { |
| 7715 | var kx, i; |
| 7716 | function scale(x) { |
| 7717 | return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))]; |
| 7718 | } |
| 7719 | function rescale() { |
| 7720 | kx = range.length / (x1 - x0); |
| 7721 | i = range.length - 1; |
| 7722 | return scale; |
| 7723 | } |
| 7724 | scale.domain = function(x) { |
| 7725 | if (!arguments.length) return [ x0, x1 ]; |
| 7726 | x0 = +x[0]; |
| 7727 | x1 = +x[x.length - 1]; |
| 7728 | return rescale(); |
| 7729 | }; |
| 7730 | scale.range = function(x) { |
| 7731 | if (!arguments.length) return range; |
| 7732 | range = x; |
| 7733 | return rescale(); |
| 7734 | }; |
| 7735 | scale.invertExtent = function(y) { |
| 7736 | y = range.indexOf(y); |
| 7737 | y = y < 0 ? NaN : y / kx + x0; |
| 7738 | return [ y, y + 1 / kx ]; |
| 7739 | }; |
| 7740 | scale.copy = function() { |
| 7741 | return d3_scale_quantize(x0, x1, range); |
| 7742 | }; |
| 7743 | return rescale(); |
| 7744 | } |
| 7745 | d3.scale.threshold = function() { |
| 7746 | return d3_scale_threshold([ .5 ], [ 0, 1 ]); |
| 7747 | }; |
| 7748 | function d3_scale_threshold(domain, range) { |
| 7749 | function scale(x) { |
| 7750 | if (x <= x) return range[d3.bisect(domain, x)]; |
| 7751 | } |
| 7752 | scale.domain = function(_) { |
| 7753 | if (!arguments.length) return domain; |
| 7754 | domain = _; |
| 7755 | return scale; |
| 7756 | }; |
| 7757 | scale.range = function(_) { |
| 7758 | if (!arguments.length) return range; |
| 7759 | range = _; |
| 7760 | return scale; |
| 7761 | }; |
| 7762 | scale.invertExtent = function(y) { |
| 7763 | y = range.indexOf(y); |
| 7764 | return [ domain[y - 1], domain[y] ]; |
| 7765 | }; |
| 7766 | scale.copy = function() { |
| 7767 | return d3_scale_threshold(domain, range); |
| 7768 | }; |
| 7769 | return scale; |
| 7770 | } |
| 7771 | d3.scale.identity = function() { |
| 7772 | return d3_scale_identity([ 0, 1 ]); |
| 7773 | }; |
| 7774 | function d3_scale_identity(domain) { |
| 7775 | function identity(x) { |
| 7776 | return +x; |
| 7777 | } |
| 7778 | identity.invert = identity; |
| 7779 | identity.domain = identity.range = function(x) { |
| 7780 | if (!arguments.length) return domain; |
| 7781 | domain = x.map(identity); |
| 7782 | return identity; |
| 7783 | }; |
| 7784 | identity.ticks = function(m) { |
| 7785 | return d3_scale_linearTicks(domain, m); |
| 7786 | }; |
| 7787 | identity.tickFormat = function(m, format) { |
| 7788 | return d3_scale_linearTickFormat(domain, m, format); |
| 7789 | }; |
| 7790 | identity.copy = function() { |
| 7791 | return d3_scale_identity(domain); |
| 7792 | }; |
| 7793 | return identity; |
| 7794 | } |
| 7795 | d3.svg = {}; |
| 7796 | d3.svg.arc = function() { |
| 7797 | var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle; |
| 7798 | function arc() { |
| 7799 | 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, |
| 7800 | 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); |
| 7801 | 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"; |
| 7802 | } |
| 7803 | arc.innerRadius = function(v) { |
| 7804 | if (!arguments.length) return innerRadius; |
| 7805 | innerRadius = d3_functor(v); |
| 7806 | return arc; |
| 7807 | }; |
| 7808 | arc.outerRadius = function(v) { |
| 7809 | if (!arguments.length) return outerRadius; |
| 7810 | outerRadius = d3_functor(v); |
| 7811 | return arc; |
| 7812 | }; |
| 7813 | arc.startAngle = function(v) { |
| 7814 | if (!arguments.length) return startAngle; |
| 7815 | startAngle = d3_functor(v); |
| 7816 | return arc; |
| 7817 | }; |
| 7818 | arc.endAngle = function(v) { |
| 7819 | if (!arguments.length) return endAngle; |
| 7820 | endAngle = d3_functor(v); |
| 7821 | return arc; |
| 7822 | }; |
| 7823 | arc.centroid = function() { |
| 7824 | var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset; |
| 7825 | return [ Math.cos(a) * r, Math.sin(a) * r ]; |
| 7826 | }; |
| 7827 | return arc; |
| 7828 | }; |
| 7829 | var d3_svg_arcOffset = -halfπ, d3_svg_arcMax = τ - ε; |
| 7830 | function d3_svg_arcInnerRadius(d) { |
| 7831 | return d.innerRadius; |
| 7832 | } |
| 7833 | function d3_svg_arcOuterRadius(d) { |
| 7834 | return d.outerRadius; |
| 7835 | } |
| 7836 | function d3_svg_arcStartAngle(d) { |
| 7837 | return d.startAngle; |
| 7838 | } |
| 7839 | function d3_svg_arcEndAngle(d) { |
| 7840 | return d.endAngle; |
| 7841 | } |
| 7842 | function d3_svg_line(projection) { |
| 7843 | var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7; |
| 7844 | function line(data) { |
| 7845 | var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y); |
| 7846 | function segment() { |
| 7847 | segments.push("M", interpolate(projection(points), tension)); |
| 7848 | } |
| 7849 | while (++i < n) { |
| 7850 | if (defined.call(this, d = data[i], i)) { |
| 7851 | points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]); |
| 7852 | } else if (points.length) { |
| 7853 | segment(); |
| 7854 | points = []; |
| 7855 | } |
| 7856 | } |
| 7857 | if (points.length) segment(); |
| 7858 | return segments.length ? segments.join("") : null; |
| 7859 | } |
| 7860 | line.x = function(_) { |
| 7861 | if (!arguments.length) return x; |
| 7862 | x = _; |
| 7863 | return line; |
| 7864 | }; |
| 7865 | line.y = function(_) { |
| 7866 | if (!arguments.length) return y; |
| 7867 | y = _; |
| 7868 | return line; |
| 7869 | }; |
| 7870 | line.defined = function(_) { |
| 7871 | if (!arguments.length) return defined; |
| 7872 | defined = _; |
| 7873 | return line; |
| 7874 | }; |
| 7875 | line.interpolate = function(_) { |
| 7876 | if (!arguments.length) return interpolateKey; |
| 7877 | if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key; |
| 7878 | return line; |
| 7879 | }; |
| 7880 | line.tension = function(_) { |
| 7881 | if (!arguments.length) return tension; |
| 7882 | tension = _; |
| 7883 | return line; |
| 7884 | }; |
| 7885 | return line; |
| 7886 | } |
| 7887 | d3.svg.line = function() { |
| 7888 | return d3_svg_line(d3_identity); |
| 7889 | }; |
| 7890 | var d3_svg_lineInterpolators = d3.map({ |
| 7891 | linear: d3_svg_lineLinear, |
| 7892 | "linear-closed": d3_svg_lineLinearClosed, |
| 7893 | step: d3_svg_lineStep, |
| 7894 | "step-before": d3_svg_lineStepBefore, |
| 7895 | "step-after": d3_svg_lineStepAfter, |
| 7896 | basis: d3_svg_lineBasis, |
| 7897 | "basis-open": d3_svg_lineBasisOpen, |
| 7898 | "basis-closed": d3_svg_lineBasisClosed, |
| 7899 | bundle: d3_svg_lineBundle, |
| 7900 | cardinal: d3_svg_lineCardinal, |
| 7901 | "cardinal-open": d3_svg_lineCardinalOpen, |
| 7902 | "cardinal-closed": d3_svg_lineCardinalClosed, |
| 7903 | monotone: d3_svg_lineMonotone |
| 7904 | }); |
| 7905 | d3_svg_lineInterpolators.forEach(function(key, value) { |
| 7906 | value.key = key; |
| 7907 | value.closed = /-closed$/.test(key); |
| 7908 | }); |
| 7909 | function d3_svg_lineLinear(points) { |
| 7910 | return points.join("L"); |
| 7911 | } |
| 7912 | function d3_svg_lineLinearClosed(points) { |
| 7913 | return d3_svg_lineLinear(points) + "Z"; |
| 7914 | } |
| 7915 | function d3_svg_lineStep(points) { |
| 7916 | var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ]; |
| 7917 | while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]); |
| 7918 | if (n > 1) path.push("H", p[0]); |
| 7919 | return path.join(""); |
| 7920 | } |
| 7921 | function d3_svg_lineStepBefore(points) { |
| 7922 | var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ]; |
| 7923 | while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]); |
| 7924 | return path.join(""); |
| 7925 | } |
| 7926 | function d3_svg_lineStepAfter(points) { |
| 7927 | var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ]; |
| 7928 | while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]); |
| 7929 | return path.join(""); |
| 7930 | } |
| 7931 | function d3_svg_lineCardinalOpen(points, tension) { |
| 7932 | return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension)); |
| 7933 | } |
| 7934 | function d3_svg_lineCardinalClosed(points, tension) { |
| 7935 | return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]), |
| 7936 | points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension)); |
| 7937 | } |
| 7938 | function d3_svg_lineCardinal(points, tension) { |
| 7939 | return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension)); |
| 7940 | } |
| 7941 | function d3_svg_lineHermite(points, tangents) { |
| 7942 | if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) { |
| 7943 | return d3_svg_lineLinear(points); |
| 7944 | } |
| 7945 | var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1; |
| 7946 | if (quad) { |
| 7947 | path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1]; |
| 7948 | p0 = points[1]; |
| 7949 | pi = 2; |
| 7950 | } |
| 7951 | if (tangents.length > 1) { |
| 7952 | t = tangents[1]; |
| 7953 | p = points[pi]; |
| 7954 | pi++; |
| 7955 | path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1]; |
| 7956 | for (var i = 2; i < tangents.length; i++, pi++) { |
| 7957 | p = points[pi]; |
| 7958 | t = tangents[i]; |
| 7959 | path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1]; |
| 7960 | } |
| 7961 | } |
| 7962 | if (quad) { |
| 7963 | var lp = points[pi]; |
| 7964 | path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1]; |
| 7965 | } |
| 7966 | return path; |
| 7967 | } |
| 7968 | function d3_svg_lineCardinalTangents(points, tension) { |
| 7969 | var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length; |
| 7970 | while (++i < n) { |
| 7971 | p0 = p1; |
| 7972 | p1 = p2; |
| 7973 | p2 = points[i]; |
| 7974 | tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]); |
| 7975 | } |
| 7976 | return tangents; |
| 7977 | } |
| 7978 | function d3_svg_lineBasis(points) { |
| 7979 | if (points.length < 3) return d3_svg_lineLinear(points); |
| 7980 | 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) ]; |
| 7981 | points.push(points[n - 1]); |
| 7982 | while (++i <= n) { |
| 7983 | pi = points[i]; |
| 7984 | px.shift(); |
| 7985 | px.push(pi[0]); |
| 7986 | py.shift(); |
| 7987 | py.push(pi[1]); |
| 7988 | d3_svg_lineBasisBezier(path, px, py); |
| 7989 | } |
| 7990 | points.pop(); |
| 7991 | path.push("L", pi); |
| 7992 | return path.join(""); |
| 7993 | } |
| 7994 | function d3_svg_lineBasisOpen(points) { |
| 7995 | if (points.length < 4) return d3_svg_lineLinear(points); |
| 7996 | var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ]; |
| 7997 | while (++i < 3) { |
| 7998 | pi = points[i]; |
| 7999 | px.push(pi[0]); |
| 8000 | py.push(pi[1]); |
| 8001 | } |
| 8002 | path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py)); |
| 8003 | --i; |
| 8004 | while (++i < n) { |
| 8005 | pi = points[i]; |
| 8006 | px.shift(); |
| 8007 | px.push(pi[0]); |
| 8008 | py.shift(); |
| 8009 | py.push(pi[1]); |
| 8010 | d3_svg_lineBasisBezier(path, px, py); |
| 8011 | } |
| 8012 | return path.join(""); |
| 8013 | } |
| 8014 | function d3_svg_lineBasisClosed(points) { |
| 8015 | var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = []; |
| 8016 | while (++i < 4) { |
| 8017 | pi = points[i % n]; |
| 8018 | px.push(pi[0]); |
| 8019 | py.push(pi[1]); |
| 8020 | } |
| 8021 | path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ]; |
| 8022 | --i; |
| 8023 | while (++i < m) { |
| 8024 | pi = points[i % n]; |
| 8025 | px.shift(); |
| 8026 | px.push(pi[0]); |
| 8027 | py.shift(); |
| 8028 | py.push(pi[1]); |
| 8029 | d3_svg_lineBasisBezier(path, px, py); |
| 8030 | } |
| 8031 | return path.join(""); |
| 8032 | } |
| 8033 | function d3_svg_lineBundle(points, tension) { |
| 8034 | var n = points.length - 1; |
| 8035 | if (n) { |
| 8036 | var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t; |
| 8037 | while (++i <= n) { |
| 8038 | p = points[i]; |
| 8039 | t = i / n; |
| 8040 | p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx); |
| 8041 | p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy); |
| 8042 | } |
| 8043 | } |
| 8044 | return d3_svg_lineBasis(points); |
| 8045 | } |
| 8046 | function d3_svg_lineDot4(a, b) { |
| 8047 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; |
| 8048 | } |
| 8049 | 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 ]; |
| 8050 | function d3_svg_lineBasisBezier(path, x, y) { |
| 8051 | 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)); |
| 8052 | } |
| 8053 | function d3_svg_lineSlope(p0, p1) { |
| 8054 | return (p1[1] - p0[1]) / (p1[0] - p0[0]); |
| 8055 | } |
| 8056 | function d3_svg_lineFiniteDifferences(points) { |
| 8057 | var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1); |
| 8058 | while (++i < j) { |
| 8059 | m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2; |
| 8060 | } |
| 8061 | m[i] = d; |
| 8062 | return m; |
| 8063 | } |
| 8064 | function d3_svg_lineMonotoneTangents(points) { |
| 8065 | var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1; |
| 8066 | while (++i < j) { |
| 8067 | d = d3_svg_lineSlope(points[i], points[i + 1]); |
| 8068 | if (abs(d) < ε) { |
| 8069 | m[i] = m[i + 1] = 0; |
| 8070 | } else { |
| 8071 | a = m[i] / d; |
| 8072 | b = m[i + 1] / d; |
| 8073 | s = a * a + b * b; |
| 8074 | if (s > 9) { |
| 8075 | s = d * 3 / Math.sqrt(s); |
| 8076 | m[i] = s * a; |
| 8077 | m[i + 1] = s * b; |
| 8078 | } |
| 8079 | } |
| 8080 | } |
| 8081 | i = -1; |
| 8082 | while (++i <= j) { |
| 8083 | s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i])); |
| 8084 | tangents.push([ s || 0, m[i] * s || 0 ]); |
| 8085 | } |
| 8086 | return tangents; |
| 8087 | } |
| 8088 | function d3_svg_lineMonotone(points) { |
| 8089 | return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points)); |
| 8090 | } |
| 8091 | d3.svg.line.radial = function() { |
| 8092 | var line = d3_svg_line(d3_svg_lineRadial); |
| 8093 | line.radius = line.x, delete line.x; |
| 8094 | line.angle = line.y, delete line.y; |
| 8095 | return line; |
| 8096 | }; |
| 8097 | function d3_svg_lineRadial(points) { |
| 8098 | var point, i = -1, n = points.length, r, a; |
| 8099 | while (++i < n) { |
| 8100 | point = points[i]; |
| 8101 | r = point[0]; |
| 8102 | a = point[1] + d3_svg_arcOffset; |
| 8103 | point[0] = r * Math.cos(a); |
| 8104 | point[1] = r * Math.sin(a); |
| 8105 | } |
| 8106 | return points; |
| 8107 | } |
| 8108 | function d3_svg_area(projection) { |
| 8109 | 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; |
| 8110 | function area(data) { |
| 8111 | var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() { |
| 8112 | return x; |
| 8113 | } : d3_functor(x1), fy1 = y0 === y1 ? function() { |
| 8114 | return y; |
| 8115 | } : d3_functor(y1), x, y; |
| 8116 | function segment() { |
| 8117 | segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z"); |
| 8118 | } |
| 8119 | while (++i < n) { |
| 8120 | if (defined.call(this, d = data[i], i)) { |
| 8121 | points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]); |
| 8122 | points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]); |
| 8123 | } else if (points0.length) { |
| 8124 | segment(); |
| 8125 | points0 = []; |
| 8126 | points1 = []; |
| 8127 | } |
| 8128 | } |
| 8129 | if (points0.length) segment(); |
| 8130 | return segments.length ? segments.join("") : null; |
| 8131 | } |
| 8132 | area.x = function(_) { |
| 8133 | if (!arguments.length) return x1; |
| 8134 | x0 = x1 = _; |
| 8135 | return area; |
| 8136 | }; |
| 8137 | area.x0 = function(_) { |
| 8138 | if (!arguments.length) return x0; |
| 8139 | x0 = _; |
| 8140 | return area; |
| 8141 | }; |
| 8142 | area.x1 = function(_) { |
| 8143 | if (!arguments.length) return x1; |
| 8144 | x1 = _; |
| 8145 | return area; |
| 8146 | }; |
| 8147 | area.y = function(_) { |
| 8148 | if (!arguments.length) return y1; |
| 8149 | y0 = y1 = _; |
| 8150 | return area; |
| 8151 | }; |
| 8152 | area.y0 = function(_) { |
| 8153 | if (!arguments.length) return y0; |
| 8154 | y0 = _; |
| 8155 | return area; |
| 8156 | }; |
| 8157 | area.y1 = function(_) { |
| 8158 | if (!arguments.length) return y1; |
| 8159 | y1 = _; |
| 8160 | return area; |
| 8161 | }; |
| 8162 | area.defined = function(_) { |
| 8163 | if (!arguments.length) return defined; |
| 8164 | defined = _; |
| 8165 | return area; |
| 8166 | }; |
| 8167 | area.interpolate = function(_) { |
| 8168 | if (!arguments.length) return interpolateKey; |
| 8169 | if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key; |
| 8170 | interpolateReverse = interpolate.reverse || interpolate; |
| 8171 | L = interpolate.closed ? "M" : "L"; |
| 8172 | return area; |
| 8173 | }; |
| 8174 | area.tension = function(_) { |
| 8175 | if (!arguments.length) return tension; |
| 8176 | tension = _; |
| 8177 | return area; |
| 8178 | }; |
| 8179 | return area; |
| 8180 | } |
| 8181 | d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter; |
| 8182 | d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore; |
| 8183 | d3.svg.area = function() { |
| 8184 | return d3_svg_area(d3_identity); |
| 8185 | }; |
| 8186 | d3.svg.area.radial = function() { |
| 8187 | var area = d3_svg_area(d3_svg_lineRadial); |
| 8188 | area.radius = area.x, delete area.x; |
| 8189 | area.innerRadius = area.x0, delete area.x0; |
| 8190 | area.outerRadius = area.x1, delete area.x1; |
| 8191 | area.angle = area.y, delete area.y; |
| 8192 | area.startAngle = area.y0, delete area.y0; |
| 8193 | area.endAngle = area.y1, delete area.y1; |
| 8194 | return area; |
| 8195 | }; |
| 8196 | d3.svg.chord = function() { |
| 8197 | var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle; |
| 8198 | function chord(d, i) { |
| 8199 | var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i); |
| 8200 | 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"; |
| 8201 | } |
| 8202 | function subgroup(self, f, d, i) { |
| 8203 | 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; |
| 8204 | return { |
| 8205 | r: r, |
| 8206 | a0: a0, |
| 8207 | a1: a1, |
| 8208 | p0: [ r * Math.cos(a0), r * Math.sin(a0) ], |
| 8209 | p1: [ r * Math.cos(a1), r * Math.sin(a1) ] |
| 8210 | }; |
| 8211 | } |
| 8212 | function equals(a, b) { |
| 8213 | return a.a0 == b.a0 && a.a1 == b.a1; |
| 8214 | } |
| 8215 | function arc(r, p, a) { |
| 8216 | return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p; |
| 8217 | } |
| 8218 | function curve(r0, p0, r1, p1) { |
| 8219 | return "Q 0,0 " + p1; |
| 8220 | } |
| 8221 | chord.radius = function(v) { |
| 8222 | if (!arguments.length) return radius; |
| 8223 | radius = d3_functor(v); |
| 8224 | return chord; |
| 8225 | }; |
| 8226 | chord.source = function(v) { |
| 8227 | if (!arguments.length) return source; |
| 8228 | source = d3_functor(v); |
| 8229 | return chord; |
| 8230 | }; |
| 8231 | chord.target = function(v) { |
| 8232 | if (!arguments.length) return target; |
| 8233 | target = d3_functor(v); |
| 8234 | return chord; |
| 8235 | }; |
| 8236 | chord.startAngle = function(v) { |
| 8237 | if (!arguments.length) return startAngle; |
| 8238 | startAngle = d3_functor(v); |
| 8239 | return chord; |
| 8240 | }; |
| 8241 | chord.endAngle = function(v) { |
| 8242 | if (!arguments.length) return endAngle; |
| 8243 | endAngle = d3_functor(v); |
| 8244 | return chord; |
| 8245 | }; |
| 8246 | return chord; |
| 8247 | }; |
| 8248 | function d3_svg_chordRadius(d) { |
| 8249 | return d.radius; |
| 8250 | } |
| 8251 | d3.svg.diagonal = function() { |
| 8252 | var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection; |
| 8253 | function diagonal(d, i) { |
| 8254 | var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, { |
| 8255 | x: p0.x, |
| 8256 | y: m |
| 8257 | }, { |
| 8258 | x: p3.x, |
| 8259 | y: m |
| 8260 | }, p3 ]; |
| 8261 | p = p.map(projection); |
| 8262 | return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3]; |
| 8263 | } |
| 8264 | diagonal.source = function(x) { |
| 8265 | if (!arguments.length) return source; |
| 8266 | source = d3_functor(x); |
| 8267 | return diagonal; |
| 8268 | }; |
| 8269 | diagonal.target = function(x) { |
| 8270 | if (!arguments.length) return target; |
| 8271 | target = d3_functor(x); |
| 8272 | return diagonal; |
| 8273 | }; |
| 8274 | diagonal.projection = function(x) { |
| 8275 | if (!arguments.length) return projection; |
| 8276 | projection = x; |
| 8277 | return diagonal; |
| 8278 | }; |
| 8279 | return diagonal; |
| 8280 | }; |
| 8281 | function d3_svg_diagonalProjection(d) { |
| 8282 | return [ d.x, d.y ]; |
| 8283 | } |
| 8284 | d3.svg.diagonal.radial = function() { |
| 8285 | var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection; |
| 8286 | diagonal.projection = function(x) { |
| 8287 | return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection; |
| 8288 | }; |
| 8289 | return diagonal; |
| 8290 | }; |
| 8291 | function d3_svg_diagonalRadialProjection(projection) { |
| 8292 | return function() { |
| 8293 | var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset; |
| 8294 | return [ r * Math.cos(a), r * Math.sin(a) ]; |
| 8295 | }; |
| 8296 | } |
| 8297 | d3.svg.symbol = function() { |
| 8298 | var type = d3_svg_symbolType, size = d3_svg_symbolSize; |
| 8299 | function symbol(d, i) { |
| 8300 | return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i)); |
| 8301 | } |
| 8302 | symbol.type = function(x) { |
| 8303 | if (!arguments.length) return type; |
| 8304 | type = d3_functor(x); |
| 8305 | return symbol; |
| 8306 | }; |
| 8307 | symbol.size = function(x) { |
| 8308 | if (!arguments.length) return size; |
| 8309 | size = d3_functor(x); |
| 8310 | return symbol; |
| 8311 | }; |
| 8312 | return symbol; |
| 8313 | }; |
| 8314 | function d3_svg_symbolSize() { |
| 8315 | return 64; |
| 8316 | } |
| 8317 | function d3_svg_symbolType() { |
| 8318 | return "circle"; |
| 8319 | } |
| 8320 | function d3_svg_symbolCircle(size) { |
| 8321 | var r = Math.sqrt(size / π); |
| 8322 | return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z"; |
| 8323 | } |
| 8324 | var d3_svg_symbols = d3.map({ |
| 8325 | circle: d3_svg_symbolCircle, |
| 8326 | cross: function(size) { |
| 8327 | var r = Math.sqrt(size / 5) / 2; |
| 8328 | 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"; |
| 8329 | }, |
| 8330 | diamond: function(size) { |
| 8331 | var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30; |
| 8332 | return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z"; |
| 8333 | }, |
| 8334 | square: function(size) { |
| 8335 | var r = Math.sqrt(size) / 2; |
| 8336 | return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z"; |
| 8337 | }, |
| 8338 | "triangle-down": function(size) { |
| 8339 | var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2; |
| 8340 | return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z"; |
| 8341 | }, |
| 8342 | "triangle-up": function(size) { |
| 8343 | var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2; |
| 8344 | return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z"; |
| 8345 | } |
| 8346 | }); |
| 8347 | d3.svg.symbolTypes = d3_svg_symbols.keys(); |
| 8348 | var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians); |
| 8349 | function d3_transition(groups, id) { |
| 8350 | d3_subclass(groups, d3_transitionPrototype); |
| 8351 | groups.id = id; |
| 8352 | return groups; |
| 8353 | } |
| 8354 | var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit; |
| 8355 | d3_transitionPrototype.call = d3_selectionPrototype.call; |
| 8356 | d3_transitionPrototype.empty = d3_selectionPrototype.empty; |
| 8357 | d3_transitionPrototype.node = d3_selectionPrototype.node; |
| 8358 | d3_transitionPrototype.size = d3_selectionPrototype.size; |
| 8359 | d3.transition = function(selection) { |
| 8360 | return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition(); |
| 8361 | }; |
| 8362 | d3.transition.prototype = d3_transitionPrototype; |
| 8363 | d3_transitionPrototype.select = function(selector) { |
| 8364 | var id = this.id, subgroups = [], subgroup, subnode, node; |
| 8365 | selector = d3_selection_selector(selector); |
| 8366 | for (var j = -1, m = this.length; ++j < m; ) { |
| 8367 | subgroups.push(subgroup = []); |
| 8368 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
| 8369 | if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) { |
| 8370 | if ("__data__" in node) subnode.__data__ = node.__data__; |
| 8371 | d3_transitionNode(subnode, i, id, node.__transition__[id]); |
| 8372 | subgroup.push(subnode); |
| 8373 | } else { |
| 8374 | subgroup.push(null); |
| 8375 | } |
| 8376 | } |
| 8377 | } |
| 8378 | return d3_transition(subgroups, id); |
| 8379 | }; |
| 8380 | d3_transitionPrototype.selectAll = function(selector) { |
| 8381 | var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition; |
| 8382 | selector = d3_selection_selectorAll(selector); |
| 8383 | for (var j = -1, m = this.length; ++j < m; ) { |
| 8384 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
| 8385 | if (node = group[i]) { |
| 8386 | transition = node.__transition__[id]; |
| 8387 | subnodes = selector.call(node, node.__data__, i, j); |
| 8388 | subgroups.push(subgroup = []); |
| 8389 | for (var k = -1, o = subnodes.length; ++k < o; ) { |
| 8390 | if (subnode = subnodes[k]) d3_transitionNode(subnode, k, id, transition); |
| 8391 | subgroup.push(subnode); |
| 8392 | } |
| 8393 | } |
| 8394 | } |
| 8395 | } |
| 8396 | return d3_transition(subgroups, id); |
| 8397 | }; |
| 8398 | d3_transitionPrototype.filter = function(filter) { |
| 8399 | var subgroups = [], subgroup, group, node; |
| 8400 | if (typeof filter !== "function") filter = d3_selection_filter(filter); |
| 8401 | for (var j = 0, m = this.length; j < m; j++) { |
| 8402 | subgroups.push(subgroup = []); |
| 8403 | for (var group = this[j], i = 0, n = group.length; i < n; i++) { |
| 8404 | if ((node = group[i]) && filter.call(node, node.__data__, i, j)) { |
| 8405 | subgroup.push(node); |
| 8406 | } |
| 8407 | } |
| 8408 | } |
| 8409 | return d3_transition(subgroups, this.id); |
| 8410 | }; |
| 8411 | d3_transitionPrototype.tween = function(name, tween) { |
| 8412 | var id = this.id; |
| 8413 | if (arguments.length < 2) return this.node().__transition__[id].tween.get(name); |
| 8414 | return d3_selection_each(this, tween == null ? function(node) { |
| 8415 | node.__transition__[id].tween.remove(name); |
| 8416 | } : function(node) { |
| 8417 | node.__transition__[id].tween.set(name, tween); |
| 8418 | }); |
| 8419 | }; |
| 8420 | function d3_transition_tween(groups, name, value, tween) { |
| 8421 | var id = groups.id; |
| 8422 | return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) { |
| 8423 | node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j))); |
| 8424 | } : (value = tween(value), function(node) { |
| 8425 | node.__transition__[id].tween.set(name, value); |
| 8426 | })); |
| 8427 | } |
| 8428 | d3_transitionPrototype.attr = function(nameNS, value) { |
| 8429 | if (arguments.length < 2) { |
| 8430 | for (value in nameNS) this.attr(value, nameNS[value]); |
| 8431 | return this; |
| 8432 | } |
| 8433 | var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS); |
| 8434 | function attrNull() { |
| 8435 | this.removeAttribute(name); |
| 8436 | } |
| 8437 | function attrNullNS() { |
| 8438 | this.removeAttributeNS(name.space, name.local); |
| 8439 | } |
| 8440 | function attrTween(b) { |
| 8441 | return b == null ? attrNull : (b += "", function() { |
| 8442 | var a = this.getAttribute(name), i; |
| 8443 | return a !== b && (i = interpolate(a, b), function(t) { |
| 8444 | this.setAttribute(name, i(t)); |
| 8445 | }); |
| 8446 | }); |
| 8447 | } |
| 8448 | function attrTweenNS(b) { |
| 8449 | return b == null ? attrNullNS : (b += "", function() { |
| 8450 | var a = this.getAttributeNS(name.space, name.local), i; |
| 8451 | return a !== b && (i = interpolate(a, b), function(t) { |
| 8452 | this.setAttributeNS(name.space, name.local, i(t)); |
| 8453 | }); |
| 8454 | }); |
| 8455 | } |
| 8456 | return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween); |
| 8457 | }; |
| 8458 | d3_transitionPrototype.attrTween = function(nameNS, tween) { |
| 8459 | var name = d3.ns.qualify(nameNS); |
| 8460 | function attrTween(d, i) { |
| 8461 | var f = tween.call(this, d, i, this.getAttribute(name)); |
| 8462 | return f && function(t) { |
| 8463 | this.setAttribute(name, f(t)); |
| 8464 | }; |
| 8465 | } |
| 8466 | function attrTweenNS(d, i) { |
| 8467 | var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local)); |
| 8468 | return f && function(t) { |
| 8469 | this.setAttributeNS(name.space, name.local, f(t)); |
| 8470 | }; |
| 8471 | } |
| 8472 | return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween); |
| 8473 | }; |
| 8474 | d3_transitionPrototype.style = function(name, value, priority) { |
| 8475 | var n = arguments.length; |
| 8476 | if (n < 3) { |
| 8477 | if (typeof name !== "string") { |
| 8478 | if (n < 2) value = ""; |
| 8479 | for (priority in name) this.style(priority, name[priority], value); |
| 8480 | return this; |
| 8481 | } |
| 8482 | priority = ""; |
| 8483 | } |
| 8484 | function styleNull() { |
| 8485 | this.style.removeProperty(name); |
| 8486 | } |
| 8487 | function styleString(b) { |
| 8488 | return b == null ? styleNull : (b += "", function() { |
| 8489 | var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i; |
| 8490 | return a !== b && (i = d3_interpolate(a, b), function(t) { |
| 8491 | this.style.setProperty(name, i(t), priority); |
| 8492 | }); |
| 8493 | }); |
| 8494 | } |
| 8495 | return d3_transition_tween(this, "style." + name, value, styleString); |
| 8496 | }; |
| 8497 | d3_transitionPrototype.styleTween = function(name, tween, priority) { |
| 8498 | if (arguments.length < 3) priority = ""; |
| 8499 | function styleTween(d, i) { |
| 8500 | var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name)); |
| 8501 | return f && function(t) { |
| 8502 | this.style.setProperty(name, f(t), priority); |
| 8503 | }; |
| 8504 | } |
| 8505 | return this.tween("style." + name, styleTween); |
| 8506 | }; |
| 8507 | d3_transitionPrototype.text = function(value) { |
| 8508 | return d3_transition_tween(this, "text", value, d3_transition_text); |
| 8509 | }; |
| 8510 | function d3_transition_text(b) { |
| 8511 | if (b == null) b = ""; |
| 8512 | return function() { |
| 8513 | this.textContent = b; |
| 8514 | }; |
| 8515 | } |
| 8516 | d3_transitionPrototype.remove = function() { |
| 8517 | return this.each("end.transition", function() { |
| 8518 | var p; |
| 8519 | if (this.__transition__.count < 2 && (p = this.parentNode)) p.removeChild(this); |
| 8520 | }); |
| 8521 | }; |
| 8522 | d3_transitionPrototype.ease = function(value) { |
| 8523 | var id = this.id; |
| 8524 | if (arguments.length < 1) return this.node().__transition__[id].ease; |
| 8525 | if (typeof value !== "function") value = d3.ease.apply(d3, arguments); |
| 8526 | return d3_selection_each(this, function(node) { |
| 8527 | node.__transition__[id].ease = value; |
| 8528 | }); |
| 8529 | }; |
| 8530 | d3_transitionPrototype.delay = function(value) { |
| 8531 | var id = this.id; |
| 8532 | if (arguments.length < 1) return this.node().__transition__[id].delay; |
| 8533 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) { |
| 8534 | node.__transition__[id].delay = +value.call(node, node.__data__, i, j); |
| 8535 | } : (value = +value, function(node) { |
| 8536 | node.__transition__[id].delay = value; |
| 8537 | })); |
| 8538 | }; |
| 8539 | d3_transitionPrototype.duration = function(value) { |
| 8540 | var id = this.id; |
| 8541 | if (arguments.length < 1) return this.node().__transition__[id].duration; |
| 8542 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) { |
| 8543 | node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j)); |
| 8544 | } : (value = Math.max(1, value), function(node) { |
| 8545 | node.__transition__[id].duration = value; |
| 8546 | })); |
| 8547 | }; |
| 8548 | d3_transitionPrototype.each = function(type, listener) { |
| 8549 | var id = this.id; |
| 8550 | if (arguments.length < 2) { |
| 8551 | var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId; |
| 8552 | d3_transitionInheritId = id; |
| 8553 | d3_selection_each(this, function(node, i, j) { |
| 8554 | d3_transitionInherit = node.__transition__[id]; |
| 8555 | type.call(node, node.__data__, i, j); |
| 8556 | }); |
| 8557 | d3_transitionInherit = inherit; |
| 8558 | d3_transitionInheritId = inheritId; |
| 8559 | } else { |
| 8560 | d3_selection_each(this, function(node) { |
| 8561 | var transition = node.__transition__[id]; |
| 8562 | (transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener); |
| 8563 | }); |
| 8564 | } |
| 8565 | return this; |
| 8566 | }; |
| 8567 | d3_transitionPrototype.transition = function() { |
| 8568 | var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition; |
| 8569 | for (var j = 0, m = this.length; j < m; j++) { |
| 8570 | subgroups.push(subgroup = []); |
| 8571 | for (var group = this[j], i = 0, n = group.length; i < n; i++) { |
| 8572 | if (node = group[i]) { |
| 8573 | transition = Object.create(node.__transition__[id0]); |
| 8574 | transition.delay += transition.duration; |
| 8575 | d3_transitionNode(node, i, id1, transition); |
| 8576 | } |
| 8577 | subgroup.push(node); |
| 8578 | } |
| 8579 | } |
| 8580 | return d3_transition(subgroups, id1); |
| 8581 | }; |
| 8582 | function d3_transitionNode(node, i, id, inherit) { |
| 8583 | var lock = node.__transition__ || (node.__transition__ = { |
| 8584 | active: 0, |
| 8585 | count: 0 |
| 8586 | }), transition = lock[id]; |
| 8587 | if (!transition) { |
| 8588 | var time = inherit.time; |
| 8589 | transition = lock[id] = { |
| 8590 | tween: new d3_Map(), |
| 8591 | time: time, |
| 8592 | ease: inherit.ease, |
| 8593 | delay: inherit.delay, |
| 8594 | duration: inherit.duration |
| 8595 | }; |
| 8596 | ++lock.count; |
| 8597 | d3.timer(function(elapsed) { |
| 8598 | var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = []; |
| 8599 | timer.t = delay + time; |
| 8600 | if (delay <= elapsed) return start(elapsed - delay); |
| 8601 | timer.c = start; |
| 8602 | function start(elapsed) { |
| 8603 | if (lock.active > id) return stop(); |
| 8604 | lock.active = id; |
| 8605 | transition.event && transition.event.start.call(node, d, i); |
| 8606 | transition.tween.forEach(function(key, value) { |
| 8607 | if (value = value.call(node, d, i)) { |
| 8608 | tweened.push(value); |
| 8609 | } |
| 8610 | }); |
| 8611 | d3.timer(function() { |
| 8612 | timer.c = tick(elapsed || 1) ? d3_true : tick; |
| 8613 | return 1; |
| 8614 | }, 0, time); |
| 8615 | } |
| 8616 | function tick(elapsed) { |
| 8617 | if (lock.active !== id) return stop(); |
| 8618 | var t = elapsed / duration, e = ease(t), n = tweened.length; |
| 8619 | while (n > 0) { |
| 8620 | tweened[--n].call(node, e); |
| 8621 | } |
| 8622 | if (t >= 1) { |
| 8623 | transition.event && transition.event.end.call(node, d, i); |
| 8624 | return stop(); |
| 8625 | } |
| 8626 | } |
| 8627 | function stop() { |
| 8628 | if (--lock.count) delete lock[id]; else delete node.__transition__; |
| 8629 | return 1; |
| 8630 | } |
| 8631 | }, 0, time); |
| 8632 | } |
| 8633 | } |
| 8634 | d3.svg.axis = function() { |
| 8635 | var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_; |
| 8636 | function axis(g) { |
| 8637 | g.each(function() { |
| 8638 | var g = d3.select(this); |
| 8639 | var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy(); |
| 8640 | 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; |
| 8641 | var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"), |
| 8642 | d3.transition(path)); |
| 8643 | tickEnter.append("line"); |
| 8644 | tickEnter.append("text"); |
| 8645 | var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"); |
| 8646 | switch (orient) { |
| 8647 | case "bottom": |
| 8648 | { |
| 8649 | tickTransform = d3_svg_axisX; |
| 8650 | lineEnter.attr("y2", innerTickSize); |
| 8651 | textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding); |
| 8652 | lineUpdate.attr("x2", 0).attr("y2", innerTickSize); |
| 8653 | textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding); |
| 8654 | text.attr("dy", ".71em").style("text-anchor", "middle"); |
| 8655 | pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize); |
| 8656 | break; |
| 8657 | } |
| 8658 | |
| 8659 | case "top": |
| 8660 | { |
| 8661 | tickTransform = d3_svg_axisX; |
| 8662 | lineEnter.attr("y2", -innerTickSize); |
| 8663 | textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); |
| 8664 | lineUpdate.attr("x2", 0).attr("y2", -innerTickSize); |
| 8665 | textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); |
| 8666 | text.attr("dy", "0em").style("text-anchor", "middle"); |
| 8667 | pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize); |
| 8668 | break; |
| 8669 | } |
| 8670 | |
| 8671 | case "left": |
| 8672 | { |
| 8673 | tickTransform = d3_svg_axisY; |
| 8674 | lineEnter.attr("x2", -innerTickSize); |
| 8675 | textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)); |
| 8676 | lineUpdate.attr("x2", -innerTickSize).attr("y2", 0); |
| 8677 | textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", 0); |
| 8678 | text.attr("dy", ".32em").style("text-anchor", "end"); |
| 8679 | pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize); |
| 8680 | break; |
| 8681 | } |
| 8682 | |
| 8683 | case "right": |
| 8684 | { |
| 8685 | tickTransform = d3_svg_axisY; |
| 8686 | lineEnter.attr("x2", innerTickSize); |
| 8687 | textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding); |
| 8688 | lineUpdate.attr("x2", innerTickSize).attr("y2", 0); |
| 8689 | textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0); |
| 8690 | text.attr("dy", ".32em").style("text-anchor", "start"); |
| 8691 | pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize); |
| 8692 | break; |
| 8693 | } |
| 8694 | } |
| 8695 | if (scale1.rangeBand) { |
| 8696 | var x = scale1, dx = x.rangeBand() / 2; |
| 8697 | scale0 = scale1 = function(d) { |
| 8698 | return x(d) + dx; |
| 8699 | }; |
| 8700 | } else if (scale0.rangeBand) { |
| 8701 | scale0 = scale1; |
| 8702 | } else { |
| 8703 | tickExit.call(tickTransform, scale1); |
| 8704 | } |
| 8705 | tickEnter.call(tickTransform, scale0); |
| 8706 | tickUpdate.call(tickTransform, scale1); |
| 8707 | }); |
| 8708 | } |
| 8709 | axis.scale = function(x) { |
| 8710 | if (!arguments.length) return scale; |
| 8711 | scale = x; |
| 8712 | return axis; |
| 8713 | }; |
| 8714 | axis.orient = function(x) { |
| 8715 | if (!arguments.length) return orient; |
| 8716 | orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient; |
| 8717 | return axis; |
| 8718 | }; |
| 8719 | axis.ticks = function() { |
| 8720 | if (!arguments.length) return tickArguments_; |
| 8721 | tickArguments_ = arguments; |
| 8722 | return axis; |
| 8723 | }; |
| 8724 | axis.tickValues = function(x) { |
| 8725 | if (!arguments.length) return tickValues; |
| 8726 | tickValues = x; |
| 8727 | return axis; |
| 8728 | }; |
| 8729 | axis.tickFormat = function(x) { |
| 8730 | if (!arguments.length) return tickFormat_; |
| 8731 | tickFormat_ = x; |
| 8732 | return axis; |
| 8733 | }; |
| 8734 | axis.tickSize = function(x) { |
| 8735 | var n = arguments.length; |
| 8736 | if (!n) return innerTickSize; |
| 8737 | innerTickSize = +x; |
| 8738 | outerTickSize = +arguments[n - 1]; |
| 8739 | return axis; |
| 8740 | }; |
| 8741 | axis.innerTickSize = function(x) { |
| 8742 | if (!arguments.length) return innerTickSize; |
| 8743 | innerTickSize = +x; |
| 8744 | return axis; |
| 8745 | }; |
| 8746 | axis.outerTickSize = function(x) { |
| 8747 | if (!arguments.length) return outerTickSize; |
| 8748 | outerTickSize = +x; |
| 8749 | return axis; |
| 8750 | }; |
| 8751 | axis.tickPadding = function(x) { |
| 8752 | if (!arguments.length) return tickPadding; |
| 8753 | tickPadding = +x; |
| 8754 | return axis; |
| 8755 | }; |
| 8756 | axis.tickSubdivide = function() { |
| 8757 | return arguments.length && axis; |
| 8758 | }; |
| 8759 | return axis; |
| 8760 | }; |
| 8761 | var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = { |
| 8762 | top: 1, |
| 8763 | right: 1, |
| 8764 | bottom: 1, |
| 8765 | left: 1 |
| 8766 | }; |
| 8767 | function d3_svg_axisX(selection, x) { |
| 8768 | selection.attr("transform", function(d) { |
| 8769 | return "translate(" + x(d) + ",0)"; |
| 8770 | }); |
| 8771 | } |
| 8772 | function d3_svg_axisY(selection, y) { |
| 8773 | selection.attr("transform", function(d) { |
| 8774 | return "translate(0," + y(d) + ")"; |
| 8775 | }); |
| 8776 | } |
| 8777 | d3.svg.brush = function() { |
| 8778 | 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]; |
| 8779 | function brush(g) { |
| 8780 | g.each(function() { |
| 8781 | 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); |
| 8782 | var background = g.selectAll(".background").data([ 0 ]); |
| 8783 | background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair"); |
| 8784 | g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move"); |
| 8785 | var resize = g.selectAll(".resize").data(resizes, d3_identity); |
| 8786 | resize.exit().remove(); |
| 8787 | resize.enter().append("g").attr("class", function(d) { |
| 8788 | return "resize " + d; |
| 8789 | }).style("cursor", function(d) { |
| 8790 | return d3_svg_brushCursor[d]; |
| 8791 | }).append("rect").attr("x", function(d) { |
| 8792 | return /[ew]$/.test(d) ? -3 : null; |
| 8793 | }).attr("y", function(d) { |
| 8794 | return /^[ns]/.test(d) ? -3 : null; |
| 8795 | }).attr("width", 6).attr("height", 6).style("visibility", "hidden"); |
| 8796 | resize.style("display", brush.empty() ? "none" : null); |
| 8797 | var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range; |
| 8798 | if (x) { |
| 8799 | range = d3_scaleRange(x); |
| 8800 | backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]); |
| 8801 | redrawX(gUpdate); |
| 8802 | } |
| 8803 | if (y) { |
| 8804 | range = d3_scaleRange(y); |
| 8805 | backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]); |
| 8806 | redrawY(gUpdate); |
| 8807 | } |
| 8808 | redraw(gUpdate); |
| 8809 | }); |
| 8810 | } |
| 8811 | brush.event = function(g) { |
| 8812 | g.each(function() { |
| 8813 | var event_ = event.of(this, arguments), extent1 = { |
| 8814 | x: xExtent, |
| 8815 | y: yExtent, |
| 8816 | i: xExtentDomain, |
| 8817 | j: yExtentDomain |
| 8818 | }, extent0 = this.__chart__ || extent1; |
| 8819 | this.__chart__ = extent1; |
| 8820 | if (d3_transitionInheritId) { |
| 8821 | d3.select(this).transition().each("start.brush", function() { |
| 8822 | xExtentDomain = extent0.i; |
| 8823 | yExtentDomain = extent0.j; |
| 8824 | xExtent = extent0.x; |
| 8825 | yExtent = extent0.y; |
| 8826 | event_({ |
| 8827 | type: "brushstart" |
| 8828 | }); |
| 8829 | }).tween("brush:brush", function() { |
| 8830 | var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y); |
| 8831 | xExtentDomain = yExtentDomain = null; |
| 8832 | return function(t) { |
| 8833 | xExtent = extent1.x = xi(t); |
| 8834 | yExtent = extent1.y = yi(t); |
| 8835 | event_({ |
| 8836 | type: "brush", |
| 8837 | mode: "resize" |
| 8838 | }); |
| 8839 | }; |
| 8840 | }).each("end.brush", function() { |
| 8841 | xExtentDomain = extent1.i; |
| 8842 | yExtentDomain = extent1.j; |
| 8843 | event_({ |
| 8844 | type: "brush", |
| 8845 | mode: "resize" |
| 8846 | }); |
| 8847 | event_({ |
| 8848 | type: "brushend" |
| 8849 | }); |
| 8850 | }); |
| 8851 | } else { |
| 8852 | event_({ |
| 8853 | type: "brushstart" |
| 8854 | }); |
| 8855 | event_({ |
| 8856 | type: "brush", |
| 8857 | mode: "resize" |
| 8858 | }); |
| 8859 | event_({ |
| 8860 | type: "brushend" |
| 8861 | }); |
| 8862 | } |
| 8863 | }); |
| 8864 | }; |
| 8865 | function redraw(g) { |
| 8866 | g.selectAll(".resize").attr("transform", function(d) { |
| 8867 | return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")"; |
| 8868 | }); |
| 8869 | } |
| 8870 | function redrawX(g) { |
| 8871 | g.select(".extent").attr("x", xExtent[0]); |
| 8872 | g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]); |
| 8873 | } |
| 8874 | function redrawY(g) { |
| 8875 | g.select(".extent").attr("y", yExtent[0]); |
| 8876 | g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]); |
| 8877 | } |
| 8878 | function brushstart() { |
| 8879 | 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; |
| 8880 | var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup); |
| 8881 | if (d3.event.changedTouches) { |
| 8882 | w.on("touchmove.brush", brushmove).on("touchend.brush", brushend); |
| 8883 | } else { |
| 8884 | w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend); |
| 8885 | } |
| 8886 | g.interrupt().selectAll("*").interrupt(); |
| 8887 | if (dragging) { |
| 8888 | origin[0] = xExtent[0] - origin[0]; |
| 8889 | origin[1] = yExtent[0] - origin[1]; |
| 8890 | } else if (resizing) { |
| 8891 | var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing); |
| 8892 | offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ]; |
| 8893 | origin[0] = xExtent[ex]; |
| 8894 | origin[1] = yExtent[ey]; |
| 8895 | } else if (d3.event.altKey) center = origin.slice(); |
| 8896 | g.style("pointer-events", "none").selectAll(".resize").style("display", null); |
| 8897 | d3.select("body").style("cursor", eventTarget.style("cursor")); |
| 8898 | event_({ |
| 8899 | type: "brushstart" |
| 8900 | }); |
| 8901 | brushmove(); |
| 8902 | function keydown() { |
| 8903 | if (d3.event.keyCode == 32) { |
| 8904 | if (!dragging) { |
| 8905 | center = null; |
| 8906 | origin[0] -= xExtent[1]; |
| 8907 | origin[1] -= yExtent[1]; |
| 8908 | dragging = 2; |
| 8909 | } |
| 8910 | d3_eventPreventDefault(); |
| 8911 | } |
| 8912 | } |
| 8913 | function keyup() { |
| 8914 | if (d3.event.keyCode == 32 && dragging == 2) { |
| 8915 | origin[0] += xExtent[1]; |
| 8916 | origin[1] += yExtent[1]; |
| 8917 | dragging = 0; |
| 8918 | d3_eventPreventDefault(); |
| 8919 | } |
| 8920 | } |
| 8921 | function brushmove() { |
| 8922 | var point = d3.mouse(target), moved = false; |
| 8923 | if (offset) { |
| 8924 | point[0] += offset[0]; |
| 8925 | point[1] += offset[1]; |
| 8926 | } |
| 8927 | if (!dragging) { |
| 8928 | if (d3.event.altKey) { |
| 8929 | if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ]; |
| 8930 | origin[0] = xExtent[+(point[0] < center[0])]; |
| 8931 | origin[1] = yExtent[+(point[1] < center[1])]; |
| 8932 | } else center = null; |
| 8933 | } |
| 8934 | if (resizingX && move1(point, x, 0)) { |
| 8935 | redrawX(g); |
| 8936 | moved = true; |
| 8937 | } |
| 8938 | if (resizingY && move1(point, y, 1)) { |
| 8939 | redrawY(g); |
| 8940 | moved = true; |
| 8941 | } |
| 8942 | if (moved) { |
| 8943 | redraw(g); |
| 8944 | event_({ |
| 8945 | type: "brush", |
| 8946 | mode: dragging ? "move" : "resize" |
| 8947 | }); |
| 8948 | } |
| 8949 | } |
| 8950 | function move1(point, scale, i) { |
| 8951 | 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; |
| 8952 | if (dragging) { |
| 8953 | r0 -= position; |
| 8954 | r1 -= size + position; |
| 8955 | } |
| 8956 | min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i]; |
| 8957 | if (dragging) { |
| 8958 | max = (min += position) + size; |
| 8959 | } else { |
| 8960 | if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min)); |
| 8961 | if (position < min) { |
| 8962 | max = min; |
| 8963 | min = position; |
| 8964 | } else { |
| 8965 | max = position; |
| 8966 | } |
| 8967 | } |
| 8968 | if (extent[0] != min || extent[1] != max) { |
| 8969 | if (i) yExtentDomain = null; else xExtentDomain = null; |
| 8970 | extent[0] = min; |
| 8971 | extent[1] = max; |
| 8972 | return true; |
| 8973 | } |
| 8974 | } |
| 8975 | function brushend() { |
| 8976 | brushmove(); |
| 8977 | g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null); |
| 8978 | d3.select("body").style("cursor", null); |
| 8979 | 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); |
| 8980 | dragRestore(); |
| 8981 | event_({ |
| 8982 | type: "brushend" |
| 8983 | }); |
| 8984 | } |
| 8985 | } |
| 8986 | brush.x = function(z) { |
| 8987 | if (!arguments.length) return x; |
| 8988 | x = z; |
| 8989 | resizes = d3_svg_brushResizes[!x << 1 | !y]; |
| 8990 | return brush; |
| 8991 | }; |
| 8992 | brush.y = function(z) { |
| 8993 | if (!arguments.length) return y; |
| 8994 | y = z; |
| 8995 | resizes = d3_svg_brushResizes[!x << 1 | !y]; |
| 8996 | return brush; |
| 8997 | }; |
| 8998 | brush.clamp = function(z) { |
| 8999 | if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null; |
| 9000 | if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z; |
| 9001 | return brush; |
| 9002 | }; |
| 9003 | brush.extent = function(z) { |
| 9004 | var x0, x1, y0, y1, t; |
| 9005 | if (!arguments.length) { |
| 9006 | if (x) { |
| 9007 | if (xExtentDomain) { |
| 9008 | x0 = xExtentDomain[0], x1 = xExtentDomain[1]; |
| 9009 | } else { |
| 9010 | x0 = xExtent[0], x1 = xExtent[1]; |
| 9011 | if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1); |
| 9012 | if (x1 < x0) t = x0, x0 = x1, x1 = t; |
| 9013 | } |
| 9014 | } |
| 9015 | if (y) { |
| 9016 | if (yExtentDomain) { |
| 9017 | y0 = yExtentDomain[0], y1 = yExtentDomain[1]; |
| 9018 | } else { |
| 9019 | y0 = yExtent[0], y1 = yExtent[1]; |
| 9020 | if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1); |
| 9021 | if (y1 < y0) t = y0, y0 = y1, y1 = t; |
| 9022 | } |
| 9023 | } |
| 9024 | return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ]; |
| 9025 | } |
| 9026 | if (x) { |
| 9027 | x0 = z[0], x1 = z[1]; |
| 9028 | if (y) x0 = x0[0], x1 = x1[0]; |
| 9029 | xExtentDomain = [ x0, x1 ]; |
| 9030 | if (x.invert) x0 = x(x0), x1 = x(x1); |
| 9031 | if (x1 < x0) t = x0, x0 = x1, x1 = t; |
| 9032 | if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ]; |
| 9033 | } |
| 9034 | if (y) { |
| 9035 | y0 = z[0], y1 = z[1]; |
| 9036 | if (x) y0 = y0[1], y1 = y1[1]; |
| 9037 | yExtentDomain = [ y0, y1 ]; |
| 9038 | if (y.invert) y0 = y(y0), y1 = y(y1); |
| 9039 | if (y1 < y0) t = y0, y0 = y1, y1 = t; |
| 9040 | if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ]; |
| 9041 | } |
| 9042 | return brush; |
| 9043 | }; |
| 9044 | brush.clear = function() { |
| 9045 | if (!brush.empty()) { |
| 9046 | xExtent = [ 0, 0 ], yExtent = [ 0, 0 ]; |
| 9047 | xExtentDomain = yExtentDomain = null; |
| 9048 | } |
| 9049 | return brush; |
| 9050 | }; |
| 9051 | brush.empty = function() { |
| 9052 | return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1]; |
| 9053 | }; |
| 9054 | return d3.rebind(brush, event, "on"); |
| 9055 | }; |
| 9056 | var d3_svg_brushCursor = { |
| 9057 | n: "ns-resize", |
| 9058 | e: "ew-resize", |
| 9059 | s: "ns-resize", |
| 9060 | w: "ew-resize", |
| 9061 | nw: "nwse-resize", |
| 9062 | ne: "nesw-resize", |
| 9063 | se: "nwse-resize", |
| 9064 | sw: "nesw-resize" |
| 9065 | }; |
| 9066 | var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ]; |
| 9067 | var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat; |
| 9068 | var d3_time_formatUtc = d3_time_format.utc; |
| 9069 | var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ"); |
| 9070 | d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso; |
| 9071 | function d3_time_formatIsoNative(date) { |
| 9072 | return date.toISOString(); |
| 9073 | } |
| 9074 | d3_time_formatIsoNative.parse = function(string) { |
| 9075 | var date = new Date(string); |
| 9076 | return isNaN(date) ? null : date; |
| 9077 | }; |
| 9078 | d3_time_formatIsoNative.toString = d3_time_formatIso.toString; |
| 9079 | d3_time.second = d3_time_interval(function(date) { |
| 9080 | return new d3_date(Math.floor(date / 1e3) * 1e3); |
| 9081 | }, function(date, offset) { |
| 9082 | date.setTime(date.getTime() + Math.floor(offset) * 1e3); |
| 9083 | }, function(date) { |
| 9084 | return date.getSeconds(); |
| 9085 | }); |
| 9086 | d3_time.seconds = d3_time.second.range; |
| 9087 | d3_time.seconds.utc = d3_time.second.utc.range; |
| 9088 | d3_time.minute = d3_time_interval(function(date) { |
| 9089 | return new d3_date(Math.floor(date / 6e4) * 6e4); |
| 9090 | }, function(date, offset) { |
| 9091 | date.setTime(date.getTime() + Math.floor(offset) * 6e4); |
| 9092 | }, function(date) { |
| 9093 | return date.getMinutes(); |
| 9094 | }); |
| 9095 | d3_time.minutes = d3_time.minute.range; |
| 9096 | d3_time.minutes.utc = d3_time.minute.utc.range; |
| 9097 | d3_time.hour = d3_time_interval(function(date) { |
| 9098 | var timezone = date.getTimezoneOffset() / 60; |
| 9099 | return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5); |
| 9100 | }, function(date, offset) { |
| 9101 | date.setTime(date.getTime() + Math.floor(offset) * 36e5); |
| 9102 | }, function(date) { |
| 9103 | return date.getHours(); |
| 9104 | }); |
| 9105 | d3_time.hours = d3_time.hour.range; |
| 9106 | d3_time.hours.utc = d3_time.hour.utc.range; |
| 9107 | d3_time.month = d3_time_interval(function(date) { |
| 9108 | date = d3_time.day(date); |
| 9109 | date.setDate(1); |
| 9110 | return date; |
| 9111 | }, function(date, offset) { |
| 9112 | date.setMonth(date.getMonth() + offset); |
| 9113 | }, function(date) { |
| 9114 | return date.getMonth(); |
| 9115 | }); |
| 9116 | d3_time.months = d3_time.month.range; |
| 9117 | d3_time.months.utc = d3_time.month.utc.range; |
| 9118 | function d3_time_scale(linear, methods, format) { |
| 9119 | function scale(x) { |
| 9120 | return linear(x); |
| 9121 | } |
| 9122 | scale.invert = function(x) { |
| 9123 | return d3_time_scaleDate(linear.invert(x)); |
| 9124 | }; |
| 9125 | scale.domain = function(x) { |
| 9126 | if (!arguments.length) return linear.domain().map(d3_time_scaleDate); |
| 9127 | linear.domain(x); |
| 9128 | return scale; |
| 9129 | }; |
| 9130 | function tickMethod(extent, count) { |
| 9131 | var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target); |
| 9132 | return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) { |
| 9133 | return d / 31536e6; |
| 9134 | }), 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]; |
| 9135 | } |
| 9136 | scale.nice = function(interval, skip) { |
| 9137 | var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval); |
| 9138 | if (method) interval = method[0], skip = method[1]; |
| 9139 | function skipped(date) { |
| 9140 | return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length; |
| 9141 | } |
| 9142 | return scale.domain(d3_scale_nice(domain, skip > 1 ? { |
| 9143 | floor: function(date) { |
| 9144 | while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1); |
| 9145 | return date; |
| 9146 | }, |
| 9147 | ceil: function(date) { |
| 9148 | while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1); |
| 9149 | return date; |
| 9150 | } |
| 9151 | } : interval)); |
| 9152 | }; |
| 9153 | scale.ticks = function(interval, skip) { |
| 9154 | var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ { |
| 9155 | range: interval |
| 9156 | }, skip ]; |
| 9157 | if (method) interval = method[0], skip = method[1]; |
| 9158 | return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip); |
| 9159 | }; |
| 9160 | scale.tickFormat = function() { |
| 9161 | return format; |
| 9162 | }; |
| 9163 | scale.copy = function() { |
| 9164 | return d3_time_scale(linear.copy(), methods, format); |
| 9165 | }; |
| 9166 | return d3_scale_linearRebind(scale, linear); |
| 9167 | } |
| 9168 | function d3_time_scaleDate(t) { |
| 9169 | return new Date(t); |
| 9170 | } |
| 9171 | var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ]; |
| 9172 | 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 ] ]; |
| 9173 | var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) { |
| 9174 | return d.getMilliseconds(); |
| 9175 | } ], [ ":%S", function(d) { |
| 9176 | return d.getSeconds(); |
| 9177 | } ], [ "%I:%M", function(d) { |
| 9178 | return d.getMinutes(); |
| 9179 | } ], [ "%I %p", function(d) { |
| 9180 | return d.getHours(); |
| 9181 | } ], [ "%a %d", function(d) { |
| 9182 | return d.getDay() && d.getDate() != 1; |
| 9183 | } ], [ "%b %d", function(d) { |
| 9184 | return d.getDate() != 1; |
| 9185 | } ], [ "%B", function(d) { |
| 9186 | return d.getMonth(); |
| 9187 | } ], [ "%Y", d3_true ] ]); |
| 9188 | var d3_time_scaleMilliseconds = { |
| 9189 | range: function(start, stop, step) { |
| 9190 | return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate); |
| 9191 | }, |
| 9192 | floor: d3_identity, |
| 9193 | ceil: d3_identity |
| 9194 | }; |
| 9195 | d3_time_scaleLocalMethods.year = d3_time.year; |
| 9196 | d3_time.scale = function() { |
| 9197 | return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat); |
| 9198 | }; |
| 9199 | var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) { |
| 9200 | return [ m[0].utc, m[1] ]; |
| 9201 | }); |
| 9202 | var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) { |
| 9203 | return d.getUTCMilliseconds(); |
| 9204 | } ], [ ":%S", function(d) { |
| 9205 | return d.getUTCSeconds(); |
| 9206 | } ], [ "%I:%M", function(d) { |
| 9207 | return d.getUTCMinutes(); |
| 9208 | } ], [ "%I %p", function(d) { |
| 9209 | return d.getUTCHours(); |
| 9210 | } ], [ "%a %d", function(d) { |
| 9211 | return d.getUTCDay() && d.getUTCDate() != 1; |
| 9212 | } ], [ "%b %d", function(d) { |
| 9213 | return d.getUTCDate() != 1; |
| 9214 | } ], [ "%B", function(d) { |
| 9215 | return d.getUTCMonth(); |
| 9216 | } ], [ "%Y", d3_true ] ]); |
| 9217 | d3_time_scaleUtcMethods.year = d3_time.year.utc; |
| 9218 | d3_time.scale.utc = function() { |
| 9219 | return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat); |
| 9220 | }; |
| 9221 | d3.text = d3_xhrType(function(request) { |
| 9222 | return request.responseText; |
| 9223 | }); |
| 9224 | d3.json = function(url, callback) { |
| 9225 | return d3_xhr(url, "application/json", d3_json, callback); |
| 9226 | }; |
| 9227 | function d3_json(request) { |
| 9228 | return JSON.parse(request.responseText); |
| 9229 | } |
| 9230 | d3.html = function(url, callback) { |
| 9231 | return d3_xhr(url, "text/html", d3_html, callback); |
| 9232 | }; |
| 9233 | function d3_html(request) { |
| 9234 | var range = d3_document.createRange(); |
| 9235 | range.selectNode(d3_document.body); |
| 9236 | return range.createContextualFragment(request.responseText); |
| 9237 | } |
| 9238 | d3.xml = d3_xhrType(function(request) { |
| 9239 | return request.responseXML; |
| 9240 | }); |
| 9241 | if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; |
| 9242 | this.d3 = d3; |
| 9243 | }(); |