diff --git a/Makefile b/Makefile index af8a2fe9..14c88111 100644 --- a/Makefile +++ b/Makefile @@ -183,6 +183,7 @@ d3.layout.js: \ d3.geo.js: \ src/geo/geo.js \ + src/geo/type.js \ src/geo/albers-usa.js \ src/geo/albers.js \ src/geo/azimuthal-equal-area.js \ @@ -201,8 +202,7 @@ d3.geo.js: \ src/geo/projection.js \ src/geo/rotation.js \ src/geo/stereographic.js \ - src/geo/azimuthal.js \ - src/geo/type.js + src/geo/azimuthal.js d3.dsv.js: \ src/dsv/dsv.js \ diff --git a/d3.v2.js b/d3.v2.js index 0ace249d..3e662dd4 100644 --- a/d3.v2.js +++ b/d3.v2.js @@ -1900,6 +1900,14 @@ }; return dsv; } + function d3_geo_type(types) { + for (var type in d3_geo_typeDefaults) { + if (!(type in types)) { + types[type] = d3_geo_typeDefaults[type]; + } + } + return types; + } function d3_geo_albers(φ0, φ1) { function albers(λ, φ) { var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n; @@ -1912,49 +1920,6 @@ }; return albers; } - function d3_geo_bounds(o, f) { - if (d3_geo_boundsTypes.hasOwnProperty(o.type)) d3_geo_boundsTypes[o.type](o, f); - } - function d3_geo_boundsFeature(o, f) { - d3_geo_bounds(o.geometry, f); - } - function d3_geo_boundsFeatureCollection(o, f) { - for (var a = o.features, i = 0, n = a.length; i < n; i++) { - d3_geo_bounds(a[i].geometry, f); - } - } - function d3_geo_boundsGeometryCollection(o, f) { - for (var a = o.geometries, i = 0, n = a.length; i < n; i++) { - d3_geo_bounds(a[i], f); - } - } - function d3_geo_boundsLineString(o, f) { - for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) { - f.apply(null, a[i]); - } - } - function d3_geo_boundsMultiLineString(o, f) { - for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) { - for (var b = a[i], j = 0, m = b.length; j < m; j++) { - f.apply(null, b[j]); - } - } - } - function d3_geo_boundsMultiPolygon(o, f) { - for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) { - for (var b = a[i][0], j = 0, m = b.length; j < m; j++) { - f.apply(null, b[j]); - } - } - } - function d3_geo_boundsPoint(o, f) { - f.apply(null, o.coordinates); - } - function d3_geo_boundsPolygon(o, f) { - for (var a = o.coordinates[0], i = 0, n = a.length; i < n; i++) { - f.apply(null, a[i]); - } - } function d3_geo_circleContext(lineStrings) { var lineString = null; return { @@ -2162,6 +2127,22 @@ function d3_geo_equirectangular(λ, φ) { return [ λ, φ ]; } + function d3_geo_graticuleX(y0, y1) { + var y = d3.range(y0, y1 - ε, d3_geo_graticulePrecision).concat(y1); + return function(x) { + return y.map(function(y) { + return [ x, y ]; + }); + }; + } + function d3_geo_graticuleY(x0, x1) { + var x = d3.range(x0, x1 - ε, d3_geo_graticulePrecision).concat(x1); + return function(y) { + return x.map(function(x) { + return [ x, y ]; + }); + }; + } function d3_geo_greatArcSource(d) { return d.source; } @@ -2231,6 +2212,7 @@ function lineTo(λ, φ) { var p = projectPoint(λ, φ); resampleLineTo(x0, y0, λ0, φ0, x0 = p[0], y0 = p[1], λ0 = λ, φ0 = φ, maxDepth); + context.lineTo(x0, y0); } function resampleLineTo(x0, y0, λ0, φ0, x1, y1, λ1, φ1, depth) { var dx = x1 - x0, dy = y1 - y0, distance2 = dx * dx + dy * dy; @@ -2238,14 +2220,15 @@ var sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), cosΩ = sinφ0 * sinφ1 + cosφ0 * cosφ1 * Math.cos(λ1 - λ0), k = 1 / (Math.SQRT2 * Math.sqrt(1 + cosΩ)), x = k * cosφ0 * Math.cos(λ0) + k * cosφ1 * Math.cos(λ1), y = k * cosφ0 * Math.sin(λ0) + k * cosφ1 * Math.sin(λ1), z = k * sinφ0 + k * sinφ1, λ2 = Math.abs(x) < ε || Math.abs(y) < ε ? (λ0 + λ1) / 2 : Math.atan2(y, x), φ2 = Math.asin(Math.max(-1, Math.min(1, z))), p = projectPoint(λ2, φ2), x2 = p[0], y2 = p[1], dz = dx * (y0 - y2) - dy * (x0 - x2); if (dz * dz / distance2 > δ2) { resampleLineTo(x0, y0, λ0, φ0, x2, y2, λ2, φ2, depth); + context.lineTo(x2, y2); resampleLineTo(x2, y2, λ2, φ2, x1, y1, λ1, φ1, depth); return; } } - context.lineTo(x1, y1); } function closePath() { - lineTo(λ00, φ00); + var p = projectPoint(λ00, φ00); + resampleLineTo(x0, y0, λ0, φ0, p[0], p[1], λ00, φ00, maxDepth); context.closePath(); } var λ00, φ00, λ0, φ0, x0, y0, maxDepth = δ2 > 0 && 16; @@ -2431,11 +2414,6 @@ function d3_geo_azimuthalMode(mode) { return d3_geo_azimuthalModes[mode]; } - function d3_geo_type(types, defaultValue) { - return function(object) { - return object && types.hasOwnProperty(object.type) ? types[object.type](object) : defaultValue; - }; - } function d3_geom_contourStart(grid) { var x = 0, y = 0; while (true) { @@ -3018,7 +2996,9 @@ d3 = { version: "2.10.2" }; - var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π; + var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π, d3_zero = function() { + return 0; + }; var d3_array = d3_arraySlice; try { d3_array(document.documentElement.childNodes)[0].nodeType; @@ -6331,6 +6311,68 @@ d3.csv = d3_dsv(",", "text/csv"); d3.tsv = d3_dsv(" ", "text/tab-separated-values"); d3.geo = {}; + var d3_geo_typeDefaults = { + Feature: function(feature) { + this.geometry(feature.geometry); + }, + FeatureCollection: function(colllection) { + var features = colllection.features, i = -1, n = features.length; + while (++i < n) this.Feature(features[i]); + }, + GeometryCollection: function(colllection) { + var geometries = colllection.geometries, i = -1, n = geometries.length; + while (++i < n) this.geometry(geometries[i]); + }, + LineString: function(lineString) { + this.line(lineString.coordinates); + }, + MultiLineString: function(multiLineString) { + var coordinates = multiLineString.coordinates, i = -1, n = coordinates.length; + while (++i < n) this.line(coordinates[i]); + }, + MultiPoint: function(multiPoint) { + var coordinates = multiPoint.coordinates, i = -1, n = coordinates.length; + while (++i < n) this.point(coordinates[i]); + }, + MultiPolygon: function(multiPolygon) { + var coordinates = multiPolygon.coordinates, i = -1, n = coordinates.length; + while (++i < n) this.polygon(coordinates[i]); + }, + Point: function(point) { + this.point(point.coordinates); + }, + Polygon: function(polygon) { + this.polygon(polygon.coordinates); + }, + object: function(object) { + return d3_geo_typeObjects.hasOwnProperty(object.type) ? this[object.type](object) : this.geometry(object); + }, + geometry: function(geometry) { + return d3_geo_typeGeometries.hasOwnProperty(geometry.type) ? this[geometry.type](geometry) : null; + }, + point: d3_noop, + line: function(coordinates) { + var i = -1, n = coordinates.length; + while (++i < n) this.point(coordinates[i]); + }, + polygon: function(coordinates) { + var i = -1, n = coordinates.length; + while (++i < n) this.line(coordinates[i]); + } + }; + var d3_geo_typeGeometries = { + LineString: 1, + MultiLineString: 1, + MultiPoint: 1, + MultiPolygon: 1, + Point: 1, + Polygon: 1 + }; + var d3_geo_typeObjects = { + Feature: 1, + FeatureCollection: 1, + GeometryCollection: 1 + }; d3.geo.albersUsa = function() { function albersUsa(coordinates) { var lon = coordinates[0], lat = coordinates[1]; @@ -6388,26 +6430,23 @@ return d3_geo_projection(d3_geo_azimuthalEquidistant); }).raw = d3_geo_azimuthalEquidistant; d3.geo.bounds = function(feature) { - var left = Infinity, bottom = Infinity, right = -Infinity, top = -Infinity; - d3_geo_bounds(feature, function(x, y) { - if (x < left) left = x; - if (x > right) right = x; - if (y < bottom) bottom = y; - if (y > top) top = y; - }); - return [ [ left, bottom ], [ right, top ] ]; - }; - var d3_geo_boundsTypes = { - Feature: d3_geo_boundsFeature, - FeatureCollection: d3_geo_boundsFeatureCollection, - GeometryCollection: d3_geo_boundsGeometryCollection, - LineString: d3_geo_boundsLineString, - MultiLineString: d3_geo_boundsMultiLineString, - MultiPoint: d3_geo_boundsLineString, - MultiPolygon: d3_geo_boundsMultiPolygon, - Point: d3_geo_boundsPoint, - Polygon: d3_geo_boundsPolygon + d3_geo_boundsTop = d3_geo_boundsRight = -(d3_geo_boundsLeft = d3_geo_boundsBottom = Infinity); + d3_geo_bounds.object(feature); + return [ [ d3_geo_boundsLeft, d3_geo_boundsBottom ], [ d3_geo_boundsRight, d3_geo_boundsTop ] ]; }; + var d3_geo_boundsLeft, d3_geo_boundsBottom, d3_geo_boundsRight, d3_geo_boundsTop; + var d3_geo_bounds = d3_geo_type({ + point: function(point) { + var x = point[0], y = point[1]; + if (x < d3_geo_boundsLeft) d3_geo_boundsLeft = x; + if (x > d3_geo_boundsRight) d3_geo_boundsRight = x; + if (y < d3_geo_boundsBottom) d3_geo_boundsBottom = y; + if (y > d3_geo_boundsTop) d3_geo_boundsTop = y; + }, + polygon: function(coordinates) { + this.line(coordinates[0]); + } + }); d3.geo.circle = function() { function circle() {} var origin = [ 0, 0 ], degrees = 90, clip, precision; @@ -6416,15 +6455,15 @@ clip = d3_geo_circleClip(degrees, function(coordinates) { return rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians); }); - return clipType(d) || null; + return clipType.object(d) || null; }; var clipType = d3_geo_type({ FeatureCollection: function(o) { - var features = o.features.map(clipType).filter(d3_identity); + var features = o.features.map(clipType.Feature, clipType).filter(d3_identity); return features && (o = Object.create(o), o.features = features, o); }, Feature: function(o) { - var geometry = clipType(o.geometry); + var geometry = clipType.geometry(o.geometry); return geometry && (o = Object.create(o), o.geometry = geometry, o); }, Point: function(o) { @@ -6437,12 +6476,9 @@ o.coordinates.forEach(function(coordinates) { clip.point(coordinates, context); }); - return coordinates.length && { - type: o.type, - coordinates: coordinates.map(function(lineString) { - return lineString[0]; - }) - }; + return coordinates.length && (o = Object.create(o), o.coordinates = coordinates.map(function(lineString) { + return lineString[0]; + }), o); }, LineString: function(o) { var lineStrings = [], context = d3_geo_circleContext(lineStrings); @@ -6475,7 +6511,7 @@ return polygons.length && (o = Object.create(o), o.type = "MultiPolygon", o.coordinates = polygons, o); }, GeometryCollection: function(o) { - var geometries = o.geometries.map(clipType).filter(d3_identity); + var geometries = o.geometries.map(clipType.geometry, clipType).filter(d3_identity); return geometries.length && (o = Object.create(o), o.geometries = geometries, o); } }); @@ -6512,18 +6548,9 @@ geometries: graticule.lines() }; } - var x1 = 180 - ε, x0 = -x1, y1 = 90 - ε, y0 = -y1, dx = 22.5, dy = dx, δx = 2, δy = 2; + var x1, x0, y1, y0, dx = 22.5, dy = dx, x, y; graticule.lines = function() { - var xSteps = d3.range(x0, x1 - ε, δx).concat(x1), ySteps = d3.range(y0, y1 - ε, δy).concat(y1), xLines = d3.range(Math.ceil(x0 / dx) * dx, x1, dx).map(function(x) { - return ySteps.map(function(y) { - return [ x, y ]; - }); - }), yLines = d3.range(Math.ceil(y0 / dy) * dy, y1, dy).map(function(y) { - return xSteps.map(function(x) { - return [ x, y ]; - }); - }); - return xLines.concat(yLines).map(function(coordinates) { + return d3.range(Math.ceil(x0 / dx) * dx, x1, dx).map(x).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).map(y)).map(function(coordinates) { return { type: "LineString", coordinates: coordinates @@ -6531,10 +6558,9 @@ }); }; graticule.outline = function() { - var x2 = (x0 + x1) / 2; return { type: "Polygon", - coordinates: [ [ [ x0, y1 ], [ x2, y1 ], [ x1, y1 ], [ x1, y0 ], [ x2, y0 ], [ x0, y0 ], [ x0, y1 ] ] ] + coordinates: [ x(x0).concat(y(y1).slice(1), x(x1).reverse().slice(1), y(y0).reverse().slice(1)) ] }; }; graticule.extent = function(_) { @@ -6543,6 +6569,8 @@ y0 = +_[0][1], y1 = +_[1][1]; if (x0 > x1) _ = x0, x0 = x1, x1 = _; if (y0 > y1) _ = y0, y0 = y1, y1 = _; + x = d3_geo_graticuleX(y0, y1); + y = d3_geo_graticuleY(x0, x1); return graticule; }; graticule.step = function(_) { @@ -6550,8 +6578,9 @@ dx = +_[0], dy = +_[1]; return graticule; }; - return graticule; + return graticule.extent([ [ -180 + ε, -90 + ε ], [ 180 - ε, 90 - ε ] ]); }; + var d3_geo_graticulePrecision = 3; d3.geo.greatArc = function() { function greatArc() { var d = greatArc.distance.apply(this, arguments), t = 0, dt = precision / d, coordinates = [ p0 ]; @@ -6604,57 +6633,19 @@ function path(object) { var result = null; if (object != result) { - if (context == result) { - if (typeof pointRadius === "function") pointCircle = d3_geo_pathCircle(pointRadius.apply(this, arguments)); - pathObject(object, bufferContext); - if (buffer.length) result = buffer.join(""), buffer = []; - } else { - pathObject(object, context); - } + if (typeof pointRadius === "function") pointCircle = d3_geo_pathCircle(pointRadius.apply(this, arguments)); + pathType.object(object); + if (buffer.length) result = buffer.join(""), buffer = []; } return result; } - function pathObject(object, context) { - var pathType = pathObjectByType.get(object.type); - if (pathType) pathType(object, context); + function ringArea(coordinates) { + return Math.abs(d3.geom.polygon(coordinates.map(projection)).area()); } - function pathGeometry(geometry, context) { - var pathType = pathGeometryByType.get(geometry.type); - if (pathType) pathType(geometry, context); + function polygonArea(coordinates) { + return ringArea(coordinates[0]) - d3.sum(coordinates.slice(1), ringArea); } - function pathFeature(feature, context) { - pathGeometry(feature.geometry, context); - } - function pathFeatureCollection(collection, context) { - var features = collection.features, i = -1, n = features.length; - while (++i < n) pathFeature(features[i], context); - } - function pathGeometryCollection(collection, context) { - var geometries = collection.geometries, i = -1, n = geometries.length; - while (++i < n) pathGeometry(geometries[i], context); - } - function pathLineString(lineString, context) { - projection.line(lineString.coordinates, context); - } - function pathMultiLineString(multiLineString, context) { - var coordinates = multiLineString.coordinates, i = -1, n = coordinates.length; - while (++i < n) projection.line(coordinates[i], context); - } - function pathMultiPoint(multiPoint, context) { - var coordinates = multiPoint.coordinates, i = -1, n = coordinates.length; - while (++i < n) projection.point(coordinates[i], context); - } - function pathMultiPolygon(multiPolygon, context) { - var coordinates = multiPolygon.coordinates, i = -1, n = coordinates.length; - while (++i < n) projection.polygon(coordinates[i], context); - } - function pathPoint(point, context) { - projection.point(point.coordinates, context); - } - function pathPolygon(polygon, context) { - projection.polygon(polygon.coordinates, context); - } - var pointRadius = 4.5, pointCircle = d3_geo_pathCircle(pointRadius), projection = d3.geo.albersUsa(), buffer = [], context; + var pointRadius = 4.5, pointCircle = d3_geo_pathCircle(pointRadius), projection = d3.geo.albersUsa(), buffer = []; var bufferContext = { point: function(x, y) { buffer.push("M", x, ",", y, pointCircle); @@ -6669,34 +6660,49 @@ buffer.push("Z"); } }; - var pathObjectByType = d3.map({ - Feature: pathFeature, - FeatureCollection: pathFeatureCollection, - GeometryCollection: pathGeometryCollection, - LineString: pathLineString, - MultiLineString: pathMultiLineString, - MultiPoint: pathMultiPoint, - MultiPolygon: pathMultiPolygon, - Point: pathPoint, - Polygon: pathPolygon + var context = bufferContext; + var pathType = d3_geo_type({ + line: function(coordinates) { + projection.line(coordinates, context); + }, + polygon: function(coordinates) { + projection.polygon(coordinates, context); + }, + point: function(coordinates) { + projection.point(coordinates, context); + } }); - var pathGeometryByType = d3.map({ - GeometryCollection: pathGeometryCollection, - LineString: pathLineString, - MultiLineString: pathMultiLineString, - MultiPoint: pathMultiPoint, - MultiPolygon: pathMultiPolygon, - Point: pathPoint, - Polygon: pathPolygon + var areaType = d3_geo_type({ + Feature: function(feature) { + return areaType.geometry(feature.geometry); + }, + FeatureCollection: function(collection) { + return d3.sum(collection.features, areaType.Feature); + }, + GeometryCollection: function(collection) { + return d3.sum(collection.geometries, areaType.geometry); + }, + LineString: d3_zero, + MultiLineString: d3_zero, + MultiPoint: d3_zero, + MultiPolygon: function(multiPolygon) { + return d3.sum(multiPolygon.coordinates, polygonArea); + }, + Point: d3_zero, + Polygon: function(polygon) { + return polygonArea(polygon.coordinates); + } }); + path.area = areaType.object; path.projection = function(_) { if (!arguments.length) return projection; projection = _; return path; }; path.context = function(_) { - if (!arguments.length) return context; + if (!arguments.length) return context === bufferContext ? null : context; context = _; + if (context == null) context = bufferContext; return path; }; path.pointRadius = function(x) { diff --git a/d3.v2.min.js b/d3.v2.min.js index d7c3cfcd..76106e6c 100644 --- a/d3.v2.min.js +++ b/d3.v2.min.js @@ -1,4 +1,4 @@ -(function(){function e(e,t){try{for(var n in t)Object.defineProperty(e.prototype,n,{value:t[n],enumerable:!1})}catch(r){e.prototype=t}}function t(e){var t=-1,n=e.length,r=[];while(++t=0?e.substring(t):(t=e.length,""),r=[];while(t>0)r.push(e.substring(t-=3,t+3));return r.reverse().join(",")+n}function b(e,t){var n=Math.pow(10,Math.abs(8-t)*3);return{scale:t>8?function(e){return e/n}:function(e){return e*n},symbol:e}}function w(e){return function(t){return t<=0?0:t>=1?1:e(t)}}function E(e){return function(t){return 1-e(1-t)}}function S(e){return function(t){return.5*(t<.5?e(2*t):2-e(2-2*t))}}function x(e){return e}function T(e){return function(t){return Math.pow(t,e)}}function N(e){return 1-Math.cos(e*xs/2)}function C(e){return Math.pow(2,10*(e-1))}function k(e){return 1-Math.sqrt(1-e*e)}function L(e,t){var n;return arguments.length<2&&(t=.45),arguments.length<1?(e=1,n=t/4):n=t/(2*xs)*Math.asin(1/e),function(r){return 1+e*Math.pow(2,10*-r)*Math.sin((r-n)*2*xs/t)}}function A(e){return e||(e=1.70158),function(t){return t*t*((e+1)*t-e)}}function O(e){return e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375}function M(){d3.event.stopPropagation(),d3.event.preventDefault()}function _(){var e=d3.event,t;while(t=e.sourceEvent)e=t;return e}function D(e){var t=new d,n=0,r=arguments.length;while(++n360?e-=360:e<0&&(e+=360),e<60?s+(o-s)*e/60:e<180?o:e<240?s+(o-s)*(240-e)/60:s}function i(e){return Math.round(r(e)*255)}var s,o;return e%=360,e<0&&(e+=360),t=t<0?0:t>1?1:t,n=n<0?0:n>1?1:n,o=n<=.5?n*(1+t):n+t-n*t,s=2*n-o,R(i(e+120),i(e),i(e-120))}function Y(e,t,n){return new Z(e,t,n)}function Z(e,t,n){this.h=e,this.c=t,this.l=n}function et(e,t,n){return tt(n,Math.cos(e*=Ns)*t,Math.sin(e)*t)}function tt(e,t,n){return new nt(e,t,n)}function nt(e,t,n){this.l=e,this.a=t,this.b=n}function rt(e,t,n){var r=(e+16)/116,i=r+t/500,s=r-n/200;return i=st(i)*$s,r=st(r)*Js,s=st(s)*Ks,R(ut(3.2404542*i-1.5371385*r-.4985314*s),ut(-0.969266*i+1.8760108*r+.041556*s),ut(.0556434*i-.2040259*r+1.0572252*s))}function it(e,t,n){return Y(Math.atan2(n,t)/xs*180,Math.sqrt(t*t+n*n),e)}function st(e){return e>.206893034?e*e*e:(e-4/29)/7.787037}function ot(e){return e>.008856?Math.pow(e,1/3):7.787037*e+4/29}function ut(e){return Math.round(255*(e<=.00304?12.92*e:1.055*Math.pow(e,1/2.4)-.055))}function at(e){return As(e,to),e}function ft(e){return function(){return Qs(e,this)}}function lt(e){return function(){return Gs(e,this)}}function ct(e,t){function n(){this.removeAttribute(e)}function r(){this.removeAttributeNS(e.space,e.local)}function i(){this.setAttribute(e,t)}function s(){this.setAttributeNS(e.space,e.local,t)}function o(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}function u(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}return e=d3.ns.qualify(e),t==null?e.local?r:n:typeof t=="function"?e.local?u:o:e.local?s:i}function ht(e){return new RegExp("(?:^|\\s+)"+d3.requote(e)+"(?:\\s+|$)","g")}function pt(e,t){function n(){var n=-1;while(++n0&&(e=e.substring(0,o)),t?i:r}function Et(e,t){for(var n=0,r=e.length;nt?c():(v.active=t,i.forEach(function(t,n){(n=n.call(e,m,u))&&h.push(n)}),s.start.call(e,m,u),l(r)||d3.timer(l,0,n),1)}function l(n){if(v.active!==t)return c();var r=(n-p)/d,i=o(r),a=h.length;while(a>0)h[--a].call(e,i);if(r>=1)return c(),oo=t,s.end.call(e,m,u),oo=0,1}function c(){return--v.count||delete e.__transition__,1}var h=[],p=e.delay,d=e.duration,v=(e=e.node).__transition__||(e.__transition__={active:0,count:0}),m=e.__data__;++v.count,p<=r?f(r):d3.timer(f,p,n)})},0,n),e}function Tt(e){var t=oo,n=ho,r=lo,i=co;return oo=this.id,ho=this.ease(),Et(this,function(t,n,r){lo=t.delay,co=t.duration,e.call(t=t.node,t.__data__,n,r)}),oo=t,ho=n,lo=r,co=i,this}function Nt(e,t,n){return n!=""&&po}function Ct(e,t){return d3.tween(e,F(t))}function kt(){var e,t=Date.now(),n=vo;while(n)e=t-n.then,e>=n.delay&&(n.flush=n.callback(e)),n=n.next;var r=Lt()-t;r>24?(isFinite(r)&&(clearTimeout(go),go=setTimeout(kt,r)),mo=0):(mo=1,yo(kt))}function Lt(){var e=null,t=vo,n=Infinity;while(t)t.flush?t=e?e.next=t.next:vo=t.next:(n=Math.min(n,t.then+t.delay),t=(e=t).next);return n}function At(e,t){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var r=n.createSVGPoint();if(bo<0&&(window.scrollX||window.scrollY)){n=d3.select(document.body).append("svg").style("position","absolute").style("top",0).style("left",0);var i=n[0][0].getScreenCTM();bo=!i.f&&!i.e,n.remove()}return bo?(r.x=t.pageX,r.y=t.pageY):(r.x=t.clientX,r.y=t.clientY),r=r.matrixTransform(e.getScreenCTM().inverse()),[r.x,r.y]}var s=e.getBoundingClientRect();return[t.clientX-s.left-e.clientLeft,t.clientY-s.top-e.clientTop]}function Ot(){}function Mt(e){var t=e[0],n=e[e.length-1];return t2?Ut:Rt,a=r?q:I;return o=i(e,t,a,n),u=i(t,e,a,d3.interpolate),s}function s(e){return o(e)}var o,u;return s.invert=function(e){return u(e)},s.domain=function(t){return arguments.length?(e=t.map(Number),i()):e},s.range=function(e){return arguments.length?(t=e,i()):t},s.rangeRound=function(e){return s.range(e).interpolate(d3.interpolateRound)},s.clamp=function(e){return arguments.length?(r=e,i()):r},s.interpolate=function(e){return arguments.length?(n=e,i()):n},s.ticks=function(t){return It(e,t)},s.tickFormat=function(t){return qt(e,t)},s.nice=function(){return Dt(e,jt),i()},s.copy=function(){return Ht(e,t,n,r)},i()}function Bt(e,t){return d3.rebind(e,t,"range","rangeRound","interpolate","clamp")}function jt(e){return e=Math.pow(10,Math.round(Math.log(e)/Math.LN10)-1),e&&{floor:function(t){return Math.floor(t/e)*e},ceil:function(t){return Math.ceil(t/e)*e}}}function Ft(e,t){var n=Mt(e),r=n[1]-n[0],i=Math.pow(10,Math.floor(Math.log(r/t)/Math.LN10)),s=t/r*i;return s<=.15?i*=10:s<=.35?i*=5:s<=.75&&(i*=2),n[0]=Math.ceil(n[0]/i)*i,n[1]=Math.floor(n[1]/i)*i+i*.5,n[2]=i,n}function It(e,t){return d3.range.apply(d3,Ft(e,t))}function qt(e,t){return d3.format(",."+Math.max(0,-Math.floor(Math.log(Ft(e,t)[2])/Math.LN10+.01))+"f")}function Rt(e,t,n,r){var i=n(e[0],e[1]),s=r(t[0],t[1]);return function(e){return s(i(e))}}function Ut(e,t,n,r){var i=[],s=[],o=0,u=Math.min(e.length,t.length)-1;e[u]0;f--)i.push(r(s)*f)}else{for(;sa;o--);i=i.slice(s,o)}return i},n.tickFormat=function(e,i){arguments.length<2&&(i=wo);if(arguments.length<1)return i;var s=Math.max(.1,e/n.ticks().length),o=t===Xt?(u=-1e-12,Math.floor):(u=1e-12,Math.ceil),u;return function(e){return e/r(o(t(e)+u))<=s?i(e):""}},n.copy=function(){return zt(e.copy(),t)},Bt(n,e)}function Wt(e){return Math.log(e<0?0:e)/Math.LN10}function Xt(e){return-Math.log(e>0?0:-e)/Math.LN10}function Vt(e,t){function n(t){return e(r(t))}var r=$t(t),i=$t(1/t);return n.invert=function(t){return i(e.invert(t))},n.domain=function(t){return arguments.length?(e.domain(t.map(r)),n):e.domain().map(i)},n.ticks=function(e){return It(n.domain(),e)},n.tickFormat=function(e){return qt(n.domain(),e)},n.nice=function(){return n.domain(Dt(n.domain(),jt))},n.exponent=function(e){if(!arguments.length)return t;var s=n.domain();return r=$t(t=e),i=$t(1/t),n.domain(s)},n.copy=function(){return Vt(e.copy(),t)},Bt(n,e)}function $t(e){return function(t){return t<0?-Math.pow(-t,e):Math.pow(t,e)}}function Jt(e,t){function n(t){return o[((s.get(t)||s.set(t,e.push(t)))-1)%o.length]}function i(t,n){return d3.range(e.length).map(function(e){return t+n*e})}var s,o,u;return n.domain=function(i){if(!arguments.length)return e;e=[],s=new r;var o=-1,u=i.length,a;while(++o1){u=t[1],s=e[a],a++,r+="C"+(i[0]+o[0])+","+(i[1]+o[1])+","+(s[0]-u[0])+","+(s[1]-u[1])+","+s[0]+","+s[1];for(var f=2;f9&&(s=n*3/Math.sqrt(s),o[u]=s*r,o[u+1]=s*i));u=-1;while(++u<=a)s=(e[Math.min(a,u+1)][0]-e[Math.max(0,u-1)][0])/(6*(1+o[u]*o[u])),t.push([s||0,o[u]*s||0]);return t}function Nn(e){return e.length<3?un(e):e[0]+dn(e,Tn(e))}function Cn(e){var t,n=-1,r=e.length,i,s;while(++n1){var r=Mt(e.domain()),i,s=-1,o=t.length,u=(t[1]-t[0])/++n,a,f;while(++s0;)(f=+t[s]-a*u)>=r[0]&&i.push(f);for(--s,a=0;++ar&&(n=t,r=i);return n}function ir(e){return e.reduce(sr,0)}function sr(e,t){return e+t[1]}function or(e,t){return ur(e,Math.ceil(Math.log(t.length)/Math.LN2+1))}function ur(e,t){var n=-1,r=+e[0],i=(e[1]-r)/t,s=[];while(++n<=t)s[n]=i*n+r;return s}function ar(e){return[d3.min(e),d3.max(e)]}function fr(e,t){return d3.rebind(e,t,"sort","children","value"),e.links=pr,e.nodes=function(t){return Ro=!0,(e.nodes=e)(t)},e}function lr(e){return e.children}function cr(e){return e.value}function hr(e,t){return t.value-e.value}function pr(e){return d3.merge(e.map(function(e){return(e.children||[]).map(function(t){return{source:e,target:t}})}))}function dr(e,t){return e.value-t.value}function vr(e,t){var n=e._pack_next;e._pack_next=t,t._pack_prev=e,t._pack_next=n,n._pack_prev=t}function mr(e,t){e._pack_next=t,t._pack_prev=e}function gr(e,t){var n=t.x-e.x,r=t.y-e.y,i=e.r+t.r;return i*i-n*n-r*r>.001}function yr(e){function t(e){r=Math.min(e.x-e.r,r),i=Math.max(e.x+e.r,i),s=Math.min(e.y-e.r,s),o=Math.max(e.y+e.r,o)}if(!(n=e.children)||!(p=n.length))return;var n,r=Infinity,i=-Infinity,s=Infinity,o=-Infinity,u,a,f,l,c,h,p;n.forEach(br),u=n[0],u.x=-u.r,u.y=0,t(u);if(p>1){a=n[1],a.x=a.r,a.y=0,t(a);if(p>2){f=n[2],Sr(u,a,f),t(f),vr(u,f),u._pack_prev=f,vr(f,a),a=u._pack_next;for(l=3;l0&&(e=r)}return e}function Mr(e,t){return e.x-t.x}function _r(e,t){return t.x-e.x}function Dr(e,t){return e.depth-t.depth}function Pr(e,t){function n(e,r){var i=e.children;if(i&&(a=i.length)){var s,o=null,u=-1,a;while(++u=0)s=r[i]._tree,s.prelim+=t,s.mod+=t,t+=s.shift+(n+=s.change)}function Br(e,t,n){e=e._tree,t=t._tree;var r=n/(t.number-e.number);e.change+=r,t.change-=r,t.shift+=n,t.prelim+=n,t.mod+=n}function jr(e,t,n){return e._tree.ancestor.parent==t.parent?e._tree.ancestor:n}function Fr(e){return{x:e.x,y:e.y,dx:e.dx,dy:e.dy}}function Ir(e,t){var n=e.x+t[3],r=e.y+t[0],i=e.dx-t[1]-t[3],s=e.dy-t[0]-t[2];return i<0&&(n+=i/2,i=0),s<0&&(r+=s/2,s=0),{x:n,y:r,dx:i,dy:s}}function qr(e,t){function n(e,r){d3.text(e,t,function(e){r(e&&n.parse(e))})}function r(t){return t.map(i).join(e)}function i(e){return o.test(e)?'"'+e.replace(/\"/g,'""')+'"':e}var s=new RegExp("\r\n|["+e+"\r\n]","g"),o=new RegExp('["'+e+"\n]"),u=e.charCodeAt(0);return n.parse=function(e){var t;return n.parseRows(e,function(e,n){if(n){var r={},i=-1,s=t.length;while(++i=e.length)return i;if(l)return l=!1,r;var t=s.lastIndex;if(e.charCodeAt(t)===34){var n=t;while(n++l}function r(e,r){if(!(u=e.length))return;var s=t(e[0]),o=n(s),u;o&&r.moveTo(s[0],s[1]);for(var a=1;at;m-=v){var g=Math.cos(m),y=Math.sin(m),b=ni([h[0]+c*(g*i+y*l),h[1]+c*(g*s+y*p),h[2]+c*(g*o+y*d)]);n.lineTo(b[0],b[1])}}var o=e*Ns,u=1,a=[1,0,0],f=[0,-1,0],l=Math.cos(o),c=Math.sin(o),h=oi(a,l),p=ei(h);return{point:function(e,r){n(e=t(e))&&r.moveTo(e[0],e[1])},line:function(e,t){r(e,t)},polygon:function(e,t){Zr(e,t,r,s,p)}}}function Zr(e,t,n,r,i){var s=0,o=[],u=[],a=ai(n);e.forEach(function(e){var n=a(e,t),r=n.length;if(r>1){var i=n[0],s=n[r-1],o=i[0],f=s[s.length-1];o[0]===f[0]&&o[1]===f[1]&&(n.shift(),n.pop(),n.push(s.concat(i)))}u=u.concat(n)});var f=[0,0,0];u.forEach(function(e){var n=e[0],r=e[e.length-1];if(n[0]!==r[0]||n[1]!==r[1]){var u={point:r,angle:i(r),points:[],other:null},a={point:n,angle:i(n),points:e,other:u};o.push(a,u),s++}else{var f=e[0],l=e.length,c=0;t.moveTo(f[0],f[1]);while(++c4*w&&c--){var v=Math.sin(o),m=Math.cos(o),g=Math.sin(l),y=Math.cos(l),b=v*g+m*y*Math.cos(f-i),E=1/(Math.SQRT2*Math.sqrt(1+b)),S=E*m*Math.cos(i)+E*y*Math.cos(f),x=E*m*Math.sin(i)+E*y*Math.sin(f),T=E*v+E*g,N=Math.abs(S)w){r(t,n,i,o,L,A,N,C,c),r(L,A,N,C,u,a,f,l,c);return}}e.lineTo(u,a)}function i(){n(o,u),e.closePath()}var o,u,a,f,l,c,h=w>0&&16;return{moveTo:t,lineTo:n,closePath:i}}function i(e){return a(e[0]*Ns,e[1]*Ns)}function s(e,t){var n=u(e,t);return[n[0]*l+y,b-n[1]*l]}function o(){f=fi(a=Ni(v,m,g),u);var e=u(p,d);return y=c-e[0]*l,b=h+e[1]*l,t}var u,a,f,l=150,c=480,h=250,p=0,d=0,v=0,m=0,g=0,y=c,b=h,w=.5,E=Ei(i),S=null;return t.point=function(e,t){E.point(e,r(t))},t.line=function(e,t){E.line(e,r(t))},t.polygon=function(e,t){E.polygon(e,r(t))},t.clipAngle=function(e){return arguments.length?(E=e==null?(S=e,Ei(i)):Yr(S=+e,i),t):S},t.scale=function(e){return arguments.length?(l=+e,o()):l},t.translate=function(e){return arguments.length?(c=+e[0],h=+e[1],o()):[c,h]},t.center=function(e){return arguments.length?(p=e[0]%360*Ns,d=e[1]%360*Ns,o()):[p*Cs,d*Cs]},t.rotate=function(e){return arguments.length?(v=e[0]%360*Ns,m=e[1]%360*Ns,g=e.length>2?e[2]%360*Ns:0,o()):[v*Cs,m*Cs,g*Cs]},t.precision=function(e){return arguments.length?(w=e*e,t):Math.sqrt(w)},function(){return u=e.apply(this,arguments),t.invert=u.invert&&n,o()}}function bi(e,t,n,r){var i,s,o=Math.sin(e-n);return Math.abs(o)>Ts?Math.atan((Math.sin(t)*(s=Math.cos(r))*Math.sin(n)-Math.sin(r)*(i=Math.cos(t))*Math.sin(e))/(i*s*o)):(t+r)/2}function wi(e,t,n){if(!(c=t.length))return;var r=e(t[0]),i=r[0],s=r[1],o,u,a=i>0?xs:-xs,f,l=0,c;n.moveTo(i,s);while(++l0?xs:-xs,a!==f&&Math.abs(o-i)>=xs&&(s=bi(i,s,o,u),n.lineTo(a,s),n.moveTo(f,s)),n.lineTo(i=o,s=u),a=f}function Ei(e){var t={point:function(t,n){var r=e(t);n.point(r[0],r[1])},line:function(t,n){if(!(c=t.length))return;var r=e(t[0]),i=r[0],s=r[1],o,u,a=i>0?xs:-xs,f,l=0,c;n.moveTo(i,s);while(++l0?xs:-xs,a!==f&&Math.abs(o-i)>=xs&&(s=bi(i,s,o,u),n.lineTo(a,s),n.moveTo(f,s)),n.lineTo(i=o,s=u),a=f},polygon:function(e,n){Zr(e,n,t.line,Ti,Si)}};return t}function Si(e){return e[0]>0?e[1]+xs/2:-xs/2-e[1]}function xi(e,t){var n=e/2;t.lineTo(-e,n),t.lineTo(0,n),t.lineTo(e,n)}function Ti(e,t,n){e=e.point,t=t.point;if(e[0]!==t[0]){var r=e[0]>t[0]?-xs:xs,i=r/2;n.lineTo(-r,i),n.lineTo(0,i),n.lineTo(r,i)}else n.lineTo(t[0],t[1])}function Ni(e,t,n){return e?t||n?fi(ki(e),Li(t,n)):ki(e):t||n?Li(t,n):li}function Ci(e){return function(t,n){return[(t+=e)>xs?t-2*xs:t<-xs?t+2*xs:t,n]}}function ki(e){var t=Ci(e);return t.invert=Ci(-e),t}function Li(e,t){function n(e,t){var n=Math.cos(t),u=Math.cos(e)*n,a=Math.sin(e)*n,f=Math.sin(t),l=f*r+u*i;return[Math.atan2(a*s-l*o,u*r-f*i),Math.asin(Math.max(-1,Math.min(1,l*s+a*o)))]}var r=Math.cos(e),i=Math.sin(e),s=Math.cos(t),o=Math.sin(t);return n.invert=function(e,t){var n=Math.cos(t),u=Math.cos(e)*n,a=Math.sin(e)*n,f=Math.sin(t),l=f*s-a*o;return[Math.atan2(a*s+f*o,u*r+l*i),Math.asin(Math.max(-1,Math.min(1,l*r-u*i)))]},n}function Ai(e,t){function n(t,n){var r=Math.cos(t),i=Math.cos(n),s=e(r*i);return[s*i*Math.sin(t),s*Math.sin(n)]}return n.invert=function(e,n){var r=Math.sqrt(e*e+n*n),i=t(r),s=Math.sin(i),o=Math.cos(i);return[Math.atan2(e*s,r*o),Math.asin(r&&n*s/r)]},n}function Oi(e){return Jo[e]}function Mi(e,t){return function(n){return n&&e.hasOwnProperty(n.type)?e[n.type](n):t}}function _i(e){var t=0,n=0;for(;;){if(e(t,n))return[t,n];t===0?(t=n+1,n=0):(t-=1,n+=1)}}function Di(e,t,n,r){var i,s,o,u,a,f,l;return i=r[e],s=i[0],o=i[1],i=r[t],u=i[0],a=i[1],i=r[n],f=i[0],l=i[1],(l-o)*(u-s)-(a-o)*(f-s)>0}function Pi(e,t,n){return(n[0]-t[0])*(e[1]-t[1])<(n[1]-t[1])*(e[0]-t[0])}function Hi(e,t,n,r){var i=e[0],s=t[0],o=n[0],u=r[0],a=e[1],f=t[1],l=n[1],c=r[1],h=i-o,p=s-i,d=u-o,v=a-l,m=f-a,g=c-l,y=(d*v-g*h)/(g*p-d*m);return[i+y*p,a+y*m]}function Bi(e,t){var n={list:e.map(function(e,t){return{index:t,x:e[0],y:e[1]}}).sort(function(e,t){return e.yt.y?1:e.xt.x?1:0}),bottomSite:null},r={list:[],leftEnd:null,rightEnd:null,init:function(){r.leftEnd=r.createHalfEdge(null,"l"),r.rightEnd=r.createHalfEdge(null,"l"),r.leftEnd.r=r.rightEnd,r.rightEnd.l=r.leftEnd,r.list.unshift(r.leftEnd,r.rightEnd)},createHalfEdge:function(e,t){return{edge:e,side:t,vertex:null,l:null,r:null}},insert:function(e,t){t.l=e,t.r=e.r,e.r.l=t,e.r=t},leftBound:function(e){var t=r.leftEnd;do t=t.r;while(t!=r.rightEnd&&i.rightOf(t,e));return t=t.l,t},del:function(e){e.l.r=e.r,e.r.l=e.l,e.edge=null},right:function(e){return e.r},left:function(e){return e.l},leftRegion:function(e){return e.edge==null?n.bottomSite:e.edge.region[e.side]},rightRegion:function(e){return e.edge==null?n.bottomSite:e.edge.region[Go[e.side]]}},i={bisect:function(e,t){var n={region:{l:e,r:t},ep:{l:null,r:null}},r=t.x-e.x,i=t.y-e.y,s=r>0?r:-r,o=i>0?i:-i;return n.c=e.x*r+e.y*i+(r*r+i*i)*.5,s>o?(n.a=1,n.b=i/r,n.c/=r):(n.b=1,n.a=r/i,n.c/=i),n},intersect:function(e,t){var n=e.edge,r=t.edge;if(!n||!r||n.region.r==r.region.r)return null;var i=n.a*r.b-n.b*r.a;if(Math.abs(i)<1e-10)return null;var s=(n.c*r.b-r.c*n.b)/i,o=(r.c*n.a-n.c*r.a)/i,u=n.region.r,a=r.region.r,f,l;u.y=l.region.r.x;return c&&f.side==="l"||!c&&f.side==="r"?null:{x:s,y:o}},rightOf:function(e,t){var n=e.edge,r=n.region.r,i=t.x>r.x;if(i&&e.side==="l")return 1;if(!i&&e.side==="r")return 0;if(n.a===1){var s=t.y-r.y,o=t.x-r.x,u=0,a=0;!i&&n.b<0||i&&n.b>=0?a=u=s>=n.b*o:(a=t.x+t.y*n.b>n.c,n.b<0&&(a=!a),a||(u=1));if(!u){var f=r.x-n.region.l.x;a=n.b*(o*o-s*s)h*h+p*p}return e.side==="l"?a:!a},endPoint:function(e,n,r){e.ep[n]=r;if(!e.ep[Go[n]])return;t(e)},distance:function(e,t){var n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}},s={list:[],insert:function(e,t,n){e.vertex=t,e.ystar=t.y+n;for(var r=0,i=s.list,o=i.length;ru.ystar||e.ystar==u.ystar&&t.x>u.vertex.x)continue;break}i.splice(r,0,e)},del:function(e){for(var t=0,n=s.list,r=n.length;td.y&&(v=p,p=d,d=v,b="r"),y=i.bisect(p,d),h=r.createHalfEdge(y,b),r.insert(l,h),i.endPoint(y,Go[b],g),m=i.intersect(l,h),m&&(s.del(l),s.insert(l,m,i.distance(m,p))),m=i.intersect(h,c),m&&s.insert(h,m,i.distance(m,p))}}for(a=r.right(r.leftEnd);a!=r.rightEnd;a=r.right(a))t(a.edge)}function ji(){return{leaf:!0,nodes:[],point:null}}function Fi(e,t,n,r,i,s){if(!e(t,n,r,i,s)){var o=(n+i)*.5,u=(r+s)*.5,a=t.nodes;a[0]&&Fi(e,a[0],n,r,o,u),a[1]&&Fi(e,a[1],o,r,i,u),a[2]&&Fi(e,a[2],n,u,o,s),a[3]&&Fi(e,a[3],o,u,i,s)}}function Ii(e){return{x:e[0],y:e[1]}}function qi(){this._=new Date(arguments.length>1?Date.UTC.apply(this,arguments):arguments[0])}function Ri(e){return e.substring(0,3)}function Ui(e,t,n,r){var i,s,o=0,u=t.length,a=n.length;while(o=a)return-1;i=t.charCodeAt(o++);if(i==37){s=bu[t.charAt(o++)];if(!s||(r=s(e,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}function zi(e){return new RegExp("^(?:"+e.map(d3.requote).join("|")+")","i")}function Wi(e){var t=new r,n=-1,i=e.length;while(++n68?1900:2e3)}function ts(e,t,n){wu.lastIndex=0;var r=wu.exec(t.substring(n,n+2));return r?(e.m=r[0]-1,n+=r[0].length):-1}function ns(e,t,n){wu.lastIndex=0;var r=wu.exec(t.substring(n,n+2));return r?(e.d=+r[0],n+=r[0].length):-1}function rs(e,t,n){wu.lastIndex=0;var r=wu.exec(t.substring(n,n+2));return r?(e.H=+r[0],n+=r[0].length):-1}function is(e,t,n){wu.lastIndex=0;var r=wu.exec(t.substring(n,n+2));return r?(e.M=+r[0],n+=r[0].length):-1}function ss(e,t,n){wu.lastIndex=0;var r=wu.exec(t.substring(n,n+2));return r?(e.S=+r[0],n+=r[0].length):-1}function os(e,t,n){wu.lastIndex=0;var r=wu.exec(t.substring(n,n+3));return r?(e.L=+r[0],n+=r[0].length):-1}function us(e,t,n){var r=Eu.get(t.substring(n,n+=2).toLowerCase());return r==null?-1:(e.p=r,n)}function as(e){var t=e.getTimezoneOffset(),n=t>0?"-":"+",r=~~(Math.abs(t)/60),i=Math.abs(t)%60;return n+au(r)+au(i)}function fs(e){return e.toISOString()}function ls(e,t,n){function r(t){var n=e(t),r=s(n,1);return t-n1)while(ot?1:e>=t?0:NaN},d3.descending=function(e,t){return te?1:t>=e?0:NaN},d3.mean=function(e,t){var n=e.length,r,i=0,s=-1,o=0;if(arguments.length===1)while(++s1&&(e=e.map(t)),e=e.filter(f),e.length?d3.quantile(e.sort(d3.ascending),.5):undefined},d3.min=function(e,t){var n=-1,r=e.length,i,s;if(arguments.length===1){while(++ns&&(i=s)}else{while(++ns&&(i=s)}return i},d3.max=function(e,t){var n=-1,r=e.length,i,s;if(arguments.length===1){while(++ni&&(i=s)}else{while(++ni&&(i=s)}return i},d3.extent=function(e,t){var n=-1,r=e.length,i,s,o;if(arguments.length===1){while(++ns&&(i=s),os&&(i=s),o1);return e+t*n*Math.sqrt(-2*Math.log(i)/i)}},logNormal:function(e,t){var n=arguments.length;n<2&&(t=1),n<1&&(e=0);var r=d3.random.normal();return function(){return Math.exp(e+t*r())}},irwinHall:function(e){return function(){for(var t=0,n=0;n>>1;e.call(t,t[s],s)>>1;n0&&(i=s);return i},d3.last=function(e,t){var n=0,r=e.length,i=e[0],s;arguments.length===1&&(t=d3.ascending);while(++n=i.length)return u?u.call(n,t):o?t.sort(o):t;var a=-1,f=t.length,l=i[s++],c,h,p=new r,d,v={};while(++a=i.length)return e;var r=[],o=s[n++],u;for(u in e)r.push({key:u,values:t(e[u],n)});return o&&r.sort(function(e,t){return o(e.key,t.key)}),r}var n={},i=[],s=[],o,u;return n.map=function(t){return e(t,0)},n.entries=function(n){return t(e(n,0),0)},n.key=function(e){return i.push(e),n},n.sortKeys=function(e){return s[i.length-1]=e,n},n.sortValues=function(e){return o=e,n},n.rollup=function(e){return u=e,n},n},d3.keys=function(e){var t=[];for(var n in e)t.push(n);return t},d3.values=function(e){var t=[];for(var n in e)t.push(e[n]);return t},d3.entries=function(e){var t=[];for(var n in e)t.push({key:n,value:e[n]});return t},d3.permute=function(e,t){var n=[],r=-1,i=t.length;while(++rt)r.push(o/i);else while((o=e+n*++s)=200&&e<300||e===304?r:null)}},r.send(null)},d3.text=function(e,t,n){function r(e){n(e&&e.responseText)}arguments.length<3&&(n=t,t=null),d3.xhr(e,t,r)},d3.json=function(e,t){d3.text(e,"application/json",function(e){t(e?JSON.parse(e):null)})},d3.html=function(e,t){d3.text(e,"text/html",function(e){if(e!=null){var n=document.createRange();n.selectNode(document.body),e=n.createContextualFragment(e)}t(e)})},d3.xml=function(e,t,n){function r(e){n(e&&e.responseXML)}arguments.length<3&&(n=t,t=null),d3.xhr(e,t,r)};var Ps={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};d3.ns={prefix:Ps,qualify:function(e){var t=e.indexOf(":"),n=e;return t>=0&&(n=e.substring(0,t),e=e.substring(t+1)),Ps.hasOwnProperty(n)?{space:Ps[n],local:e}:e}},d3.dispatch=function(){var e=new d,t=-1,n=arguments.length;while(++t0&&(r=e.substring(n+1),e=e.substring(0,n)),arguments.length<2?this[e].on(r):this[e].on(r,t)},d3.format=function(e){var t=Hs.exec(e),n=t[1]||" ",r=t[3]||"",i=t[5],s=+t[6],o=t[7],u=t[8],a=t[9],f=1,l="",c=!1;u&&(u=+u.substring(1)),i&&(n="0",o&&(s-=Math.floor((s-1)/4)));switch(a){case"n":o=!0,a="g";break;case"%":f=100,l="%",a="f";break;case"p":f=100,l="%",a="r";break;case"d":c=!0,u=0;break;case"s":f=-1,a="r"}return a=="r"&&!u&&(a="g"),a=Bs.get(a)||g,function(e){if(c&&e%1)return"";var t=e<0&&(e=-e)?"-":r;if(f<0){var h=d3.formatPrefix(e,u);e=h.scale(e),l=h.symbol}else e*=f;e=a(e,u);if(i){var p=e.length+t.length;p=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/,Bs=d3.map({g:function(e,t){return e.toPrecision(t)},e:function(e,t){return e.toExponential(t)},f:function(e,t){return e.toFixed(t)},r:function(e,t){return d3.round(e,t=m(e,t)).toFixed(Math.max(0,Math.min(20,t)))}}),js=["y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y"].map(b);d3.formatPrefix=function(e,t){var n=0;return e&&(e<0&&(e*=-1),t&&(e=d3.round(e,m(e,t))),n=1+Math.floor(1e-12+Math.log(e)/Math.LN10),n=Math.max(-24,Math.min(24,Math.floor((n<=0?n+1:n-1)/3)*3))),js[8+n/3]};var Fs=T(2),Is=T(3),qs=function(){return x},Rs=d3.map({linear:qs,poly:T,quad:function(){return Fs},cubic:function(){return Is},sin:function(){return N},exp:function(){return C},circle:function(){return k},elastic:L,back:A,bounce:function(){return O}}),Us=d3.map({"in":x,out:E,"in-out":S,"out-in":function(e){return S(E(e))}});d3.ease=function(e){var t=e.indexOf("-"),n=t>=0?e.substring(0,t):e,r=t>=0?e.substring(t+1):"in";return n=Rs.get(n)||qs,r=Us.get(r)||x,w(r(n.apply(null,Array.prototype.slice.call(arguments,1))))},d3.event=null,d3.transform=function(e){var t=document.createElementNS(d3.ns.prefix.svg,"g");return(d3.transform=function(e){t.setAttribute("transform",e);var n=t.transform.baseVal.consolidate();return new P(n?n.matrix:zs)})(e)},P.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var zs={a:1,b:0,c:0,d:1,e:0,f:0};d3.interpolate=function(e,t){var n=d3.interpolators.length,r;while(--n>=0&&!(r=d3.interpolators[n](e,t)));return r},d3.interpolateNumber=function(e,t){return t-=e,function(n){return e+t*n}},d3.interpolateRound=function(e,t){return t-=e,function(n){return Math.round(e+t*n)}},d3.interpolateString=function(e,t){var n,r,i,s=0,o=0,u=[],a=[],f,l;Ws.lastIndex=0;for(r=0;n=Ws.exec(t);++r)n.index&&u.push(t.substring(s,o=n.index)),a.push({i:u.length,x:n[0]}),u.push(null),s=Ws.lastIndex;s180?l+=360:l-f>180&&(f+=360),r.push({i:n.push(n.pop()+"rotate(",null,")")-2,x:d3.interpolateNumber(f,l)})):l&&n.push(n.pop()+"rotate("+l+")"),c!=h?r.push({i:n.push(n.pop()+"skewX(",null,")")-2,x:d3.interpolateNumber(c,h)}):h&&n.push(n.pop()+"skewX("+h+")"),p[0]!=d[0]||p[1]!=d[1]?(i=n.push(n.pop()+"scale(",null,",",null,")"),r.push({i:i-4,x:d3.interpolateNumber(p[0],d[0])},{i:i-2,x:d3.interpolateNumber(p[1],d[1])})):(d[0]!=1||d[1]!=1)&&n.push(n.pop()+"scale("+d+")"),i=r.length,function(e){var t=-1,s;while(++t180?s-=360:s<-180&&(s+=360),function(e){return G(n+s*e,r+o*e,i+u*e)+""}},d3.interpolateLab=function(e,t){e=d3.lab(e),t=d3.lab(t);var n=e.l,r=e.a,i=e.b,s=t.l-n,o=t.a-r,u=t.b-i;return function(e){return rt(n+s*e,r+o*e,i+u*e)+""}},d3.interpolateHcl=function(e,t){e=d3.hcl(e),t=d3.hcl(t);var n=e.h,r=e.c,i=e.l,s=t.h-n,o=t.c-r,u=t.l-i;return s>180?s-=360:s<-180&&(s+=360),function(e){return et(n+s*e,r+o*e,i+u*e)+""}},d3.interpolateArray=function(e,t){var n=[],r=[],i=e.length,s=t.length,o=Math.min(e.length,t.length),u;for(u=0;u=0;)if(s=n[r])i&&i!==s.nextSibling&&i.parentNode.insertBefore(s,i),i=s;return this},to.sort=function(e){e=bt.apply(this,arguments);for(var t=-1,n=this.length;++t=Co?e?"M0,"+s+"A"+s+","+s+" 0 1,1 0,"+ -s+"A"+s+","+s+" 0 1,1 0,"+s+"M0,"+e+"A"+e+","+e+" 0 1,0 0,"+ -e+"A"+e+","+e+" 0 1,0 0,"+e+"Z":"M0,"+s+"A"+s+","+s+" 0 1,1 0,"+ -s+"A"+s+","+s+" 0 1,1 0,"+s+"Z":e?"M"+s*l+","+s*c+"A"+s+","+s+" 0 "+f+",1 "+s*h+","+s*p+"L"+e*h+","+e*p+"A"+e+","+e+" 0 "+f+",0 "+e*l+","+e*c+"Z":"M"+s*l+","+s*c+"A"+s+","+s+" 0 "+f+",1 "+s*h+","+s*p+"L0,0"+"Z"}var t=Zt,n=en,r=tn,i=nn;return e.innerRadius=function(n){return arguments.length?(t=u(n),e):t},e.outerRadius=function(t){return arguments.length?(n=u(t),e):n},e.startAngle=function(t){return arguments.length?(r=u(t),e):r},e.endAngle=function(t){return arguments.length?(i=u(t),e):i},e.centroid=function(){var e=(t.apply(this,arguments)+n.apply(this,arguments))/2,s=(r.apply(this,arguments)+i.apply(this,arguments))/2+No;return[Math.cos(s)*e,Math.sin(s)*e]},e};var No=-xs/2,Co=2*xs-1e-6;d3.svg.line=function(){return rn(i)};var ko=d3.map({linear:un,"linear-closed":an,"step-before":fn,"step-after":ln,basis:mn,"basis-open":gn,"basis-closed":yn,bundle:bn,cardinal:pn,"cardinal-open":cn,"cardinal-closed":hn,monotone:Nn});ko.forEach(function(e,t){t.key=e,t.closed=/-closed$/.test(e)});var Lo=[0,2/3,1/3,0],Ao=[0,1/3,2/3,0],Oo=[0,1/6,2/3,1/6];d3.svg.line.radial=function(){var e=rn(Cn);return e.radius=e.x,delete e.x,e.angle=e.y,delete e.y,e},fn.reverse=ln,ln.reverse=fn,d3.svg.area=function(){return kn(i)},d3.svg.area.radial=function(){var e=kn(Cn);return e.radius=e.x,delete e.x,e.innerRadius=e.x0,delete e.x0,e.outerRadius=e.x1,delete e.x1,e.angle=e.y,delete e.y,e.startAngle=e.y0,delete e.y0,e.endAngle=e.y1,delete e.y1,e},d3.svg.chord=function(){function e(e,u){var a=t(this,s,e,u),f=t(this,o,e,u);return"M"+a.p0+r(a.r,a.p1,a.a1-a.a0)+(n(a,f)?i(a.r,a.p1,a.r,a.p0):i(a.r,a.p1,f.r,f.p0)+r(f.r,f.p1,f.a1-f.a0)+i(f.r,f.p1,a.r,a.p0))+"Z"}function t(e,t,n,r){var i=t.call(e,n,r),s=a.call(e,i,r),o=f.call(e,i,r)+No,u=l.call(e,i,r)+No;return{r:s,a0:o,a1:u,p0:[s*Math.cos(o),s*Math.sin(o)],p1:[s*Math.cos(u),s*Math.sin(u)]}}function n(e,t){return e.a0==t.a0&&e.a1==t.a1}function r(e,t,n){return"A"+e+","+e+" 0 "+ +(n>xs)+",1 "+t}function i(e,t,n,r){return"Q 0,0 "+r}var s=Ln,o=An,a=On,f=tn,l=nn;return e.radius=function(t){return arguments.length?(a=u(t),e):a},e.source=function(t){return arguments.length?(s=u(t),e):s},e.target=function(t){return arguments.length?(o=u(t),e):o},e.startAngle=function(t){return arguments.length?(f=u(t),e):f},e.endAngle=function(t){return arguments.length?(l=u(t),e):l},e},d3.svg.diagonal=function(){function e(e,i){var s=t.call(this,e,i),o=n.call(this,e,i),u=(s.y+o.y)/2,a=[s,{x:s.x,y:u},{x:o.x,y:u},o];return a=a.map(r),"M"+a[0]+"C"+a[1]+" "+a[2]+" "+a[3]}var t=Ln,n=An,r=Dn;return e.source=function(n){return arguments.length?(t=u(n),e):t},e.target=function(t){return arguments.length?(n=u(t),e):n},e.projection=function(t){return arguments.length?(r=t,e):r},e},d3.svg.diagonal.radial=function(){var e=d3.svg.diagonal(),t=Dn,n=e.projection;return e.projection=function(e){return arguments.length?n(Pn(t=e)):t},e},d3.svg.mouse=d3.mouse,d3.svg.touches=d3.touches,d3.svg.symbol=function(){function e(e,r){return(Mo.get(t.call(this,e,r))||jn)(n.call(this,e,r))}var t=Bn,n=Hn;return e.type=function(n){return arguments.length?(t=u(n),e):t},e.size=function(t){return arguments.length?(n=u(t),e):n},e};var Mo=d3.map({circle:jn,cross:function(e){var t=Math.sqrt(e/5)/2;return"M"+ -3*t+","+ -t+"H"+ -t+"V"+ -3*t+"H"+t+"V"+ -t+"H"+3*t+"V"+t+"H"+t+"V"+3*t+"H"+ -t+"V"+t+"H"+ -3*t+"Z"},diamond:function(e){var t=Math.sqrt(e/(2*Do)),n=t*Do;return"M0,"+ -t+"L"+n+",0"+" 0,"+t+" "+ -n+",0"+"Z"},square:function(e){var t=Math.sqrt(e)/2;return"M"+ -t+","+ -t+"L"+t+","+ -t+" "+t+","+t+" "+ -t+","+t+"Z"},"triangle-down":function(e){var t=Math.sqrt(e/_o),n=t*_o/2;return"M0,"+n+"L"+t+","+ -n+" "+ -t+","+ -n+"Z"},"triangle-up":function(e){var t=Math.sqrt(e/_o),n=t*_o/2;return"M0,"+ -n+"L"+t+","+n+" "+ -t+","+n+"Z"}});d3.svg.symbolTypes=Mo.keys();var _o=Math.sqrt(3),Do=Math.tan(30*Ns);d3.svg.axis=function(){function e(e){e.each(function(){var e=d3.select(this),c=a==null?t.ticks?t.ticks.apply(t,u):t.domain():a,h=f==null?t.tickFormat?t.tickFormat.apply(t,u):String:f,p=qn(t,c,l),d=e.selectAll(".minor").data(p,String),v=d.enter().insert("line","g").attr("class","tick minor").style("opacity",1e-6),m=d3.transition(d.exit()).style("opacity",1e-6).remove(),g=d3.transition(d).style("opacity",1),y=e.selectAll("g").data(c,String),b=y.enter().insert("g","path").style("opacity",1e-6),w=d3.transition(y.exit()).style("opacity",1e-6).remove(),E=d3.transition(y).style("opacity",1),S,x=_t(t),T=e.selectAll(".domain").data([0]),N=T.enter().append("path").attr("class","domain"),C=d3.transition(T),k=t.copy(),L=this.__chart__||k;this.__chart__=k,b.append("line").attr("class","tick"),b.append("text");var A=b.select("line"),O=E.select("line"),M=y.select("text").text(h),_=b.select("text"),D=E.select("text");switch(n){case"bottom":S=Fn,v.attr("y2",i),g.attr("x2",0).attr("y2",i),A.attr("y2",r),_.attr("y",Math.max(r,0)+o),O.attr("x2",0).attr("y2",r),D.attr("x",0).attr("y",Math.max(r,0)+o),M.attr("dy",".71em").attr("text-anchor","middle"),C.attr("d","M"+x[0]+","+s+"V0H"+x[1]+"V"+s);break;case"top":S=Fn,v.attr("y2",-i),g.attr("x2",0).attr("y2",-i),A.attr("y2",-r),_.attr("y",-(Math.max(r,0)+o)),O.attr("x2",0).attr("y2",-r),D.attr("x",0).attr("y",-(Math.max(r,0)+o)),M.attr("dy","0em").attr("text-anchor","middle"),C.attr("d","M"+x[0]+","+ -s+"V0H"+x[1]+"V"+ -s);break;case"left":S=In,v.attr("x2",-i),g.attr("x2",-i).attr("y2",0),A.attr("x2",-r),_.attr("x",-(Math.max(r,0)+o)),O.attr("x2",-r).attr("y2",0),D.attr("x",-(Math.max(r,0)+o)).attr("y",0),M.attr("dy",".32em").attr("text-anchor","end"),C.attr("d","M"+ -s+","+x[0]+"H0V"+x[1]+"H"+ -s);break;case"right":S=In,v.attr("x2",i),g.attr("x2",i).attr("y2",0),A.attr("x2",r),_.attr("x",Math.max(r,0)+o),O.attr("x2",r).attr("y2",0),D.attr("x",Math.max(r,0)+o).attr("y",0),M.attr("dy",".32em").attr("text-anchor","start"),C.attr("d","M"+s+","+x[0]+"H0V"+x[1]+"H"+s)}if(t.ticks)b.call(S,L),E.call(S,k),w.call(S,k),v.call(S,L),g.call(S,k),m.call(S,k);else{var P=k.rangeBand()/2,H=function(e){return k(e)+P};b.call(S,H),E.call(S,H)}})}var t=d3.scale.linear(),n="bottom",r=6,i=6,s=6,o=3,u=[10],a=null,f,l=0;return e.scale=function(n){return arguments.length?(t=n,e):t},e.orient=function(t){return arguments.length?(n=t,e):n},e.ticks=function(){return arguments.length?(u=arguments,e):u},e.tickValues=function(t){return arguments.length?(a=t,e):a},e.tickFormat=function(t){return arguments.length?(f=t,e):f},e.tickSize=function(t,n,o){if(!arguments.length)return r;var u=arguments.length-1;return r=+t,i=u>1?+n:r,s=u>0?+arguments[u]:r,e},e.tickPadding=function(t){return arguments.length?(o=+t,e):o},e.tickSubdivide=function(t){return arguments.length?(l=+t,e):l},e},d3.svg.brush=function(){function e(s){s.each(function(){var s=d3.select(this),f=s.selectAll(".background").data([0]),l=s.selectAll(".extent").data([0]),c=s.selectAll(".resize").data(a,String),h;s.style("pointer-events","all").on("mousedown.brush",i).on("touchstart.brush",i),f.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),l.enter().append("rect").attr("class","extent").style("cursor","move"),c.enter().append("g").attr("class",function(e){return"resize "+e}).style("cursor",function(e){return Po[e]}).append("rect").attr("x",function(e){return/[ew]$/.test(e)?-3:null}).attr("y",function(e){return/^[ns]/.test(e)?-3:null}).attr("width",6).attr("height",6).style("visibility","hidden"),c.style("display",e.empty()?"none":null),c.exit().remove(),o&&(h=_t(o),f.attr("x",h[0]).attr("width",h[1]-h[0]),n(s)),u&&(h=_t(u),f.attr("y",h[0]).attr("height",h[1]-h[0]),r(s)),t(s)})}function t(e){e.selectAll(".resize").attr("transform",function(e){return"translate("+f[+/e$/.test(e)][0]+","+f[+/^s/.test(e)][1]+")"})}function n(e){e.select(".extent").attr("x",f[0][0]),e.selectAll(".extent,.n>rect,.s>rect").attr("width",f[1][0]-f[0][0])}function r(e){e.select(".extent").attr("y",f[0][1]),e.selectAll(".extent,.e>rect,.w>rect").attr("height",f[1][1]-f[0][1])}function i(){function i(){var e=d3.event.changedTouches;return e?d3.touches(v,e)[0]:d3.mouse(v)}function a(){d3.event.keyCode==32&&(S||(x=null,T[0]-=f[1][0],T[1]-=f[1][1],S=2),M())}function c(){d3.event.keyCode==32&&S==2&&(T[0]+=f[1][0],T[1]+=f[1][1],S=0,M())}function h(){var e=i(),s=!1;N&&(e[0]+=N[0],e[1]+=N[1]),S||(d3.event.altKey?(x||(x=[(f[0][0]+f[1][0])/2,(f[0][1]+f[1][1])/2]),T[0]=f[+(e[0]0?a=e:a=0:e>0&&(r.start({type:"start",alpha:a=e}),d3.timer(n.tick)),n):a},n.start=function(){function e(e,n){var i=t(r),s=-1,o=i.length,u;while(++si&&(i=u),r.push(u)}for(o=0;o0){s=-1;while(++s=a[0]&&d<=a[1]&&(l=o[d3.bisect(f,d,1,h)-1],l.y+=p,l.push(e[s]))}return o}var t=!0,n=Number,r=ar,i=or;return e.value=function(t){return arguments.length?(n=t,e):n},e.range=function(t){return arguments.length?(r=u(t),e):r},e.bins=function(t){return arguments.length?(i=typeof t=="number"?function(e){return ur(e,t)}:u(t),e):i},e.frequency=function(n){return arguments.length?(t=!!n,e):t},e},d3.layout.hierarchy=function(){function e(t,o,u){var a=i.call(n,t,o),f=Ro?t:{data:t};f.depth=o,u.push(f);if(a&&(c=a.length)){var l=-1,c,h=f.children=[],p=0,d=o+1,v;while(++l0){var l=n*f/2;Pr(o,function(e){e.r+=l}),Pr(o,yr),Pr(o,function(e){e.r-=l}),f=Math.max(2*o.r/u,2*o.r/a)}return Er(o,u/2,a/2,1/f),s}var t=d3.layout.hierarchy().sort(dr),n=0,r=[1,1];return e.size=function(t){return arguments.length?(r=t,e):r},e.padding=function(t){return arguments.length?(n=+t,e):n},fr(e,t)},d3.layout.cluster=function(){function e(e,i){var s=t.call(this,e,i),o=s[0],u,a=0,f,l;Pr(o,function(e){var t=e.children;t&&t.length?(e.x=Tr(t),e.y=xr(t)):(e.x=u?a+=n(e,u):0,e.y=0,u=e)});var c=Nr(o),h=Cr(o),p=c.x-n(c,h)/2,d=h.x+n(h,c)/2;return Pr(o,function(e){e.x=(e.x-p)/(d-p)*r[0],e.y=(1-(o.y?e.y/o.y:1))*r[1]}),s}var t=d3.layout.hierarchy().sort(null).value(null),n=kr,r=[1,1];return e.separation=function(t){return arguments.length?(n=t,e):n},e.size=function(t){return arguments.length?(r=t,e):r},fr(e,t)},d3.layout.tree=function(){function e(e,i){function s(e,t){var r=e.children,i=e._tree;if(r&&(o=r.length)){var o,a=r[0],f,l=a,c,h=-1;while(++h0&&(Br(jr(o,e,r),e,h),a+=h,f+=h),l+=o._tree.mod,a+=i._tree.mod,c+=u._tree.mod,f+=s._tree.mod;o&&!Ar(s)&&(s._tree.thread=o,s._tree.mod+=l-f),i&&!Lr(u)&&(u._tree.thread=i,u._tree.mod+=a-c,r=e)}return r}var a=t.call(this,e,i),f=a[0];Pr(f,function(e,t){e._tree={ancestor:e,prelim:0,mod:0,change:0,shift:0,number:t?t._tree.number+1:0}}),s(f),o(f,-f._tree.prelim);var l=Or(f,_r),c=Or(f,Mr),h=Or(f,Dr),p=l.x-n(l,c)/2,d=c.x+n(c,l)/2,v=h.depth||1;return Pr(f,function(e){e.x=(e.x-p)/(d-p)*r[0],e.y=e.depth/v*r[1],delete e._tree}),a}var t=d3.layout.hierarchy().sort(null).value(null),n=kr,r=[1,1];return e.separation=function(t){return arguments.length?(n=t,e):n},e.size=function(t){return arguments.length?(r=t,e):r},fr(e,t)},d3.layout.treemap=function(){function e(e,t){var n=-1,r=e.length,i,s;while(++n0)u.push(f=a[d-1]),u.area+=f.area,(h=r(u,p))<=c?(a.pop(),c=h):(u.area-=u.pop().area,i(u,p,o,!1),p=Math.min(o.dx,o.dy),u.length=u.area=0,c=Infinity);u.length&&(i(u,p,o,!0),u.length=u.area=0),s.forEach(t)}}function n(t){var r=t.children;if(r&&r.length){var s=l(t),o=r.slice(),u,a=[];e(o,s.dx*s.dy/t.value),a.area=0;while(u=o.pop())a.push(u),a.area+=u.area,u.z!=null&&(i(a,u.z?s.dx:s.dy,s,!o.length),a.length=a.area=0);r.forEach(n)}}function r(e,t){var n=e.area,r,i=0,s=Infinity,o=-1,u=e.length;while(++oi&&(i=r)}return n*=n,t*=t,n?Math.max(t*i*p/n,n/(t*s*p)):Infinity}function i(e,t,n,r){var i=-1,s=e.length,o=n.x,a=n.y,f=t?u(e.area/t):0,l;if(t==n.dx){if(r||f>n.dy)f=n.dy;while(++in.dx)f=n.dx;while(++i50?n:s<-140?r:o<21?i:t)(e)}var t=d3.geo.albers(),n=d3.geo.albers().origin([-160,60]).parallels([55,65]),r=d3.geo.albers().origin([-160,20]).parallels([8,18]),i=d3.geo.albers().origin([-60,10]).parallels([8,18]);return e.scale=function(s){return arguments.length?(t.scale(s),n.scale(s*.6),r.scale(s),i.scale(s*1.5),e.translate(t.translate())):t.scale()},e.translate=function(s){if(!arguments.length)return t.translate();var o=t.scale(),u=s[0],a=s[1];return t.translate(s),n.translate([u-.4*o,a+.17*o]),r.translate([u-.19*o,a+.2*o]),i.translate([u+.58*o,a+.43*o]),e},e.scale(t.scale())},(d3.geo.albers=function(){var e=29.5*Ns,t=45.5*Ns,n=yi(Rr),r=n(e,t);return r.origin=function(e){var t=r.rotate(),n=r.center();return arguments.length?r.rotate([-e[0],t[1]]).center([n[0],e[1]]):[-t[0],n[1]]},r.parallels=function(r){return arguments.length?n(e=r[0]*Ns,t=r[1]*Ns):[e*Cs,t*Cs]},r.origin([-98,38]).scale(1e3)}).raw=Rr;var Uo=Ai(function(e){return Math.sqrt(2/(1+e))},function(e){return 2*Math.asin(e/2)});(d3.geo.azimuthalEqualArea=function(){return gi(Uo)}).raw=Uo;var zo=Ai(function(e){var t=Math.acos(e);return t&&t/Math.sin(t)},i);(d3.geo.azimuthalEquidistant=function(){return gi(zo)}).raw=zo,d3.geo.bounds=function(e){var t=Infinity,n=Infinity,r=-Infinity,i=-Infinity;return Ur(e,function(e,s){er&&(r=e),si&&(i=s)}),[[t,n],[r,i]]};var Wo={Feature:zr,FeatureCollection:Wr,GeometryCollection:Xr,LineString:Vr,MultiLineString:$r,MultiPoint:Vr,MultiPolygon:Jr,Point:Kr,Polygon:Qr};d3.geo.circle=function(){function e(){}var t=[0,0],n=90,r,s;e.clip=function(e){var i=typeof t=="function"?t.apply(this,arguments):t,s=Ni(-i[0]*Ns,-i[1]*Ns,0);return r=Yr(n,function(e){return s(e[0]*Ns,e[1]*Ns)}),o(e)||null};var o=Mi({FeatureCollection:function(e){var t=e.features.map(o).filter(i);return t&&(e=Object.create(e),e.features=t,e)},Feature:function(e){var t=o(e.geometry);return t&&(e=Object.create(e),e.geometry=t,e)},Point:function(e){var t=[];return r.point(e.coordinates,Gr(t)),t.length&&e},MultiPoint:function(e){var t=[],n=Gr(t);return e.coordinates.forEach(function(e){r.point(e,n)}),t.length&&{type:e.type,coordinates:t.map(function(e){return e[0]})}},LineString:function(e){var t=[],n=Gr(t);return r.line(e.coordinates,n),t.length&&(e=Object.create(e),e.type="MultiLineString",e.coordinates=t,e)},MultiLineString:function(e){var t=[],n=Gr(t);return e.coordinates.forEach(function(e){r.line(e,n)}),t.length&&(e=Object.create(e),e.coordinates=t,e)},Polygon:function(e){var t=[];r.polygon(e.coordinates,Gr(t));var n=t.map(function(e){return[e]});return n.length&&(e=Object.create(e),e.type="MultiPolygon",e.coordinates=n,e)},MultiPolygon:function(e){var t=[],n=Gr(t);e.coordinates.forEach(function(e){r.polygon(e,n)});var i=t.map(function(e){return[e]});return i.length&&(e=Object.create(e),e.type="MultiPolygon",e.coordinates=i,e)},GeometryCollection:function(e){var t=e.geometries.map(o).filter(i);return t.length&&(e=Object.create(e),e.geometries=t,e)}});return e.origin=function(n){return arguments.length?(t=n,e):t},e.angle=function(t){return arguments.length?(n=+t,e):n},e.precision=function(t){return arguments.length?(s=+t,e):s},e},(d3.geo.equirectangular=function(){return gi(li).scale(250/xs)}).raw=li.invert=li;var Xo=Ai(function(e){return 1/e},Math.atan);(d3.geo.gnomonic=function(){return gi(Xo)}).raw=Xo,d3.geo.graticule=function(){function e(){return{type:"GeometryCollection",geometries:e.lines()}}var t=180-Ts,n=-t,r=90-Ts,i=-r,s=22.5,o=s,u=2,a=2;return e.lines=function(){var e=d3.range(n,t-Ts,u).concat(t),f=d3.range(i,r-Ts,a).concat(r),l=d3.range(Math.ceil(n/s)*s,t,s).map(function(e){return f.map(function(t){return[e,t]})}),c=d3.range(Math.ceil(i/o)*o,r,o).map(function(t){return e.map(function(e){return[e,t]})});return l.concat(c).map(function(e){return{type:"LineString",coordinates:e}})},e.outline=function(){var e=(n+t)/2;return{type:"Polygon",coordinates:[[[n,r],[e,r],[t,r],[t,i],[e,i],[n,i],[n,r]]]}},e.extent=function(s){return arguments.length?(n=+s[0][0],t=+s[1][0],i=+s[0][1],r=+s[1][1],n>t&&(s=n,n=t,t=s),i>r&&(s=i,i=r,r=s),e):[[n,i],[t,r]]},e.step=function(t){return arguments.length?(s=+t[0],o=+t[1],e):[s,o]},e},d3.geo.greatArc=function(){function e(){var t=e.distance.apply(this,arguments),r=0,u=s/t,a=[n];while((r+=u)<1)a.push(o(r));return a.push(i),{type:"LineString",coordinates:a}}var t=ci,n,r=hi,i,s=6*Ns,o=pi();return e.distance=function(){return typeof t=="function"&&o.source(n=t.apply(this,arguments)),typeof r=="function"&&o.target(i=r.apply(this,arguments)),o.distance()},e.source=function(r){return arguments.length?(t=r,typeof t!="function"&&o.source(n=t),e):t},e.target=function(t){return arguments.length?(r=t,typeof r!="function"&&o.target(i=r),e):r},e.precision=function(t){return arguments.length?(s=t*Ns,e):s/Ns},e},d3.geo.greatCircle=d3.geo.circle,vi.invert=function(e,t){return[2*xs*e,2*Math.atan(Math.exp(2*xs*t))-xs/2]},(d3.geo.mercator=function(){return gi(vi).scale(500)}).raw=vi;var Vo=Ai(function(){return 1},Math.asin);(d3.geo.orthographic=function(){return gi(Vo)}).raw=Vo,d3.geo.path=function(){function e(e){var n=null;return e!=n&&(m==n?(typeof h=="function"&&(p=mi(h.apply(this,arguments))),t(e,g),v.length&&(n=v.join(""),v=[])):t(e,m)),n}function t(e,t){var n=y.get(e.type);n&&n(e,t)}function n(e,t){var n=b.get(e.type);n&&n(e,t)}function r(e,t){n(e.geometry,t)}function i(e,t){var n=e.features,i=-1,s=n.length;while(++i=l*l+c*c?r[s].index=-1:(r[h].index=-1,d=r[s].angle,h=s,p=o)):(d=r[s].angle,h=s,p=o);i.push(u);for(s=0,o=0;s<2;++o)r[o].index!==-1&&(i.push(r[o].index),s++);v=i.length;for(;o=0?(n=e.ep.r,r=e.ep.l):(n=e.ep.l,r=e.ep.r),e.a===1?(o=n?n.y:-1e6,i=e.c-e.b*o,u=r?r.y:1e6,s=e.c-e.b*u):(i=n?n.x:-1e6,o=e.c-e.a*i,s=r?r.x:1e6,u=e.c-e.a*s);var a=[i,o],f=[s,u];t[e.region.l.index].push(a,f),t[e.region.r.index].push(a,f)}),t.map(function(t,n){var r=e[n][0],i=e[n][1];return t.forEach(function(e){e.angle=Math.atan2(e[0]-r,e[1]-i)}),t.sort(function(e,t){return e.angle-t.angle}).filter(function(e,n){return!n||e.angle-t[n-1].angle>1e-10})})};var Go={l:"r",r:"l"};d3.geom.delaunay=function(e){var t=e.map(function(){return[]}),n=[];return Bi(e,function(n){t[n.region.l.index].push(e[n.region.r.index])}),t.forEach(function(t,r){var i=e[r],s=i[0],o=i[1];t.forEach(function(e){e.angle=Math.atan2(e[0]-s,e[1]-o)}),t.sort(function(e,t){return e.angle-t.angle});for(var u=0,a=t.length-1;u=u,l=t.y>=a,c=(l<<1)+f;e.leaf=!1,e=e.nodes[c]||(e.nodes[c]=ji()),f?n=u:i=u,l?r=a:o=a,s(e,t,n,r,i,o)}var u,a=-1,f=e.length;f&&isNaN(e[0].x)&&(e=e.map(Ii));if(arguments.length<5)if(arguments.length===3)i=r=n,n=t;else{t=n=Infinity,r=i=-Infinity;while(++ar&&(r=u.x),u.y>i&&(i=u.y);var l=r-t,c=i-n;l>c?i=n+l:r=t+c}var h=ji();return h.add=function(e){s(h,e,t,n,r,i)},h.visit=function(e){Fi(e,h,t,n,r,i)},e.forEach(h.add),h},d3.time={};var Yo=Date,Zo=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];qi.prototype={getDate:function(){return this._.getUTCDate()},getDay:function(){return this._.getUTCDay()},getFullYear:function(){return this._.getUTCFullYear()},getHours:function(){return this._.getUTCHours()},getMilliseconds:function(){return this._.getUTCMilliseconds()},getMinutes:function(){return this._.getUTCMinutes()},getMonth:function(){return this._.getUTCMonth()},getSeconds:function(){return this._.getUTCSeconds()},getTime:function(){return this._.getTime()},getTimezoneOffset:function(){return 0},valueOf:function(){return this._.valueOf()},setDate:function(){eu.setUTCDate.apply(this._,arguments)},setDay:function(){eu.setUTCDay.apply(this._,arguments)},setFullYear:function(){eu.setUTCFullYear.apply(this._,arguments)},setHours:function(){eu.setUTCHours.apply(this._,arguments)},setMilliseconds:function(){eu.setUTCMilliseconds.apply(this._,arguments)},setMinutes:function(){eu.setUTCMinutes.apply(this._,arguments)},setMonth:function(){eu.setUTCMonth.apply(this._,arguments)},setSeconds:function(){eu.setUTCSeconds.apply(this._,arguments)},setTime:function(){eu.setTime.apply(this._,arguments)}};var eu=Date.prototype,tu="%a %b %e %H:%M:%S %Y",nu="%m/%d/%y",ru="%H:%M:%S",iu=Zo,su=iu.map(Ri),ou=["January","February","March","April","May","June","July","August","September","October","November","December"],uu=ou.map(Ri);d3.time.format=function(e){function t(t){var r=[],i=-1,s=0,o,u;while(++i=12?"PM":"AM"},S:function(e){return au(e.getSeconds())},U:function(e){return au(d3.time.sundayOfYear(e))},w:function(e){return e.getDay()},W:function(e){return au(d3.time.mondayOfYear(e))},x:d3.time.format(nu),X:d3.time.format(ru),y:function(e){return au(e.getFullYear()%100)},Y:function(e){return lu(e.getFullYear()%1e4)},Z:as,"%":function(e){return"%"}},bu={a:Xi,A:Vi,b:$i,B:Ji,c:Ki,d:ns,e:ns,H:rs,I:rs,L:os,m:ts,M:is,p:us,S:ss,x:Qi,X:Gi,y:Zi,Y:Yi},wu=/^\s*\d+/,Eu=d3.map({am:0,pm:1});d3.time.format.utc=function(e){function t(e){try{Yo=qi;var t=new Yo;return t._=e,n(t)}finally{Yo=Date}}var n=d3.time.format(e);return t.parse=function(e){try{Yo=qi;var t=n.parse(e);return t&&t._}finally{Yo=Date}},t.toString=n.toString,t};var Su=d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");d3.time.format.iso=Date.prototype.toISOString?fs:Su,fs.parse=function(e){var t=new Date(e);return isNaN(t)?null:t},fs.toString=Su.toString,d3.time.second=ls(function(e){return new Yo(Math.floor(e/1e3)*1e3)},function(e,t){e.setTime(e.getTime()+Math.floor(t)*1e3)},function(e){return e.getSeconds()}),d3.time.seconds=d3.time.second.range,d3.time.seconds.utc=d3.time.second.utc.range,d3.time.minute=ls(function(e){return new Yo(Math.floor(e/6e4)*6e4)},function(e,t){e.setTime(e.getTime()+Math.floor(t)*6e4)},function(e){return e.getMinutes()}),d3.time.minutes=d3.time.minute.range,d3.time.minutes.utc=d3.time.minute.utc.range,d3.time.hour=ls(function(e){var t=e.getTimezoneOffset()/60;return new Yo((Math.floor(e/36e5-t)+t)*36e5)},function(e,t){e.setTime(e.getTime()+Math.floor(t)*36e5)},function(e){return e.getHours()}),d3.time.hours=d3.time.hour.range,d3.time.hours.utc=d3.time.hour.utc.range,d3.time.day=ls(function(e){var t=new Yo(1970,0);return t.setFullYear(e.getFullYear(),e.getMonth(),e.getDate()),t},function(e,t){e.setDate(e.getDate()+t)},function(e){return e.getDate()-1}),d3.time.days=d3.time.day.range,d3.time.days.utc=d3.time.day.utc.range,d3.time.dayOfYear=function(e){var t=d3.time.year(e);return Math.floor((e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*6e4)/864e5)},Zo.forEach(function(e,t){e=e.toLowerCase(),t=7-t;var n=d3.time[e]=ls(function(e){return(e=d3.time.day(e)).setDate(e.getDate()-(e.getDay()+t)%7),e},function(e,t){e.setDate(e.getDate()+Math.floor(t)*7)},function(e){var n=d3.time.year(e).getDay();return Math.floor((d3.time.dayOfYear(e)+(n+t)%7)/7)-(n!==t)});d3.time[e+"s"]=n.range,d3.time[e+"s"].utc=n.utc.range,d3.time[e+"OfYear"]=function(e){var n=d3.time.year(e).getDay();return Math.floor((d3.time.dayOfYear(e)+(n+t)%7)/7)}}),d3.time.week=d3.time.sunday,d3.time.weeks=d3.time.sunday.range,d3.time.weeks.utc=d3.time.sunday.utc.range,d3.time.weekOfYear=d3.time.sundayOfYear,d3.time.month=ls(function(e){return e=d3.time.day(e),e.setDate(1),e},function(e,t){e.setMonth(e.getMonth()+t)},function(e){return e.getMonth()}),d3.time.months=d3.time.month.range,d3.time.months.utc=d3.time.month.utc.range,d3.time.year=ls(function(e){return e=d3.time.day(e),e.setMonth(0,1),e},function(e,t){e.setFullYear(e.getFullYear()+t)},function(e){return e.getFullYear()}),d3.time.years=d3.time.year.range,d3.time.years.utc=d3.time.year.utc.range;var xu=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,108e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6],Tu=[[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]],Nu=[[d3.time.format("%Y"),function(e){return!0}],[d3.time.format("%B"),function(e){return e.getMonth()}],[d3.time.format("%b %d"),function(e){return e.getDate()!=1}],[d3.time.format("%a %d"),function(e){return e.getDay()&&e.getDate()!=1}],[d3.time.format("%I %p"),function(e){return e.getHours()}],[d3.time.format("%I:%M"),function(e){return e.getMinutes()}],[d3.time.format(":%S"),function(e){return e.getSeconds()}],[d3.time.format(".%L"),function(e){return e.getMilliseconds()}]],Cu=d3.scale.linear(),ku=vs(Nu);Tu.year=function(e,t){return Cu.domain(e.map(gs)).ticks(t).map(ms)},d3.time.scale=function(){return hs(d3.scale.linear(),Tu,ku)};var Lu=Tu.map(function(e){return[e[0].utc,e[1]]}),Au=[[d3.time.format.utc("%Y"),function(e){return!0}],[d3.time.format.utc("%B"),function(e){return e.getUTCMonth()}],[d3.time.format.utc("%b %d"),function(e){return e.getUTCDate()!=1}],[d3.time.format.utc("%a %d"),function(e){return e.getUTCDay()&&e.getUTCDate()!=1}],[d3.time.format.utc("%I %p"),function(e){return e.getUTCHours()}],[d3.time.format.utc("%I:%M"),function(e){return e.getUTCMinutes()}],[d3.time.format.utc(":%S"),function(e){return e.getUTCSeconds()}],[d3.time.format.utc(".%L"),function(e){return e.getUTCMilliseconds()}]],Ou=vs(Au);Lu.year=function(e,t){return Cu.domain(e.map(bs)).ticks(t).map(ys)},d3.time.scale.utc=function(){return hs(d3.scale.linear(),Lu,Ou)}})(); \ No newline at end of file +(function(){function e(e,t){try{for(var n in t)Object.defineProperty(e.prototype,n,{value:t[n],enumerable:!1})}catch(r){e.prototype=t}}function t(e){var t=-1,n=e.length,r=[];while(++t=0?e.substring(t):(t=e.length,""),r=[];while(t>0)r.push(e.substring(t-=3,t+3));return r.reverse().join(",")+n}function b(e,t){var n=Math.pow(10,Math.abs(8-t)*3);return{scale:t>8?function(e){return e/n}:function(e){return e*n},symbol:e}}function w(e){return function(t){return t<=0?0:t>=1?1:e(t)}}function E(e){return function(t){return 1-e(1-t)}}function S(e){return function(t){return.5*(t<.5?e(2*t):2-e(2-2*t))}}function x(e){return e}function T(e){return function(t){return Math.pow(t,e)}}function N(e){return 1-Math.cos(e*ms/2)}function C(e){return Math.pow(2,10*(e-1))}function k(e){return 1-Math.sqrt(1-e*e)}function L(e,t){var n;return arguments.length<2&&(t=.45),arguments.length<1?(e=1,n=t/4):n=t/(2*ms)*Math.asin(1/e),function(r){return 1+e*Math.pow(2,10*-r)*Math.sin((r-n)*2*ms/t)}}function A(e){return e||(e=1.70158),function(t){return t*t*((e+1)*t-e)}}function O(e){return e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375}function M(){d3.event.stopPropagation(),d3.event.preventDefault()}function _(){var e=d3.event,t;while(t=e.sourceEvent)e=t;return e}function D(e){var t=new d,n=0,r=arguments.length;while(++n360?e-=360:e<0&&(e+=360),e<60?s+(o-s)*e/60:e<180?o:e<240?s+(o-s)*(240-e)/60:s}function i(e){return Math.round(r(e)*255)}var s,o;return e%=360,e<0&&(e+=360),t=t<0?0:t>1?1:t,n=n<0?0:n>1?1:n,o=n<=.5?n*(1+t):n+t-n*t,s=2*n-o,R(i(e+120),i(e),i(e-120))}function Y(e,t,n){return new Z(e,t,n)}function Z(e,t,n){this.h=e,this.c=t,this.l=n}function et(e,t,n){return tt(n,Math.cos(e*=ys)*t,Math.sin(e)*t)}function tt(e,t,n){return new nt(e,t,n)}function nt(e,t,n){this.l=e,this.a=t,this.b=n}function rt(e,t,n){var r=(e+16)/116,i=r+t/500,s=r-n/200;return i=st(i)*Rs,r=st(r)*Us,s=st(s)*zs,R(ut(3.2404542*i-1.5371385*r-.4985314*s),ut(-0.969266*i+1.8760108*r+.041556*s),ut(.0556434*i-.2040259*r+1.0572252*s))}function it(e,t,n){return Y(Math.atan2(n,t)/ms*180,Math.sqrt(t*t+n*n),e)}function st(e){return e>.206893034?e*e*e:(e-4/29)/7.787037}function ot(e){return e>.008856?Math.pow(e,1/3):7.787037*e+4/29}function ut(e){return Math.round(255*(e<=.00304?12.92*e:1.055*Math.pow(e,1/2.4)-.055))}function at(e){return xs(e,Ks),e}function ft(e){return function(){return Ws(e,this)}}function lt(e){return function(){return Xs(e,this)}}function ct(e,t){function n(){this.removeAttribute(e)}function r(){this.removeAttributeNS(e.space,e.local)}function i(){this.setAttribute(e,t)}function s(){this.setAttributeNS(e.space,e.local,t)}function o(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}function u(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}return e=d3.ns.qualify(e),t==null?e.local?r:n:typeof t=="function"?e.local?u:o:e.local?s:i}function ht(e){return new RegExp("(?:^|\\s+)"+d3.requote(e)+"(?:\\s+|$)","g")}function pt(e,t){function n(){var n=-1;while(++n0&&(e=e.substring(0,o)),t?i:r}function Et(e,t){for(var n=0,r=e.length;nt?c():(v.active=t,i.forEach(function(t,n){(n=n.call(e,m,u))&&h.push(n)}),s.start.call(e,m,u),l(r)||d3.timer(l,0,n),1)}function l(n){if(v.active!==t)return c();var r=(n-p)/d,i=o(r),a=h.length;while(a>0)h[--a].call(e,i);if(r>=1)return c(),eo=t,s.end.call(e,m,u),eo=0,1}function c(){return--v.count||delete e.__transition__,1}var h=[],p=e.delay,d=e.duration,v=(e=e.node).__transition__||(e.__transition__={active:0,count:0}),m=e.__data__;++v.count,p<=r?f(r):d3.timer(f,p,n)})},0,n),e}function Tt(e){var t=eo,n=oo,r=io,i=so;return eo=this.id,oo=this.ease(),Et(this,function(t,n,r){io=t.delay,so=t.duration,e.call(t=t.node,t.__data__,n,r)}),eo=t,oo=n,io=r,so=i,this}function Nt(e,t,n){return n!=""&&uo}function Ct(e,t){return d3.tween(e,F(t))}function kt(){var e,t=Date.now(),n=ao;while(n)e=t-n.then,e>=n.delay&&(n.flush=n.callback(e)),n=n.next;var r=Lt()-t;r>24?(isFinite(r)&&(clearTimeout(lo),lo=setTimeout(kt,r)),fo=0):(fo=1,co(kt))}function Lt(){var e=null,t=ao,n=Infinity;while(t)t.flush?t=e?e.next=t.next:ao=t.next:(n=Math.min(n,t.then+t.delay),t=(e=t).next);return n}function At(e,t){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var r=n.createSVGPoint();if(ho<0&&(window.scrollX||window.scrollY)){n=d3.select(document.body).append("svg").style("position","absolute").style("top",0).style("left",0);var i=n[0][0].getScreenCTM();ho=!i.f&&!i.e,n.remove()}return ho?(r.x=t.pageX,r.y=t.pageY):(r.x=t.clientX,r.y=t.clientY),r=r.matrixTransform(e.getScreenCTM().inverse()),[r.x,r.y]}var s=e.getBoundingClientRect();return[t.clientX-s.left-e.clientLeft,t.clientY-s.top-e.clientTop]}function Ot(){}function Mt(e){var t=e[0],n=e[e.length-1];return t2?Ut:Rt,a=r?q:I;return o=i(e,t,a,n),u=i(t,e,a,d3.interpolate),s}function s(e){return o(e)}var o,u;return s.invert=function(e){return u(e)},s.domain=function(t){return arguments.length?(e=t.map(Number),i()):e},s.range=function(e){return arguments.length?(t=e,i()):t},s.rangeRound=function(e){return s.range(e).interpolate(d3.interpolateRound)},s.clamp=function(e){return arguments.length?(r=e,i()):r},s.interpolate=function(e){return arguments.length?(n=e,i()):n},s.ticks=function(t){return It(e,t)},s.tickFormat=function(t){return qt(e,t)},s.nice=function(){return Dt(e,jt),i()},s.copy=function(){return Ht(e,t,n,r)},i()}function Bt(e,t){return d3.rebind(e,t,"range","rangeRound","interpolate","clamp")}function jt(e){return e=Math.pow(10,Math.round(Math.log(e)/Math.LN10)-1),e&&{floor:function(t){return Math.floor(t/e)*e},ceil:function(t){return Math.ceil(t/e)*e}}}function Ft(e,t){var n=Mt(e),r=n[1]-n[0],i=Math.pow(10,Math.floor(Math.log(r/t)/Math.LN10)),s=t/r*i;return s<=.15?i*=10:s<=.35?i*=5:s<=.75&&(i*=2),n[0]=Math.ceil(n[0]/i)*i,n[1]=Math.floor(n[1]/i)*i+i*.5,n[2]=i,n}function It(e,t){return d3.range.apply(d3,Ft(e,t))}function qt(e,t){return d3.format(",."+Math.max(0,-Math.floor(Math.log(Ft(e,t)[2])/Math.LN10+.01))+"f")}function Rt(e,t,n,r){var i=n(e[0],e[1]),s=r(t[0],t[1]);return function(e){return s(i(e))}}function Ut(e,t,n,r){var i=[],s=[],o=0,u=Math.min(e.length,t.length)-1;e[u]0;f--)i.push(r(s)*f)}else{for(;sa;o--);i=i.slice(s,o)}return i},n.tickFormat=function(e,i){arguments.length<2&&(i=po);if(arguments.length<1)return i;var s=Math.max(.1,e/n.ticks().length),o=t===Xt?(u=-1e-12,Math.floor):(u=1e-12,Math.ceil),u;return function(e){return e/r(o(t(e)+u))<=s?i(e):""}},n.copy=function(){return zt(e.copy(),t)},Bt(n,e)}function Wt(e){return Math.log(e<0?0:e)/Math.LN10}function Xt(e){return-Math.log(e>0?0:-e)/Math.LN10}function Vt(e,t){function n(t){return e(r(t))}var r=$t(t),i=$t(1/t);return n.invert=function(t){return i(e.invert(t))},n.domain=function(t){return arguments.length?(e.domain(t.map(r)),n):e.domain().map(i)},n.ticks=function(e){return It(n.domain(),e)},n.tickFormat=function(e){return qt(n.domain(),e)},n.nice=function(){return n.domain(Dt(n.domain(),jt))},n.exponent=function(e){if(!arguments.length)return t;var s=n.domain();return r=$t(t=e),i=$t(1/t),n.domain(s)},n.copy=function(){return Vt(e.copy(),t)},Bt(n,e)}function $t(e){return function(t){return t<0?-Math.pow(-t,e):Math.pow(t,e)}}function Jt(e,t){function n(t){return o[((s.get(t)||s.set(t,e.push(t)))-1)%o.length]}function i(t,n){return d3.range(e.length).map(function(e){return t+n*e})}var s,o,u;return n.domain=function(i){if(!arguments.length)return e;e=[],s=new r;var o=-1,u=i.length,a;while(++o1){u=t[1],s=e[a],a++,r+="C"+(i[0]+o[0])+","+(i[1]+o[1])+","+(s[0]-u[0])+","+(s[1]-u[1])+","+s[0]+","+s[1];for(var f=2;f9&&(s=n*3/Math.sqrt(s),o[u]=s*r,o[u+1]=s*i));u=-1;while(++u<=a)s=(e[Math.min(a,u+1)][0]-e[Math.max(0,u-1)][0])/(6*(1+o[u]*o[u])),t.push([s||0,o[u]*s||0]);return t}function Nn(e){return e.length<3?un(e):e[0]+dn(e,Tn(e))}function Cn(e){var t,n=-1,r=e.length,i,s;while(++n1){var r=Mt(e.domain()),i,s=-1,o=t.length,u=(t[1]-t[0])/++n,a,f;while(++s0;)(f=+t[s]-a*u)>=r[0]&&i.push(f);for(--s,a=0;++ar&&(n=t,r=i);return n}function ir(e){return e.reduce(sr,0)}function sr(e,t){return e+t[1]}function or(e,t){return ur(e,Math.ceil(Math.log(t.length)/Math.LN2+1))}function ur(e,t){var n=-1,r=+e[0],i=(e[1]-r)/t,s=[];while(++n<=t)s[n]=i*n+r;return s}function ar(e){return[d3.min(e),d3.max(e)]}function fr(e,t){return d3.rebind(e,t,"sort","children","value"),e.links=pr,e.nodes=function(t){return Ho=!0,(e.nodes=e)(t)},e}function lr(e){return e.children}function cr(e){return e.value}function hr(e,t){return t.value-e.value}function pr(e){return d3.merge(e.map(function(e){return(e.children||[]).map(function(t){return{source:e,target:t}})}))}function dr(e,t){return e.value-t.value}function vr(e,t){var n=e._pack_next;e._pack_next=t,t._pack_prev=e,t._pack_next=n,n._pack_prev=t}function mr(e,t){e._pack_next=t,t._pack_prev=e}function gr(e,t){var n=t.x-e.x,r=t.y-e.y,i=e.r+t.r;return i*i-n*n-r*r>.001}function yr(e){function t(e){r=Math.min(e.x-e.r,r),i=Math.max(e.x+e.r,i),s=Math.min(e.y-e.r,s),o=Math.max(e.y+e.r,o)}if(!(n=e.children)||!(p=n.length))return;var n,r=Infinity,i=-Infinity,s=Infinity,o=-Infinity,u,a,f,l,c,h,p;n.forEach(br),u=n[0],u.x=-u.r,u.y=0,t(u);if(p>1){a=n[1],a.x=a.r,a.y=0,t(a);if(p>2){f=n[2],Sr(u,a,f),t(f),vr(u,f),u._pack_prev=f,vr(f,a),a=u._pack_next;for(l=3;l0&&(e=r)}return e}function Mr(e,t){return e.x-t.x}function _r(e,t){return t.x-e.x}function Dr(e,t){return e.depth-t.depth}function Pr(e,t){function n(e,r){var i=e.children;if(i&&(a=i.length)){var s,o=null,u=-1,a;while(++u=0)s=r[i]._tree,s.prelim+=t,s.mod+=t,t+=s.shift+(n+=s.change)}function Br(e,t,n){e=e._tree,t=t._tree;var r=n/(t.number-e.number);e.change+=r,t.change-=r,t.shift+=n,t.prelim+=n,t.mod+=n}function jr(e,t,n){return e._tree.ancestor.parent==t.parent?e._tree.ancestor:n}function Fr(e){return{x:e.x,y:e.y,dx:e.dx,dy:e.dy}}function Ir(e,t){var n=e.x+t[3],r=e.y+t[0],i=e.dx-t[1]-t[3],s=e.dy-t[0]-t[2];return i<0&&(n+=i/2,i=0),s<0&&(r+=s/2,s=0),{x:n,y:r,dx:i,dy:s}}function qr(e,t){function n(e,r){d3.text(e,t,function(e){r(e&&n.parse(e))})}function r(t){return t.map(i).join(e)}function i(e){return o.test(e)?'"'+e.replace(/\"/g,'""')+'"':e}var s=new RegExp("\r\n|["+e+"\r\n]","g"),o=new RegExp('["'+e+"\n]"),u=e.charCodeAt(0);return n.parse=function(e){var t;return n.parseRows(e,function(e,n){if(n){var r={},i=-1,s=t.length;while(++i=e.length)return i;if(l)return l=!1,r;var t=s.lastIndex;if(e.charCodeAt(t)===34){var n=t;while(n++l}function r(e,r){if(!(u=e.length))return;var s=t(e[0]),o=n(s),u;o&&r.moveTo(s[0],s[1]);for(var a=1;at;m-=v){var g=Math.cos(m),y=Math.sin(m),b=Jr([h[0]+c*(g*i+y*l),h[1]+c*(g*s+y*p),h[2]+c*(g*o+y*d)]);n.lineTo(b[0],b[1])}}var o=e*ys,u=1,a=[1,0,0],f=[0,-1,0],l=Math.cos(o),c=Math.sin(o),h=Yr(a,l),p=Vr(h);return{point:function(e,r){n(e=t(e))&&r.moveTo(e[0],e[1])},line:function(e,t){r(e,t)},polygon:function(e,t){Xr(e,t,r,s,p)}}}function Xr(e,t,n,r,i){var s=0,o=[],u=[],a=ei(n);e.forEach(function(e){var n=a(e,t),r=n.length;if(r>1){var i=n[0],s=n[r-1],o=i[0],f=s[s.length-1];o[0]===f[0]&&o[1]===f[1]&&(n.shift(),n.pop(),n.push(s.concat(i)))}u=u.concat(n)});var f=[0,0,0];u.forEach(function(e){var n=e[0],r=e[e.length-1];if(n[0]!==r[0]||n[1]!==r[1]){var u={point:r,angle:i(r),points:[],other:null},a={point:n,angle:i(n),points:e,other:u};o.push(a,u),s++}else{var f=e[0],l=e.length,c=0;t.moveTo(f[0],f[1]);while(++c4*w&&c--){var v=Math.sin(o),m=Math.cos(o),g=Math.sin(l),y=Math.cos(l),b=v*g+m*y*Math.cos(f-i),E=1/(Math.SQRT2*Math.sqrt(1+b)),S=E*m*Math.cos(i)+E*y*Math.cos(f),x=E*m*Math.sin(i)+E*y*Math.sin(f),T=E*v+E*g,N=Math.abs(S)w){r(t,n,i,o,L,A,N,C,c),e.lineTo(L,A),r(L,A,N,C,u,a,f,l,c);return}}}function i(){var t=s(o,u);r(l,c,a,f,t[0],t[1],o,u,h),e.closePath()}var o,u,a,f,l,c,h=w>0&&16;return{moveTo:t,lineTo:n,closePath:i}}function i(e){return a(e[0]*ys,e[1]*ys)}function s(e,t){var n=u(e,t);return[n[0]*l+y,b-n[1]*l]}function o(){f=ti(a=bi(v,m,g),u);var e=u(p,d);return y=c-e[0]*l,b=h+e[1]*l,t}var u,a,f,l=150,c=480,h=250,p=0,d=0,v=0,m=0,g=0,y=c,b=h,w=.5,E=vi(i),S=null;return t.point=function(e,t){E.point(e,r(t))},t.line=function(e,t){E.line(e,r(t))},t.polygon=function(e,t){E.polygon(e,r(t))},t.clipAngle=function(e){return arguments.length?(E=e==null?(S=e,vi(i)):Wr(S=+e,i),t):S},t.scale=function(e){return arguments.length?(l=+e,o()):l},t.translate=function(e){return arguments.length?(c=+e[0],h=+e[1],o()):[c,h]},t.center=function(e){return arguments.length?(p=e[0]%360*ys,d=e[1]%360*ys,o()):[p*bs,d*bs]},t.rotate=function(e){return arguments.length?(v=e[0]%360*ys,m=e[1]%360*ys,g=e.length>2?e[2]%360*ys:0,o()):[v*bs,m*bs,g*bs]},t.precision=function(e){return arguments.length?(w=e*e,t):Math.sqrt(w)},function(){return u=e.apply(this,arguments),t.invert=u.invert&&n,o()}}function pi(e,t,n,r){var i,s,o=Math.sin(e-n);return Math.abs(o)>gs?Math.atan((Math.sin(t)*(s=Math.cos(r))*Math.sin(n)-Math.sin(r)*(i=Math.cos(t))*Math.sin(e))/(i*s*o)):(t+r)/2}function di(e,t,n){if(!(c=t.length))return;var r=e(t[0]),i=r[0],s=r[1],o,u,a=i>0?ms:-ms,f,l=0,c;n.moveTo(i,s);while(++l0?ms:-ms,a!==f&&Math.abs(o-i)>=ms&&(s=pi(i,s,o,u),n.lineTo(a,s),n.moveTo(f,s)),n.lineTo(i=o,s=u),a=f}function vi(e){var t={point:function(t,n){var r=e(t);n.point(r[0],r[1])},line:function(t,n){if(!(c=t.length))return;var r=e(t[0]),i=r[0],s=r[1],o,u,a=i>0?ms:-ms,f,l=0,c;n.moveTo(i,s);while(++l0?ms:-ms,a!==f&&Math.abs(o-i)>=ms&&(s=pi(i,s,o,u),n.lineTo(a,s),n.moveTo(f,s)),n.lineTo(i=o,s=u),a=f},polygon:function(e,n){Xr(e,n,t.line,yi,mi)}};return t}function mi(e){return e[0]>0?e[1]+ms/2:-ms/2-e[1]}function gi(e,t){var n=e/2;t.lineTo(-e,n),t.lineTo(0,n),t.lineTo(e,n)}function yi(e,t,n){e=e.point,t=t.point;if(e[0]!==t[0]){var r=e[0]>t[0]?-ms:ms,i=r/2;n.lineTo(-r,i),n.lineTo(0,i),n.lineTo(r,i)}else n.lineTo(t[0],t[1])}function bi(e,t,n){return e?t||n?ti(Ei(e),Si(t,n)):Ei(e):t||n?Si(t,n):ni}function wi(e){return function(t,n){return[(t+=e)>ms?t-2*ms:t<-ms?t+2*ms:t,n]}}function Ei(e){var t=wi(e);return t.invert=wi(-e),t}function Si(e,t){function n(e,t){var n=Math.cos(t),u=Math.cos(e)*n,a=Math.sin(e)*n,f=Math.sin(t),l=f*r+u*i;return[Math.atan2(a*s-l*o,u*r-f*i),Math.asin(Math.max(-1,Math.min(1,l*s+a*o)))]}var r=Math.cos(e),i=Math.sin(e),s=Math.cos(t),o=Math.sin(t);return n.invert=function(e,t){var n=Math.cos(t),u=Math.cos(e)*n,a=Math.sin(e)*n,f=Math.sin(t),l=f*s-a*o;return[Math.atan2(a*s+f*o,u*r+l*i),Math.asin(Math.max(-1,Math.min(1,l*r-u*i)))]},n}function xi(e,t){function n(t,n){var r=Math.cos(t),i=Math.cos(n),s=e(r*i);return[s*i*Math.sin(t),s*Math.sin(n)]}return n.invert=function(e,n){var r=Math.sqrt(e*e+n*n),i=t(r),s=Math.sin(i),o=Math.cos(i);return[Math.atan2(e*s,r*o),Math.asin(r&&n*s/r)]},n}function Ti(e){return Qo[e]}function Ni(e){var t=0,n=0;for(;;){if(e(t,n))return[t,n];t===0?(t=n+1,n=0):(t-=1,n+=1)}}function Ci(e,t,n,r){var i,s,o,u,a,f,l;return i=r[e],s=i[0],o=i[1],i=r[t],u=i[0],a=i[1],i=r[n],f=i[0],l=i[1],(l-o)*(u-s)-(a-o)*(f-s)>0}function ki(e,t,n){return(n[0]-t[0])*(e[1]-t[1])<(n[1]-t[1])*(e[0]-t[0])}function Li(e,t,n,r){var i=e[0],s=t[0],o=n[0],u=r[0],a=e[1],f=t[1],l=n[1],c=r[1],h=i-o,p=s-i,d=u-o,v=a-l,m=f-a,g=c-l,y=(d*v-g*h)/(g*p-d*m);return[i+y*p,a+y*m]}function Ai(e,t){var n={list:e.map(function(e,t){return{index:t,x:e[0],y:e[1]}}).sort(function(e,t){return e.yt.y?1:e.xt.x?1:0}),bottomSite:null},r={list:[],leftEnd:null,rightEnd:null,init:function(){r.leftEnd=r.createHalfEdge(null,"l"),r.rightEnd=r.createHalfEdge(null,"l"),r.leftEnd.r=r.rightEnd,r.rightEnd.l=r.leftEnd,r.list.unshift(r.leftEnd,r.rightEnd)},createHalfEdge:function(e,t){return{edge:e,side:t,vertex:null,l:null,r:null}},insert:function(e,t){t.l=e,t.r=e.r,e.r.l=t,e.r=t},leftBound:function(e){var t=r.leftEnd;do t=t.r;while(t!=r.rightEnd&&i.rightOf(t,e));return t=t.l,t},del:function(e){e.l.r=e.r,e.r.l=e.l,e.edge=null},right:function(e){return e.r},left:function(e){return e.l},leftRegion:function(e){return e.edge==null?n.bottomSite:e.edge.region[e.side]},rightRegion:function(e){return e.edge==null?n.bottomSite:e.edge.region[Zo[e.side]]}},i={bisect:function(e,t){var n={region:{l:e,r:t},ep:{l:null,r:null}},r=t.x-e.x,i=t.y-e.y,s=r>0?r:-r,o=i>0?i:-i;return n.c=e.x*r+e.y*i+(r*r+i*i)*.5,s>o?(n.a=1,n.b=i/r,n.c/=r):(n.b=1,n.a=r/i,n.c/=i),n},intersect:function(e,t){var n=e.edge,r=t.edge;if(!n||!r||n.region.r==r.region.r)return null;var i=n.a*r.b-n.b*r.a;if(Math.abs(i)<1e-10)return null;var s=(n.c*r.b-r.c*n.b)/i,o=(r.c*n.a-n.c*r.a)/i,u=n.region.r,a=r.region.r,f,l;u.y=l.region.r.x;return c&&f.side==="l"||!c&&f.side==="r"?null:{x:s,y:o}},rightOf:function(e,t){var n=e.edge,r=n.region.r,i=t.x>r.x;if(i&&e.side==="l")return 1;if(!i&&e.side==="r")return 0;if(n.a===1){var s=t.y-r.y,o=t.x-r.x,u=0,a=0;!i&&n.b<0||i&&n.b>=0?a=u=s>=n.b*o:(a=t.x+t.y*n.b>n.c,n.b<0&&(a=!a),a||(u=1));if(!u){var f=r.x-n.region.l.x;a=n.b*(o*o-s*s)h*h+p*p}return e.side==="l"?a:!a},endPoint:function(e,n,r){e.ep[n]=r;if(!e.ep[Zo[n]])return;t(e)},distance:function(e,t){var n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}},s={list:[],insert:function(e,t,n){e.vertex=t,e.ystar=t.y+n;for(var r=0,i=s.list,o=i.length;ru.ystar||e.ystar==u.ystar&&t.x>u.vertex.x)continue;break}i.splice(r,0,e)},del:function(e){for(var t=0,n=s.list,r=n.length;td.y&&(v=p,p=d,d=v,b="r"),y=i.bisect(p,d),h=r.createHalfEdge(y,b),r.insert(l,h),i.endPoint(y,Zo[b],g),m=i.intersect(l,h),m&&(s.del(l),s.insert(l,m,i.distance(m,p))),m=i.intersect(h,c),m&&s.insert(h,m,i.distance(m,p))}}for(a=r.right(r.leftEnd);a!=r.rightEnd;a=r.right(a))t(a.edge)}function Oi(){return{leaf:!0,nodes:[],point:null}}function Mi(e,t,n,r,i,s){if(!e(t,n,r,i,s)){var o=(n+i)*.5,u=(r+s)*.5,a=t.nodes;a[0]&&Mi(e,a[0],n,r,o,u),a[1]&&Mi(e,a[1],o,r,i,u),a[2]&&Mi(e,a[2],n,u,o,s),a[3]&&Mi(e,a[3],o,u,i,s)}}function _i(e){return{x:e[0],y:e[1]}}function Di(){this._=new Date(arguments.length>1?Date.UTC.apply(this,arguments):arguments[0])}function Pi(e){return e.substring(0,3)}function Hi(e,t,n,r){var i,s,o=0,u=t.length,a=n.length;while(o=a)return-1;i=t.charCodeAt(o++);if(i==37){s=Eu[t.charAt(o++)];if(!s||(r=s(e,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}function Bi(e){return new RegExp("^(?:"+e.map(d3.requote).join("|")+")","i")}function ji(e){var t=new r,n=-1,i=e.length;while(++n68?1900:2e3)}function Ji(e,t,n){Su.lastIndex=0;var r=Su.exec(t.substring(n,n+2));return r?(e.m=r[0]-1,n+=r[0].length):-1}function Ki(e,t,n){Su.lastIndex=0;var r=Su.exec(t.substring(n,n+2));return r?(e.d=+r[0],n+=r[0].length):-1}function Qi(e,t,n){Su.lastIndex=0;var r=Su.exec(t.substring(n,n+2));return r?(e.H=+r[0],n+=r[0].length):-1}function Gi(e,t,n){Su.lastIndex=0;var r=Su.exec(t.substring(n,n+2));return r?(e.M=+r[0],n+=r[0].length):-1}function Yi(e,t,n){Su.lastIndex=0;var r=Su.exec(t.substring(n,n+2));return r?(e.S=+r[0],n+=r[0].length):-1}function Zi(e,t,n){Su.lastIndex=0;var r=Su.exec(t.substring(n,n+3));return r?(e.L=+r[0],n+=r[0].length):-1}function es(e,t,n){var r=xu.get(t.substring(n,n+=2).toLowerCase());return r==null?-1:(e.p=r,n)}function ts(e){var t=e.getTimezoneOffset(),n=t>0?"-":"+",r=~~(Math.abs(t)/60),i=Math.abs(t)%60;return n+lu(r)+lu(i)}function ns(e){return e.toISOString()}function rs(e,t,n){function r(t){var n=e(t),r=s(n,1);return t-n1)while(ot?1:e>=t?0:NaN},d3.descending=function(e,t){return te?1:t>=e?0:NaN},d3.mean=function(e,t){var n=e.length,r,i=0,s=-1,o=0;if(arguments.length===1)while(++s1&&(e=e.map(t)),e=e.filter(f),e.length?d3.quantile(e.sort(d3.ascending),.5):undefined},d3.min=function(e,t){var n=-1,r=e.length,i,s;if(arguments.length===1){while(++ns&&(i=s)}else{while(++ns&&(i=s)}return i},d3.max=function(e,t){var n=-1,r=e.length,i,s;if(arguments.length===1){while(++ni&&(i=s)}else{while(++ni&&(i=s)}return i},d3.extent=function(e,t){var n=-1,r=e.length,i,s,o;if(arguments.length===1){while(++ns&&(i=s),os&&(i=s),o1);return e+t*n*Math.sqrt(-2*Math.log(i)/i)}},logNormal:function(e,t){var n=arguments.length;n<2&&(t=1),n<1&&(e=0);var r=d3.random.normal();return function(){return Math.exp(e+t*r())}},irwinHall:function(e){return function(){for(var t=0,n=0;n>>1;e.call(t,t[s],s)>>1;n0&&(i=s);return i},d3.last=function(e,t){var n=0,r=e.length,i=e[0],s;arguments.length===1&&(t=d3.ascending);while(++n=i.length)return u?u.call(n,t):o?t.sort(o):t;var a=-1,f=t.length,l=i[s++],c,h,p=new r,d,v={};while(++a=i.length)return e;var r=[],o=s[n++],u;for(u in e)r.push({key:u,values:t(e[u],n)});return o&&r.sort(function(e,t){return o(e.key,t.key)}),r}var n={},i=[],s=[],o,u;return n.map=function(t){return e(t,0)},n.entries=function(n){return t(e(n,0),0)},n.key=function(e){return i.push(e),n},n.sortKeys=function(e){return s[i.length-1]=e,n},n.sortValues=function(e){return o=e,n},n.rollup=function(e){return u=e,n},n},d3.keys=function(e){var t=[];for(var n in e)t.push(n);return t},d3.values=function(e){var t=[];for(var n in e)t.push(e[n]);return t},d3.entries=function(e){var t=[];for(var n in e)t.push({key:n,value:e[n]});return t},d3.permute=function(e,t){var n=[],r=-1,i=t.length;while(++rt)r.push(o/i);else while((o=e+n*++s)=200&&e<300||e===304?r:null)}},r.send(null)},d3.text=function(e,t,n){function r(e){n(e&&e.responseText)}arguments.length<3&&(n=t,t=null),d3.xhr(e,t,r)},d3.json=function(e,t){d3.text(e,"application/json",function(e){t(e?JSON.parse(e):null)})},d3.html=function(e,t){d3.text(e,"text/html",function(e){if(e!=null){var n=document.createRange();n.selectNode(document.body),e=n.createContextualFragment(e)}t(e)})},d3.xml=function(e,t,n){function r(e){n(e&&e.responseXML)}arguments.length<3&&(n=t,t=null),d3.xhr(e,t,r)};var Ls={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};d3.ns={prefix:Ls,qualify:function(e){var t=e.indexOf(":"),n=e;return t>=0&&(n=e.substring(0,t),e=e.substring(t+1)),Ls.hasOwnProperty(n)?{space:Ls[n],local:e}:e}},d3.dispatch=function(){var e=new d,t=-1,n=arguments.length;while(++t0&&(r=e.substring(n+1),e=e.substring(0,n)),arguments.length<2?this[e].on(r):this[e].on(r,t)},d3.format=function(e){var t=As.exec(e),n=t[1]||" ",r=t[3]||"",i=t[5],s=+t[6],o=t[7],u=t[8],a=t[9],f=1,l="",c=!1;u&&(u=+u.substring(1)),i&&(n="0",o&&(s-=Math.floor((s-1)/4)));switch(a){case"n":o=!0,a="g";break;case"%":f=100,l="%",a="f";break;case"p":f=100,l="%",a="r";break;case"d":c=!0,u=0;break;case"s":f=-1,a="r"}return a=="r"&&!u&&(a="g"),a=Os.get(a)||g,function(e){if(c&&e%1)return"";var t=e<0&&(e=-e)?"-":r;if(f<0){var h=d3.formatPrefix(e,u);e=h.scale(e),l=h.symbol}else e*=f;e=a(e,u);if(i){var p=e.length+t.length;p=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/,Os=d3.map({g:function(e,t){return e.toPrecision(t)},e:function(e,t){return e.toExponential(t)},f:function(e,t){return e.toFixed(t)},r:function(e,t){return d3.round(e,t=m(e,t)).toFixed(Math.max(0,Math.min(20,t)))}}),Ms=["y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y"].map(b);d3.formatPrefix=function(e,t){var n=0;return e&&(e<0&&(e*=-1),t&&(e=d3.round(e,m(e,t))),n=1+Math.floor(1e-12+Math.log(e)/Math.LN10),n=Math.max(-24,Math.min(24,Math.floor((n<=0?n+1:n-1)/3)*3))),Ms[8+n/3]};var _s=T(2),Ds=T(3),Ps=function(){return x},Hs=d3.map({linear:Ps,poly:T,quad:function(){return _s},cubic:function(){return Ds},sin:function(){return N},exp:function(){return C},circle:function(){return k},elastic:L,back:A,bounce:function(){return O}}),Bs=d3.map({"in":x,out:E,"in-out":S,"out-in":function(e){return S(E(e))}});d3.ease=function(e){var t=e.indexOf("-"),n=t>=0?e.substring(0,t):e,r=t>=0?e.substring(t+1):"in";return n=Hs.get(n)||Ps,r=Bs.get(r)||x,w(r(n.apply(null,Array.prototype.slice.call(arguments,1))))},d3.event=null,d3.transform=function(e){var t=document.createElementNS(d3.ns.prefix.svg,"g");return(d3.transform=function(e){t.setAttribute("transform",e);var n=t.transform.baseVal.consolidate();return new P(n?n.matrix:js)})(e)},P.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var js={a:1,b:0,c:0,d:1,e:0,f:0};d3.interpolate=function(e,t){var n=d3.interpolators.length,r;while(--n>=0&&!(r=d3.interpolators[n](e,t)));return r},d3.interpolateNumber=function(e,t){return t-=e,function(n){return e+t*n}},d3.interpolateRound=function(e,t){return t-=e,function(n){return Math.round(e+t*n)}},d3.interpolateString=function(e,t){var n,r,i,s=0,o=0,u=[],a=[],f,l;Fs.lastIndex=0;for(r=0;n=Fs.exec(t);++r)n.index&&u.push(t.substring(s,o=n.index)),a.push({i:u.length,x:n[0]}),u.push(null),s=Fs.lastIndex;s180?l+=360:l-f>180&&(f+=360),r.push({i:n.push(n.pop()+"rotate(",null,")")-2,x:d3.interpolateNumber(f,l)})):l&&n.push(n.pop()+"rotate("+l+")"),c!=h?r.push({i:n.push(n.pop()+"skewX(",null,")")-2,x:d3.interpolateNumber(c,h)}):h&&n.push(n.pop()+"skewX("+h+")"),p[0]!=d[0]||p[1]!=d[1]?(i=n.push(n.pop()+"scale(",null,",",null,")"),r.push({i:i-4,x:d3.interpolateNumber(p[0],d[0])},{i:i-2,x:d3.interpolateNumber(p[1],d[1])})):(d[0]!=1||d[1]!=1)&&n.push(n.pop()+"scale("+d+")"),i=r.length,function(e){var t=-1,s;while(++t180?s-=360:s<-180&&(s+=360),function(e){return G(n+s*e,r+o*e,i+u*e)+""}},d3.interpolateLab=function(e,t){e=d3.lab(e),t=d3.lab(t);var n=e.l,r=e.a,i=e.b,s=t.l-n,o=t.a-r,u=t.b-i;return function(e){return rt(n+s*e,r+o*e,i+u*e)+""}},d3.interpolateHcl=function(e,t){e=d3.hcl(e),t=d3.hcl(t);var n=e.h,r=e.c,i=e.l,s=t.h-n,o=t.c-r,u=t.l-i;return s>180?s-=360:s<-180&&(s+=360),function(e){return et(n+s*e,r+o*e,i+u*e)+""}},d3.interpolateArray=function(e,t){var n=[],r=[],i=e.length,s=t.length,o=Math.min(e.length,t.length),u;for(u=0;u=0;)if(s=n[r])i&&i!==s.nextSibling&&i.parentNode.insertBefore(s,i),i=s;return this},Ks.sort=function(e){e=bt.apply(this,arguments);for(var t=-1,n=this.length;++t=wo?e?"M0,"+s+"A"+s+","+s+" 0 1,1 0,"+ -s+"A"+s+","+s+" 0 1,1 0,"+s+"M0,"+e+"A"+e+","+e+" 0 1,0 0,"+ -e+"A"+e+","+e+" 0 1,0 0,"+e+"Z":"M0,"+s+"A"+s+","+s+" 0 1,1 0,"+ -s+"A"+s+","+s+" 0 1,1 0,"+s+"Z":e?"M"+s*l+","+s*c+"A"+s+","+s+" 0 "+f+",1 "+s*h+","+s*p+"L"+e*h+","+e*p+"A"+e+","+e+" 0 "+f+",0 "+e*l+","+e*c+"Z":"M"+s*l+","+s*c+"A"+s+","+s+" 0 "+f+",1 "+s*h+","+s*p+"L0,0"+"Z"}var t=Zt,n=en,r=tn,i=nn;return e.innerRadius=function(n){return arguments.length?(t=u(n),e):t},e.outerRadius=function(t){return arguments.length?(n=u(t),e):n},e.startAngle=function(t){return arguments.length?(r=u(t),e):r},e.endAngle=function(t){return arguments.length?(i=u(t),e):i},e.centroid=function(){var e=(t.apply(this,arguments)+n.apply(this,arguments))/2,s=(r.apply(this,arguments)+i.apply(this,arguments))/2+bo;return[Math.cos(s)*e,Math.sin(s)*e]},e};var bo=-ms/2,wo=2*ms-1e-6;d3.svg.line=function(){return rn(i)};var Eo=d3.map({linear:un,"linear-closed":an,"step-before":fn,"step-after":ln,basis:mn,"basis-open":gn,"basis-closed":yn,bundle:bn,cardinal:pn,"cardinal-open":cn,"cardinal-closed":hn,monotone:Nn});Eo.forEach(function(e,t){t.key=e,t.closed=/-closed$/.test(e)});var So=[0,2/3,1/3,0],xo=[0,1/3,2/3,0],To=[0,1/6,2/3,1/6];d3.svg.line.radial=function(){var e=rn(Cn);return e.radius=e.x,delete e.x,e.angle=e.y,delete e.y,e},fn.reverse=ln,ln.reverse=fn,d3.svg.area=function(){return kn(i)},d3.svg.area.radial=function(){var e=kn(Cn);return e.radius=e.x,delete e.x,e.innerRadius=e.x0,delete e.x0,e.outerRadius=e.x1,delete e.x1,e.angle=e.y,delete e.y,e.startAngle=e.y0,delete e.y0,e.endAngle=e.y1,delete e.y1,e},d3.svg.chord=function(){function e(e,u){var a=t(this,s,e,u),f=t(this,o,e,u);return"M"+a.p0+r(a.r,a.p1,a.a1-a.a0)+(n(a,f)?i(a.r,a.p1,a.r,a.p0):i(a.r,a.p1,f.r,f.p0)+r(f.r,f.p1,f.a1-f.a0)+i(f.r,f.p1,a.r,a.p0))+"Z"}function t(e,t,n,r){var i=t.call(e,n,r),s=a.call(e,i,r),o=f.call(e,i,r)+bo,u=l.call(e,i,r)+bo;return{r:s,a0:o,a1:u,p0:[s*Math.cos(o),s*Math.sin(o)],p1:[s*Math.cos(u),s*Math.sin(u)]}}function n(e,t){return e.a0==t.a0&&e.a1==t.a1}function r(e,t,n){return"A"+e+","+e+" 0 "+ +(n>ms)+",1 "+t}function i(e,t,n,r){return"Q 0,0 "+r}var s=Ln,o=An,a=On,f=tn,l=nn;return e.radius=function(t){return arguments.length?(a=u(t),e):a},e.source=function(t){return arguments.length?(s=u(t),e):s},e.target=function(t){return arguments.length?(o=u(t),e):o},e.startAngle=function(t){return arguments.length?(f=u(t),e):f},e.endAngle=function(t){return arguments.length?(l=u(t),e):l},e},d3.svg.diagonal=function(){function e(e,i){var s=t.call(this,e,i),o=n.call(this,e,i),u=(s.y+o.y)/2,a=[s,{x:s.x,y:u},{x:o.x,y:u},o];return a=a.map(r),"M"+a[0]+"C"+a[1]+" "+a[2]+" "+a[3]}var t=Ln,n=An,r=Dn;return e.source=function(n){return arguments.length?(t=u(n),e):t},e.target=function(t){return arguments.length?(n=u(t),e):n},e.projection=function(t){return arguments.length?(r=t,e):r},e},d3.svg.diagonal.radial=function(){var e=d3.svg.diagonal(),t=Dn,n=e.projection;return e.projection=function(e){return arguments.length?n(Pn(t=e)):t},e},d3.svg.mouse=d3.mouse,d3.svg.touches=d3.touches,d3.svg.symbol=function(){function e(e,r){return(No.get(t.call(this,e,r))||jn)(n.call(this,e,r))}var t=Bn,n=Hn;return e.type=function(n){return arguments.length?(t=u(n),e):t},e.size=function(t){return arguments.length?(n=u(t),e):n},e};var No=d3.map({circle:jn,cross:function(e){var t=Math.sqrt(e/5)/2;return"M"+ -3*t+","+ -t+"H"+ -t+"V"+ -3*t+"H"+t+"V"+ -t+"H"+3*t+"V"+t+"H"+t+"V"+3*t+"H"+ -t+"V"+t+"H"+ -3*t+"Z"},diamond:function(e){var t=Math.sqrt(e/(2*ko)),n=t*ko;return"M0,"+ -t+"L"+n+",0"+" 0,"+t+" "+ -n+",0"+"Z"},square:function(e){var t=Math.sqrt(e)/2;return"M"+ -t+","+ -t+"L"+t+","+ -t+" "+t+","+t+" "+ -t+","+t+"Z"},"triangle-down":function(e){var t=Math.sqrt(e/Co),n=t*Co/2;return"M0,"+n+"L"+t+","+ -n+" "+ -t+","+ -n+"Z"},"triangle-up":function(e){var t=Math.sqrt(e/Co),n=t*Co/2;return"M0,"+ -n+"L"+t+","+n+" "+ -t+","+n+"Z"}});d3.svg.symbolTypes=No.keys();var Co=Math.sqrt(3),ko=Math.tan(30*ys);d3.svg.axis=function(){function e(e){e.each(function(){var e=d3.select(this),c=a==null?t.ticks?t.ticks.apply(t,u):t.domain():a,h=f==null?t.tickFormat?t.tickFormat.apply(t,u):String:f,p=qn(t,c,l),d=e.selectAll(".minor").data(p,String),v=d.enter().insert("line","g").attr("class","tick minor").style("opacity",1e-6),m=d3.transition(d.exit()).style("opacity",1e-6).remove(),g=d3.transition(d).style("opacity",1),y=e.selectAll("g").data(c,String),b=y.enter().insert("g","path").style("opacity",1e-6),w=d3.transition(y.exit()).style("opacity",1e-6).remove(),E=d3.transition(y).style("opacity",1),S,x=_t(t),T=e.selectAll(".domain").data([0]),N=T.enter().append("path").attr("class","domain"),C=d3.transition(T),k=t.copy(),L=this.__chart__||k;this.__chart__=k,b.append("line").attr("class","tick"),b.append("text");var A=b.select("line"),O=E.select("line"),M=y.select("text").text(h),_=b.select("text"),D=E.select("text");switch(n){case"bottom":S=Fn,v.attr("y2",i),g.attr("x2",0).attr("y2",i),A.attr("y2",r),_.attr("y",Math.max(r,0)+o),O.attr("x2",0).attr("y2",r),D.attr("x",0).attr("y",Math.max(r,0)+o),M.attr("dy",".71em").attr("text-anchor","middle"),C.attr("d","M"+x[0]+","+s+"V0H"+x[1]+"V"+s);break;case"top":S=Fn,v.attr("y2",-i),g.attr("x2",0).attr("y2",-i),A.attr("y2",-r),_.attr("y",-(Math.max(r,0)+o)),O.attr("x2",0).attr("y2",-r),D.attr("x",0).attr("y",-(Math.max(r,0)+o)),M.attr("dy","0em").attr("text-anchor","middle"),C.attr("d","M"+x[0]+","+ -s+"V0H"+x[1]+"V"+ -s);break;case"left":S=In,v.attr("x2",-i),g.attr("x2",-i).attr("y2",0),A.attr("x2",-r),_.attr("x",-(Math.max(r,0)+o)),O.attr("x2",-r).attr("y2",0),D.attr("x",-(Math.max(r,0)+o)).attr("y",0),M.attr("dy",".32em").attr("text-anchor","end"),C.attr("d","M"+ -s+","+x[0]+"H0V"+x[1]+"H"+ -s);break;case"right":S=In,v.attr("x2",i),g.attr("x2",i).attr("y2",0),A.attr("x2",r),_.attr("x",Math.max(r,0)+o),O.attr("x2",r).attr("y2",0),D.attr("x",Math.max(r,0)+o).attr("y",0),M.attr("dy",".32em").attr("text-anchor","start"),C.attr("d","M"+s+","+x[0]+"H0V"+x[1]+"H"+s)}if(t.ticks)b.call(S,L),E.call(S,k),w.call(S,k),v.call(S,L),g.call(S,k),m.call(S,k);else{var P=k.rangeBand()/2,H=function(e){return k(e)+P};b.call(S,H),E.call(S,H)}})}var t=d3.scale.linear(),n="bottom",r=6,i=6,s=6,o=3,u=[10],a=null,f,l=0;return e.scale=function(n){return arguments.length?(t=n,e):t},e.orient=function(t){return arguments.length?(n=t,e):n},e.ticks=function(){return arguments.length?(u=arguments,e):u},e.tickValues=function(t){return arguments.length?(a=t,e):a},e.tickFormat=function(t){return arguments.length?(f=t,e):f},e.tickSize=function(t,n,o){if(!arguments.length)return r;var u=arguments.length-1;return r=+t,i=u>1?+n:r,s=u>0?+arguments[u]:r,e},e.tickPadding=function(t){return arguments.length?(o=+t,e):o},e.tickSubdivide=function(t){return arguments.length?(l=+t,e):l},e},d3.svg.brush=function(){function e(s){s.each(function(){var s=d3.select(this),f=s.selectAll(".background").data([0]),l=s.selectAll(".extent").data([0]),c=s.selectAll(".resize").data(a,String),h;s.style("pointer-events","all").on("mousedown.brush",i).on("touchstart.brush",i),f.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),l.enter().append("rect").attr("class","extent").style("cursor","move"),c.enter().append("g").attr("class",function(e){return"resize "+e}).style("cursor",function(e){return Lo[e]}).append("rect").attr("x",function(e){return/[ew]$/.test(e)?-3:null}).attr("y",function(e){return/^[ns]/.test(e)?-3:null}).attr("width",6).attr("height",6).style("visibility","hidden"),c.style("display",e.empty()?"none":null),c.exit().remove(),o&&(h=_t(o),f.attr("x",h[0]).attr("width",h[1]-h[0]),n(s)),u&&(h=_t(u),f.attr("y",h[0]).attr("height",h[1]-h[0]),r(s)),t(s)})}function t(e){e.selectAll(".resize").attr("transform",function(e){return"translate("+f[+/e$/.test(e)][0]+","+f[+/^s/.test(e)][1]+")"})}function n(e){e.select(".extent").attr("x",f[0][0]),e.selectAll(".extent,.n>rect,.s>rect").attr("width",f[1][0]-f[0][0])}function r(e){e.select(".extent").attr("y",f[0][1]),e.selectAll(".extent,.e>rect,.w>rect").attr("height",f[1][1]-f[0][1])}function i(){function i(){var e=d3.event.changedTouches;return e?d3.touches(v,e)[0]:d3.mouse(v)}function a(){d3.event.keyCode==32&&(S||(x=null,T[0]-=f[1][0],T[1]-=f[1][1],S=2),M())}function c(){d3.event.keyCode==32&&S==2&&(T[0]+=f[1][0],T[1]+=f[1][1],S=0,M())}function h(){var e=i(),s=!1;N&&(e[0]+=N[0],e[1]+=N[1]),S||(d3.event.altKey?(x||(x=[(f[0][0]+f[1][0])/2,(f[0][1]+f[1][1])/2]),T[0]=f[+(e[0]0?a=e:a=0:e>0&&(r.start({type:"start",alpha:a=e}),d3.timer(n.tick)),n):a},n.start=function(){function e(e,n){var i=t(r),s=-1,o=i.length,u;while(++si&&(i=u),r.push(u)}for(o=0;o0){s=-1;while(++s=a[0]&&d<=a[1]&&(l=o[d3.bisect(f,d,1,h)-1],l.y+=p,l.push(e[s]))}return o}var t=!0,n=Number,r=ar,i=or;return e.value=function(t){return arguments.length?(n=t,e):n},e.range=function(t){return arguments.length?(r=u(t),e):r},e.bins=function(t){return arguments.length?(i=typeof t=="number"?function(e){return ur(e,t)}:u(t),e):i},e.frequency=function(n){return arguments.length?(t=!!n,e):t},e},d3.layout.hierarchy=function(){function e(t,o,u){var a=i.call(n,t,o),f=Ho?t:{data:t};f.depth=o,u.push(f);if(a&&(c=a.length)){var l=-1,c,h=f.children=[],p=0,d=o+1,v;while(++l0){var l=n*f/2;Pr(o,function(e){e.r+=l}),Pr(o,yr),Pr(o,function(e){e.r-=l}),f=Math.max(2*o.r/u,2*o.r/a)}return Er(o,u/2,a/2,1/f),s}var t=d3.layout.hierarchy().sort(dr),n=0,r=[1,1];return e.size=function(t){return arguments.length?(r=t,e):r},e.padding=function(t){return arguments.length?(n=+t,e):n},fr(e,t)},d3.layout.cluster=function(){function e(e,i){var s= +t.call(this,e,i),o=s[0],u,a=0,f,l;Pr(o,function(e){var t=e.children;t&&t.length?(e.x=Tr(t),e.y=xr(t)):(e.x=u?a+=n(e,u):0,e.y=0,u=e)});var c=Nr(o),h=Cr(o),p=c.x-n(c,h)/2,d=h.x+n(h,c)/2;return Pr(o,function(e){e.x=(e.x-p)/(d-p)*r[0],e.y=(1-(o.y?e.y/o.y:1))*r[1]}),s}var t=d3.layout.hierarchy().sort(null).value(null),n=kr,r=[1,1];return e.separation=function(t){return arguments.length?(n=t,e):n},e.size=function(t){return arguments.length?(r=t,e):r},fr(e,t)},d3.layout.tree=function(){function e(e,i){function s(e,t){var r=e.children,i=e._tree;if(r&&(o=r.length)){var o,a=r[0],f,l=a,c,h=-1;while(++h0&&(Br(jr(o,e,r),e,h),a+=h,f+=h),l+=o._tree.mod,a+=i._tree.mod,c+=u._tree.mod,f+=s._tree.mod;o&&!Ar(s)&&(s._tree.thread=o,s._tree.mod+=l-f),i&&!Lr(u)&&(u._tree.thread=i,u._tree.mod+=a-c,r=e)}return r}var a=t.call(this,e,i),f=a[0];Pr(f,function(e,t){e._tree={ancestor:e,prelim:0,mod:0,change:0,shift:0,number:t?t._tree.number+1:0}}),s(f),o(f,-f._tree.prelim);var l=Or(f,_r),c=Or(f,Mr),h=Or(f,Dr),p=l.x-n(l,c)/2,d=c.x+n(c,l)/2,v=h.depth||1;return Pr(f,function(e){e.x=(e.x-p)/(d-p)*r[0],e.y=e.depth/v*r[1],delete e._tree}),a}var t=d3.layout.hierarchy().sort(null).value(null),n=kr,r=[1,1];return e.separation=function(t){return arguments.length?(n=t,e):n},e.size=function(t){return arguments.length?(r=t,e):r},fr(e,t)},d3.layout.treemap=function(){function e(e,t){var n=-1,r=e.length,i,s;while(++n0)u.push(f=a[d-1]),u.area+=f.area,(h=r(u,p))<=c?(a.pop(),c=h):(u.area-=u.pop().area,i(u,p,o,!1),p=Math.min(o.dx,o.dy),u.length=u.area=0,c=Infinity);u.length&&(i(u,p,o,!0),u.length=u.area=0),s.forEach(t)}}function n(t){var r=t.children;if(r&&r.length){var s=l(t),o=r.slice(),u,a=[];e(o,s.dx*s.dy/t.value),a.area=0;while(u=o.pop())a.push(u),a.area+=u.area,u.z!=null&&(i(a,u.z?s.dx:s.dy,s,!o.length),a.length=a.area=0);r.forEach(n)}}function r(e,t){var n=e.area,r,i=0,s=Infinity,o=-1,u=e.length;while(++oi&&(i=r)}return n*=n,t*=t,n?Math.max(t*i*p/n,n/(t*s*p)):Infinity}function i(e,t,n,r){var i=-1,s=e.length,o=n.x,a=n.y,f=t?u(e.area/t):0,l;if(t==n.dx){if(r||f>n.dy)f=n.dy;while(++in.dx)f=n.dx;while(++i50?n:s<-140?r:o<21?i:t)(e)}var t=d3.geo.albers(),n=d3.geo.albers().origin([-160,60]).parallels([55,65]),r=d3.geo.albers().origin([-160,20]).parallels([8,18]),i=d3.geo.albers().origin([-60,10]).parallels([8,18]);return e.scale=function(s){return arguments.length?(t.scale(s),n.scale(s*.6),r.scale(s),i.scale(s*1.5),e.translate(t.translate())):t.scale()},e.translate=function(s){if(!arguments.length)return t.translate();var o=t.scale(),u=s[0],a=s[1];return t.translate(s),n.translate([u-.4*o,a+.17*o]),r.translate([u-.19*o,a+.2*o]),i.translate([u+.58*o,a+.43*o]),e},e.scale(t.scale())},(d3.geo.albers=function(){var e=29.5*ys,t=45.5*ys,n=hi(Ur),r=n(e,t);return r.origin=function(e){var t=r.rotate(),n=r.center();return arguments.length?r.rotate([-e[0],t[1]]).center([n[0],e[1]]):[-t[0],n[1]]},r.parallels=function(r){return arguments.length?n(e=r[0]*ys,t=r[1]*ys):[e*bs,t*bs]},r.origin([-98,38]).scale(1e3)}).raw=Ur;var Io=xi(function(e){return Math.sqrt(2/(1+e))},function(e){return 2*Math.asin(e/2)});(d3.geo.azimuthalEqualArea=function(){return ci(Io)}).raw=Io;var qo=xi(function(e){var t=Math.acos(e);return t&&t/Math.sin(t)},i);(d3.geo.azimuthalEquidistant=function(){return ci(qo)}).raw=qo,d3.geo.bounds=function(e){return Wo=zo=-(Ro=Uo=Infinity),Xo.object(e),[[Ro,Uo],[zo,Wo]]};var Ro,Uo,zo,Wo,Xo=Rr({point:function(e){var t=e[0],n=e[1];tzo&&(zo=t),nWo&&(Wo=n)},polygon:function(e){this.line(e[0])}});d3.geo.circle=function(){function e(){}var t=[0,0],n=90,r,s;e.clip=function(e){var i=typeof t=="function"?t.apply(this,arguments):t,s=bi(-i[0]*ys,-i[1]*ys,0);return r=Wr(n,function(e){return s(e[0]*ys,e[1]*ys)}),o.object(e)||null};var o=Rr({FeatureCollection:function(e){var t=e.features.map(o.Feature,o).filter(i);return t&&(e=Object.create(e),e.features=t,e)},Feature:function(e){var t=o.geometry(e.geometry);return t&&(e=Object.create(e),e.geometry=t,e)},Point:function(e){var t=[];return r.point(e.coordinates,zr(t)),t.length&&e},MultiPoint:function(e){var t=[],n=zr(t);return e.coordinates.forEach(function(e){r.point(e,n)}),t.length&&(e=Object.create(e),e.coordinates=t.map(function(e){return e[0]}),e)},LineString:function(e){var t=[],n=zr(t);return r.line(e.coordinates,n),t.length&&(e=Object.create(e),e.type="MultiLineString",e.coordinates=t,e)},MultiLineString:function(e){var t=[],n=zr(t);return e.coordinates.forEach(function(e){r.line(e,n)}),t.length&&(e=Object.create(e),e.coordinates=t,e)},Polygon:function(e){var t=[];r.polygon(e.coordinates,zr(t));var n=t.map(function(e){return[e]});return n.length&&(e=Object.create(e),e.type="MultiPolygon",e.coordinates=n,e)},MultiPolygon:function(e){var t=[],n=zr(t);e.coordinates.forEach(function(e){r.polygon(e,n)});var i=t.map(function(e){return[e]});return i.length&&(e=Object.create(e),e.type="MultiPolygon",e.coordinates=i,e)},GeometryCollection:function(e){var t=e.geometries.map(o.geometry,o).filter(i);return t.length&&(e=Object.create(e),e.geometries=t,e)}});return e.origin=function(n){return arguments.length?(t=n,e):t},e.angle=function(t){return arguments.length?(n=+t,e):n},e.precision=function(t){return arguments.length?(s=+t,e):s},e},(d3.geo.equirectangular=function(){return ci(ni).scale(250/ms)}).raw=ni.invert=ni;var Vo=xi(function(e){return 1/e},Math.atan);(d3.geo.gnomonic=function(){return ci(Vo)}).raw=Vo,d3.geo.graticule=function(){function e(){return{type:"GeometryCollection",geometries:e.lines()}}var t,n,r,i,s=22.5,o=s,u,a;return e.lines=function(){return d3.range(Math.ceil(n/s)*s,t,s).map(u).concat(d3.range(Math.ceil(i/o)*o,r,o).map(a)).map(function(e){return{type:"LineString",coordinates:e}})},e.outline=function(){return{type:"Polygon",coordinates:[u(n).concat(a(r).slice(1),u(t).reverse().slice(1),a(i).reverse().slice(1))]}},e.extent=function(s){return arguments.length?(n=+s[0][0],t=+s[1][0],i=+s[0][1],r=+s[1][1],n>t&&(s=n,n=t,t=s),i>r&&(s=i,i=r,r=s),u=ri(i,r),a=ii(n,t),e):[[n,i],[t,r]]},e.step=function(t){return arguments.length?(s=+t[0],o=+t[1],e):[s,o]},e.extent([[-180+gs,-90+gs],[180-gs,90-gs]])};var $o=3;d3.geo.greatArc=function(){function e(){var t=e.distance.apply(this,arguments),r=0,u=s/t,a=[n];while((r+=u)<1)a.push(o(r));return a.push(i),{type:"LineString",coordinates:a}}var t=si,n,r=oi,i,s=6*ys,o=ui();return e.distance=function(){return typeof t=="function"&&o.source(n=t.apply(this,arguments)),typeof r=="function"&&o.target(i=r.apply(this,arguments)),o.distance()},e.source=function(r){return arguments.length?(t=r,typeof t!="function"&&o.source(n=t),e):t},e.target=function(t){return arguments.length?(r=t,typeof r!="function"&&o.target(i=r),e):r},e.precision=function(t){return arguments.length?(s=t*ys,e):s/ys},e},d3.geo.greatCircle=d3.geo.circle,fi.invert=function(e,t){return[2*ms*e,2*Math.atan(Math.exp(2*ms*t))-ms/2]},(d3.geo.mercator=function(){return ci(fi).scale(500)}).raw=fi;var Jo=xi(function(){return 1},Math.asin);(d3.geo.orthographic=function(){return ci(Jo)}).raw=Jo,d3.geo.path=function(){function e(e){var t=null;return e!=t&&(typeof r=="function"&&(i=li(r.apply(this,arguments))),f.object(e),o.length&&(t=o.join(""),o=[])),t}function t(e){return Math.abs(d3.geom.polygon(e.map(s)).area())}function n(e){return t(e[0])-d3.sum(e.slice(1),t)}var r=4.5,i=li(r),s=d3.geo.albersUsa(),o=[],u={point:function(e,t){o.push("M",e,",",t,i)},moveTo:function(e,t){o.push("M",e,",",t)},lineTo:function(e,t){o.push("L",e,",",t)},closePath:function(){o.push("Z")}},a=u,f=Rr({line:function(e){s.line(e,a)},polygon:function(e){s.polygon(e,a)},point:function(e){s.point(e,a)}}),l=Rr({Feature:function(e){return l.geometry(e.geometry)},FeatureCollection:function(e){return d3.sum(e.features,l.Feature)},GeometryCollection:function(e){return d3.sum(e.geometries,l.geometry)},LineString:ws,MultiLineString:ws,MultiPoint:ws,MultiPolygon:function(e){return d3.sum(e.coordinates,n)},Point:ws,Polygon:function(e){return n(e.coordinates)}});return e.area=l.object,e.projection=function(t){return arguments.length?(s=t,e):s},e.context=function(t){return arguments.length?(a=t,a==null&&(a=u),e):a===u?null:a},e.pointRadius=function(t){return arguments.length?(typeof t=="function"?r=t:i=li(r=+t),e):r},e},d3.geo.projection=ci,d3.geo.projectionMutator=hi;var Ko=xi(function(e){return 1/(1+e)},function(e){return 2*Math.atan(e)});(d3.geo.stereographic=function(){return ci(Ko)}).raw=Ko,d3.geo.azimuthal=function(){var e="orthographic",t=hi(Ti),n=t(e);return n.mode=function(n){return arguments.length?t(e=n+""):e},n.origin=function(e){if(!arguments.length){var t=n.rotate();return[-t[0],-t[1]]}return n.rotate([-e[0],-e[1]])},n.scale(200)};var Qo={equalarea:Io,equidistant:qo,gnomonic:Vo,orthographic:Jo,stereographic:Ko};d3.geom={},d3.geom.contour=function(e,t){var n=t||Ni(e),r=[],i=n[0],s=n[1],o=0,u=0,a=NaN,f=NaN,l=0;do l=0,e(i-1,s-1)&&(l+=1),e(i,s-1)&&(l+=2),e(i-1,s)&&(l+=4),e(i,s)&&(l+=8),l===6?(o=f===-1?-1:1,u=0):l===9?(o=0,u=a===1?-1:1):(o=Go[l],u=Yo[l]),o!=a&&u!=f&&(r.push([i,s]),a=o,f=u),i+=o,s+=u;while(n[0]!=i||n[1]!=s);return r};var Go=[1,0,1,1,-1,0,-1,1,0,0,0,0,-1,0,-1,NaN],Yo=[0,-1,0,0,0,-1,0,0,1,-1,1,1,0,-1,0,NaN];d3.geom.hull=function(e){if(e.length<3)return[];var t=e.length,n=t-1,r=[],i=[],s,o,u=0,a,f,l,c,h,p,d,v;for(s=1;s=l*l+c*c?r[s].index=-1:(r[h].index=-1,d=r[s].angle,h=s,p=o)):(d=r[s].angle,h=s,p=o);i.push(u);for(s=0,o=0;s<2;++o)r[o].index!==-1&&(i.push(r[o].index),s++);v=i.length;for(;o=0?(n=e.ep.r,r=e.ep.l):(n=e.ep.l,r=e.ep.r),e.a===1?(o=n?n.y:-1e6,i=e.c-e.b*o,u=r?r.y:1e6,s=e.c-e.b*u):(i=n?n.x:-1e6,o=e.c-e.a*i,s=r?r.x:1e6,u=e.c-e.a*s);var a=[i,o],f=[s,u];t[e.region.l.index].push(a,f),t[e.region.r.index].push(a,f)}),t.map(function(t,n){var r=e[n][0],i=e[n][1];return t.forEach(function(e){e.angle=Math.atan2(e[0]-r,e[1]-i)}),t.sort(function(e,t){return e.angle-t.angle}).filter(function(e,n){return!n||e.angle-t[n-1].angle>1e-10})})};var Zo={l:"r",r:"l"};d3.geom.delaunay=function(e){var t=e.map(function(){return[]}),n=[];return Ai(e,function(n){t[n.region.l.index].push(e[n.region.r.index])}),t.forEach(function(t,r){var i=e[r],s=i[0],o=i[1];t.forEach(function(e){e.angle=Math.atan2(e[0]-s,e[1]-o)}),t.sort(function(e,t){return e.angle-t.angle});for(var u=0,a=t.length-1;u=u,l=t.y>=a,c=(l<<1)+f;e.leaf=!1,e=e.nodes[c]||(e.nodes[c]=Oi()),f?n=u:i=u,l?r=a:o=a,s(e,t,n,r,i,o)}var u,a=-1,f=e.length;f&&isNaN(e[0].x)&&(e=e.map(_i));if(arguments.length<5)if(arguments.length===3)i=r=n,n=t;else{t=n=Infinity,r=i=-Infinity;while(++ar&&(r=u.x),u.y>i&&(i=u.y);var l=r-t,c=i-n;l>c?i=n+l:r=t+c}var h=Oi();return h.add=function(e){s(h,e,t,n,r,i)},h.visit=function(e){Mi(e,h,t,n,r,i)},e.forEach(h.add),h},d3.time={};var eu=Date,tu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];Di.prototype={getDate:function(){return this._.getUTCDate()},getDay:function(){return this._.getUTCDay()},getFullYear:function(){return this._.getUTCFullYear()},getHours:function(){return this._.getUTCHours()},getMilliseconds:function(){return this._.getUTCMilliseconds()},getMinutes:function(){return this._.getUTCMinutes()},getMonth:function(){return this._.getUTCMonth()},getSeconds:function(){return this._.getUTCSeconds()},getTime:function(){return this._.getTime()},getTimezoneOffset:function(){return 0},valueOf:function(){return this._.valueOf()},setDate:function(){nu.setUTCDate.apply(this._,arguments)},setDay:function(){nu.setUTCDay.apply(this._,arguments)},setFullYear:function(){nu.setUTCFullYear.apply(this._,arguments)},setHours:function(){nu.setUTCHours.apply(this._,arguments)},setMilliseconds:function(){nu.setUTCMilliseconds.apply(this._,arguments)},setMinutes:function(){nu.setUTCMinutes.apply(this._,arguments)},setMonth:function(){nu.setUTCMonth.apply(this._,arguments)},setSeconds:function(){nu.setUTCSeconds.apply(this._,arguments)},setTime:function(){nu.setTime.apply(this._,arguments)}};var nu=Date.prototype,ru="%a %b %e %H:%M:%S %Y",iu="%m/%d/%y",su="%H:%M:%S",ou=tu,uu=ou.map(Pi),au=["January","February","March","April","May","June","July","August","September","October","November","December"],fu=au.map(Pi);d3.time.format=function(e){function t(t){var r=[],i=-1,s=0,o,u;while(++i=12?"PM":"AM"},S:function(e){return lu(e.getSeconds())},U:function(e){return lu(d3.time.sundayOfYear(e))},w:function(e){return e.getDay()},W:function(e){return lu(d3.time.mondayOfYear(e))},x:d3.time.format(iu),X:d3.time.format(su),y:function(e){return lu(e.getFullYear()%100)},Y:function(e){return hu(e.getFullYear()%1e4)},Z:ts,"%":function(e){return"%"}},Eu={a:Fi,A:Ii,b:qi,B:Ri,c:Ui,d:Ki,e:Ki,H:Qi,I:Qi,L:Zi,m:Ji,M:Gi,p:es,S:Yi,x:zi,X:Wi,y:Vi,Y:Xi},Su=/^\s*\d+/,xu=d3.map({am:0,pm:1});d3.time.format.utc=function(e){function t(e){try{eu=Di;var t=new eu;return t._=e,n(t)}finally{eu=Date}}var n=d3.time.format(e);return t.parse=function(e){try{eu=Di;var t=n.parse(e);return t&&t._}finally{eu=Date}},t.toString=n.toString,t};var Tu=d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");d3.time.format.iso=Date.prototype.toISOString?ns:Tu,ns.parse=function(e){var t=new Date(e);return isNaN(t)?null:t},ns.toString=Tu.toString,d3.time.second=rs(function(e){return new eu(Math.floor(e/1e3)*1e3)},function(e,t){e.setTime(e.getTime()+Math.floor(t)*1e3)},function(e){return e.getSeconds()}),d3.time.seconds=d3.time.second.range,d3.time.seconds.utc=d3.time.second.utc.range,d3.time.minute=rs(function(e){return new eu(Math.floor(e/6e4)*6e4)},function(e,t){e.setTime(e.getTime()+Math.floor(t)*6e4)},function(e){return e.getMinutes()}),d3.time.minutes=d3.time.minute.range,d3.time.minutes.utc=d3.time.minute.utc.range,d3.time.hour=rs(function(e){var t=e.getTimezoneOffset()/60;return new eu((Math.floor(e/36e5-t)+t)*36e5)},function(e,t){e.setTime(e.getTime()+Math.floor(t)*36e5)},function(e){return e.getHours()}),d3.time.hours=d3.time.hour.range,d3.time.hours.utc=d3.time.hour.utc.range,d3.time.day=rs(function(e){var t=new eu(1970,0);return t.setFullYear(e.getFullYear(),e.getMonth(),e.getDate()),t},function(e,t){e.setDate(e.getDate()+t)},function(e){return e.getDate()-1}),d3.time.days=d3.time.day.range,d3.time.days.utc=d3.time.day.utc.range,d3.time.dayOfYear=function(e){var t=d3.time.year(e);return Math.floor((e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*6e4)/864e5)},tu.forEach(function(e,t){e=e.toLowerCase(),t=7-t;var n=d3.time[e]=rs(function(e){return(e=d3.time.day(e)).setDate(e.getDate()-(e.getDay()+t)%7),e},function(e,t){e.setDate(e.getDate()+Math.floor(t)*7)},function(e){var n=d3.time.year(e).getDay();return Math.floor((d3.time.dayOfYear(e)+(n+t)%7)/7)-(n!==t)});d3.time[e+"s"]=n.range,d3.time[e+"s"].utc=n.utc.range,d3.time[e+"OfYear"]=function(e){var n=d3.time.year(e).getDay();return Math.floor((d3.time.dayOfYear(e)+(n+t)%7)/7)}}),d3.time.week=d3.time.sunday,d3.time.weeks=d3.time.sunday.range,d3.time.weeks.utc=d3.time.sunday.utc.range,d3.time.weekOfYear=d3.time.sundayOfYear,d3.time.month=rs(function(e){return e=d3.time.day(e),e.setDate(1),e},function(e,t){e.setMonth(e.getMonth()+t)},function(e){return e.getMonth()}),d3.time.months=d3.time.month.range,d3.time.months.utc=d3.time.month.utc.range,d3.time.year=rs(function(e){return e=d3.time.day(e),e.setMonth(0,1),e},function(e,t){e.setFullYear(e.getFullYear()+t)},function(e){return e.getFullYear()}),d3.time.years=d3.time.year.range,d3.time.years.utc=d3.time.year.utc.range;var Nu=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,108e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6],Cu=[[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]],ku=[[d3.time.format("%Y"),function(e){return!0}],[d3.time.format("%B"),function(e){return e.getMonth()}],[d3.time.format("%b %d"),function(e){return e.getDate()!=1}],[d3.time.format("%a %d"),function(e){return e.getDay()&&e.getDate()!=1}],[d3.time.format("%I %p"),function(e){return e.getHours()}],[d3.time.format("%I:%M"),function(e){return e.getMinutes()}],[d3.time.format(":%S"),function(e){return e.getSeconds()}],[d3.time.format(".%L"),function(e){return e.getMilliseconds()}]],Lu=d3.scale.linear(),Au=as(ku);Cu.year=function(e,t){return Lu.domain(e.map(ls)).ticks(t).map(fs)},d3.time.scale=function(){return ss(d3.scale.linear(),Cu,Au)};var Ou=Cu.map(function(e){return[e[0].utc,e[1]]}),Mu=[[d3.time.format.utc("%Y"),function(e){return!0}],[d3.time.format.utc("%B"),function(e){return e.getUTCMonth()}],[d3.time.format.utc("%b %d"),function(e){return e.getUTCDate()!=1}],[d3.time.format.utc("%a %d"),function(e){return e.getUTCDay()&&e.getUTCDate()!=1}],[d3.time.format.utc("%I %p"),function(e){return e.getUTCHours()}],[d3.time.format.utc("%I:%M"),function(e){return e.getUTCMinutes()}],[d3.time.format.utc(":%S"),function(e){return e.getUTCSeconds()}],[d3.time.format.utc(".%L"),function(e){return e.getUTCMilliseconds()}]],_u=as(Mu);Ou.year=function(e,t){return Lu.domain(e.map(hs)).ticks(t).map(cs)},d3.time.scale.utc=function(){return ss(d3.scale.linear(),Ou,_u)}})(); \ No newline at end of file diff --git a/src/core/core.js b/src/core/core.js index 1c89ff64..0d81d79f 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -3,4 +3,5 @@ d3 = {version: "2.10.2"}; // semver var π = Math.PI, ε = 1e-6, d3_radians = π / 180, - d3_degrees = 180 / π; + d3_degrees = 180 / π, + d3_zero = function() { return 0; }; diff --git a/src/geo/albers-usa.js b/src/geo/albers-usa.js index b2d53984..3d3ed47d 100644 --- a/src/geo/albers-usa.js +++ b/src/geo/albers-usa.js @@ -1,4 +1,5 @@ // TODO composite invert +// TODO projection.{point,line,polygon} // A composite projection for the United States, 960x500. The set of standard // parallels for each region comes from USGS, which is published here: diff --git a/src/geo/bounds.js b/src/geo/bounds.js index 741a084d..4bb130f8 100644 --- a/src/geo/bounds.js +++ b/src/geo/bounds.js @@ -1,83 +1,23 @@ -/** - * Given a GeoJSON object, returns the corresponding bounding box. The bounding - * box is represented by a two-dimensional array: [[left, bottom], [right, - * top]], where left is the minimum longitude, bottom is the minimum latitude, - * right is maximum longitude, and top is the maximum latitude. - */ d3.geo.bounds = function(feature) { - var left = Infinity, - bottom = Infinity, - right = -Infinity, - top = -Infinity; - d3_geo_bounds(feature, function(x, y) { - if (x < left) left = x; - if (x > right) right = x; - if (y < bottom) bottom = y; - if (y > top) top = y; - }); - return [[left, bottom], [right, top]]; + d3_geo_boundsTop = d3_geo_boundsRight = -(d3_geo_boundsLeft = d3_geo_boundsBottom = Infinity); + d3_geo_bounds.object(feature); + return [[d3_geo_boundsLeft, d3_geo_boundsBottom], [d3_geo_boundsRight, d3_geo_boundsTop]]; }; -function d3_geo_bounds(o, f) { - if (d3_geo_boundsTypes.hasOwnProperty(o.type)) d3_geo_boundsTypes[o.type](o, f); -} +var d3_geo_boundsLeft, + d3_geo_boundsBottom, + d3_geo_boundsRight, + d3_geo_boundsTop; -var d3_geo_boundsTypes = { - Feature: d3_geo_boundsFeature, - FeatureCollection: d3_geo_boundsFeatureCollection, - GeometryCollection: d3_geo_boundsGeometryCollection, - LineString: d3_geo_boundsLineString, - MultiLineString: d3_geo_boundsMultiLineString, - MultiPoint: d3_geo_boundsLineString, - MultiPolygon: d3_geo_boundsMultiPolygon, - Point: d3_geo_boundsPoint, - Polygon: d3_geo_boundsPolygon -}; - -function d3_geo_boundsFeature(o, f) { - d3_geo_bounds(o.geometry, f); -} - -function d3_geo_boundsFeatureCollection(o, f) { - for (var a = o.features, i = 0, n = a.length; i < n; i++) { - d3_geo_bounds(a[i].geometry, f); +var d3_geo_bounds = d3_geo_type({ + point: function(point) { + var x = point[0], y = point[1]; + if (x < d3_geo_boundsLeft) d3_geo_boundsLeft = x; + if (x > d3_geo_boundsRight) d3_geo_boundsRight = x; + if (y < d3_geo_boundsBottom) d3_geo_boundsBottom = y; + if (y > d3_geo_boundsTop) d3_geo_boundsTop = y; + }, + polygon: function(coordinates) { + this.line(coordinates[0]); // ignore holes } -} - -function d3_geo_boundsGeometryCollection(o, f) { - for (var a = o.geometries, i = 0, n = a.length; i < n; i++) { - d3_geo_bounds(a[i], f); - } -} - -function d3_geo_boundsLineString(o, f) { - for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) { - f.apply(null, a[i]); - } -} - -function d3_geo_boundsMultiLineString(o, f) { - for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) { - for (var b = a[i], j = 0, m = b.length; j < m; j++) { - f.apply(null, b[j]); - } - } -} - -function d3_geo_boundsMultiPolygon(o, f) { - for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) { - for (var b = a[i][0], j = 0, m = b.length; j < m; j++) { - f.apply(null, b[j]); - } - } -} - -function d3_geo_boundsPoint(o, f) { - f.apply(null, o.coordinates); -} - -function d3_geo_boundsPolygon(o, f) { - for (var a = o.coordinates[0], i = 0, n = a.length; i < n; i++) { - f.apply(null, a[i]); - } -} +}); diff --git a/src/geo/circle.js b/src/geo/circle.js index 64c9ab07..85ac11a0 100644 --- a/src/geo/circle.js +++ b/src/geo/circle.js @@ -14,16 +14,16 @@ d3.geo.circle = function() { clip = d3_geo_circleClip(degrees, function(coordinates) { return rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians); }); - return clipType(d) || null; + return clipType.object(d) || null; }; var clipType = d3_geo_type({ FeatureCollection: function(o) { - var features = o.features.map(clipType).filter(d3_identity); + var features = o.features.map(clipType.Feature, clipType).filter(d3_identity); return features && (o = Object.create(o), o.features = features, o); }, Feature: function(o) { - var geometry = clipType(o.geometry); + var geometry = clipType.geometry(o.geometry); return geometry && (o = Object.create(o), o.geometry = geometry, o); }, Point: function(o) { // TODO check @@ -37,10 +37,8 @@ d3.geo.circle = function() { o.coordinates.forEach(function(coordinates) { clip.point(coordinates, context); }); - return coordinates.length && { - type: o.type, - coordinates: coordinates.map(function(lineString) { return lineString[0]; }) - }; + return coordinates.length && (o = Object.create(o), + o.coordinates = coordinates.map(function(lineString) { return lineString[0]; }), o); }, LineString: function(o) { var lineStrings = [], @@ -72,7 +70,7 @@ d3.geo.circle = function() { return polygons.length && (o = Object.create(o), o.type = "MultiPolygon", o.coordinates = polygons, o); }, GeometryCollection: function(o) { - var geometries = o.geometries.map(clipType).filter(d3_identity); + var geometries = o.geometries.map(clipType.geometry, clipType).filter(d3_identity); return geometries.length && (o = Object.create(o), o.geometries = geometries, o); } }); diff --git a/src/geo/graticule.js b/src/geo/graticule.js index eecc6468..c7e33c63 100644 --- a/src/geo/graticule.js +++ b/src/geo/graticule.js @@ -1,8 +1,8 @@ d3.geo.graticule = function() { - var x1 = 180 - ε, x0 = -x1, - y1 = 90 - ε, y0 = -y1, + var x1, x0, + y1, y0, dx = 22.5, dy = dx, - δx = 2, δy = 2; + x, y; function graticule() { return { @@ -12,27 +12,25 @@ d3.geo.graticule = function() { } graticule.lines = function() { - var xSteps = d3.range(x0, x1 - ε, δx).concat(x1), - ySteps = d3.range(y0, y1 - ε, δy).concat(y1), - xLines = d3.range(Math.ceil(x0 / dx) * dx, x1, dx).map(function(x) { return ySteps.map(function(y) { return [x, y]; }); }), - yLines = d3.range(Math.ceil(y0 / dy) * dy, y1, dy).map(function(y) { return xSteps.map(function(x) { return [x, y]; }); }); - return xLines.concat(yLines).map(function(coordinates) { - return { - type: "LineString", - coordinates: coordinates - }; - }); + return d3.range(Math.ceil(x0 / dx) * dx, x1, dx).map(x) + .concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).map(y)) + .map(function(coordinates) { + return { + type: "LineString", + coordinates: coordinates + }; + }); } graticule.outline = function() { - var x2 = (x0 + x1) / 2; return { type: "Polygon", - coordinates: [[ - [x0, y1], [x2, y1], [x1, y1], - [x1, y0], [x2, y0], [x0, y0], - [x0, y1] - ]] + coordinates: [ + x(x0) + .concat(y(y1).slice(1), + x(x1).reverse().slice(1), + y(y0).reverse().slice(1)) + ] }; }; @@ -42,6 +40,8 @@ d3.geo.graticule = function() { y0 = +_[0][1], y1 = +_[1][1]; if (x0 > x1) _ = x0, x0 = x1, x1 = _; if (y0 > y1) _ = y0, y0 = y1, y1 = _; + x = d3_geo_graticuleX(y0, y1); + y = d3_geo_graticuleY(x0, x1); return graticule; }; @@ -51,5 +51,25 @@ d3.geo.graticule = function() { return graticule; }; - return graticule; + return graticule.extent([[-180 + ε, -90 + ε], [180 - ε, 90 - ε]]); }; + +var d3_geo_graticulePrecision = 3; + +function d3_geo_graticuleX(y0, y1) { + var y = d3.range(y0, y1 - ε, d3_geo_graticulePrecision).concat(y1); + return function(x) { + return y.map(function(y) { + return [x, y]; + }); + }; +} + +function d3_geo_graticuleY(x0, x1) { + var x = d3.range(x0, x1 - ε, d3_geo_graticulePrecision).concat(x1); + return function(y) { + return x.map(function(x) { + return [x, y]; + }); + }; +} diff --git a/src/geo/path.js b/src/geo/path.js index 1a8911a2..8dab34c1 100644 --- a/src/geo/path.js +++ b/src/geo/path.js @@ -5,8 +5,7 @@ d3.geo.path = function() { var pointRadius = 4.5, pointCircle = d3_geo_pathCircle(pointRadius), projection = d3.geo.albersUsa(), - buffer = [], - context; + buffer = []; var bufferContext = { point: function(x, y) { buffer.push("M", x, ",", y, pointCircle); }, @@ -15,93 +14,46 @@ d3.geo.path = function() { closePath: function() { buffer.push("Z"); } }; + var context = bufferContext; + function path(object) { var result = null; if (object != result) { - if (context == result) { - if (typeof pointRadius === "function") pointCircle = d3_geo_pathCircle(pointRadius.apply(this, arguments)); - pathObject(object, bufferContext); - if (buffer.length) result = buffer.join(""), buffer = []; - } else { - pathObject(object, context); - } + if (typeof pointRadius === "function") pointCircle = d3_geo_pathCircle(pointRadius.apply(this, arguments)); + pathType.object(object); + if (buffer.length) result = buffer.join(""), buffer = []; } return result; } - function pathObject(object, context) { - var pathType = pathObjectByType.get(object.type); - if (pathType) pathType(object, context); - } - - function pathGeometry(geometry, context) { - var pathType = pathGeometryByType.get(geometry.type); - if (pathType) pathType(geometry, context); - } - - function pathFeature(feature, context) { - pathGeometry(feature.geometry, context); - } - - function pathFeatureCollection(collection, context) { - var features = collection.features, i = -1, n = features.length; - while (++i < n) pathFeature(features[i], context); - } - - function pathGeometryCollection(collection, context) { - var geometries = collection.geometries, i = -1, n = geometries.length; - while (++i < n) pathGeometry(geometries[i], context); - } - - function pathLineString(lineString, context) { - projection.line(lineString.coordinates, context); - } - - function pathMultiLineString(multiLineString, context) { - var coordinates = multiLineString.coordinates, i = -1, n = coordinates.length; - while (++i < n) projection.line(coordinates[i], context); - } - - function pathMultiPoint(multiPoint, context) { - var coordinates = multiPoint.coordinates, i = -1, n = coordinates.length; - while (++i < n) projection.point(coordinates[i], context); - } - - function pathMultiPolygon(multiPolygon, context) { - var coordinates = multiPolygon.coordinates, i = -1, n = coordinates.length; - while (++i < n) projection.polygon(coordinates[i], context); - } - - function pathPoint(point, context) { - projection.point(point.coordinates, context); - } - - function pathPolygon(polygon, context) { - projection.polygon(polygon.coordinates, context); - } - - var pathObjectByType = d3.map({ - Feature: pathFeature, - FeatureCollection: pathFeatureCollection, - GeometryCollection: pathGeometryCollection, - LineString: pathLineString, - MultiLineString: pathMultiLineString, - MultiPoint: pathMultiPoint, - MultiPolygon: pathMultiPolygon, - Point: pathPoint, - Polygon: pathPolygon + var pathType = d3_geo_type({ + line: function(coordinates) { projection.line(coordinates, context); }, + polygon: function(coordinates) { projection.polygon(coordinates, context); }, + point: function(coordinates) { projection.point(coordinates, context); } }); - var pathGeometryByType = d3.map({ - GeometryCollection: pathGeometryCollection, - LineString: pathLineString, - MultiLineString: pathMultiLineString, - MultiPoint: pathMultiPoint, - MultiPolygon: pathMultiPolygon, - Point: pathPoint, - Polygon: pathPolygon + var areaType = d3_geo_type({ + Feature: function(feature) { return areaType.geometry(feature.geometry); }, + FeatureCollection: function(collection) { return d3.sum(collection.features, areaType.Feature); }, + GeometryCollection: function(collection) { return d3.sum(collection.geometries, areaType.geometry); }, + LineString: d3_zero, + MultiLineString: d3_zero, + MultiPoint: d3_zero, + MultiPolygon: function(multiPolygon) { return d3.sum(multiPolygon.coordinates, polygonArea); }, + Point: d3_zero, + Polygon: function(polygon) { return polygonArea(polygon.coordinates); } }); + function ringArea(coordinates) { + return Math.abs(d3.geom.polygon(coordinates.map(projection)).area()); + } + + function polygonArea(coordinates) { + return ringArea(coordinates[0]) - d3.sum(coordinates.slice(1), ringArea); + } + + path.area = areaType.object; + path.projection = function(_) { if (!arguments.length) return projection; projection = _; @@ -109,8 +61,9 @@ d3.geo.path = function() { }; path.context = function(_) { - if (!arguments.length) return context; + if (!arguments.length) return context === bufferContext ? null : context; context = _; + if (context == null) context = bufferContext; return path; }; @@ -131,14 +84,6 @@ function d3_geo_pathCircle(radius) { + "z"; } - // function polygonArea(coordinates) { - // var sum = area(coordinates[0]), // exterior ring - // i = 0, // coordinates.index - // n = coordinates.length; - // while (++i < n) sum -= area(coordinates[i]); // holes - // return sum; - // } - // function polygonCentroid(coordinates) { // var polygon = d3.geom.polygon(coordinates[0].map(projection)), // exterior ring // area = polygon.area(), @@ -196,46 +141,3 @@ function d3_geo_pathCircle(radius) { // } // }); - - // function area(coordinates) { - // return Math.abs(d3.geom.polygon(coordinates.map(projection)).area()); - // } - - // var areaType = path.area = d3_geo_type({ - - // FeatureCollection: function(o) { - // var area = 0, - // features = o.features, - // i = -1, // features.index - // n = features.length; - // while (++i < n) area += areaType(features[i]); - // return area; - // }, - - // Feature: function(o) { - // return areaType(o.geometry); - // }, - - // Polygon: function(o) { - // return polygonArea(o.coordinates); - // }, - - // MultiPolygon: function(o) { - // var sum = 0, - // coordinates = o.coordinates, - // i = -1, // coordinates index - // n = coordinates.length; - // while (++i < n) sum += polygonArea(coordinates[i]); - // return sum; - // }, - - // GeometryCollection: function(o) { - // var sum = 0, - // geometries = o.geometries, - // i = -1, // geometries index - // n = geometries.length; - // while (++i < n) sum += areaType(geometries[i]); - // return sum; - // } - - // }, 0); diff --git a/src/geo/projection.js b/src/geo/projection.js index 9054592f..fa619514 100644 --- a/src/geo/projection.js +++ b/src/geo/projection.js @@ -65,6 +65,7 @@ function d3_geo_projectionMutator(projectAt) { function lineTo(λ, φ) { var p = projectPoint(λ, φ); resampleLineTo(x0, y0, λ0, φ0, x0 = p[0], y0 = p[1], λ0 = λ, φ0 = φ, maxDepth); + context.lineTo(x0, y0); } function resampleLineTo(x0, y0, λ0, φ0, x1, y1, λ1, φ1, depth) { @@ -89,15 +90,16 @@ function d3_geo_projectionMutator(projectAt) { dz = dx * (y0 - y2) - dy * (x0 - x2); if (dz * dz / distance2 > δ2) { resampleLineTo(x0, y0, λ0, φ0, x2, y2, λ2, φ2, depth); + context.lineTo(x2, y2); resampleLineTo(x2, y2, λ2, φ2, x1, y1, λ1, φ1, depth); return; } } - context.lineTo(x1, y1); } function closePath() { - lineTo(λ00, φ00); + var p = projectPoint(λ00, φ00); + resampleLineTo(x0, y0, λ0, φ0, p[0], p[1], λ00, φ00, maxDepth); context.closePath(); } diff --git a/src/geo/type.js b/src/geo/type.js index 79982693..19e9fae8 100644 --- a/src/geo/type.js +++ b/src/geo/type.js @@ -1,5 +1,96 @@ -function d3_geo_type(types, defaultValue) { - return function(object) { - return object && types.hasOwnProperty(object.type) ? types[object.type](object) : defaultValue; - }; +function d3_geo_type(types) { + for (var type in d3_geo_typeDefaults) { + if (!(type in types)) { + types[type] = d3_geo_typeDefaults[type]; + } + } + return types; } + +var d3_geo_typeDefaults = { + + Feature: function(feature) { + this.geometry(feature.geometry); + }, + + FeatureCollection: function(colllection) { + var features = colllection.features, i = -1, n = features.length; + while (++i < n) this.Feature(features[i]); + }, + + GeometryCollection: function(colllection) { + var geometries = colllection.geometries, i = -1, n = geometries.length; + while (++i < n) this.geometry(geometries[i]); + }, + + LineString: function(lineString) { + this.line(lineString.coordinates); + }, + + MultiLineString: function(multiLineString) { + var coordinates = multiLineString.coordinates, i = -1, n = coordinates.length; + while (++i < n) this.line(coordinates[i]); + }, + + MultiPoint: function(multiPoint) { + var coordinates = multiPoint.coordinates, i = -1, n = coordinates.length; + while (++i < n) this.point(coordinates[i]); + }, + + MultiPolygon: function(multiPolygon) { + var coordinates = multiPolygon.coordinates, i = -1, n = coordinates.length; + while (++i < n) this.polygon(coordinates[i]); + }, + + Point: function(point) { + this.point(point.coordinates); + }, + + Polygon: function(polygon) { + this.polygon(polygon.coordinates); + }, + + // dispatch for any GeoJSON object type + object: function(object) { + return d3_geo_typeObjects.hasOwnProperty(object.type) + ? this[object.type](object) + : this.geometry(object); + }, + + // dispatch for any GeoJSON geometry type + geometry: function(geometry) { + return d3_geo_typeGeometries.hasOwnProperty(geometry.type) + ? this[geometry.type](geometry) + : null; + }, + + // coordinates [x, y] + point: d3_noop, + + // coordinates [[x1, y1], [x2, y2], …] + line: function(coordinates) { + var i = -1, n = coordinates.length; + while (++i < n) this.point(coordinates[i]); + }, + + // coordinates [[[x1, y1], [x2, y2], …], [[x1, y1], [x2, y2], …], …] + polygon: function(coordinates) { + var i = -1, n = coordinates.length; + while (++i < n) this.line(coordinates[i]); + } +}; + +var d3_geo_typeGeometries = { + LineString: 1, + MultiLineString: 1, + MultiPoint: 1, + MultiPolygon: 1, + Point: 1, + Polygon: 1 +}; + +var d3_geo_typeObjects = { + Feature: 1, + FeatureCollection: 1, + GeometryCollection: 1 +}; diff --git a/test/geo/bounds-test.js b/test/geo/bounds-test.js new file mode 100644 index 00000000..a4265d1d --- /dev/null +++ b/test/geo/bounds-test.js @@ -0,0 +1,97 @@ +require("../env"); + +var vows = require("vows"), + assert = require("assert"); + +var suite = vows.describe("d3.geo.bounds"); + +suite.addBatch({ + "bounds": { + topic: function() { + return d3.geo.bounds; + }, + "Feature": function(bounds) { + assert.deepEqual(bounds({ + type: "Feature", + geometry: { + type: "MultiPoint", + coordinates: [[-123, 39], [-122, 38]] + } + }), [[-123, 38], [-122, 39]]) + }, + "FeatureCollection": function(bounds) { + assert.deepEqual(bounds({ + type: "FeatureCollection", + features: [ + { + type: "Feature", + geometry: { + type: "Point", + coordinates: [-123, 39] + } + }, + { + type: "Feature", + geometry: { + type: "Point", + coordinates: [-122, 38] + } + } + ] + }), [[-123, 38], [-122, 39]]) + }, + "GeometryCollection": function(bounds) { + assert.deepEqual(bounds({ + type: "GeometryCollection", + geometries: [ + { + type: "Point", + coordinates: [-123, 39] + }, + { + type: "Point", + coordinates: [-122, 38] + } + ] + }), [[-123, 38], [-122, 39]]) + }, + "LineString": function(bounds) { + assert.deepEqual(bounds({ + type: "LineString", + coordinates: [[-123, 39], [-122, 38]] + }), [[-123, 38], [-122, 39]]) + }, + "MultiLineString": function(bounds) { + assert.deepEqual(bounds({ + type: "MultiLineString", + coordinates: [[[-123, 39], [-122, 38]]] + }), [[-123, 38], [-122, 39]]) + }, + "MultiPoint": function(bounds) { + assert.deepEqual(bounds({ + type: "MultiPoint", + coordinates: [[-123, 39], [-122, 38]] + }), [[-123, 38], [-122, 39]]) + }, + "MultiPolygon": function(bounds) { + assert.deepEqual(bounds({ + type: "MultiPolygon", + coordinates: [[[[-123, 39], [-122, 39], [-122, 38], [-123, 39]], [[10, 20], [20, 20], [20, 10], [10, 10], [10, 20]]]] + }), [[-123, 38], [-122, 39]]) + }, + "Point": function(bounds) { + assert.deepEqual(bounds({ + type: "Point", + coordinates: [-123, 39] + }), [[-123, 39], [-123, 39]]) + }, + "Polygon": function(bounds) { + assert.deepEqual(bounds({ + type: "Polygon", + coordinates: [[[-123, 39], [-122, 39], [-122, 38], [-123, 39]], [[10, 20], [20, 20], [20, 10], [10, 10], [10, 20]]] + }), [[-123, 38], [-122, 39]]) + } + } +}); + +suite.export(module); diff --git a/test/geo/graticule-test.js b/test/geo/graticule-test.js new file mode 100644 index 00000000..00b9ea68 --- /dev/null +++ b/test/geo/graticule-test.js @@ -0,0 +1,87 @@ +require("../env"); + +var vows = require("vows"), + assert = require("assert"); + +var suite = vows.describe("d3.geo.graticule"); + +var ε = 1e-6; + +suite.addBatch({ + "graticule": { + topic: function() { + return d3.geo.graticule() + .extent([[-90, -45], [90, 45]]) + .step([45, 45]); + }, + + "extent": { + "defaults to just inside –180º, -90º to +180º, +90º": function() { + assert.deepEqual(d3.geo.graticule().extent(), [[-180 + ε, -90 + ε], [180 - ε, 90 - ε]]); + }, + "coerces input values to numbers": function() { + var graticule = d3.geo.graticule().extent([["-90", "-45"], ["+90", "+45"]]), + extent = graticule.extent(); + assert.strictEqual(extent[0][0], -90); + assert.strictEqual(extent[0][1], -45); + assert.strictEqual(extent[1][0], +90); + assert.strictEqual(extent[1][1], +45); + } + }, + + "returns a GeometryCollection of LineStrings": function(graticule) { + assert.deepEqual(graticule(), { + type: "GeometryCollection", + geometries: [ + {type: "LineString", coordinates: [[-90,-45],[-90,-42],[-90,-39],[-90,-36],[-90,-33],[-90,-30],[-90,-27],[-90,-24],[-90,-21],[-90,-18],[-90,-15],[-90,-12],[-90,-9],[-90,-6],[-90,-3],[-90,0],[-90,3],[-90,6],[-90,9],[-90,12],[-90,15],[-90,18],[-90,21],[-90,24],[-90,27],[-90,30],[-90,33],[-90,36],[-90,39],[-90,42],[-90,45]]}, + {type: "LineString", coordinates: [[-45,-45],[-45,-42],[-45,-39],[-45,-36],[-45,-33],[-45,-30],[-45,-27],[-45,-24],[-45,-21],[-45,-18],[-45,-15],[-45,-12],[-45,-9],[-45,-6],[-45,-3],[-45,0],[-45,3],[-45,6],[-45,9],[-45,12],[-45,15],[-45,18],[-45,21],[-45,24],[-45,27],[-45,30],[-45,33],[-45,36],[-45,39],[-45,42],[-45,45]]}, + {type: "LineString", coordinates: [[0,-45],[0,-42],[0,-39],[0,-36],[0,-33],[0,-30],[0,-27],[0,-24],[0,-21],[0,-18],[0,-15],[0,-12],[0,-9],[0,-6],[0,-3],[0,0],[0,3],[0,6],[0,9],[0,12],[0,15],[0,18],[0,21],[0,24],[0,27],[0,30],[0,33],[0,36],[0,39],[0,42],[0,45]]}, + {type: "LineString", coordinates: [[45,-45],[45,-42],[45,-39],[45,-36],[45,-33],[45,-30],[45,-27],[45,-24],[45,-21],[45,-18],[45,-15],[45,-12],[45,-9],[45,-6],[45,-3],[45,0],[45,3],[45,6],[45,9],[45,12],[45,15],[45,18],[45,21],[45,24],[45,27],[45,30],[45,33],[45,36],[45,39],[45,42],[45,45]]}, + {type: "LineString", coordinates: [[-90,-45],[-87,-45],[-84,-45],[-81,-45],[-78,-45],[-75,-45],[-72,-45],[-69,-45],[-66,-45],[-63,-45],[-60,-45],[-57,-45],[-54,-45],[-51,-45],[-48,-45],[-45,-45],[-42,-45],[-39,-45],[-36,-45],[-33,-45],[-30,-45],[-27,-45],[-24,-45],[-21,-45],[-18,-45],[-15,-45],[-12,-45],[-9,-45],[-6,-45],[-3,-45],[0,-45],[3,-45],[6,-45],[9,-45],[12,-45],[15,-45],[18,-45],[21,-45],[24,-45],[27,-45],[30,-45],[33,-45],[36,-45],[39,-45],[42,-45],[45,-45],[48,-45],[51,-45],[54,-45],[57,-45],[60,-45],[63,-45],[66,-45],[69,-45],[72,-45],[75,-45],[78,-45],[81,-45],[84,-45],[87,-45],[90,-45]]}, + {type: "LineString", coordinates: [[-90,0],[-87,0],[-84,0],[-81,0],[-78,0],[-75,0],[-72,0],[-69,0],[-66,0],[-63,0],[-60,0],[-57,0],[-54,0],[-51,0],[-48,0],[-45,0],[-42,0],[-39,0],[-36,0],[-33,0],[-30,0],[-27,0],[-24,0],[-21,0],[-18,0],[-15,0],[-12,0],[-9,0],[-6,0],[-3,0],[0,0],[3,0],[6,0],[9,0],[12,0],[15,0],[18,0],[21,0],[24,0],[27,0],[30,0],[33,0],[36,0],[39,0],[42,0],[45,0],[48,0],[51,0],[54,0],[57,0],[60,0],[63,0],[66,0],[69,0],[72,0],[75,0],[78,0],[81,0],[84,0],[87,0],[90,0]]} + ] + }); + }, + + "step": { + "defaults to 22.5º, 22.5º": function(graticule) { + assert.deepEqual(d3.geo.graticule().step(), [22.5, 22.5]); + }, + "coerces input values to numbers": function() { + var graticule = d3.geo.graticule().step(["45", "11.25"]), + step = graticule.step(); + assert.strictEqual(step[0], 45); + assert.strictEqual(step[1], 11.25); + } + }, + + "outline": { + "returns a Polygon": function(graticule) { + assert.deepEqual(graticule.outline(), { + type: "Polygon", + coordinates: [[ + [-90,-45],[-90,-42],[-90,-39],[-90,-36],[-90,-33],[-90,-30],[-90,-27],[-90,-24],[-90,-21],[-90,-18],[-90,-15],[-90,-12],[-90,-9],[-90,-6],[-90,-3],[-90,0],[-90,3],[-90,6],[-90,9],[-90,12],[-90,15],[-90,18],[-90,21],[-90,24],[-90,27],[-90,30],[-90,33],[-90,36],[-90,39],[-90,42],[-90,45], + [-87,45],[-84,45],[-81,45],[-78,45],[-75,45],[-72,45],[-69,45],[-66,45],[-63,45],[-60,45],[-57,45],[-54,45],[-51,45],[-48,45],[-45,45],[-42,45],[-39,45],[-36,45],[-33,45],[-30,45],[-27,45],[-24,45],[-21,45],[-18,45],[-15,45],[-12,45],[-9,45],[-6,45],[-3,45],[0,45],[3,45],[6,45],[9,45],[12,45],[15,45],[18,45],[21,45],[24,45],[27,45],[30,45],[33,45],[36,45],[39,45],[42,45],[45,45],[48,45],[51,45],[54,45],[57,45],[60,45],[63,45],[66,45],[69,45],[72,45],[75,45],[78,45],[81,45],[84,45],[87,45],[90,45], + [90,42],[90,39],[90,36],[90,33],[90,30],[90,27],[90,24],[90,21],[90,18],[90,15],[90,12],[90,9],[90,6],[90,3],[90,0],[90,-3],[90,-6],[90,-9],[90,-12],[90,-15],[90,-18],[90,-21],[90,-24],[90,-27],[90,-30],[90,-33],[90,-36],[90,-39],[90,-42],[90,-45], + [87,-45],[84,-45],[81,-45],[78,-45],[75,-45],[72,-45],[69,-45],[66,-45],[63,-45],[60,-45],[57,-45],[54,-45],[51,-45],[48,-45],[45,-45],[42,-45],[39,-45],[36,-45],[33,-45],[30,-45],[27,-45],[24,-45],[21,-45],[18,-45],[15,-45],[12,-45],[9,-45],[6,-45],[3,-45],[0,-45],[-3,-45],[-6,-45],[-9,-45],[-12,-45],[-15,-45],[-18,-45],[-21,-45],[-24,-45],[-27,-45],[-30,-45],[-33,-45],[-36,-45],[-39,-45],[-42,-45],[-45,-45],[-48,-45],[-51,-45],[-54,-45],[-57,-45],[-60,-45],[-63,-45],[-66,-45],[-69,-45],[-72,-45],[-75,-45],[-78,-45],[-81,-45],[-84,-45],[-87,-45],[-90,-45] + ]] + }); + } + }, + + "line": { + "returns an array of LineStrings": function(graticule) { + assert.deepEqual(graticule.lines(), [ + {type: "LineString", coordinates: [[-90,-45],[-90,-42],[-90,-39],[-90,-36],[-90,-33],[-90,-30],[-90,-27],[-90,-24],[-90,-21],[-90,-18],[-90,-15],[-90,-12],[-90,-9],[-90,-6],[-90,-3],[-90,0],[-90,3],[-90,6],[-90,9],[-90,12],[-90,15],[-90,18],[-90,21],[-90,24],[-90,27],[-90,30],[-90,33],[-90,36],[-90,39],[-90,42],[-90,45]]}, + {type: "LineString", coordinates: [[-45,-45],[-45,-42],[-45,-39],[-45,-36],[-45,-33],[-45,-30],[-45,-27],[-45,-24],[-45,-21],[-45,-18],[-45,-15],[-45,-12],[-45,-9],[-45,-6],[-45,-3],[-45,0],[-45,3],[-45,6],[-45,9],[-45,12],[-45,15],[-45,18],[-45,21],[-45,24],[-45,27],[-45,30],[-45,33],[-45,36],[-45,39],[-45,42],[-45,45]]}, + {type: "LineString", coordinates: [[0,-45],[0,-42],[0,-39],[0,-36],[0,-33],[0,-30],[0,-27],[0,-24],[0,-21],[0,-18],[0,-15],[0,-12],[0,-9],[0,-6],[0,-3],[0,0],[0,3],[0,6],[0,9],[0,12],[0,15],[0,18],[0,21],[0,24],[0,27],[0,30],[0,33],[0,36],[0,39],[0,42],[0,45]]}, + {type: "LineString", coordinates: [[45,-45],[45,-42],[45,-39],[45,-36],[45,-33],[45,-30],[45,-27],[45,-24],[45,-21],[45,-18],[45,-15],[45,-12],[45,-9],[45,-6],[45,-3],[45,0],[45,3],[45,6],[45,9],[45,12],[45,15],[45,18],[45,21],[45,24],[45,27],[45,30],[45,33],[45,36],[45,39],[45,42],[45,45]]}, + {type: "LineString", coordinates: [[-90,-45],[-87,-45],[-84,-45],[-81,-45],[-78,-45],[-75,-45],[-72,-45],[-69,-45],[-66,-45],[-63,-45],[-60,-45],[-57,-45],[-54,-45],[-51,-45],[-48,-45],[-45,-45],[-42,-45],[-39,-45],[-36,-45],[-33,-45],[-30,-45],[-27,-45],[-24,-45],[-21,-45],[-18,-45],[-15,-45],[-12,-45],[-9,-45],[-6,-45],[-3,-45],[0,-45],[3,-45],[6,-45],[9,-45],[12,-45],[15,-45],[18,-45],[21,-45],[24,-45],[27,-45],[30,-45],[33,-45],[36,-45],[39,-45],[42,-45],[45,-45],[48,-45],[51,-45],[54,-45],[57,-45],[60,-45],[63,-45],[66,-45],[69,-45],[72,-45],[75,-45],[78,-45],[81,-45],[84,-45],[87,-45],[90,-45]]}, + {type: "LineString", coordinates: [[-90,0],[-87,0],[-84,0],[-81,0],[-78,0],[-75,0],[-72,0],[-69,0],[-66,0],[-63,0],[-60,0],[-57,0],[-54,0],[-51,0],[-48,0],[-45,0],[-42,0],[-39,0],[-36,0],[-33,0],[-30,0],[-27,0],[-24,0],[-21,0],[-18,0],[-15,0],[-12,0],[-9,0],[-6,0],[-3,0],[0,0],[3,0],[6,0],[9,0],[12,0],[15,0],[18,0],[21,0],[24,0],[27,0],[30,0],[33,0],[36,0],[39,0],[42,0],[45,0],[48,0],[51,0],[54,0],[57,0],[60,0],[63,0],[66,0],[69,0],[72,0],[75,0],[78,0],[81,0],[84,0],[87,0],[90,0]]} + ]); + } + } + } +}); + +suite.export(module); diff --git a/test/geo/path-test.js b/test/geo/path-test.js index 013f3096..82e49312 100644 --- a/test/geo/path-test.js +++ b/test/geo/path-test.js @@ -7,32 +7,49 @@ var suite = vows.describe("d3.geo.path"); suite.addBatch({ "path": { - topic: d3.geo.path, - "returns null when passed a null object": function(path) { - assert.isNull(path(null)); + topic: function() { + return d3.geo.path() + .context(testContext) + .projection(d3.geo.equirectangular() + .scale(900 / Math.PI) + .precision(0)); }, - "projection": { - "returns the current projection when called with no arguments": function() { - var path = d3.geo.path(), projection = d3.geo.albers(); - path.projection(projection); - assert.strictEqual(path.projection(), projection); - } - }, - "pointRadius": { - "returns the current point radius when called with no arguments": function() { - var path = d3.geo.path(), radius = function() { return 5; }; - assert.strictEqual(path.pointRadius(), 4.5); - assert.strictEqual(path.pointRadius(radius).pointRadius(), radius); - } + + "LineString": function(path) { + path({ + type: "Feature", + geometry: { + type: "LineString", + coordinates: [[-63, 18], [-62, 18], [-62, 17]] + }, + }); + assert.deepEqual(testContext.buffer(), [ + {type: "moveTo", x: 165, y: 160}, + {type: "lineTo", x: 170, y: 160}, + {type: "lineTo", x: 170, y: 165} + ]); }, + "Polygon": function(path) { - assert.equal(path({ + path({ type: "Feature", geometry: { type: "Polygon", - coordinates: [[[-63.03, 18.02], [-63.14, 18.06], [-63.01, 18.07], [-63.03, 18.02]]] + coordinates: [[[-63, 18], [-62, 18], [-62, 17], [-63, 18]]] }, - }), "M984.5652086349427,468.99159422596244L981.8396467935554,467.9114977057422L985.0785139575695,467.688661596079Z"); + }); + assert.deepEqual(testContext.buffer(), [ + {type: "moveTo", x: 165, y: 160}, + {type: "lineTo", x: 170, y: 160}, + {type: "lineTo", x: 170, y: 165}, + {type: "closePath"} + ]); + }, + + "returns null when passed null or undefined": function(path) { + assert.isNull(path(null)); + assert.isNull(path(undefined)); + assert.isNull(path()); }, "bogus type name": function(path) { assert.isNull(path({ @@ -42,8 +59,34 @@ suite.addBatch({ coordinates: [[[-63.03, 18.02], [-63.14, 18.06], [-63.01, 18.07], [-63.03, 18.02]]] }, })); + }, + + "projection": { + "returns the current projection when called with no arguments": function() { + var path = d3.geo.path(), projection = d3.geo.albers(); + path.projection(projection); + assert.strictEqual(path.projection(), projection); + } + }, + + "pointRadius": { + "returns the current point radius when called with no arguments": function() { + var path = d3.geo.path(), radius = function() { return 5; }; + assert.strictEqual(path.pointRadius(), 4.5); + assert.strictEqual(path.pointRadius(radius).pointRadius(), radius); + } } } }); +var testBuffer = []; + +var testContext = { + point: function(x, y) { testBuffer.push({type: "point", x: Math.round(x), y: Math.round(y)}); }, + moveTo: function(x, y) { testBuffer.push({type: "moveTo", x: Math.round(x), y: Math.round(y)}); }, + lineTo: function(x, y) { testBuffer.push({type: "lineTo", x: Math.round(x), y: Math.round(y)}); }, + closePath: function() { testBuffer.push({type: "closePath"}); }, + buffer: function() { var result = testBuffer; testBuffer = []; return result; } +}; + suite.export(module);