Skip to content

Instantly share code, notes, and snippets.

@rveciana
Last active December 8, 2019 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rveciana/9026255839233498dbe979ea69ad3af2 to your computer and use it in GitHub Desktop.
Save rveciana/9026255839233498dbe979ea69ad3af2 to your computer and use it in GitHub Desktop.
Mapping with Svelte: color scale
licence: mit

Second example of a map drawn with Svelte and the d3 projections. More than one path is created and colored using the d3-scale library.

Check this blog post from Geoexamples for more explanations.

To test it, clone the standard svelte template by

npx degit sveltejs/template svelte-app cd svelte-app

And copy the App.svelte file into the src directory.

<script>
import { geoAlbers, geoPath } from "d3-geo";
import { scaleLinear } from "d3-scale";
import { extent } from "d3-array";
import { onMount } from "svelte";
import { feature } from "topojson";
let data = [];
let colorScale = () => {};
const width = "960";
const height = "500";
const projectionAlbers = geoAlbers()
.rotate([4.4, 0.8])
.center([0, 55.4])
.parallels([50, 60])
.scale(3800)
.translate([width / 2, (1.8 * height) / 2]);
let currentProj = projectionAlbers;
let path = geoPath().projection(currentProj);
onMount(async function() {
const response = await fetch(
"https://gist.githubusercontent.com/rveciana/27272a581e975835aaa321ddf816d726/raw/c40062a328843322208b8e98c2104dc8f6ad5301/uk-counties.json"
);
const json = await response.json();
const topoData = feature(json, json.objects.UK);
const land = {
...topoData,
features: topoData.features.filter(
d => d.properties.NAME_1 === "Scotland"
)
};
const namesExtent = extent(land.features, d => d.properties.NAME_2.length);
colorScale = scaleLinear()
.domain(namesExtent)
.range(["#feedde", "#fd8d3c"]);
data = land.features;
});
</script>
<style>
svg {
width: 960px;
height: 500px;
background-color: "#eeeeee";
}
.provinceShape {
stroke: #444444;
stroke-width: 0.5;
}
</style>
<svg width="960" height="500">
{#each data as feature}
<path
d={path(feature)}
class="provinceShape"
fill={colorScale(feature.properties.NAME_2.length)} />
{/each}
</svg>
svg.svelte-8wv364 {
width: 960px;
height: 500px;
background-color: "#eeeeee";
}
.provinceShape.svelte-8wv364 {
stroke: #444444;
stroke-width: 0.5;
}
var app=function(){"use strict";function n(){}function t(n){return n()}function r(){return Object.create(null)}function e(n){n.forEach(t)}function i(n){return"function"==typeof n}function o(n,t){return n!=n?t==t:n!==t||n&&"object"==typeof n||"function"==typeof n}function u(n,t,r){n.insertBefore(t,r||null)}function a(n){n.parentNode.removeChild(n)}function l(n){return document.createElementNS("http://www.w3.org/2000/svg",n)}function c(n,t,r){null==r?n.removeAttribute(t):n.getAttribute(t)!==r&&n.setAttribute(t,r)}let f;function s(n){f=n}function h(n){(function(){if(!f)throw new Error("Function called outside component initialization");return f})().$$.on_mount.push(n)}const p=[],g=[],d=[],v=[],m=Promise.resolve();let y=!1;function b(n){d.push(n)}function M(){const n=new Set;do{for(;p.length;){const n=p.shift();s(n),w(n.$$)}for(;g.length;)g.pop()();for(let t=0;t<d.length;t+=1){const r=d[t];n.has(r)||(r(),n.add(r))}d.length=0}while(p.length);for(;v.length;)v.pop()();y=!1}function w(n){null!==n.fragment&&(n.update(),e(n.before_update),n.fragment&&n.fragment.p(n.ctx,n.dirty),n.dirty=[-1],n.after_update.forEach(b))}const x=new Set;function E(n,t){-1===n.$$.dirty[0]&&(p.push(n),y||(y=!0,m.then(M)),n.$$.dirty.fill(0)),n.$$.dirty[t/31|0]|=1<<t%31}function N(o,u,a,l,c,h,p=[-1]){const g=f;s(o);const d=u.props||{},v=o.$$={fragment:null,ctx:null,props:h,update:n,not_equal:c,bound:r(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(g?g.$$.context:[]),callbacks:r(),dirty:p};let m=!1;var y,w,N;v.ctx=a?a(o,d,(n,t,r=t)=>(v.ctx&&c(v.ctx[n],v.ctx[n]=r)&&(v.bound[n]&&v.bound[n](r),m&&E(o,n)),t)):[],v.update(),m=!0,e(v.before_update),v.fragment=!!l&&l(v.ctx),u.target&&(u.hydrate?v.fragment&&v.fragment.l((N=u.target,Array.from(N.childNodes))):v.fragment&&v.fragment.c(),u.intro&&((y=o.$$.fragment)&&y.i&&(x.delete(y),y.i(w))),function(n,r,o){const{fragment:u,on_mount:a,on_destroy:l,after_update:c}=n.$$;u&&u.m(r,o),b(()=>{const r=a.map(t).filter(i);l?l.push(...r):e(r),n.$$.on_mount=[]}),c.forEach(b)}(o,u.target,u.anchor),M()),s(g)}class S{$destroy(){!function(n,t){const r=n.$$;null!==r.fragment&&(e(r.on_destroy),r.fragment&&r.fragment.d(t),r.on_destroy=r.fragment=null,r.ctx=[])}(this,1),this.$destroy=n}$on(n,t){const r=this.$$.callbacks[n]||(this.$$.callbacks[n]=[]);return r.push(t),()=>{const n=r.indexOf(t);-1!==n&&r.splice(n,1)}}$set(){}}function k(){return new _}function _(){this.reset()}_.prototype={constructor:_,reset:function(){this.s=this.t=0},add:function(n){A($,n,this.t),A(this,$.s,this.s),this.s?this.t+=$.t:this.s=$.t},valueOf:function(){return this.s}};var $=new _;function A(n,t,r){var e=n.s=t+r,i=e-t,o=e-i;n.t=t-o+(r-i)}var j=1e-6,P=Math.PI,R=P/2,z=P/4,q=2*P,F=180/P,C=P/180,O=Math.abs,L=Math.atan,H=Math.atan2,I=Math.cos,T=Math.sin,G=Math.sign||function(n){return n>0?1:n<0?-1:0},D=Math.sqrt;function B(n){return n>1?R:n<-1?-R:Math.asin(n)}function U(){}function V(n,t){n&&Z.hasOwnProperty(n.type)&&Z[n.type](n,t)}var X={Feature:function(n,t){V(n.geometry,t)},FeatureCollection:function(n,t){for(var r=n.features,e=-1,i=r.length;++e<i;)V(r[e].geometry,t)}},Z={Sphere:function(n,t){t.sphere()},Point:function(n,t){n=n.coordinates,t.point(n[0],n[1],n[2])},MultiPoint:function(n,t){for(var r=n.coordinates,e=-1,i=r.length;++e<i;)n=r[e],t.point(n[0],n[1],n[2])},LineString:function(n,t){K(n.coordinates,t,0)},MultiLineString:function(n,t){for(var r=n.coordinates,e=-1,i=r.length;++e<i;)K(r[e],t,0)},Polygon:function(n,t){W(n.coordinates,t)},MultiPolygon:function(n,t){for(var r=n.coordinates,e=-1,i=r.length;++e<i;)W(r[e],t)},GeometryCollection:function(n,t){for(var r=n.geometries,e=-1,i=r.length;++e<i;)V(r[e],t)}};function K(n,t,r){var e,i=-1,o=n.length-r;for(t.lineStart();++i<o;)e=n[i],t.point(e[0],e[1],e[2]);t.lineEnd()}function W(n,t){var r=-1,e=n.length;for(t.polygonStart();++r<e;)K(n[r],t,1);t.polygonEnd()}function Y(n,t){n&&X.hasOwnProperty(n.type)?X[n.type](n,t):V(n,t)}function J(n){return[H(n[1],n[0]),B(n[2])]}function Q(n){var t=n[0],r=n[1],e=I(r);return[e*I(t),e*T(t),T(r)]}function nn(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]}function tn(n,t){return[n[1]*t[2]-n[2]*t[1],n[2]*t[0]-n[0]*t[2],n[0]*t[1]-n[1]*t[0]]}function rn(n,t){n[0]+=t[0],n[1]+=t[1],n[2]+=t[2]}function en(n,t){return[n[0]*t,n[1]*t,n[2]*t]}function on(n){var t=D(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);n[0]/=t,n[1]/=t,n[2]/=t}function un(n,t){function r(r,e){return r=n(r,e),t(r[0],r[1])}return n.invert&&t.invert&&(r.invert=function(r,e){return(r=t.invert(r,e))&&n.invert(r[0],r[1])}),r}function an(n,t){return[O(n)>P?n+Math.round(-n/q)*q:n,t]}function ln(n){return function(t,r){return[(t+=n)>P?t-q:t<-P?t+q:t,r]}}function cn(n){var t=ln(n);return t.invert=ln(-n),t}function fn(n,t){var r=I(n),e=T(n),i=I(t),o=T(t);function u(n,t){var u=I(t),a=I(n)*u,l=T(n)*u,c=T(t),f=c*r+a*e;return[H(l*i-f*o,a*r-c*e),B(f*i+l*o)]}return u.invert=function(n,t){var u=I(t),a=I(n)*u,l=T(n)*u,c=T(t),f=c*i-l*o;return[H(l*i+c*o,a*r+f*e),B(f*r-a*e)]},u}function sn(n,t){(t=Q(t))[0]-=n,on(t);var r,e=(r=-t[1])>1?0:r<-1?P:Math.acos(r);return((-t[2]<0?-e:e)+q-j)%q}function hn(){var n,t=[];return{point:function(t,r){n.push([t,r])},lineStart:function(){t.push(n=[])},lineEnd:U,rejoin:function(){t.length>1&&t.push(t.pop().concat(t.shift()))},result:function(){var r=t;return t=[],n=null,r}}}function pn(n,t){return O(n[0]-t[0])<j&&O(n[1]-t[1])<j}function gn(n,t,r,e){this.x=n,this.z=t,this.o=r,this.e=e,this.v=!1,this.n=this.p=null}function dn(n,t,r,e,i){var o,u,a=[],l=[];if(n.forEach((function(n){if(!((t=n.length-1)<=0)){var t,r,e=n[0],u=n[t];if(pn(e,u)){for(i.lineStart(),o=0;o<t;++o)i.point((e=n[o])[0],e[1]);i.lineEnd()}else a.push(r=new gn(e,n,null,!0)),l.push(r.o=new gn(e,null,r,!1)),a.push(r=new gn(u,n,null,!1)),l.push(r.o=new gn(u,null,r,!0))}})),a.length){for(l.sort(t),vn(a),vn(l),o=0,u=l.length;o<u;++o)l[o].e=r=!r;for(var c,f,s=a[0];;){for(var h=s,p=!0;h.v;)if((h=h.n)===s)return;c=h.z,i.lineStart();do{if(h.v=h.o.v=!0,h.e){if(p)for(o=0,u=c.length;o<u;++o)i.point((f=c[o])[0],f[1]);else e(h.x,h.n.x,1,i);h=h.n}else{if(p)for(c=h.p.z,o=c.length-1;o>=0;--o)i.point((f=c[o])[0],f[1]);else e(h.x,h.p.x,-1,i);h=h.p}c=(h=h.o).z,p=!p}while(!h.v);i.lineEnd()}}}function vn(n){if(t=n.length){for(var t,r,e=0,i=n[0];++e<t;)i.n=r=n[e],r.p=i,i=r;i.n=r=n[0],r.p=i}}an.invert=an;var mn=k();function yn(n){return O(n[0])<=P?n[0]:G(n[0])*((O(n[0])+P)%q-P)}function bn(n,t){return n<t?-1:n>t?1:n>=t?0:NaN}var Mn,wn,xn=(1===(Mn=bn).length&&(wn=Mn,Mn=function(n,t){return bn(wn(n),t)}),{left:function(n,t,r,e){for(null==r&&(r=0),null==e&&(e=n.length);r<e;){var i=r+e>>>1;Mn(n[i],t)<0?r=i+1:e=i}return r},right:function(n,t,r,e){for(null==r&&(r=0),null==e&&(e=n.length);r<e;){var i=r+e>>>1;Mn(n[i],t)>0?e=i:r=i+1}return r}}).right;var En=Math.sqrt(50),Nn=Math.sqrt(10),Sn=Math.sqrt(2);function kn(n,t,r){var e=(t-n)/Math.max(0,r),i=Math.floor(Math.log(e)/Math.LN10),o=e/Math.pow(10,i);return i>=0?(o>=En?10:o>=Nn?5:o>=Sn?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(o>=En?10:o>=Nn?5:o>=Sn?2:1)}function _n(n){for(var t,r,e,i=n.length,o=-1,u=0;++o<i;)u+=n[o].length;for(r=new Array(u);--i>=0;)for(t=(e=n[i]).length;--t>=0;)r[--u]=e[t];return r}function $n(n,t,r,e){return function(i){var o,u,a,l=t(i),c=hn(),f=t(c),s=!1,h={point:p,lineStart:d,lineEnd:v,polygonStart:function(){h.point=m,h.lineStart=y,h.lineEnd=b,u=[],o=[]},polygonEnd:function(){h.point=p,h.lineStart=d,h.lineEnd=v,u=_n(u);var n=function(n,t){var r=yn(t),e=t[1],i=T(e),o=[T(r),-I(r),0],u=0,a=0;mn.reset(),1===i?e=R+j:-1===i&&(e=-R-j);for(var l=0,c=n.length;l<c;++l)if(s=(f=n[l]).length)for(var f,s,h=f[s-1],p=yn(h),g=h[1]/2+z,d=T(g),v=I(g),m=0;m<s;++m,p=b,d=w,v=x,h=y){var y=f[m],b=yn(y),M=y[1]/2+z,w=T(M),x=I(M),E=b-p,N=E>=0?1:-1,S=N*E,k=S>P,_=d*w;if(mn.add(H(_*N*T(S),v*x+_*I(S))),u+=k?E+N*q:E,k^p>=r^b>=r){var $=tn(Q(h),Q(y));on($);var A=tn(o,$);on(A);var F=(k^E>=0?-1:1)*B(A[2]);(e>F||e===F&&($[0]||$[1]))&&(a+=k^E>=0?1:-1)}}return(u<-j||u<j&&mn<-j)^1&a}(o,e);u.length?(s||(i.polygonStart(),s=!0),dn(u,jn,n,r,i)):n&&(s||(i.polygonStart(),s=!0),i.lineStart(),r(null,null,1,i),i.lineEnd()),s&&(i.polygonEnd(),s=!1),u=o=null},sphere:function(){i.polygonStart(),i.lineStart(),r(null,null,1,i),i.lineEnd(),i.polygonEnd()}};function p(t,r){n(t,r)&&i.point(t,r)}function g(n,t){l.point(n,t)}function d(){h.point=g,l.lineStart()}function v(){h.point=p,l.lineEnd()}function m(n,t){a.push([n,t]),f.point(n,t)}function y(){f.lineStart(),a=[]}function b(){m(a[0][0],a[0][1]),f.lineEnd();var n,t,r,e,l=f.clean(),h=c.result(),p=h.length;if(a.pop(),o.push(a),a=null,p)if(1&l){if((t=(r=h[0]).length-1)>0){for(s||(i.polygonStart(),s=!0),i.lineStart(),n=0;n<t;++n)i.point((e=r[n])[0],e[1]);i.lineEnd()}}else p>1&&2&l&&h.push(h.pop().concat(h.shift())),u.push(h.filter(An))}return h}}function An(n){return n.length>1}function jn(n,t){return((n=n.x)[0]<0?n[1]-R-j:R-n[1])-((t=t.x)[0]<0?t[1]-R-j:R-t[1])}var Pn=$n((function(){return!0}),(function(n){var t,r=NaN,e=NaN,i=NaN;return{lineStart:function(){n.lineStart(),t=1},point:function(o,u){var a=o>0?P:-P,l=O(o-r);O(l-P)<j?(n.point(r,e=(e+u)/2>0?R:-R),n.point(i,e),n.lineEnd(),n.lineStart(),n.point(a,e),n.point(o,e),t=0):i!==a&&l>=P&&(O(r-i)<j&&(r-=i*j),O(o-a)<j&&(o-=a*j),e=function(n,t,r,e){var i,o,u=T(n-r);return O(u)>j?L((T(t)*(o=I(e))*T(r)-T(e)*(i=I(t))*T(n))/(i*o*u)):(t+e)/2}(r,e,o,u),n.point(i,e),n.lineEnd(),n.lineStart(),n.point(a,e),t=0),n.point(r=o,e=u),i=a},lineEnd:function(){n.lineEnd(),r=e=NaN},clean:function(){return 2-t}}}),(function(n,t,r,e){var i;if(null==n)i=r*R,e.point(-P,i),e.point(0,i),e.point(P,i),e.point(P,0),e.point(P,-i),e.point(0,-i),e.point(-P,-i),e.point(-P,0),e.point(-P,i);else if(O(n[0]-t[0])>j){var o=n[0]<t[0]?P:-P;i=r*o/2,e.point(-o,i),e.point(0,i),e.point(o,i)}else e.point(t[0],t[1])}),[-P,-R]);function Rn(n){var t=I(n),r=6*C,e=t>0,i=O(t)>j;function o(n,r){return I(n)*I(r)>t}function u(n,r,e){var i=[1,0,0],o=tn(Q(n),Q(r)),u=nn(o,o),a=o[0],l=u-a*a;if(!l)return!e&&n;var c=t*u/l,f=-t*a/l,s=tn(i,o),h=en(i,c);rn(h,en(o,f));var p=s,g=nn(h,p),d=nn(p,p),v=g*g-d*(nn(h,h)-1);if(!(v<0)){var m=D(v),y=en(p,(-g-m)/d);if(rn(y,h),y=J(y),!e)return y;var b,M=n[0],w=r[0],x=n[1],E=r[1];w<M&&(b=M,M=w,w=b);var N=w-M,S=O(N-P)<j;if(!S&&E<x&&(b=x,x=E,E=b),S||N<j?S?x+E>0^y[1]<(O(y[0]-M)<j?x:E):x<=y[1]&&y[1]<=E:N>P^(M<=y[0]&&y[0]<=w)){var k=en(p,(-g+m)/d);return rn(k,h),[y,J(k)]}}}function a(t,r){var i=e?n:P-n,o=0;return t<-i?o|=1:t>i&&(o|=2),r<-i?o|=4:r>i&&(o|=8),o}return $n(o,(function(n){var t,r,l,c,f;return{lineStart:function(){c=l=!1,f=1},point:function(s,h){var p,g=[s,h],d=o(s,h),v=e?d?0:a(s,h):d?a(s+(s<0?P:-P),h):0;if(!t&&(c=l=d)&&n.lineStart(),d!==l&&(!(p=u(t,g))||pn(t,p)||pn(g,p))&&(g[0]+=j,g[1]+=j,d=o(g[0],g[1])),d!==l)f=0,d?(n.lineStart(),p=u(g,t),n.point(p[0],p[1])):(p=u(t,g),n.point(p[0],p[1]),n.lineEnd()),t=p;else if(i&&t&&e^d){var m;v&r||!(m=u(g,t,!0))||(f=0,e?(n.lineStart(),n.point(m[0][0],m[0][1]),n.point(m[1][0],m[1][1]),n.lineEnd()):(n.point(m[1][0],m[1][1]),n.lineEnd(),n.lineStart(),n.point(m[0][0],m[0][1])))}!d||t&&pn(t,g)||n.point(g[0],g[1]),t=g,l=d,r=v},lineEnd:function(){l&&n.lineEnd(),t=null},clean:function(){return f|(c&&l)<<1}}}),(function(t,e,i,o){!function(n,t,r,e,i,o){if(r){var u=I(t),a=T(t),l=e*r;null==i?(i=t+e*q,o=t-l/2):(i=sn(u,i),o=sn(u,o),(e>0?i<o:i>o)&&(i+=e*q));for(var c,f=i;e>0?f>o:f<o;f-=l)c=J([u,-a*I(f),-a*T(f)]),n.point(c[0],c[1])}}(o,n,r,i,t,e)}),e?[0,-n]:[-P,n-P])}var zn=1e9,qn=-zn;function Fn(n,t,r,e){function i(i,o){return n<=i&&i<=r&&t<=o&&o<=e}function o(i,o,a,c){var f=0,s=0;if(null==i||(f=u(i,a))!==(s=u(o,a))||l(i,o)<0^a>0)do{c.point(0===f||3===f?n:r,f>1?e:t)}while((f=(f+a+4)%4)!==s);else c.point(o[0],o[1])}function u(e,i){return O(e[0]-n)<j?i>0?0:3:O(e[0]-r)<j?i>0?2:1:O(e[1]-t)<j?i>0?1:0:i>0?3:2}function a(n,t){return l(n.x,t.x)}function l(n,t){var r=u(n,1),e=u(t,1);return r!==e?r-e:0===r?t[1]-n[1]:1===r?n[0]-t[0]:2===r?n[1]-t[1]:t[0]-n[0]}return function(u){var l,c,f,s,h,p,g,d,v,m,y,b=u,M=hn(),w={point:x,lineStart:function(){w.point=E,c&&c.push(f=[]);m=!0,v=!1,g=d=NaN},lineEnd:function(){l&&(E(s,h),p&&v&&M.rejoin(),l.push(M.result()));w.point=x,v&&b.lineEnd()},polygonStart:function(){b=M,l=[],c=[],y=!0},polygonEnd:function(){var t=function(){for(var t=0,r=0,i=c.length;r<i;++r)for(var o,u,a=c[r],l=1,f=a.length,s=a[0],h=s[0],p=s[1];l<f;++l)o=h,u=p,s=a[l],h=s[0],p=s[1],u<=e?p>e&&(h-o)*(e-u)>(p-u)*(n-o)&&++t:p<=e&&(h-o)*(e-u)<(p-u)*(n-o)&&--t;return t}(),r=y&&t,i=(l=_n(l)).length;(r||i)&&(u.polygonStart(),r&&(u.lineStart(),o(null,null,1,u),u.lineEnd()),i&&dn(l,a,t,o,u),u.polygonEnd());b=u,l=c=f=null}};function x(n,t){i(n,t)&&b.point(n,t)}function E(o,u){var a=i(o,u);if(c&&f.push([o,u]),m)s=o,h=u,p=a,m=!1,a&&(b.lineStart(),b.point(o,u));else if(a&&v)b.point(o,u);else{var l=[g=Math.max(qn,Math.min(zn,g)),d=Math.max(qn,Math.min(zn,d))],M=[o=Math.max(qn,Math.min(zn,o)),u=Math.max(qn,Math.min(zn,u))];!function(n,t,r,e,i,o){var u,a=n[0],l=n[1],c=0,f=1,s=t[0]-a,h=t[1]-l;if(u=r-a,s||!(u>0)){if(u/=s,s<0){if(u<c)return;u<f&&(f=u)}else if(s>0){if(u>f)return;u>c&&(c=u)}if(u=i-a,s||!(u<0)){if(u/=s,s<0){if(u>f)return;u>c&&(c=u)}else if(s>0){if(u<c)return;u<f&&(f=u)}if(u=e-l,h||!(u>0)){if(u/=h,h<0){if(u<c)return;u<f&&(f=u)}else if(h>0){if(u>f)return;u>c&&(c=u)}if(u=o-l,h||!(u<0)){if(u/=h,h<0){if(u>f)return;u>c&&(c=u)}else if(h>0){if(u<c)return;u<f&&(f=u)}return c>0&&(n[0]=a+c*s,n[1]=l+c*h),f<1&&(t[0]=a+f*s,t[1]=l+f*h),!0}}}}}(l,M,n,t,r,e)?a&&(b.lineStart(),b.point(o,u),y=!1):(v||(b.lineStart(),b.point(l[0],l[1])),b.point(M[0],M[1]),a||b.lineEnd(),y=!1)}g=o,d=u,v=a}return w}}function Cn(n){return n}var On,Ln,Hn,In,Tn=k(),Gn=k(),Dn={point:U,lineStart:U,lineEnd:U,polygonStart:function(){Dn.lineStart=Bn,Dn.lineEnd=Xn},polygonEnd:function(){Dn.lineStart=Dn.lineEnd=Dn.point=U,Tn.add(O(Gn)),Gn.reset()},result:function(){var n=Tn/2;return Tn.reset(),n}};function Bn(){Dn.point=Un}function Un(n,t){Dn.point=Vn,On=Hn=n,Ln=In=t}function Vn(n,t){Gn.add(In*n-Hn*t),Hn=n,In=t}function Xn(){Vn(On,Ln)}var Zn=1/0,Kn=Zn,Wn=-Zn,Yn=Wn,Jn={point:function(n,t){n<Zn&&(Zn=n);n>Wn&&(Wn=n);t<Kn&&(Kn=t);t>Yn&&(Yn=t)},lineStart:U,lineEnd:U,polygonStart:U,polygonEnd:U,result:function(){var n=[[Zn,Kn],[Wn,Yn]];return Wn=Yn=-(Kn=Zn=1/0),n}};var Qn,nt,tt,rt,et=0,it=0,ot=0,ut=0,at=0,lt=0,ct=0,ft=0,st=0,ht={point:pt,lineStart:gt,lineEnd:mt,polygonStart:function(){ht.lineStart=yt,ht.lineEnd=bt},polygonEnd:function(){ht.point=pt,ht.lineStart=gt,ht.lineEnd=mt},result:function(){var n=st?[ct/st,ft/st]:lt?[ut/lt,at/lt]:ot?[et/ot,it/ot]:[NaN,NaN];return et=it=ot=ut=at=lt=ct=ft=st=0,n}};function pt(n,t){et+=n,it+=t,++ot}function gt(){ht.point=dt}function dt(n,t){ht.point=vt,pt(tt=n,rt=t)}function vt(n,t){var r=n-tt,e=t-rt,i=D(r*r+e*e);ut+=i*(tt+n)/2,at+=i*(rt+t)/2,lt+=i,pt(tt=n,rt=t)}function mt(){ht.point=pt}function yt(){ht.point=Mt}function bt(){wt(Qn,nt)}function Mt(n,t){ht.point=wt,pt(Qn=tt=n,nt=rt=t)}function wt(n,t){var r=n-tt,e=t-rt,i=D(r*r+e*e);ut+=i*(tt+n)/2,at+=i*(rt+t)/2,lt+=i,ct+=(i=rt*n-tt*t)*(tt+n),ft+=i*(rt+t),st+=3*i,pt(tt=n,rt=t)}function xt(n){this._context=n}xt.prototype={_radius:4.5,pointRadius:function(n){return this._radius=n,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(n,t){switch(this._point){case 0:this._context.moveTo(n,t),this._point=1;break;case 1:this._context.lineTo(n,t);break;default:this._context.moveTo(n+this._radius,t),this._context.arc(n,t,this._radius,0,q)}},result:U};var Et,Nt,St,kt,_t,$t=k(),At={point:U,lineStart:function(){At.point=jt},lineEnd:function(){Et&&Pt(Nt,St),At.point=U},polygonStart:function(){Et=!0},polygonEnd:function(){Et=null},result:function(){var n=+$t;return $t.reset(),n}};function jt(n,t){At.point=Pt,Nt=kt=n,St=_t=t}function Pt(n,t){kt-=n,_t-=t,$t.add(D(kt*kt+_t*_t)),kt=n,_t=t}function Rt(){this._string=[]}function zt(n){return"m0,"+n+"a"+n+","+n+" 0 1,1 0,"+-2*n+"a"+n+","+n+" 0 1,1 0,"+2*n+"z"}function qt(n){return function(t){var r=new Ft;for(var e in n)r[e]=n[e];return r.stream=t,r}}function Ft(){}function Ct(n,t,r){var e=n.clipExtent&&n.clipExtent();return n.scale(150).translate([0,0]),null!=e&&n.clipExtent(null),Y(r,n.stream(Jn)),t(Jn.result()),null!=e&&n.clipExtent(e),n}function Ot(n,t,r){return Ct(n,(function(r){var e=t[1][0]-t[0][0],i=t[1][1]-t[0][1],o=Math.min(e/(r[1][0]-r[0][0]),i/(r[1][1]-r[0][1])),u=+t[0][0]+(e-o*(r[1][0]+r[0][0]))/2,a=+t[0][1]+(i-o*(r[1][1]+r[0][1]))/2;n.scale(150*o).translate([u,a])}),r)}Rt.prototype={_radius:4.5,_circle:zt(4.5),pointRadius:function(n){return(n=+n)!==this._radius&&(this._radius=n,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._string.push("Z"),this._point=NaN},point:function(n,t){switch(this._point){case 0:this._string.push("M",n,",",t),this._point=1;break;case 1:this._string.push("L",n,",",t);break;default:null==this._circle&&(this._circle=zt(this._radius)),this._string.push("M",n,",",t,this._circle)}},result:function(){if(this._string.length){var n=this._string.join("");return this._string=[],n}return null}},Ft.prototype={constructor:Ft,point:function(n,t){this.stream.point(n,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var Lt=16,Ht=I(30*C);function It(n,t){return+t?function(n,t){function r(e,i,o,u,a,l,c,f,s,h,p,g,d,v){var m=c-e,y=f-i,b=m*m+y*y;if(b>4*t&&d--){var M=u+h,w=a+p,x=l+g,E=D(M*M+w*w+x*x),N=B(x/=E),S=O(O(x)-1)<j||O(o-s)<j?(o+s)/2:H(w,M),k=n(S,N),_=k[0],$=k[1],A=_-e,P=$-i,R=y*A-m*P;(R*R/b>t||O((m*A+y*P)/b-.5)>.3||u*h+a*p+l*g<Ht)&&(r(e,i,o,u,a,l,_,$,S,M/=E,w/=E,x,d,v),v.point(_,$),r(_,$,S,M,w,x,c,f,s,h,p,g,d,v))}}return function(t){var e,i,o,u,a,l,c,f,s,h,p,g,d={point:v,lineStart:m,lineEnd:b,polygonStart:function(){t.polygonStart(),d.lineStart=M},polygonEnd:function(){t.polygonEnd(),d.lineStart=m}};function v(r,e){r=n(r,e),t.point(r[0],r[1])}function m(){f=NaN,d.point=y,t.lineStart()}function y(e,i){var o=Q([e,i]),u=n(e,i);r(f,s,c,h,p,g,f=u[0],s=u[1],c=e,h=o[0],p=o[1],g=o[2],Lt,t),t.point(f,s)}function b(){d.point=v,t.lineEnd()}function M(){m(),d.point=w,d.lineEnd=x}function w(n,t){y(e=n,t),i=f,o=s,u=h,a=p,l=g,d.point=y}function x(){r(f,s,c,h,p,g,i,o,e,u,a,l,Lt,t),d.lineEnd=b,b()}return d}}(n,t):function(n){return qt({point:function(t,r){t=n(t,r),this.stream.point(t[0],t[1])}})}(n)}var Tt=qt({point:function(n,t){this.stream.point(n*C,t*C)}});function Gt(n,t,r){function e(e,i){return[t+n*e,r-n*i]}return e.invert=function(e,i){return[(e-t)/n,(r-i)/n]},e}function Dt(n,t,r,e){var i=I(e),o=T(e),u=i*n,a=o*n,l=i/n,c=o/n,f=(o*r-i*t)/n,s=(o*t+i*r)/n;function h(n,e){return[u*n-a*e+t,r-a*n-u*e]}return h.invert=function(n,t){return[l*n-c*t+f,s-c*n-l*t]},h}function Bt(n){var t,r,e,i,o,u,a,l,c,f,s=150,h=480,p=250,g=0,d=0,v=0,m=0,y=0,b=0,M=null,w=Pn,x=null,E=Cn,N=.5;function S(n){return l(n[0]*C,n[1]*C)}function k(n){return(n=l.invert(n[0],n[1]))&&[n[0]*F,n[1]*F]}function _(){var n=Dt(s,0,0,b).apply(null,t(g,d)),e=(b?Dt:Gt)(s,h-n[0],p-n[1],b);return r=function(n,t,r){return(n%=q)?t||r?un(cn(n),fn(t,r)):cn(n):t||r?fn(t,r):an}(v,m,y),a=un(t,e),l=un(r,a),u=It(a,N),$()}function $(){return c=f=null,S}return S.stream=function(n){return c&&f===n?c:c=Tt(function(n){return qt({point:function(t,r){var e=n(t,r);return this.stream.point(e[0],e[1])}})}(r)(w(u(E(f=n)))))},S.preclip=function(n){return arguments.length?(w=n,M=void 0,$()):w},S.postclip=function(n){return arguments.length?(E=n,x=e=i=o=null,$()):E},S.clipAngle=function(n){return arguments.length?(w=+n?Rn(M=n*C):(M=null,Pn),$()):M*F},S.clipExtent=function(n){return arguments.length?(E=null==n?(x=e=i=o=null,Cn):Fn(x=+n[0][0],e=+n[0][1],i=+n[1][0],o=+n[1][1]),$()):null==x?null:[[x,e],[i,o]]},S.scale=function(n){return arguments.length?(s=+n,_()):s},S.translate=function(n){return arguments.length?(h=+n[0],p=+n[1],_()):[h,p]},S.center=function(n){return arguments.length?(g=n[0]%360*C,d=n[1]%360*C,_()):[g*F,d*F]},S.rotate=function(n){return arguments.length?(v=n[0]%360*C,m=n[1]%360*C,y=n.length>2?n[2]%360*C:0,_()):[v*F,m*F,y*F]},S.angle=function(n){return arguments.length?(b=n%360*C,_()):b*F},S.precision=function(n){return arguments.length?(u=It(a,N=n*n),$()):D(N)},S.fitExtent=function(n,t){return Ot(S,n,t)},S.fitSize=function(n,t){return function(n,t,r){return Ot(n,[[0,0],t],r)}(S,n,t)},S.fitWidth=function(n,t){return function(n,t,r){return Ct(n,(function(r){var e=+t,i=e/(r[1][0]-r[0][0]),o=(e-i*(r[1][0]+r[0][0]))/2,u=-i*r[0][1];n.scale(150*i).translate([o,u])}),r)}(S,n,t)},S.fitHeight=function(n,t){return function(n,t,r){return Ct(n,(function(r){var e=+t,i=e/(r[1][1]-r[0][1]),o=-i*r[0][0],u=(e-i*(r[1][1]+r[0][1]))/2;n.scale(150*i).translate([o,u])}),r)}(S,n,t)},function(){return t=n.apply(this,arguments),S.invert=t.invert&&k,_()}}function Ut(n,t){var r=T(n),e=(r+T(t))/2;if(O(e)<j)return function(n){var t=I(n);function r(n,r){return[n*t,T(r)/t]}return r.invert=function(n,r){return[n/t,B(r*t)]},r}(n);var i=1+r*(2*e-r),o=D(i)/e;function u(n,t){var r=D(i-2*e*T(t))/e;return[r*T(n*=e),o-r*I(n)]}return u.invert=function(n,t){var r=o-t;return[H(n,O(r))/e*G(r),B((i-(n*n+r*r)*e*e)/(2*e))]},u}function Vt(){return(n=Ut,t=0,r=P/3,e=Bt(n),i=e(t,r),i.parallels=function(n){return arguments.length?e(t=n[0]*C,r=n[1]*C):[t*F,r*F]},i).scale(155.424).center([0,33.6442]);var n,t,r,e,i}function Xt(n,t){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(t).domain(n)}return this}function Zt(n,t,r){n.prototype=t.prototype=r,r.constructor=n}function Kt(n,t){var r=Object.create(n.prototype);for(var e in t)r[e]=t[e];return r}function Wt(){}var Yt="\\s*([+-]?\\d+)\\s*",Jt="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",Qt="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",nr=/^#([0-9a-f]{3,8})$/,tr=new RegExp("^rgb\\("+[Yt,Yt,Yt]+"\\)$"),rr=new RegExp("^rgb\\("+[Qt,Qt,Qt]+"\\)$"),er=new RegExp("^rgba\\("+[Yt,Yt,Yt,Jt]+"\\)$"),ir=new RegExp("^rgba\\("+[Qt,Qt,Qt,Jt]+"\\)$"),or=new RegExp("^hsl\\("+[Jt,Qt,Qt]+"\\)$"),ur=new RegExp("^hsla\\("+[Jt,Qt,Qt,Jt]+"\\)$"),ar={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function lr(){return this.rgb().formatHex()}function cr(){return this.rgb().formatRgb()}function fr(n){var t,r;return n=(n+"").trim().toLowerCase(),(t=nr.exec(n))?(r=t[1].length,t=parseInt(t[1],16),6===r?sr(t):3===r?new gr(t>>8&15|t>>4&240,t>>4&15|240&t,(15&t)<<4|15&t,1):8===r?new gr(t>>24&255,t>>16&255,t>>8&255,(255&t)/255):4===r?new gr(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|240&t,((15&t)<<4|15&t)/255):null):(t=tr.exec(n))?new gr(t[1],t[2],t[3],1):(t=rr.exec(n))?new gr(255*t[1]/100,255*t[2]/100,255*t[3]/100,1):(t=er.exec(n))?hr(t[1],t[2],t[3],t[4]):(t=ir.exec(n))?hr(255*t[1]/100,255*t[2]/100,255*t[3]/100,t[4]):(t=or.exec(n))?yr(t[1],t[2]/100,t[3]/100,1):(t=ur.exec(n))?yr(t[1],t[2]/100,t[3]/100,t[4]):ar.hasOwnProperty(n)?sr(ar[n]):"transparent"===n?new gr(NaN,NaN,NaN,0):null}function sr(n){return new gr(n>>16&255,n>>8&255,255&n,1)}function hr(n,t,r,e){return e<=0&&(n=t=r=NaN),new gr(n,t,r,e)}function pr(n,t,r,e){return 1===arguments.length?((i=n)instanceof Wt||(i=fr(i)),i?new gr((i=i.rgb()).r,i.g,i.b,i.opacity):new gr):new gr(n,t,r,null==e?1:e);var i}function gr(n,t,r,e){this.r=+n,this.g=+t,this.b=+r,this.opacity=+e}function dr(){return"#"+mr(this.r)+mr(this.g)+mr(this.b)}function vr(){var n=this.opacity;return(1===(n=isNaN(n)?1:Math.max(0,Math.min(1,n)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===n?")":", "+n+")")}function mr(n){return((n=Math.max(0,Math.min(255,Math.round(n)||0)))<16?"0":"")+n.toString(16)}function yr(n,t,r,e){return e<=0?n=t=r=NaN:r<=0||r>=1?n=t=NaN:t<=0&&(n=NaN),new Mr(n,t,r,e)}function br(n){if(n instanceof Mr)return new Mr(n.h,n.s,n.l,n.opacity);if(n instanceof Wt||(n=fr(n)),!n)return new Mr;if(n instanceof Mr)return n;var t=(n=n.rgb()).r/255,r=n.g/255,e=n.b/255,i=Math.min(t,r,e),o=Math.max(t,r,e),u=NaN,a=o-i,l=(o+i)/2;return a?(u=t===o?(r-e)/a+6*(r<e):r===o?(e-t)/a+2:(t-r)/a+4,a/=l<.5?o+i:2-o-i,u*=60):a=l>0&&l<1?0:u,new Mr(u,a,l,n.opacity)}function Mr(n,t,r,e){this.h=+n,this.s=+t,this.l=+r,this.opacity=+e}function wr(n,t,r){return 255*(n<60?t+(r-t)*n/60:n<180?r:n<240?t+(r-t)*(240-n)/60:t)}function xr(n){return function(){return n}}function Er(n){return 1==(n=+n)?Nr:function(t,r){return r-t?function(n,t,r){return n=Math.pow(n,r),t=Math.pow(t,r)-n,r=1/r,function(e){return Math.pow(n+e*t,r)}}(t,r,n):xr(isNaN(t)?r:t)}}function Nr(n,t){var r=t-n;return r?function(n,t){return function(r){return n+r*t}}(n,r):xr(isNaN(n)?t:n)}Zt(Wt,fr,{copy:function(n){return Object.assign(new this.constructor,this,n)},displayable:function(){return this.rgb().displayable()},hex:lr,formatHex:lr,formatHsl:function(){return br(this).formatHsl()},formatRgb:cr,toString:cr}),Zt(gr,pr,Kt(Wt,{brighter:function(n){return n=null==n?1/.7:Math.pow(1/.7,n),new gr(this.r*n,this.g*n,this.b*n,this.opacity)},darker:function(n){return n=null==n?.7:Math.pow(.7,n),new gr(this.r*n,this.g*n,this.b*n,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:dr,formatHex:dr,formatRgb:vr,toString:vr})),Zt(Mr,(function(n,t,r,e){return 1===arguments.length?br(n):new Mr(n,t,r,null==e?1:e)}),Kt(Wt,{brighter:function(n){return n=null==n?1/.7:Math.pow(1/.7,n),new Mr(this.h,this.s,this.l*n,this.opacity)},darker:function(n){return n=null==n?.7:Math.pow(.7,n),new Mr(this.h,this.s,this.l*n,this.opacity)},rgb:function(){var n=this.h%360+360*(this.h<0),t=isNaN(n)||isNaN(this.s)?0:this.s,r=this.l,e=r+(r<.5?r:1-r)*t,i=2*r-e;return new gr(wr(n>=240?n-240:n+120,i,e),wr(n,i,e),wr(n<120?n+240:n-120,i,e),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var n=this.opacity;return(1===(n=isNaN(n)?1:Math.max(0,Math.min(1,n)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===n?")":", "+n+")")}}));var Sr=function n(t){var r=Er(t);function e(n,t){var e=r((n=pr(n)).r,(t=pr(t)).r),i=r(n.g,t.g),o=r(n.b,t.b),u=Nr(n.opacity,t.opacity);return function(t){return n.r=e(t),n.g=i(t),n.b=o(t),n.opacity=u(t),n+""}}return e.gamma=n,e}(1);function kr(n,t){t||(t=[]);var r,e=n?Math.min(t.length,n.length):0,i=t.slice();return function(o){for(r=0;r<e;++r)i[r]=n[r]*(1-o)+t[r]*o;return i}}function _r(n,t){var r,e=t?t.length:0,i=n?Math.min(e,n.length):0,o=new Array(i),u=new Array(e);for(r=0;r<i;++r)o[r]=qr(n[r],t[r]);for(;r<e;++r)u[r]=t[r];return function(n){for(r=0;r<i;++r)u[r]=o[r](n);return u}}function $r(n,t){var r=new Date;return n=+n,t=+t,function(e){return r.setTime(n*(1-e)+t*e),r}}function Ar(n,t){return n=+n,t=+t,function(r){return n*(1-r)+t*r}}function jr(n,t){var r,e={},i={};for(r in null!==n&&"object"==typeof n||(n={}),null!==t&&"object"==typeof t||(t={}),t)r in n?e[r]=qr(n[r],t[r]):i[r]=t[r];return function(n){for(r in e)i[r]=e[r](n);return i}}var Pr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Rr=new RegExp(Pr.source,"g");function zr(n,t){var r,e,i,o=Pr.lastIndex=Rr.lastIndex=0,u=-1,a=[],l=[];for(n+="",t+="";(r=Pr.exec(n))&&(e=Rr.exec(t));)(i=e.index)>o&&(i=t.slice(o,i),a[u]?a[u]+=i:a[++u]=i),(r=r[0])===(e=e[0])?a[u]?a[u]+=e:a[++u]=e:(a[++u]=null,l.push({i:u,x:Ar(r,e)})),o=Rr.lastIndex;return o<t.length&&(i=t.slice(o),a[u]?a[u]+=i:a[++u]=i),a.length<2?l[0]?function(n){return function(t){return n(t)+""}}(l[0].x):function(n){return function(){return n}}(t):(t=l.length,function(n){for(var r,e=0;e<t;++e)a[(r=l[e]).i]=r.x(n);return a.join("")})}function qr(n,t){var r,e,i=typeof t;return null==t||"boolean"===i?xr(t):("number"===i?Ar:"string"===i?(r=fr(t))?(t=r,Sr):zr:t instanceof fr?Sr:t instanceof Date?$r:(e=t,!ArrayBuffer.isView(e)||e instanceof DataView?Array.isArray(t)?_r:"function"!=typeof t.valueOf&&"function"!=typeof t.toString||isNaN(t)?jr:Ar:kr))(n,t)}function Fr(n,t){return n=+n,t=+t,function(r){return Math.round(n*(1-r)+t*r)}}function Cr(n){return+n}var Or=[0,1];function Lr(n){return n}function Hr(n,t){return(t-=n=+n)?function(r){return(r-n)/t}:(r=isNaN(t)?NaN:.5,function(){return r});var r}function Ir(n,t,r){var e=n[0],i=n[1],o=t[0],u=t[1];return i<e?(e=Hr(i,e),o=r(u,o)):(e=Hr(e,i),o=r(o,u)),function(n){return o(e(n))}}function Tr(n,t,r){var e=Math.min(n.length,t.length)-1,i=new Array(e),o=new Array(e),u=-1;for(n[e]<n[0]&&(n=n.slice().reverse(),t=t.slice().reverse());++u<e;)i[u]=Hr(n[u],n[u+1]),o[u]=r(t[u],t[u+1]);return function(t){var r=xn(n,t,1,e)-1;return o[r](i[r](t))}}function Gr(){var n,t,r,e,i,o,u=Or,a=Or,l=qr,c=Lr;function f(){var n,t,r,l=Math.min(u.length,a.length);return c!==Lr&&(n=u[0],t=u[l-1],n>t&&(r=n,n=t,t=r),c=function(r){return Math.max(n,Math.min(t,r))}),e=l>2?Tr:Ir,i=o=null,s}function s(t){return isNaN(t=+t)?r:(i||(i=e(u.map(n),a,l)))(n(c(t)))}return s.invert=function(r){return c(t((o||(o=e(a,u.map(n),Ar)))(r)))},s.domain=function(n){return arguments.length?(u=Array.from(n,Cr),f()):u.slice()},s.range=function(n){return arguments.length?(a=Array.from(n),f()):a.slice()},s.rangeRound=function(n){return a=Array.from(n),l=Fr,f()},s.clamp=function(n){return arguments.length?(c=!!n||Lr,f()):c!==Lr},s.interpolate=function(n){return arguments.length?(l=n,f()):l},s.unknown=function(n){return arguments.length?(r=n,s):r},function(r,e){return n=r,t=e,f()}}function Dr(n,t){if((r=(n=t?n.toExponential(t-1):n.toExponential()).indexOf("e"))<0)return null;var r,e=n.slice(0,r);return[e.length>1?e[0]+e.slice(2):e,+n.slice(r+1)]}function Br(n){return(n=Dr(Math.abs(n)))?n[1]:NaN}var Ur,Vr=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Xr(n){if(!(t=Vr.exec(n)))throw new Error("invalid format: "+n);var t;return new Zr({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}function Zr(n){this.fill=void 0===n.fill?" ":n.fill+"",this.align=void 0===n.align?">":n.align+"",this.sign=void 0===n.sign?"-":n.sign+"",this.symbol=void 0===n.symbol?"":n.symbol+"",this.zero=!!n.zero,this.width=void 0===n.width?void 0:+n.width,this.comma=!!n.comma,this.precision=void 0===n.precision?void 0:+n.precision,this.trim=!!n.trim,this.type=void 0===n.type?"":n.type+""}function Kr(n,t){var r=Dr(n,t);if(!r)return n+"";var e=r[0],i=r[1];return i<0?"0."+new Array(-i).join("0")+e:e.length>i+1?e.slice(0,i+1)+"."+e.slice(i+1):e+new Array(i-e.length+2).join("0")}Xr.prototype=Zr.prototype,Zr.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var Wr={"%":function(n,t){return(100*n).toFixed(t)},b:function(n){return Math.round(n).toString(2)},c:function(n){return n+""},d:function(n){return Math.round(n).toString(10)},e:function(n,t){return n.toExponential(t)},f:function(n,t){return n.toFixed(t)},g:function(n,t){return n.toPrecision(t)},o:function(n){return Math.round(n).toString(8)},p:function(n,t){return Kr(100*n,t)},r:Kr,s:function(n,t){var r=Dr(n,t);if(!r)return n+"";var e=r[0],i=r[1],o=i-(Ur=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,u=e.length;return o===u?e:o>u?e+new Array(o-u+1).join("0"):o>0?e.slice(0,o)+"."+e.slice(o):"0."+new Array(1-o).join("0")+Dr(n,Math.max(0,t+o-1))[0]},X:function(n){return Math.round(n).toString(16).toUpperCase()},x:function(n){return Math.round(n).toString(16)}};function Yr(n){return n}var Jr,Qr,ne,te=Array.prototype.map,re=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function ee(n){var t,r,e=void 0===n.grouping||void 0===n.thousands?Yr:(t=te.call(n.grouping,Number),r=n.thousands+"",function(n,e){for(var i=n.length,o=[],u=0,a=t[0],l=0;i>0&&a>0&&(l+a+1>e&&(a=Math.max(1,e-l)),o.push(n.substring(i-=a,i+a)),!((l+=a+1)>e));)a=t[u=(u+1)%t.length];return o.reverse().join(r)}),i=void 0===n.currency?"":n.currency[0]+"",o=void 0===n.currency?"":n.currency[1]+"",u=void 0===n.decimal?".":n.decimal+"",a=void 0===n.numerals?Yr:function(n){return function(t){return t.replace(/[0-9]/g,(function(t){return n[+t]}))}}(te.call(n.numerals,String)),l=void 0===n.percent?"%":n.percent+"",c=void 0===n.minus?"-":n.minus+"",f=void 0===n.nan?"NaN":n.nan+"";function s(n){var t=(n=Xr(n)).fill,r=n.align,s=n.sign,h=n.symbol,p=n.zero,g=n.width,d=n.comma,v=n.precision,m=n.trim,y=n.type;"n"===y?(d=!0,y="g"):Wr[y]||(void 0===v&&(v=12),m=!0,y="g"),(p||"0"===t&&"="===r)&&(p=!0,t="0",r="=");var b="$"===h?i:"#"===h&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",M="$"===h?o:/[%p]/.test(y)?l:"",w=Wr[y],x=/[defgprs%]/.test(y);function E(n){var i,o,l,h=b,E=M;if("c"===y)E=w(n)+E,n="";else{var N=(n=+n)<0;if(n=isNaN(n)?f:w(Math.abs(n),v),m&&(n=function(n){n:for(var t,r=n.length,e=1,i=-1;e<r;++e)switch(n[e]){case".":i=t=e;break;case"0":0===i&&(i=e),t=e;break;default:if(i>0){if(!+n[e])break n;i=0}}return i>0?n.slice(0,i)+n.slice(t+1):n}(n)),N&&0==+n&&(N=!1),h=(N?"("===s?s:c:"-"===s||"("===s?"":s)+h,E=("s"===y?re[8+Ur/3]:"")+E+(N&&"("===s?")":""),x)for(i=-1,o=n.length;++i<o;)if(48>(l=n.charCodeAt(i))||l>57){E=(46===l?u+n.slice(i+1):n.slice(i))+E,n=n.slice(0,i);break}}d&&!p&&(n=e(n,1/0));var S=h.length+n.length+E.length,k=S<g?new Array(g-S+1).join(t):"";switch(d&&p&&(n=e(k+n,k.length?g-E.length:1/0),k=""),r){case"<":n=h+n+E+k;break;case"=":n=h+k+n+E;break;case"^":n=k.slice(0,S=k.length>>1)+h+n+E+k.slice(S);break;default:n=k+h+n+E}return a(n)}return v=void 0===v?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,v)):Math.max(0,Math.min(20,v)),E.toString=function(){return n+""},E}return{format:s,formatPrefix:function(n,t){var r=s(((n=Xr(n)).type="f",n)),e=3*Math.max(-8,Math.min(8,Math.floor(Br(t)/3))),i=Math.pow(10,-e),o=re[8+e/3];return function(n){return r(i*n)+o}}}}function ie(n,t,r,e){var i,o=function(n,t,r){var e=Math.abs(t-n)/Math.max(0,r),i=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),o=e/i;return o>=En?i*=10:o>=Nn?i*=5:o>=Sn&&(i*=2),t<n?-i:i}(n,t,r);switch((e=Xr(null==e?",f":e)).type){case"s":var u=Math.max(Math.abs(n),Math.abs(t));return null!=e.precision||isNaN(i=function(n,t){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Br(t)/3)))-Br(Math.abs(n)))}(o,u))||(e.precision=i),ne(e,u);case"":case"e":case"g":case"p":case"r":null!=e.precision||isNaN(i=function(n,t){return n=Math.abs(n),t=Math.abs(t)-n,Math.max(0,Br(t)-Br(n))+1}(o,Math.max(Math.abs(n),Math.abs(t))))||(e.precision=i-("e"===e.type));break;case"f":case"%":null!=e.precision||isNaN(i=function(n){return Math.max(0,-Br(Math.abs(n)))}(o))||(e.precision=i-2*("%"===e.type))}return Qr(e)}function oe(n){var t=n.domain;return n.ticks=function(n){var r=t();return function(n,t,r){var e,i,o,u,a=-1;if(r=+r,(n=+n)===(t=+t)&&r>0)return[n];if((e=t<n)&&(i=n,n=t,t=i),0===(u=kn(n,t,r))||!isFinite(u))return[];if(u>0)for(n=Math.ceil(n/u),t=Math.floor(t/u),o=new Array(i=Math.ceil(t-n+1));++a<i;)o[a]=(n+a)*u;else for(n=Math.floor(n*u),t=Math.ceil(t*u),o=new Array(i=Math.ceil(n-t+1));++a<i;)o[a]=(n-a)/u;return e&&o.reverse(),o}(r[0],r[r.length-1],null==n?10:n)},n.tickFormat=function(n,r){var e=t();return ie(e[0],e[e.length-1],null==n?10:n,r)},n.nice=function(r){null==r&&(r=10);var e,i=t(),o=0,u=i.length-1,a=i[o],l=i[u];return l<a&&(e=a,a=l,l=e,e=o,o=u,u=e),(e=kn(a,l,r))>0?e=kn(a=Math.floor(a/e)*e,l=Math.ceil(l/e)*e,r):e<0&&(e=kn(a=Math.ceil(a*e)/e,l=Math.floor(l*e)/e,r)),e>0?(i[o]=Math.floor(a/e)*e,i[u]=Math.ceil(l/e)*e,t(i)):e<0&&(i[o]=Math.ceil(a*e)/e,i[u]=Math.floor(l*e)/e,t(i)),n},n}function ue(){var n=Gr()(Lr,Lr);return n.copy=function(){return t=n,ue().domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp()).unknown(t.unknown());var t},Xt.apply(n,arguments),oe(n)}function ae(n){return n}function le(n,t){var r=t.id,e=t.bbox,i=null==t.properties?{}:t.properties,o=function(n,t){var r=function(n){if(null==n)return ae;var t,r,e=n.scale[0],i=n.scale[1],o=n.translate[0],u=n.translate[1];return function(n,a){a||(t=r=0);var l=2,c=n.length,f=new Array(c);for(f[0]=(t+=n[0])*e+o,f[1]=(r+=n[1])*i+u;l<c;)f[l]=n[l],++l;return f}}(n.transform),e=n.arcs;function i(n,t){t.length&&t.pop();for(var i=e[n<0?~n:n],o=0,u=i.length;o<u;++o)t.push(r(i[o],o));n<0&&function(n,t){for(var r,e=n.length,i=e-t;i<--e;)r=n[i],n[i++]=n[e],n[e]=r}(t,u)}function o(n){return r(n)}function u(n){for(var t=[],r=0,e=n.length;r<e;++r)i(n[r],t);return t.length<2&&t.push(t[0]),t}function a(n){for(var t=u(n);t.length<4;)t.push(t[0]);return t}function l(n){return n.map(a)}return function n(t){var r,e=t.type;switch(e){case"GeometryCollection":return{type:e,geometries:t.geometries.map(n)};case"Point":r=o(t.coordinates);break;case"MultiPoint":r=t.coordinates.map(o);break;case"LineString":r=u(t.arcs);break;case"MultiLineString":r=t.arcs.map(u);break;case"Polygon":r=l(t.arcs);break;case"MultiPolygon":r=t.arcs.map(l);break;default:return null}return{type:e,coordinates:r}}(t)}(n,t);return null==r&&null==e?{type:"Feature",properties:i,geometry:o}:null==e?{type:"Feature",id:r,properties:i,geometry:o}:{type:"Feature",id:r,bbox:e,properties:i,geometry:o}}function ce(n,t,r){const e=n.slice();return e[5]=t[r],e}function fe(n){let t,r,e;return{c(){t=l("path"),c(t,"d",r=n[2](n[5])),c(t,"class","provinceShape svelte-8wv364"),c(t,"fill",e=n[1](n[5].properties.NAME_2.length))},m(n,r){u(n,t,r)},p(n,i){1&i&&r!==(r=n[2](n[5]))&&c(t,"d",r),3&i&&e!==(e=n[1](n[5].properties.NAME_2.length))&&c(t,"fill",e)},d(n){n&&a(t)}}}function se(t){let r,e=t[0],i=[];for(let n=0;n<e.length;n+=1)i[n]=fe(ce(t,e,n));return{c(){r=l("svg");for(let n=0;n<i.length;n+=1)i[n].c();c(r,"width","960"),c(r,"height","500"),c(r,"class","svelte-8wv364")},m(n,t){u(n,r,t);for(let n=0;n<i.length;n+=1)i[n].m(r,null)},p(n,[t]){if(7&t){let o;for(e=n[0],o=0;o<e.length;o+=1){const u=ce(n,e,o);i[o]?i[o].p(u,t):(i[o]=fe(u),i[o].c(),i[o].m(r,null))}for(;o<i.length;o+=1)i[o].d(1);i.length=e.length}},i:n,o:n,d(n){n&&a(r),function(n,t){for(let r=0;r<n.length;r+=1)n[r]&&n[r].d(t)}(i,n)}}}Jr=ee({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"}),Qr=Jr.format,ne=Jr.formatPrefix;const he="960",pe="500";function ge(n,t,r){let e=[],i=()=>{};let o=Vt().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7]).rotate([4.4,.8]).center([0,55.4]).parallels([50,60]).scale(3800).translate([he/2,1.8*pe/2]),u=function(n,t){var r,e,i=4.5;function o(n){return n&&("function"==typeof i&&e.pointRadius(+i.apply(this,arguments)),Y(n,r(e))),e.result()}return o.area=function(n){return Y(n,r(Dn)),Dn.result()},o.measure=function(n){return Y(n,r(At)),At.result()},o.bounds=function(n){return Y(n,r(Jn)),Jn.result()},o.centroid=function(n){return Y(n,r(ht)),ht.result()},o.projection=function(t){return arguments.length?(r=null==t?(n=null,Cn):(n=t).stream,o):n},o.context=function(n){return arguments.length?(e=null==n?(t=null,new Rt):new xt(t=n),"function"!=typeof i&&e.pointRadius(i),o):t},o.pointRadius=function(n){return arguments.length?(i="function"==typeof n?n:(e.pointRadius(+n),+n),o):i},o.projection(n).context(t)}().projection(o);return h((async function(){const n=await fetch("https://gist.githubusercontent.com/rveciana/27272a581e975835aaa321ddf816d726/raw/c40062a328843322208b8e98c2104dc8f6ad5301/uk-counties.json"),t=await n.json(),o=(u=t,"GeometryCollection"===(a=t.objects.UK).type?{type:"FeatureCollection",features:a.geometries.map((function(n){return le(u,n)}))}:le(u,a));var u,a;const l={...o,features:o.features.filter(n=>"Scotland"===n.properties.NAME_1)},c=function(n,t){var r,e,i,o=n.length,u=-1;if(null==t){for(;++u<o;)if(null!=(r=n[u])&&r>=r)for(e=i=r;++u<o;)null!=(r=n[u])&&(e>r&&(e=r),i<r&&(i=r))}else for(;++u<o;)if(null!=(r=t(n[u],u,n))&&r>=r)for(e=i=r;++u<o;)null!=(r=t(n[u],u,n))&&(e>r&&(e=r),i<r&&(i=r));return[e,i]}(l.features,n=>n.properties.NAME_2.length);r(1,i=ue().domain(c).range(["#feedde","#fd8d3c"])),r(0,e=l.features)})),[e,i,u]}return new class extends S{constructor(n){super(),N(this,n,ge,se,o,{})}}({target:document.body})}();
//# sourceMappingURL=bundle.js.map
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Svelte app</title>
<link rel="stylesheet" href="bundle.css" />
<script defer src="bundle.js"></script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment