bharat-choropleth-js 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +13 -7
- package/dist/bharat-choropleth.min.js +2 -2
- package/dist/bharat-choropleth.min.js.map +1 -1
- package/dist/index.d.ts +87 -8
- package/dist/index.js +220 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Added an optional sub-district level below districts — tehsils, taluks,
|
|
6
|
+
mandals and blocks. On `IndiaChoropleth`, `loadSubDistricts` is called only
|
|
7
|
+
after a district is activated, with `subDistrictDrillDownId` and
|
|
8
|
+
`onSubDistrictDrillDownChange` to drive it from outside.
|
|
9
|
+
- A `loadSubDistricts` that resolves `null` marks that district a leaf: the map
|
|
10
|
+
stays on the district view and selects it rather than opening an empty level,
|
|
11
|
+
and the district is not asked again. Omit the option and every district stays
|
|
12
|
+
a leaf, exactly as before.
|
|
13
|
+
- The zero-config `BharatChoropleth` gained `subDistricts`, which defaults to on
|
|
14
|
+
when the map is using the bundled data source and off when you supply your own
|
|
15
|
+
geometry — the same rule `districts` already follows.
|
|
16
|
+
- `drillDown(null)` returns to the national map from any depth. It is the
|
|
17
|
+
state-level control, so it does not merely step back one level.
|
|
18
|
+
- Exported `MapLevel` and `SubDistrictLoader`.
|
|
19
|
+
- **Possibly breaking for TypeScript callers:** `level` on `TooltipContext` and
|
|
20
|
+
`InsightContext` widened from `"state" | "district"` to `MapLevel`, which adds
|
|
21
|
+
`"subdistrict"`. A `switch` over it that the compiler checks for
|
|
22
|
+
exhaustiveness now needs the third case. Nothing changes at runtime for a
|
|
23
|
+
two-level map.
|
|
24
|
+
|
|
25
|
+
## 0.1.0
|
|
26
|
+
|
|
27
|
+
- Initial public release of the framework-free India state and district
|
|
28
|
+
choropleth renderer.
|
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# `bharat-choropleth-js`
|
|
2
2
|
|
|
3
|
-
An accessible SVG India state-to-district choropleth with no framework dependency. Drop one `<script>` tag into any HTML page, or import it as an ES module from a bundler. Same behavior, CSS classes, and stylesheet as the React [`bharat-choropleth`](https://www.npmjs.com/package/bharat-choropleth) package.
|
|
3
|
+
An accessible SVG India state-to-district-to-sub-district choropleth with no framework dependency. Drop one `<script>` tag into any HTML page, or import it as an ES module from a bundler. Same behavior, CSS classes, and stylesheet as the React [`bharat-choropleth`](https://www.npmjs.com/package/bharat-choropleth) package.
|
|
4
|
+
|
|
5
|
+

|
|
4
6
|
|
|
5
7
|
## One script tag
|
|
6
8
|
|
|
7
9
|
```html
|
|
8
10
|
<div id="map"></div>
|
|
9
11
|
|
|
10
|
-
<script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js"></script>
|
|
12
|
+
<script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js@0.1.0"></script>
|
|
11
13
|
<script>
|
|
12
14
|
var map = new BharatChoropleth("#map");
|
|
13
15
|
|
|
@@ -26,7 +28,7 @@ That's the whole setup. No stylesheet link, no build step, no `await`, no bounda
|
|
|
26
28
|
- **The script tag injects its own CSS.** (Bundler users import `bharat-choropleth-js/style.css` instead, so their pipeline can extract and hash it — see [From a bundler](#from-a-bundler).)
|
|
27
29
|
- **Boundary data is fetched, not bundled.** The package ships no geometry; the prepared current-vintage state bundle is downloaded from `dataBaseUrl` on construction. Set `dataBaseUrl` to self-host — see [Boundary data](#boundary-data).
|
|
28
30
|
- **Values set before the data arrives are applied when it arrives.** Every line above runs while the download is still in flight; nothing is dropped and nothing needs awaiting. `map.ready` is a promise if you want one.
|
|
29
|
-
- **Clicking a state drills into its districts**, fetched from the same base URL. Pass `districts: false` to turn
|
|
31
|
+
- **Clicking a state drills into its districts**, and a district into its sub-districts (tehsils / taluks / mandals / blocks), fetched from the same base URL. Pass `districts: false` or `subDistricts: false` to turn either off.
|
|
30
32
|
|
|
31
33
|
See the [complete example](https://github.com/shashankbudem/bharat-choropleth/tree/main/packages/js/example) in the repository. To run it locally, serve the **repo root** over HTTP (`npx serve`), then open `/packages/js/example/bharat-choropleth.html`.
|
|
32
34
|
|
|
@@ -66,6 +68,7 @@ var map = new BharatChoropleth({ container: "#map", showRegionValues: true });
|
|
|
66
68
|
| `geometry` | fetched from `dataBaseUrl` | Inline GeoJSON/TopoJSON, a URL string, or a promise of either. |
|
|
67
69
|
| `dataBaseUrl` | jsDelivr copy of `data/generated` | Base URL for the prepared bundles. Point at your own copy to self-host. |
|
|
68
70
|
| `districts` | `true` with default data, else `false` | Click-to-drill-down into districts. |
|
|
71
|
+
| `subDistricts` | `true` with default data, else `false` | Click-to-drill-down from a district into its sub-districts. Districts the bundle has none for stay leaves. |
|
|
69
72
|
| `fontColor` / `borderColor` | — | Sets the `--india-map-text` / `--india-map-stroke` CSS variables. |
|
|
70
73
|
| `borderWidth` | `2.5` | Region border thickness in px. Sets `--india-map-border-width`. |
|
|
71
74
|
| `selectionWidth` | `3` | Selection ring thickness in px; its halo is drawn at twice this. Sets `--india-map-selection-width`. |
|
|
@@ -88,7 +91,7 @@ Every thickness is a CSS variable, so you can theme without touching the rendere
|
|
|
88
91
|
|
|
89
92
|
Every other [`IndiaChoroplethOptions`](https://github.com/shashankbudem/bharat-choropleth/blob/main/packages/js/src/types.ts) field (`referenceOverlay`, `loadDistricts`, `onRegionClick`, `formatValue`, `renderTooltip`, `showLegend`, ...) is accepted and forwarded.
|
|
90
93
|
|
|
91
|
-
Methods: `setValues`, `getValues`, `select(id)`, `drillDown(name | null)`, `getSelected()`, `getInspected()`, `destroy()`. The full engine is at `map.engine` (`null` until the data loads — `await map.ready` first).
|
|
94
|
+
Methods: `setValues`, `getValues`, `select(id)`, `drillDown(name | null)`, `drillDownSubDistrict(id | null)`, `getSelected()`, `getInspected()`, `destroy()`. The full engine is at `map.engine` (`null` until the data loads — `await map.ready` first).
|
|
92
95
|
|
|
93
96
|
## Hover and focus detail
|
|
94
97
|
|
|
@@ -112,9 +115,9 @@ var map = new BharatChoropleth("#map", {
|
|
|
112
115
|
|
|
113
116
|
The package deliberately bundles no geographic boundaries; it downloads them. By default that means the prepared bundles in this repo's `data/generated`, served over jsDelivr, which must be attributed as:
|
|
114
117
|
|
|
115
|
-
> State/UT and district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).
|
|
118
|
+
> State/UT, district and sub-district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).
|
|
116
119
|
|
|
117
|
-
For production, offline or air-gapped use, copy `data/generated/current-2019-states/` and `data/generated/current-2019-
|
|
120
|
+
For production, offline or air-gapped use, copy `data/generated/current-2019-states/`, `data/generated/current-2019-districts/` and `data/generated/current-2019-subdistricts/` next to your app and point at them — no third-party CDN request at runtime:
|
|
118
121
|
|
|
119
122
|
```js
|
|
120
123
|
var map = new BharatChoropleth("#map", { dataBaseUrl: "/maps" });
|
|
@@ -164,10 +167,13 @@ It requires an explicit `states` layer with `getId`/`getLabel`/`getValue` access
|
|
|
164
167
|
- `update(partialOptions)` — merge new options (new data, controlled `selectedId`/`drillDownId`, swapped callbacks) and re-render.
|
|
165
168
|
- `select(id | null)` — select a region at the current level without changing drill-down.
|
|
166
169
|
- `drillDown(id | null)` — drill into a state, or pass `null` to return to the state view.
|
|
170
|
+
- `drillDownSubDistrict(id | null)` — drill into a district's sub-districts, or pass `null` to return to the district view. Only meaningful while a state is drilled into, so its district layer has to have loaded first.
|
|
167
171
|
- `getSelected()` / `getInspected()` — read the current `MapRegion | null`.
|
|
168
172
|
- `destroy()` — remove all DOM content and cancel any in-flight loads. Call this before discarding the instance.
|
|
169
173
|
|
|
170
|
-
Controlled vs. uncontrolled state works the same way as the React version: pass `selectedId`/`drillDownId` (and keep passing them via `update()`) for controlled usage, or `defaultSelectedId`/`defaultDrillDownId` to let the instance manage its own.
|
|
174
|
+
Controlled vs. uncontrolled state works the same way as the React version: pass `selectedId`/`drillDownId`/`subDistrictDrillDownId` (and keep passing them via `update()`) for controlled usage, or `defaultSelectedId`/`defaultDrillDownId`/`defaultSubDistrictDrillDownId` to let the instance manage its own. A district id means nothing outside the state it came from, so changing `drillDownId` clears the level below it.
|
|
175
|
+
|
|
176
|
+
`loadSubDistricts` may return `null` for a district with no sub-district level; that district is left as a leaf rather than opening an empty view, and stops offering the level once it has answered.
|
|
171
177
|
|
|
172
178
|
## Design notes
|
|
173
179
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
1
|
+
"use strict";(()=>{var Ke=`.india-choropleth {
|
|
2
2
|
--india-map-stroke: #fff;
|
|
3
3
|
--india-map-stroke-active: #0f1b38;
|
|
4
4
|
/* Border widths, in screen pixels (the strokes are non-scaling). Override any
|
|
@@ -122,5 +122,5 @@ button.india-choropleth__swatch[aria-disabled="true"] { cursor: default; }
|
|
|
122
122
|
being fetched, and for the message if that fetch fails. */
|
|
123
123
|
.bharat-choropleth__status { padding: 1.25rem; border-radius: .625rem; background: var(--india-map-empty, #eef1f7); color: var(--india-map-muted, #53617b); font: 500 .875rem/1.45 system-ui, sans-serif; text-align: center; }
|
|
124
124
|
.bharat-choropleth__status--error { background: #fdeceb; color: #8a1c14; }
|
|
125
|
-
`;var K=class{constructor(){this._partials=new Float64Array(32),this._n=0}add(e){let n=this._partials,r=0;for(let i=0;i<this._n&&i<32;i++){let o=n[i],a=e+o,l=Math.abs(e)<Math.abs(o)?e-(a-o):o-(a-e);l&&(n[r++]=l),e=a}return n[r]=e,this._n=r+1,this}valueOf(){let e=this._partials,n=this._n,r,i,o,a=0;if(n>0){for(a=e[--n];n>0&&(r=a,i=e[--n],a=r+i,o=i-(a-r),!o););n>0&&(o<0&&e[n-1]<0||o>0&&e[n-1]>0)&&(i=o*2,r=a+i,i==r-a&&(a=r))}return a}};function*hr(t){for(let e of t)yield*e}function pe(t){return Array.from(hr(t))}var P=1e-6,Vt=1e-12,I=Math.PI,$=I/2,dt=I/4,q=I*2,U=180/I,B=I/180,M=Math.abs,je=Math.atan,re=Math.atan2,D=Math.cos;var Wt=Math.exp;var Kt=Math.log;var T=Math.sin,Yt=Math.sign||function(t){return t>0?1:t<0?-1:0},Y=Math.sqrt,Xt=Math.tan;function Jt(t){return t>1?0:t<-1?I:Math.acos(t)}function ie(t){return t>1?$:t<-1?-$:Math.asin(t)}function z(){}function $e(t,e){t&&Qt.hasOwnProperty(t.type)&&Qt[t.type](t,e)}var Zt={Feature:function(t,e){$e(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,i=n.length;++r<i;)$e(n[r].geometry,e)}},Qt={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)t=n[r],e.point(t[0],t[1],t[2])},LineString:function(t,e){ut(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)ut(n[r],e,0)},Polygon:function(t,e){en(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)en(n[r],e)},GeometryCollection:function(t,e){for(var n=t.geometries,r=-1,i=n.length;++r<i;)$e(n[r],e)}};function ut(t,e,n){var r=-1,i=t.length-n,o;for(e.lineStart();++r<i;)o=t[r],e.point(o[0],o[1],o[2]);e.lineEnd()}function en(t,e){var n=-1,r=t.length;for(e.polygonStart();++n<r;)ut(t[n],e,1);e.polygonEnd()}function ae(t,e){t&&Zt.hasOwnProperty(t.type)?Zt[t.type](t,e):$e(t,e)}function we(t){return[re(t[1],t[0]),ie(t[2])]}function Z(t){var e=t[0],n=t[1],r=D(n);return[r*D(e),r*T(e),T(n)]}function Se(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function fe(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function qe(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function _e(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function ke(t){var e=Y(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}function Ie(t,e){function n(r,i){return r=t(r,i),e(r[0],r[1])}return t.invert&&e.invert&&(n.invert=function(r,i){return r=e.invert(r,i),r&&t.invert(r[0],r[1])}),n}function ht(t,e){return M(t)>I&&(t-=Math.round(t/q)*q),[t,e]}ht.invert=ht;function pt(t,e,n){return(t%=q)?e||n?Ie(nn(t),rn(e,n)):nn(t):e||n?rn(e,n):ht}function tn(t){return function(e,n){return e+=t,M(e)>I&&(e-=Math.round(e/q)*q),[e,n]}}function nn(t){var e=tn(t);return e.invert=tn(-t),e}function rn(t,e){var n=D(t),r=T(t),i=D(e),o=T(e);function a(l,h){var d=D(h),s=D(l)*d,c=T(l)*d,u=T(h),p=u*n+s*r;return[re(c*i-p*o,s*n-u*r),ie(p*i+c*o)]}return a.invert=function(l,h){var d=D(h),s=D(l)*d,c=T(l)*d,u=T(h),p=u*i-c*o;return[re(c*i+u*o,s*n+p*r),ie(p*n-s*r)]},a}function on(t){t=pt(t[0]*B,t[1]*B,t.length>2?t[2]*B:0);function e(n){return n=t(n[0]*B,n[1]*B),n[0]*=U,n[1]*=U,n}return e.invert=function(n){return n=t.invert(n[0]*B,n[1]*B),n[0]*=U,n[1]*=U,n},e}function sn(t,e,n,r,i,o){if(n){var a=D(e),l=T(e),h=r*n;i==null?(i=e+r*q,o=e-h/2):(i=an(a,i),o=an(a,o),(r>0?i<o:i>o)&&(i+=r*q));for(var d,s=i;r>0?s>o:s<o;s-=h)d=we([a,-l*D(s),-l*T(s)]),t.point(d[0],d[1])}}function an(t,e){e=Z(e),e[0]-=t,ke(e);var n=Jt(-e[1]);return((-e[2]<0?-n:n)+q-P)%q}function ze(){var t=[],e;return{point:function(n,r,i){e.push([n,r,i])},lineStart:function(){t.push(e=[])},lineEnd:z,rejoin:function(){t.length>1&&t.push(t.pop().concat(t.shift()))},result:function(){var n=t;return t=[],e=null,n}}}function me(t,e){return M(t[0]-e[0])<P&&M(t[1]-e[1])<P}function He(t,e,n,r){this.x=t,this.z=e,this.o=n,this.e=r,this.v=!1,this.n=this.p=null}function Ue(t,e,n,r,i){var o=[],a=[],l,h;if(t.forEach(function(f){if(!((m=f.length-1)<=0)){var m,v=f[0],b=f[m],y;if(me(v,b)){if(!v[2]&&!b[2]){for(i.lineStart(),l=0;l<m;++l)i.point((v=f[l])[0],v[1]);i.lineEnd();return}b[0]+=2*P}o.push(y=new He(v,f,null,!0)),a.push(y.o=new He(v,null,y,!1)),o.push(y=new He(b,f,null,!1)),a.push(y.o=new He(b,null,y,!0))}}),!!o.length){for(a.sort(e),ln(o),ln(a),l=0,h=a.length;l<h;++l)a[l].e=n=!n;for(var d=o[0],s,c;;){for(var u=d,p=!0;u.v;)if((u=u.n)===d)return;s=u.z,i.lineStart();do{if(u.v=u.o.v=!0,u.e){if(p)for(l=0,h=s.length;l<h;++l)i.point((c=s[l])[0],c[1]);else r(u.x,u.n.x,1,i);u=u.n}else{if(p)for(s=u.p.z,l=s.length-1;l>=0;--l)i.point((c=s[l])[0],c[1]);else r(u.x,u.p.x,-1,i);u=u.p}u=u.o,s=u.z,p=!p}while(!u.v);i.lineEnd()}}}function ln(t){if(e=t.length){for(var e,n=0,r=t[0],i;++n<e;)r.n=i=t[n],i.p=r,r=i;r.n=i=t[0],i.p=r}}function ft(t){return M(t[0])<=I?t[0]:Yt(t[0])*((M(t[0])+I)%q-I)}function cn(t,e){var n=ft(e),r=e[1],i=T(r),o=[T(n),-D(n),0],a=0,l=0,h=new K;i===1?r=$+P:i===-1&&(r=-$-P);for(var d=0,s=t.length;d<s;++d)if(u=(c=t[d]).length)for(var c,u,p=c[u-1],f=ft(p),m=p[1]/2+dt,v=T(m),b=D(m),y=0;y<u;++y,f=E,v=k,b=L,p=x){var x=c[y],E=ft(x),w=x[1]/2+dt,k=T(w),L=D(w),S=E-f,C=S>=0?1:-1,O=C*S,_=O>I,V=v*k;if(h.add(re(V*C*T(O),b*L+V*D(O))),a+=_?S+C*q:S,_^f>=n^E>=n){var F=fe(Z(p),Z(x));ke(F);var A=fe(o,F);ke(A);var g=(_^S>=0?-1:1)*ie(A[2]);(r>g||r===g&&(F[0]||F[1]))&&(l+=_^S>=0?1:-1)}}return(a<-P||a<P&&h<-Vt)^l&1}function Ve(t,e,n,r){return function(i){var o=e(i),a=ze(),l=e(a),h=!1,d,s,c,u={point:p,lineStart:m,lineEnd:v,polygonStart:function(){u.point=b,u.lineStart=y,u.lineEnd=x,s=[],d=[]},polygonEnd:function(){u.point=p,u.lineStart=m,u.lineEnd=v,s=pe(s);var E=cn(d,r);s.length?(h||(i.polygonStart(),h=!0),Ue(s,fr,E,n,i)):E&&(h||(i.polygonStart(),h=!0),i.lineStart(),n(null,null,1,i),i.lineEnd()),h&&(i.polygonEnd(),h=!1),s=d=null},sphere:function(){i.polygonStart(),i.lineStart(),n(null,null,1,i),i.lineEnd(),i.polygonEnd()}};function p(E,w){t(E,w)&&i.point(E,w)}function f(E,w){o.point(E,w)}function m(){u.point=f,o.lineStart()}function v(){u.point=p,o.lineEnd()}function b(E,w){c.push([E,w]),l.point(E,w)}function y(){l.lineStart(),c=[]}function x(){b(c[0][0],c[0][1]),l.lineEnd();var E=l.clean(),w=a.result(),k,L=w.length,S,C,O;if(c.pop(),d.push(c),c=null,!!L){if(E&1){if(C=w[0],(S=C.length-1)>0){for(h||(i.polygonStart(),h=!0),i.lineStart(),k=0;k<S;++k)i.point((O=C[k])[0],O[1]);i.lineEnd()}return}L>1&&E&2&&w.push(w.pop().concat(w.shift())),s.push(w.filter(pr))}}return u}}function pr(t){return t.length>1}function fr(t,e){return((t=t.x)[0]<0?t[1]-$-P:$-t[1])-((e=e.x)[0]<0?e[1]-$-P:$-e[1])}var mt=Ve(function(){return!0},mr,vr,[-I,-$]);function mr(t){var e=NaN,n=NaN,r=NaN,i;return{lineStart:function(){t.lineStart(),i=1},point:function(o,a){var l=o>0?I:-I,h=M(o-e);M(h-I)<P?(t.point(e,n=(n+a)/2>0?$:-$),t.point(r,n),t.lineEnd(),t.lineStart(),t.point(l,n),t.point(o,n),i=0):r!==l&&h>=I&&(M(e-r)<P&&(e-=r*P),M(o-l)<P&&(o-=l*P),n=gr(e,n,o,a),t.point(r,n),t.lineEnd(),t.lineStart(),t.point(l,n),i=0),t.point(e=o,n=a),r=l},lineEnd:function(){t.lineEnd(),e=n=NaN},clean:function(){return 2-i}}}function gr(t,e,n,r){var i,o,a=T(t-n);return M(a)>P?je((T(e)*(o=D(r))*T(n)-T(r)*(i=D(e))*T(t))/(i*o*a)):(e+r)/2}function vr(t,e,n,r){var i;if(t==null)i=n*$,r.point(-I,i),r.point(0,i),r.point(I,i),r.point(I,0),r.point(I,-i),r.point(0,-i),r.point(-I,-i),r.point(-I,0),r.point(-I,i);else if(M(t[0]-e[0])>P){var o=t[0]<e[0]?I:-I;i=n*o/2,r.point(-o,i),r.point(0,i),r.point(o,i)}else r.point(e[0],e[1])}function dn(t){var e=D(t),n=2*B,r=e>0,i=M(e)>P;function o(s,c,u,p){sn(p,t,n,u,s,c)}function a(s,c){return D(s)*D(c)>e}function l(s){var c,u,p,f,m;return{lineStart:function(){f=p=!1,m=1},point:function(v,b){var y=[v,b],x,E=a(v,b),w=r?E?0:d(v,b):E?d(v+(v<0?I:-I),b):0;if(!c&&(f=p=E)&&s.lineStart(),E!==p&&(x=h(c,y),(!x||me(c,x)||me(y,x))&&(y[2]=1)),E!==p)m=0,E?(s.lineStart(),x=h(y,c),s.point(x[0],x[1])):(x=h(c,y),s.point(x[0],x[1],2),s.lineEnd()),c=x;else if(i&&c&&r^E){var k;!(w&u)&&(k=h(y,c,!0))&&(m=0,r?(s.lineStart(),s.point(k[0][0],k[0][1]),s.point(k[1][0],k[1][1]),s.lineEnd()):(s.point(k[1][0],k[1][1]),s.lineEnd(),s.lineStart(),s.point(k[0][0],k[0][1],3)))}E&&(!c||!me(c,y))&&s.point(y[0],y[1]),c=y,p=E,u=w},lineEnd:function(){p&&s.lineEnd(),c=null},clean:function(){return m|(f&&p)<<1}}}function h(s,c,u){var p=Z(s),f=Z(c),m=[1,0,0],v=fe(p,f),b=Se(v,v),y=v[0],x=b-y*y;if(!x)return!u&&s;var E=e*b/x,w=-e*y/x,k=fe(m,v),L=_e(m,E),S=_e(v,w);qe(L,S);var C=k,O=Se(L,C),_=Se(C,C),V=O*O-_*(Se(L,L)-1);if(!(V<0)){var F=Y(V),A=_e(C,(-O-F)/_);if(qe(A,L),A=we(A),!u)return A;var g=s[0],R=c[0],j=s[1],W=c[1],X;R<g&&(X=g,g=R,R=X);var Ee=R-g,te=M(Ee-I)<P,le=te||Ee<P;if(!te&&W<j&&(X=j,j=W,W=X),le?te?j+W>0^A[1]<(M(A[0]-g)<P?j:W):j<=A[1]&&A[1]<=W:Ee>I^(g<=A[0]&&A[0]<=R)){var ne=_e(C,(-O+F)/_);return qe(ne,L),[A,we(ne)]}}}function d(s,c){var u=r?t:I-t,p=0;return s<-u?p|=1:s>u&&(p|=2),c<-u?p|=4:c>u&&(p|=8),p}return Ve(a,l,o,r?[0,-t]:[-I,t-I])}function un(t,e,n,r,i,o){var a=t[0],l=t[1],h=e[0],d=e[1],s=0,c=1,u=h-a,p=d-l,f;if(f=n-a,!(!u&&f>0)){if(f/=u,u<0){if(f<s)return;f<c&&(c=f)}else if(u>0){if(f>c)return;f>s&&(s=f)}if(f=i-a,!(!u&&f<0)){if(f/=u,u<0){if(f>c)return;f>s&&(s=f)}else if(u>0){if(f<s)return;f<c&&(c=f)}if(f=r-l,!(!p&&f>0)){if(f/=p,p<0){if(f<s)return;f<c&&(c=f)}else if(p>0){if(f>c)return;f>s&&(s=f)}if(f=o-l,!(!p&&f<0)){if(f/=p,p<0){if(f>c)return;f>s&&(s=f)}else if(p>0){if(f<s)return;f<c&&(c=f)}return s>0&&(t[0]=a+s*u,t[1]=l+s*p),c<1&&(e[0]=a+c*u,e[1]=l+c*p),!0}}}}}var Re=1e9,We=-Re;function gt(t,e,n,r){function i(d,s){return t<=d&&d<=n&&e<=s&&s<=r}function o(d,s,c,u){var p=0,f=0;if(d==null||(p=a(d,c))!==(f=a(s,c))||h(d,s)<0^c>0)do u.point(p===0||p===3?t:n,p>1?r:e);while((p=(p+c+4)%4)!==f);else u.point(s[0],s[1])}function a(d,s){return M(d[0]-t)<P?s>0?0:3:M(d[0]-n)<P?s>0?2:1:M(d[1]-e)<P?s>0?1:0:s>0?3:2}function l(d,s){return h(d.x,s.x)}function h(d,s){var c=a(d,1),u=a(s,1);return c!==u?c-u:c===0?s[1]-d[1]:c===1?d[0]-s[0]:c===2?d[1]-s[1]:s[0]-d[0]}return function(d){var s=d,c=ze(),u,p,f,m,v,b,y,x,E,w,k,L={point:S,lineStart:V,lineEnd:F,polygonStart:O,polygonEnd:_};function S(g,R){i(g,R)&&s.point(g,R)}function C(){for(var g=0,R=0,j=p.length;R<j;++R)for(var W=p[R],X=1,Ee=W.length,te=W[0],le,ne,Ne=te[0],he=te[1];X<Ee;++X)le=Ne,ne=he,te=W[X],Ne=te[0],he=te[1],ne<=r?he>r&&(Ne-le)*(r-ne)>(he-ne)*(t-le)&&++g:he<=r&&(Ne-le)*(r-ne)<(he-ne)*(t-le)&&--g;return g}function O(){s=c,u=[],p=[],k=!0}function _(){var g=C(),R=k&&g,j=(u=pe(u)).length;(R||j)&&(d.polygonStart(),R&&(d.lineStart(),o(null,null,1,d),d.lineEnd()),j&&Ue(u,l,g,o,d),d.polygonEnd()),s=d,u=p=f=null}function V(){L.point=A,p&&p.push(f=[]),w=!0,E=!1,y=x=NaN}function F(){u&&(A(m,v),b&&E&&c.rejoin(),u.push(c.result())),L.point=S,E&&s.lineEnd()}function A(g,R){var j=i(g,R);if(p&&f.push([g,R]),w)m=g,v=R,b=j,w=!1,j&&(s.lineStart(),s.point(g,R));else if(j&&E)s.point(g,R);else{var W=[y=Math.max(We,Math.min(Re,y)),x=Math.max(We,Math.min(Re,x))],X=[g=Math.max(We,Math.min(Re,g)),R=Math.max(We,Math.min(Re,R))];un(W,X,t,e,n,r)?(E||(s.lineStart(),s.point(W[0],W[1])),s.point(X[0],X[1]),j||s.lineEnd(),k=!1):j&&(s.lineStart(),s.point(g,R),k=!1)}y=g,x=R,E=j}return L}}var Pe=t=>t;var vt=new K,yt=new K,hn,pn,bt,xt,se={point:z,lineStart:z,lineEnd:z,polygonStart:function(){se.lineStart=yr,se.lineEnd=xr},polygonEnd:function(){se.lineStart=se.lineEnd=se.point=z,vt.add(M(yt)),yt=new K},result:function(){var t=vt/2;return vt=new K,t}};function yr(){se.point=br}function br(t,e){se.point=fn,hn=bt=t,pn=xt=e}function fn(t,e){yt.add(xt*t-bt*e),bt=t,xt=e}function xr(){fn(hn,pn)}var Et=se;var ge=1/0,Ke=ge,Ce=-ge,Ye=Ce,Er={point:wr,lineStart:z,lineEnd:z,polygonStart:z,polygonEnd:z,result:function(){var t=[[ge,Ke],[Ce,Ye]];return Ce=Ye=-(Ke=ge=1/0),t}};function wr(t,e){t<ge&&(ge=t),t>Ce&&(Ce=t),e<Ke&&(Ke=e),e>Ye&&(Ye=e)}var ve=Er;var wt=0,St=0,Me=0,Xe=0,Je=0,ye=0,_t=0,kt=0,Le=0,vn,yn,Q,ee,J={point:ce,lineStart:mn,lineEnd:gn,polygonStart:function(){J.lineStart=kr,J.lineEnd=Ir},polygonEnd:function(){J.point=ce,J.lineStart=mn,J.lineEnd=gn},result:function(){var t=Le?[_t/Le,kt/Le]:ye?[Xe/ye,Je/ye]:Me?[wt/Me,St/Me]:[NaN,NaN];return wt=St=Me=Xe=Je=ye=_t=kt=Le=0,t}};function ce(t,e){wt+=t,St+=e,++Me}function mn(){J.point=Sr}function Sr(t,e){J.point=_r,ce(Q=t,ee=e)}function _r(t,e){var n=t-Q,r=e-ee,i=Y(n*n+r*r);Xe+=i*(Q+t)/2,Je+=i*(ee+e)/2,ye+=i,ce(Q=t,ee=e)}function gn(){J.point=ce}function kr(){J.point=Rr}function Ir(){bn(vn,yn)}function Rr(t,e){J.point=bn,ce(vn=Q=t,yn=ee=e)}function bn(t,e){var n=t-Q,r=e-ee,i=Y(n*n+r*r);Xe+=i*(Q+t)/2,Je+=i*(ee+e)/2,ye+=i,i=ee*t-Q*e,_t+=i*(Q+t),kt+=i*(ee+e),Le+=i*3,ce(Q=t,ee=e)}var It=J;function Ze(t){this._context=t}Ze.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(t,e){switch(this._point){case 0:{this._context.moveTo(t,e),this._point=1;break}case 1:{this._context.lineTo(t,e);break}default:{this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,q);break}}},result:z};var Pt=new K,Rt,xn,En,De,Ae,Qe={point:z,lineStart:function(){Qe.point=Pr},lineEnd:function(){Rt&&wn(xn,En),Qe.point=z},polygonStart:function(){Rt=!0},polygonEnd:function(){Rt=null},result:function(){var t=+Pt;return Pt=new K,t}};function Pr(t,e){Qe.point=wn,xn=De=t,En=Ae=e}function wn(t,e){De-=t,Ae-=e,Pt.add(Y(De*De+Ae*Ae)),De=t,Ae=e}var Ct=Qe;var Sn,et,_n,kn,be=class{constructor(e){this._append=e==null?In:Cr(e),this._radius=4.5,this._=""}pointRadius(e){return this._radius=+e,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(e,n){switch(this._point){case 0:{this._append`M${e},${n}`,this._point=1;break}case 1:{this._append`L${e},${n}`;break}default:{if(this._append`M${e},${n}`,this._radius!==_n||this._append!==et){let r=this._radius,i=this._;this._="",this._append`m0,${r}a${r},${r} 0 1,1 0,${-2*r}a${r},${r} 0 1,1 0,${2*r}z`,_n=r,et=this._append,kn=this._,this._=i}this._+=kn;break}}}result(){let e=this._;return this._="",e.length?e:null}};function In(t){let e=1;this._+=t[0];for(let n=t.length;e<n;++e)this._+=arguments[e]+t[e]}function Cr(t){let e=Math.floor(t);if(!(e>=0))throw new RangeError(`invalid digits: ${t}`);if(e>15)return In;if(e!==Sn){let n=10**e;Sn=e,et=function(i){let o=1;this._+=i[0];for(let a=i.length;o<a;++o)this._+=Math.round(arguments[o]*n)/n+i[o]}}return et}function tt(t,e){let n=3,r=4.5,i,o;function a(l){return l&&(typeof r=="function"&&o.pointRadius(+r.apply(this,arguments)),ae(l,i(o))),o.result()}return a.area=function(l){return ae(l,i(Et)),Et.result()},a.measure=function(l){return ae(l,i(Ct)),Ct.result()},a.bounds=function(l){return ae(l,i(ve)),ve.result()},a.centroid=function(l){return ae(l,i(It)),It.result()},a.projection=function(l){return arguments.length?(i=l==null?(t=null,Pe):(t=l).stream,a):t},a.context=function(l){return arguments.length?(o=l==null?(e=null,new be(n)):new Ze(e=l),typeof r!="function"&&o.pointRadius(r),a):e},a.pointRadius=function(l){return arguments.length?(r=typeof l=="function"?l:(o.pointRadius(+l),+l),a):r},a.digits=function(l){if(!arguments.length)return n;if(l==null)n=null;else{let h=Math.floor(l);if(!(h>=0))throw new RangeError(`invalid digits: ${l}`);n=h}return e===null&&(o=new be(n)),a},a.projection(t).digits(n).context(e)}function Te(t){return function(e){var n=new Mt;for(var r in t)n[r]=t[r];return n.stream=e,n}}function Mt(){}Mt.prototype={constructor:Mt,point:function(t,e){this.stream.point(t,e)},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()}};function Lt(t,e,n){var r=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),r!=null&&t.clipExtent(null),ae(n,t.stream(ve)),e(ve.result()),r!=null&&t.clipExtent(r),t}function Dt(t,e,n){return Lt(t,function(r){var i=e[1][0]-e[0][0],o=e[1][1]-e[0][1],a=Math.min(i/(r[1][0]-r[0][0]),o/(r[1][1]-r[0][1])),l=+e[0][0]+(i-a*(r[1][0]+r[0][0]))/2,h=+e[0][1]+(o-a*(r[1][1]+r[0][1]))/2;t.scale(150*a).translate([l,h])},n)}function Rn(t,e,n){return Dt(t,[[0,0],e],n)}function Pn(t,e,n){return Lt(t,function(r){var i=+e,o=i/(r[1][0]-r[0][0]),a=(i-o*(r[1][0]+r[0][0]))/2,l=-o*r[0][1];t.scale(150*o).translate([a,l])},n)}function Cn(t,e,n){return Lt(t,function(r){var i=+e,o=i/(r[1][1]-r[0][1]),a=-o*r[0][0],l=(i-o*(r[1][1]+r[0][1]))/2;t.scale(150*o).translate([a,l])},n)}var Mn=16,Mr=D(30*B);function At(t,e){return+e?Dr(t,e):Lr(t)}function Lr(t){return Te({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}function Dr(t,e){function n(r,i,o,a,l,h,d,s,c,u,p,f,m,v){var b=d-r,y=s-i,x=b*b+y*y;if(x>4*e&&m--){var E=a+u,w=l+p,k=h+f,L=Y(E*E+w*w+k*k),S=ie(k/=L),C=M(M(k)-1)<P||M(o-c)<P?(o+c)/2:re(w,E),O=t(C,S),_=O[0],V=O[1],F=_-r,A=V-i,g=y*F-b*A;(g*g/x>e||M((b*F+y*A)/x-.5)>.3||a*u+l*p+h*f<Mr)&&(n(r,i,o,a,l,h,_,V,C,E/=L,w/=L,k,m,v),v.point(_,V),n(_,V,C,E,w,k,d,s,c,u,p,f,m,v))}}return function(r){var i,o,a,l,h,d,s,c,u,p,f,m,v={point:b,lineStart:y,lineEnd:E,polygonStart:function(){r.polygonStart(),v.lineStart=w},polygonEnd:function(){r.polygonEnd(),v.lineStart=y}};function b(S,C){S=t(S,C),r.point(S[0],S[1])}function y(){c=NaN,v.point=x,r.lineStart()}function x(S,C){var O=Z([S,C]),_=t(S,C);n(c,u,s,p,f,m,c=_[0],u=_[1],s=S,p=O[0],f=O[1],m=O[2],Mn,r),r.point(c,u)}function E(){v.point=b,r.lineEnd()}function w(){y(),v.point=k,v.lineEnd=L}function k(S,C){x(i=S,C),o=c,a=u,l=p,h=f,d=m,v.point=x}function L(){n(c,u,s,p,f,m,o,a,i,l,h,d,Mn,r),v.lineEnd=E,E()}return v}}var Ar=Te({point:function(t,e){this.stream.point(t*B,e*B)}});function Tr(t){return Te({point:function(e,n){var r=t(e,n);return this.stream.point(r[0],r[1])}})}function Br(t,e,n,r,i){function o(a,l){return a*=r,l*=i,[e+t*a,n-t*l]}return o.invert=function(a,l){return[(a-e)/t*r,(n-l)/t*i]},o}function Ln(t,e,n,r,i,o){if(!o)return Br(t,e,n,r,i);var a=D(o),l=T(o),h=a*t,d=l*t,s=a/t,c=l/t,u=(l*n-a*e)/t,p=(l*e+a*n)/t;function f(m,v){return m*=r,v*=i,[h*m-d*v+e,n-d*m-h*v]}return f.invert=function(m,v){return[r*(s*m-c*v+u),i*(p-c*m-s*v)]},f}function Tt(t){return Or(function(){return t})()}function Or(t){var e,n=150,r=480,i=250,o=0,a=0,l=0,h=0,d=0,s,c=0,u=1,p=1,f=null,m=mt,v=null,b,y,x,E=Pe,w=.5,k,L,S,C,O;function _(g){return S(g[0]*B,g[1]*B)}function V(g){return g=S.invert(g[0],g[1]),g&&[g[0]*U,g[1]*U]}_.stream=function(g){return C&&O===g?C:C=Ar(Tr(s)(m(k(E(O=g)))))},_.preclip=function(g){return arguments.length?(m=g,f=void 0,A()):m},_.postclip=function(g){return arguments.length?(E=g,v=b=y=x=null,A()):E},_.clipAngle=function(g){return arguments.length?(m=+g?dn(f=g*B):(f=null,mt),A()):f*U},_.clipExtent=function(g){return arguments.length?(E=g==null?(v=b=y=x=null,Pe):gt(v=+g[0][0],b=+g[0][1],y=+g[1][0],x=+g[1][1]),A()):v==null?null:[[v,b],[y,x]]},_.scale=function(g){return arguments.length?(n=+g,F()):n},_.translate=function(g){return arguments.length?(r=+g[0],i=+g[1],F()):[r,i]},_.center=function(g){return arguments.length?(o=g[0]%360*B,a=g[1]%360*B,F()):[o*U,a*U]},_.rotate=function(g){return arguments.length?(l=g[0]%360*B,h=g[1]%360*B,d=g.length>2?g[2]%360*B:0,F()):[l*U,h*U,d*U]},_.angle=function(g){return arguments.length?(c=g%360*B,F()):c*U},_.reflectX=function(g){return arguments.length?(u=g?-1:1,F()):u<0},_.reflectY=function(g){return arguments.length?(p=g?-1:1,F()):p<0},_.precision=function(g){return arguments.length?(k=At(L,w=g*g),A()):Y(w)},_.fitExtent=function(g,R){return Dt(_,g,R)},_.fitSize=function(g,R){return Rn(_,g,R)},_.fitWidth=function(g,R){return Pn(_,g,R)},_.fitHeight=function(g,R){return Cn(_,g,R)};function F(){var g=Ln(n,0,0,u,p,c).apply(null,e(o,a)),R=Ln(n,r-g[0],i-g[1],u,p,c);return s=pt(l,h,d),L=Ie(e,R),S=Ie(s,L),k=At(L,w),A()}function A(){return C=O=null,_}return function(){return e=t.apply(this,arguments),_.invert=e.invert&&V,F()}}function nt(t,e){return[t,Kt(Xt(($+e)/2))]}nt.invert=function(t,e){return[t,2*je(Wt(e))-$]};function Bt(){return Fr(nt).scale(961/q)}function Fr(t){var e=Tt(t),n=e.center,r=e.scale,i=e.translate,o=e.clipExtent,a=null,l,h,d;e.scale=function(c){return arguments.length?(r(c),s()):r()},e.translate=function(c){return arguments.length?(i(c),s()):i()},e.center=function(c){return arguments.length?(n(c),s()):n()},e.clipExtent=function(c){return arguments.length?(c==null?a=l=h=d=null:(a=+c[0][0],l=+c[0][1],h=+c[1][0],d=+c[1][1]),s()):a==null?null:[[a,l],[h,d]]};function s(){var c=I*r(),u=e(on(e.rotate()).invert([0,0]));return o(a==null?[[u[0]-c,u[1]-c],[u[0]+c,u[1]+c]]:t===nt?[[Math.max(u[0]-c,a),l],[Math.min(u[0]+c,h),d]]:[[a,Math.max(u[1]-c,l)],[h,Math.min(u[1]+c,d)]])}return s()}function Ot(t){return t}function rt(t){if(t==null)return Ot;var e,n,r=t.scale[0],i=t.scale[1],o=t.translate[0],a=t.translate[1];return function(l,h){h||(e=n=0);var d=2,s=l.length,c=new Array(s);for(c[0]=(e+=l[0])*r+o,c[1]=(n+=l[1])*i+a;d<s;)c[d]=l[d],++d;return c}}function Dn(t,e){for(var n,r=t.length,i=r-e;i<--r;)n=t[i],t[i++]=t[r],t[r]=n}function Ft(t,e){return typeof e=="string"&&(e=t.objects[e]),e.type==="GeometryCollection"?{type:"FeatureCollection",features:e.geometries.map(function(n){return An(t,n)})}:An(t,e)}function An(t,e){var n=e.id,r=e.bbox,i=e.properties==null?{}:e.properties,o=Gt(t,e);return n==null&&r==null?{type:"Feature",properties:i,geometry:o}:r==null?{type:"Feature",id:n,properties:i,geometry:o}:{type:"Feature",id:n,bbox:r,properties:i,geometry:o}}function Gt(t,e){var n=rt(t.transform),r=t.arcs;function i(s,c){c.length&&c.pop();for(var u=r[s<0?~s:s],p=0,f=u.length;p<f;++p)c.push(n(u[p],p));s<0&&Dn(c,f)}function o(s){return n(s)}function a(s){for(var c=[],u=0,p=s.length;u<p;++u)i(s[u],c);return c.length<2&&c.push(c[0]),c}function l(s){for(var c=a(s);c.length<4;)c.push(c[0]);return c}function h(s){return s.map(l)}function d(s){var c=s.type,u;switch(c){case"GeometryCollection":return{type:c,geometries:s.geometries.map(d)};case"Point":u=o(s.coordinates);break;case"MultiPoint":u=s.coordinates.map(o);break;case"LineString":u=a(s.arcs);break;case"MultiLineString":u=s.arcs.map(a);break;case"Polygon":u=h(s.arcs);break;case"MultiPolygon":u=s.arcs.map(h);break;default:return null}return{type:c,coordinates:u}}return d(e)}function oe(t){if("type"in t&&t.type==="FeatureCollection")return t;let e=t,n=typeof e.object=="string"?e.topology.objects[e.object]:e.object;if(!n)throw new Error("The named TopoJSON object does not exist in this topology.");let r=Ft(e.topology,n);return r.type==="FeatureCollection"?r:{type:"FeatureCollection",features:[r]}}function Tn(t){return t.reduce((e,n)=>e+(n??0),0)}function it(t,e,n,r){if(t===null||r<=0)return null;if(r===1||n===e)return r-1;let i=Math.round((t-e)/(n-e)*(r-1));return Math.min(Math.max(i,0),r-1)}function Bn(t,e,n,r){let i=t.length;return t.map((o,a)=>{let l=e.filter(h=>it(h,n,r,i)===a);return{index:a,color:o,from:l.length?Math.min(...l):null,to:l.length?Math.max(...l):null,matches:l.length}})}function On(t,e){if(t.matches===0||t.from===null||t.to===null)return"No regions in this band";let n=t.from===t.to?e(t.from):`${e(t.from)} to ${e(t.to)}`;return`Highlight ${t.matches} ${t.matches===1?"region":"regions"}, ${n}`}function Fn(t,e,n,r=4){let i=0;t.right>e.right-r&&(i=e.right-r-t.right),t.left+i<e.left+r&&(i=e.left+r-t.left);let o=t.top<e.top+r?"below":"above";return{dx:i,side:o}}var $r=["puducherry"];function jn(t){let e=t.toLowerCase();return $r.some(n=>e.includes(n))}function ot(t){let e=1/0,n=1/0,r=-1/0,i=-1/0;for(let[o,a]of t)o<e&&(e=o),o>r&&(r=o),a<n&&(n=a),a>i&&(i=a);return[e,n,r,i]}function at(t){let e=0;for(let n of t){if(n.length===0)continue;let[r,i,o,a]=ot(n),l=Math.max(o-r,a-i);l>e&&(e=l)}return e}function Gn(t){let e=0;for(let n=0;n<t.length;n++){let[r,i]=t[n],[o,a]=t[(n+1)%t.length];e+=r*a-o*i}return e/2}function $n(t,e){let n=null,r=0;for(let h of t){if(h.length<3)continue;let d=Math.abs(Gn(h));d>r&&(r=d,n=h)}if(!n||r===0)return e;let i=Gn(n),o=0,a=0;for(let h=0;h<n.length;h++){let[d,s]=n[h],[c,u]=n[(h+1)%n.length],p=d*u-c*s;o+=(d+c)*p,a+=(s+u)*p}let l=[o/(6*i),a/(6*i)];return Number.isFinite(l[0])&&Number.isFinite(l[1])?l:e}function qr(t,e){let[n,r]=t,[i,o,a,l]=e,h=Math.max(i-n,0)+Math.max(n-a,0),d=Math.max(o-r,0)+Math.max(r-l,0);return Math.hypot(h,d)}function qn(t,e){let n=1/0;for(let r of e){let i=qr(t,r);i<n&&(n=i)}return n}var zr=[0,Math.PI/6,-Math.PI/6,Math.PI/3,-Math.PI/3,Math.PI/2,-Math.PI/2,2*Math.PI/3,-(2*Math.PI)/3,5*Math.PI/6,-(5*Math.PI)/6,Math.PI];function zn(t){let{anchor:e,clearance:n,halfSize:r,viewBox:i,centre:o,isBlocked:a}=t,l=e[0]-o[0],h=e[1]-o[1],d=l===0&&h===0?0:Math.atan2(h,l);for(let s of zr){let c=d+s,u=[Nn(e[0]+Math.cos(c)*n,r[0],i[0]-r[0]),Nn(e[1]+Math.sin(c)*n,r[1],i[1]-r[1])];if(!a(u))return u}return null}function Nn(t,e,n){return Math.min(Math.max(t,e),n)}function Hn(t,e,n=8){let r=()=>t.map(o=>[...o]);if(e<=0)return r();let i=at(t);return i<=0||i>=e?r():t.map(o=>{let[a,l,h,d]=ot(o),s=Math.max(h-a,d-l),c=s<=0?1:Math.min(e/s,n),u=(a+h)/2,p=(l+d)/2;return o.map(([f,m])=>[u+(f-u)*c,p+(m-p)*c])})}function Hr(t){let e=[...t].sort((h,d)=>h[0]-d[0]||h[1]-d[1]),n=[];for(let h of e){let d=n.at(-1);(!d||d[0]!==h[0]||d[1]!==h[1])&&n.push(h)}if(n.length<3)return n.map(h=>[...h]);let r=(h,d,s)=>(d[0]-h[0])*(s[1]-h[1])-(d[1]-h[1])*(s[0]-h[0]),i=h=>{let d=[];for(let s of h){for(;d.length>=2&&r(d[d.length-2],d[d.length-1],s)<=0;)d.pop();d.push(s)}return d},o=i(n),a=i([...n].reverse()),l=[...o.slice(0,-1),...a.slice(0,-1)];return l.length>=3?l:n.map(h=>[...h])}function Un(t,e){if(t.length<2||e<=0)return null;let n=at(t);if(n<=0||n>=e)return null;let r=Hr(t.flat());return r.length>=3?r:null}function Nt(t){let e="";for(let n of t)if(n.length!==0){e+=`M${n[0][0]},${n[0][1]}`;for(let r=1;r<n.length;r++)e+=`L${n[r][0]},${n[r][1]}`;e+="Z"}return e}var Ur="http://www.w3.org/2000/svg",H={width:960,height:640,padding:28},Be=["#d9f1ed","#b9e3dd","#8fd1c8","#5bb9ae","#2f9c90","#147b71","#075b55"],st=new Intl.NumberFormat("en-IN").format,Vn=12,jt=22,Vr=14,lt=7;function Wn(t,e){let n=t.geometry;if(!n)return[];let r=n.type==="Polygon"?[n.coordinates]:n.type==="MultiPolygon"?n.coordinates:[],i=[];for(let o of r)for(let a of o){let l=[];for(let h of a){let d=e(h);d&&Number.isFinite(d[0])&&Number.isFinite(d[1])&&l.push([d[0],d[1]])}l.length>0&&i.push(l)}return i}var Wr=0;function Kn(t,e,n,r,i){if(typeof i=="function"){let a={min:n,max:r,feature:e.feature,id:e.id};return i(t,a)}let o=it(t,n,r,i.length);return o===null?"var(--india-map-empty)":i[o]??"var(--india-map-empty)"}function Yn(t){return typeof t.colorScale=="function"?Be:t.colorScale??Be}function Xn(t){return Bt().fitExtent([[H.padding,H.padding],[H.width-H.padding,H.height-H.padding]],t)}function Jn(t,e,n=0){let r=oe(t.geometry),i=tt(e);return r.features.map(o=>{let a=i.centroid(o),l=i.bounds(o),h=[(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2],d={id:t.getId(o),label:t.getLabel(o),value:t.getValue(o),meta:t.getMeta?.(o),feature:o},s=n>0&&!jn(d.id),c=s?Hn(Wn(o,e),n):Wn(o,e),u=Un(c,jt);return{...d,path:s?Nt(c):i(o)??"",hitPath:u?Nt([u]):null,centroid:c.length>0?$n(c,a.every(Number.isFinite)?a:h):a.every(Number.isFinite)?a:h,partBounds:c.map(ot),extent:at(c)}})}function Zn(t,e){let n=tt(e);return oe(t.geometry).features.map(r=>({id:t.getId(r),label:t.getLabel(r),description:t.getDescription(r),path:n(r)??""}))}function Kr(t){let e=t%100;return e>=11&&e<=13?`${t}th`:`${t}${["th","st","nd","rd"][t%10]??"th"}`}function Yr(t,e){let n=document.createDocumentFragment(),r=document.createElement("strong");r.textContent=t.label;let i=document.createElement("b");if(i.textContent=t.value===null?"No data":e(t.value),n.append(r,i),t.share!==null){let o=document.createElement("span");o.className="india-choropleth__tooltip-bar",o.setAttribute("aria-hidden","true");let a=document.createElement("span");a.style.width=`${Math.max(t.share,1.5)}%`,o.append(a);let l=document.createElement("small"),h=[`${t.share.toFixed(1)}% of total`];t.rank!==null&&h.push(`${Kr(t.rank)} of ${t.rankedCount}`),l.textContent=h.join(" \xB7 "),n.append(o,l)}return n}function N(t,e){let n=document.createElement(t);for(let[r,i]of Object.entries(e??{}))n.setAttribute(r,i);return n}function G(t,e){let n=document.createElementNS(Ur,t);for(let[r,i]of Object.entries(e??{}))n.setAttribute(r,i);return n}function Xr(t,e){typeof e=="string"?t.textContent=e:t.appendChild(e)}var de=class{containerEl;options;instanceId=`india-choropleth-${++Wr}`;tooltipId=`${this.instanceId}-tooltip`;hatchId=`${this.instanceId}-hatch`;activeDrillDownId;activeSelectedId;inspectedId=null;loadedDistricts=null;loadedDistrictReferenceOverlay=null;loadingState=null;loadError=null;districtGeneration=0;overlayGeneration=0;restoreFocusId=null;destroyed=!1;attemptedDistrictLoadForId=null;attemptedOverlayLoadForId=null;pathRefs=new Map;derived;rootEl;toolbarEl;canvasEl;legendEl=null;swatchEls=[];bucketEls=[];activeBucket=null;bandsKey=null;insightsEl=null;tooltipAnchorEl=null;tooltipContentEl=null;svgRootEl=null;selectionGroupEl=null;selectionPathEls=[];constructor(e,n){let r=typeof e=="string"?document.querySelector(e):e;if(!r)throw new Error(`IndiaChoropleth: container ${typeof e=="string"?`"${e}"`:""} was not found.`);this.containerEl=r,this.options=n,this.activeDrillDownId=n.drillDownId!==void 0?n.drillDownId:n.defaultDrillDownId??null,this.activeSelectedId=n.selectedId!==void 0?n.selectedId:n.defaultSelectedId??null,this.buildShell(),this.renderStructure()}update(e){"loadDistricts"in e&&e.loadDistricts!==this.options.loadDistricts&&(this.attemptedDistrictLoadForId=null),"loadDistrictReferenceOverlay"in e&&e.loadDistrictReferenceOverlay!==this.options.loadDistrictReferenceOverlay&&(this.attemptedOverlayLoadForId=null),this.options={...this.options,...e},"drillDownId"in e&&e.drillDownId!==void 0&&(this.activeDrillDownId=e.drillDownId),"selectedId"in e&&e.selectedId!==void 0&&(this.activeSelectedId=e.selectedId),this.renderStructure()}select(e){let n=this.derived.regions.find(r=>r.id===e)??null;this.setActiveSelectedId(n?.id??null),n&&this.options.onSelectedChange?.(n,this.derived.level),this.applyInteractionState()}drillDown(e){if(e===null){this.goBack();return}let n=this.derived.stateRegions.find(r=>r.id===e);n&&(this.setActiveDrillDownId(e),this.options.onDrillDownChange?.(e,n),this.renderStructure())}getSelected(){return this.derived.selected}getInspected(){return this.derived.inspected}destroy(){this.destroyed=!0,this.districtGeneration+=1,this.overlayGeneration+=1,this.pathRefs.clear(),this.containerEl.textContent=""}setActiveDrillDownId(e){this.options.drillDownId===void 0&&(this.activeDrillDownId=e)}setActiveSelectedId(e){this.options.selectedId===void 0&&(this.activeSelectedId=e)}buildShell(){this.rootEl=N("section"),this.toolbarEl=N("div",{class:"india-choropleth__toolbar"}),this.canvasEl=N("div",{class:"india-choropleth__canvas"}),this.canvasEl.addEventListener("mouseleave",()=>{this.options.interactive!==!1&&this.inspect(null)}),this.rootEl.append(this.toolbarEl,this.canvasEl),this.containerEl.textContent="",this.containerEl.appendChild(this.rootEl)}recompute(){let e=this.options,n=oe(e.states.geometry),r=e.referenceOverlay?oe(e.referenceOverlay.geometry):null,i=Xn({type:"FeatureCollection",features:[...n.features,...r?.features??[]]}),o=Jn(e.states,i,e.minPartExtent??0),a=e.referenceOverlay?Zn(e.referenceOverlay,i):[],l=o.find(S=>S.id===this.activeDrillDownId)??null,d=!!(l&&this.activeDrillDownId)?"district":"state",s=this.loadedDistricts?.stateId===this.activeDrillDownId?this.loadedDistricts.layer:null,c=this.loadedDistrictReferenceOverlay?.stateId===this.activeDrillDownId?this.loadedDistrictReferenceOverlay.overlay:null,u=s?oe(s.geometry):null,p=c?oe(c.geometry):null,f=u?Xn({type:"FeatureCollection",features:[...u.features,...p?.features??[]]}):null,m=d==="district"&&s&&f?Jn(s,f,e.minDistrictPartExtent??e.minPartExtent??0):d==="state"?o:[],v=d==="district"&&c&&f?Zn(c,f):[],b=m.find(S=>S.id===this.activeSelectedId)??null,y=m.find(S=>S.id===this.inspectedId)??null;this.inspectedId&&!y&&(this.inspectedId=null);let x=m.map(S=>S.value).filter(S=>S!==null),E=Tn(x),w=x.length?Math.min(...x):0,k=x.length?Math.max(...x):0;this.derived={stateRegions:o,referenceRegions:a,drilledState:l,level:d,regions:m,visibleReferenceRegions:d==="state"?a:v,selected:b,inspected:y,total:E,min:w,max:k,canDrill:!!(e.loadDistricts&&d==="state"),mergedReferenceIds:new Set(e.referenceOverlayMergeIds??[]),buckets:Bn(Yn(e),m.map(S=>S.value),w,k)};let L=[d,this.activeDrillDownId??"",typeof e.colorScale=="function"?"function":(e.colorScale??Be).join(",")].join("|");L!==this.bandsKey&&(this.bandsKey=L,this.activeBucket=null),this.activeBucket!==null&&this.activeBucket>=this.derived.buckets.length&&(this.activeBucket=null)}loadDistrictsFor(e){let n=this.options;if(!n.loadDistricts){this.loadedDistricts=null,this.loadingState=null,this.loadError=null;return}let r=this.derived.stateRegions.find(o=>o.id===e);if(!r)return;let i=++this.districtGeneration;this.loadingState=e,this.loadError=null,this.loadedDistricts=null,n.loadDistricts(e,r).then(o=>{this.destroyed||i!==this.districtGeneration||(this.loadedDistricts={stateId:e,layer:o},this.loadingState=null,this.renderStructure())}).catch(o=>{this.destroyed||i!==this.districtGeneration||(this.loadError=o instanceof Error?o:new Error("Unable to load districts."),this.loadingState=null,this.renderStructure())})}loadDistrictReferenceOverlayFor(e){let n=this.options;if(!n.loadDistrictReferenceOverlay){this.loadedDistrictReferenceOverlay=null;return}let r=this.derived.stateRegions.find(o=>o.id===e);if(!r)return;let i=++this.overlayGeneration;this.loadedDistrictReferenceOverlay=null,n.loadDistrictReferenceOverlay(e,r).then(o=>{this.destroyed||i!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:e,overlay:o},this.renderStructure())}).catch(()=>{this.destroyed||i!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:e,overlay:null},this.renderStructure())})}inspect(e){let n=e?.id??null;n===null&&this.inspectedId===null||(this.inspectedId=n,this.derived.inspected=e,this.options.onInspect?.(e??null,this.derived.level),this.applyInteractionState())}toViewBox(e){let n=this.canvasEl.querySelector("svg");if(!n)return null;let r=n.getBoundingClientRect();if(r.width===0||r.height===0)return null;let i=Math.min(r.width/H.width,r.height/H.height),o=(r.width-H.width*i)/2,a=(r.height-H.height*i)/2;return[(e.clientX-r.left-o)/i,(e.clientY-r.top-a)/i]}smallRegionNear(e){let n=null,r=1/0;for(let i of this.derived.regions){if(i.extent<=0||i.extent>=jt)continue;let o=qn(e,i.partBounds);o<=Vr&&o<r&&(r=o,n=i)}return n}activate(e){let n=this.options;n.onRegionClick?.(e,this.derived.level),this.setActiveSelectedId(e.id),n.onSelectedChange?.(e,this.derived.level),this.derived.level==="state"&&n.loadDistricts?(this.setActiveSelectedId(null),this.setActiveDrillDownId(e.id),n.onDrillDownChange?.(e.id,e),this.renderStructure()):this.applyInteractionState()}goBack(){let e=this.derived.drilledState??void 0;this.setActiveDrillDownId(null),this.setActiveSelectedId(e?.id??null),this.inspectedId=e?.id??null,this.restoreFocusId=e?.id??null,this.options.onDrillDownChange?.(null,e),this.renderStructure()}renderStructure(){if(this.destroyed)return;this.recompute();let e=this.options;this.activeDrillDownId&&e.loadDistricts&&this.attemptedDistrictLoadForId!==this.activeDrillDownId&&(this.attemptedDistrictLoadForId=this.activeDrillDownId,this.loadDistrictsFor(this.activeDrillDownId)),this.activeDrillDownId||(this.loadedDistricts=null,this.loadingState=null,this.loadError=null,this.attemptedDistrictLoadForId=null),this.activeDrillDownId&&e.loadDistrictReferenceOverlay&&this.attemptedOverlayLoadForId!==this.activeDrillDownId&&(this.attemptedOverlayLoadForId=this.activeDrillDownId,this.loadDistrictReferenceOverlayFor(this.activeDrillDownId)),(!this.activeDrillDownId||!e.loadDistrictReferenceOverlay)&&(this.loadedDistrictReferenceOverlay=null,this.attemptedOverlayLoadForId=null);let n=e.interactive!==!1;if(this.rootEl.className=["india-choropleth",!n&&"india-choropleth--static",e.className].filter(Boolean).join(" "),this.loadingState?this.rootEl.setAttribute("aria-busy","true"):this.rootEl.removeAttribute("aria-busy"),this.renderToolbar(),this.renderCanvas(),this.renderLegend(),this.restoreFocusId&&this.derived.level==="state"){let r=this.restoreFocusId;this.restoreFocusId=null,this.pathRefs.get(r)?.focus()}}renderToolbar(){let e=this.options;if(this.toolbarEl.textContent="",e.showBreadcrumb===!1)return;let n=N("nav",{class:"india-choropleth__breadcrumb","aria-label":"Map hierarchy"});if(this.derived.drilledState){let r=N("button",{class:"india-choropleth__back",type:"button"});r.textContent="All states",r.addEventListener("click",()=>this.goBack());let i=N("span",{"aria-hidden":"true"});i.textContent="/";let o=N("span",{"aria-current":"page"});o.textContent=this.derived.drilledState.label,n.append(r,i,o)}else{let r=N("span");r.textContent="All states",n.append(r)}this.toolbarEl.append(n)}renderCanvas(){let e=this.options,n=e.interactive!==!1;this.canvasEl.textContent="",this.pathRefs.clear(),this.bucketEls=[],this.svgRootEl=null,this.tooltipAnchorEl=null,this.tooltipContentEl=null,this.selectionGroupEl=null,this.selectionPathEls=[];let i=!!(this.derived.drilledState&&this.activeDrillDownId)&&(!this.loadedDistricts||this.loadedDistricts.stateId!==this.activeDrillDownId||this.loadError),o=!i&&this.derived.regions.length===0;if(i||o){let m=N("div",{class:"india-choropleth__status",role:i&&this.loadError?"alert":"status"});m.textContent=o?"No district data is available for this state.":this.loadError?this.loadError.message:this.loadingState?"Loading districts\u2026":"District data is unavailable for this state.",this.canvasEl.append(m),this.applyInteractionState();return}let a=G("svg",{class:"india-choropleth__svg",viewBox:`0 0 ${H.width} ${H.height}`,role:"group","aria-label":e.ariaLabel??"Interactive choropleth map"});if(this.svgRootEl=a,n&&(a.addEventListener("keydown",m=>{m.key==="Escape"&&(m.preventDefault(),this.inspect(null))}),a.addEventListener("click",m=>{if(m.target!==a)return;let v=this.toViewBox(m),b=v?this.smallRegionNear(v):null;if(b){this.activate(b);return}this.options.onBackgroundClick?.(),this.activeSelectedId!==null&&(this.setActiveSelectedId(null),this.options.onSelectedChange?.(null,this.derived.level),this.applyInteractionState())})),this.derived.visibleReferenceRegions.length>0){let m=G("defs"),v=G("pattern",{id:this.hatchId,width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)"});v.append(G("rect",{width:"8",height:"8",fill:"var(--india-map-reference-bg)"}),G("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:"var(--india-map-reference-hatch)","stroke-width":"2"})),m.append(v),a.append(m);let b=G("g",{class:"india-choropleth__reference-fill",role:"group","aria-label":"Non-statistical reference context."});for(let y of this.derived.visibleReferenceRegions)b.append(G("path",{d:y.path,fill:e.referenceOverlayFill==="solid"?"var(--india-map-reference-bg)":`url(#${this.hatchId})`,"aria-label":`${y.label}.${y.description?` ${y.description}`:""}`,role:"img"}));a.append(b)}let l=n?this.derived.regions.filter(m=>m.hitPath):[];if(l.length>0){let m=G("g",{class:"india-choropleth__hit-areas","aria-hidden":"true"});for(let v of l){let b=G("path",{d:v.hitPath,fill:"none","pointer-events":"all",tabindex:"-1"});b.addEventListener("mouseenter",()=>this.inspect(v)),b.addEventListener("mouseleave",()=>this.inspect(null)),b.addEventListener("click",()=>this.activate(v)),m.append(b)}a.append(m)}let h=m=>it(m.value,this.derived.min,this.derived.max,Yn(e).length);for(let m of this.derived.regions){let v=this.derived.canDrill?"Activate to view districts.":"Activate to select.",b=m.value===null?"No data":(e.formatValue??st)(m.value),y=G("path",{class:"india-choropleth__region",d:m.path,fill:Kn(m.value,m,this.derived.min,this.derived.max,e.colorScale??Be),tabindex:n?"0":"-1","aria-label":`${m.label}, ${b}. ${v}`});n&&y.setAttribute("role","button"),this.derived.mergedReferenceIds.has(m.id)&&y.classList.add("india-choropleth__region--reference-merged"),n&&(y.setAttribute("aria-pressed",m.id===this.derived.selected?.id?"true":"false"),y.addEventListener("mouseenter",()=>this.inspect(m)),y.addEventListener("mouseleave",()=>this.inspect(null)),y.addEventListener("focus",()=>this.inspect(m)),y.addEventListener("blur",()=>this.inspect(null)),y.addEventListener("click",()=>this.activate(m)),y.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),this.activate(m))})),a.append(y),this.pathRefs.set(m.id,y),this.bucketEls.push({el:y,bucket:h(m)})}let d=this.derived.regions.filter(m=>m.extent>0&&m.extent<lt);if(d.length>0){let m=G("g",{class:"india-choropleth__small-markers","aria-hidden":"true"});for(let v of d){let b=G("circle",{cx:String(v.centroid[0]),cy:String(v.centroid[1]),r:String(lt/2),fill:Kn(v.value,v,this.derived.min,this.derived.max,e.colorScale??Be)});n&&(b.addEventListener("mouseenter",()=>this.inspect(v)),b.addEventListener("mouseleave",()=>this.inspect(null)),b.addEventListener("click",()=>this.activate(v))),this.bucketEls.push({el:b,bucket:h(v)}),m.append(b)}a.append(m)}if(e.showRegionValues){let m=G("g",{class:`india-choropleth__region-values${this.derived.level==="district"?" india-choropleth__region-values--district":""}`,"aria-hidden":"true"}),v=G("g",{class:"india-choropleth__value-leaders","aria-hidden":"true"});for(let b of this.derived.regions){if(!b.centroid.every(Number.isFinite))continue;let y=b.value===null?"\u2014":(e.formatValue??st)(b.value),x=this.placeRegionValue(b,y);if(!x)continue;let E=G("text",{x:String(x.at[0]),y:String(x.at[1]),"text-anchor":"middle","dominant-baseline":"central"});if(E.textContent=y,m.append(E),this.bucketEls.push({el:E,bucket:h(b)}),x.leader){let w=G("line",{x1:String(x.leader[0][0]),y1:String(x.leader[0][1]),x2:String(x.leader[1][0]),y2:String(x.leader[1][1])});this.bucketEls.push({el:w,bucket:h(b)}),v.append(w)}}a.append(v,m)}if(this.derived.visibleReferenceRegions.length>0){let m=G("g",{class:"india-choropleth__reference-outline","aria-hidden":"true"});for(let v of this.derived.visibleReferenceRegions)m.append(G("path",{d:v.path,fill:"none"}));a.append(m)}let s=G("g",{class:"india-choropleth__selection","aria-hidden":"true"}),c=G("path",{class:"india-choropleth__selection-halo",fill:"none"}),u=G("path",{class:"india-choropleth__selection-ring",fill:"none"});s.append(c,u),a.append(s),this.selectionGroupEl=s,this.selectionPathEls=[c,u],this.canvasEl.append(a);let p=N("div",{class:"india-choropleth__tooltip-anchor"});p.style.display="none";let f=N("div",{id:this.tooltipId,class:"india-choropleth__tooltip"});p.append(f),this.canvasEl.append(p),this.tooltipAnchorEl=p,this.tooltipContentEl=f,this.applyInteractionState()}placeRegionValue(e,n){let r=e.extent>0&&e.extent<jt,i=Math.max(n.length*3.1,3),o=5.5,a=e.partBounds.some(([f,m,v,b])=>v-f>=i*2&&b-m>=o*2);if(!r&&a)return{at:e.centroid};let l=r?zn({anchor:e.centroid,clearance:Math.max(e.extent,lt)/2+4+i,halfSize:[i,o],viewBox:[H.width,H.height],centre:[H.width/2,H.height/2],isBlocked:f=>this.coversAnotherRegion(e,f,i,o)}):null;if(!l)return a?{at:e.centroid}:null;let h=Math.max(e.extent,lt)/2+1,d=l[0]-e.centroid[0],s=l[1]-e.centroid[1],c=Math.hypot(d,s);if(c<=h+i)return{at:l};let u=[e.centroid[0]+d/c*h,e.centroid[1]+s/c*h],p=[l[0]-d/c*(i+1.5),l[1]-s/c*(i+1.5)];return{at:l,leader:[u,p]}}coversAnotherRegion(e,n,r,i){let o=[n,[n[0]-r,n[1]-i],[n[0]+r,n[1]+i],[n[0]+r,n[1]-i],[n[0]-r,n[1]+i]];for(let a of this.derived.regions)if(a.id!==e.id){for(let l of o)if(a.partBounds.some(([h,d,s,c])=>l[0]>=h&&l[0]<=s&&l[1]>=d&&l[1]<=c))return!0}return!1}renderLegend(){let e=this.options;if(this.legendEl&&(this.legendEl.remove(),this.legendEl=null),e.showLegend===!1)return;let[n,r]=e.legendLabels??["Lower","Higher"],i=N("div",{class:"india-choropleth__legend",role:"group","aria-label":`Color scale: ${n} to ${r} values`}),o=N("span");o.textContent=n;let a=e.interactive!==!1,l=N("div",{class:"india-choropleth__swatches"});a||l.setAttribute("aria-hidden","true"),this.swatchEls=[];for(let d of this.derived.buckets){let s=N(a?"button":"i",{class:"india-choropleth__swatch"});if(s.style.backgroundColor=d.color,a){s.setAttribute("type","button");let c=On(d,e.formatValue??st);s.setAttribute("aria-label",c),s.setAttribute("title",c),d.matches===0&&s.setAttribute("aria-disabled","true"),s.addEventListener("click",()=>{d.matches!==0&&(this.activeBucket=this.activeBucket===d.index?null:d.index,this.applyInteractionState())}),this.swatchEls.push(s)}l.append(s)}let h=N("span");if(h.textContent=r,i.append(o,l,h),this.derived.visibleReferenceRegions.length>0){let d=N("i",{class:`india-choropleth__reference-key${e.referenceOverlayFill==="solid"?" india-choropleth__reference-key--solid":""}`,"aria-hidden":"true"}),s=N("span");s.textContent=e.referenceOverlayLegendLabel??"Reference context \xB7 data unavailable",i.append(d,s)}this.insightsEl?this.rootEl.insertBefore(i,this.insightsEl):this.rootEl.append(i),this.legendEl=i,a&&i.addEventListener("keydown",d=>{d.key==="Escape"&&(d.preventDefault(),this.activeBucket=null,this.applyInteractionState())}),this.applyLegendState()}renderInsights(){let e=this.options;if(this.insightsEl&&(this.insightsEl.remove(),this.insightsEl=null),!e.renderInsights)return;let n=N("aside",{class:"india-choropleth__insights","aria-live":"polite"});e.renderInsights(this.computeInsightContext(),n),this.rootEl.append(n),this.insightsEl=n}applyInteractionState(){if(this.destroyed)return;this.derived.selected=this.derived.regions.find(n=>n.id===this.activeSelectedId)??null,this.derived.inspected=this.derived.regions.find(n=>n.id===this.inspectedId)??null;let e=this.options.interactive!==!1;for(let[n,r]of this.pathRefs){let i=n===this.derived.inspected?.id,o=n===this.derived.selected?.id;r.classList.toggle("india-choropleth__region--inspected",i),r.classList.toggle("india-choropleth__region--selected",o),e&&(r.setAttribute("aria-pressed",o?"true":"false"),i?r.setAttribute("aria-describedby",this.tooltipId):r.removeAttribute("aria-describedby"))}for(let{el:n,bucket:r}of this.bucketEls)n.classList.toggle("india-choropleth__dimmed",this.activeBucket!==null&&r!==this.activeBucket);this.svgRootEl?.classList.toggle("india-choropleth__svg--filtered",this.activeBucket!==null),this.applyLegendState(),this.renderSelectionRing(),this.renderTooltip(),this.renderInsights(),this.options.onInsight?.(this.computeInsightContext())}applyLegendState(){if(this.legendEl)for(let[e,n]of this.swatchEls.entries()){let r=this.activeBucket===e;n.classList.toggle("india-choropleth__swatch--active",r),n.classList.toggle("india-choropleth__swatch--muted",this.activeBucket!==null&&!r),n.setAttribute("aria-pressed",r?"true":"false")}}renderTooltip(){if(!this.tooltipAnchorEl||!this.tooltipContentEl)return;let e=this.derived.inspected;if(!e){this.tooltipAnchorEl.style.display="none";return}let n=this.toTooltipContext(e);this.tooltipAnchorEl.style.display="",this.tooltipAnchorEl.style.left=`${e.centroid[0]/H.width*100}%`,this.tooltipAnchorEl.style.top=`${e.centroid[1]/H.height*100}%`,this.tooltipContentEl.textContent="";let r=this.options.renderTooltip?this.options.renderTooltip(n):Yr(n,this.options.formatValue??st);Xr(this.tooltipContentEl,r),this.positionTooltip()}renderSelectionRing(){let e=this.selectionGroupEl;if(!e)return;let n=this.derived.selected;if(!n){e.style.display="none";return}e.style.display="";for(let r of this.selectionPathEls)r.setAttribute("d",n.path);e.classList.toggle("india-choropleth__selection--lifted",n.id===this.derived.inspected?.id)}positionTooltip(){let e=this.tooltipAnchorEl;if(!e)return;e.style.removeProperty("--india-map-tooltip-dx"),e.style.removeProperty("--india-map-tooltip-dy");let n=e.getBoundingClientRect(),r=this.canvasEl.getBoundingClientRect();if(n.width===0||r.width===0)return;let{dx:i,side:o}=Fn(n,r,Vn);i!==0&&e.style.setProperty("--india-map-tooltip-dx",`${Math.round(i)}px`),o==="below"&&e.style.setProperty("--india-map-tooltip-dy",`${Vn}px`)}toTooltipContext(e){let n=this.derived.regions.filter(i=>i.value!==null),r=e.value===null?null:n.filter(i=>(i.value??0)>(e.value??0)).length+1;return{...e,level:this.derived.level,total:this.derived.total,share:e.value===null||this.derived.total===0?null:e.value/this.derived.total*100,rank:r,rankedCount:n.length}}computeInsightContext(){let e=this.derived.inspected??this.derived.selected;return e?{...this.toTooltipContext(e),selected:e.id===this.derived.selected?.id}:null}};var ct="https://cdn.jsdelivr.net/gh/shashankbudem/bharat-choropleth@v0.1.0/data/generated",Qn="State/UT and district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).";function er(t){return t.replace(/\/+$/,"")}function tr(t){return`${er(t)}/current-2019-states/states.topo.json`}function Jr(t,e){return`${er(t)}/current-2019-districts/districts/${e}.topo.json`}async function nr(t,e){if(typeof fetch!="function")throw new Error("BharatChoropleth: no global fetch is available, so boundary data cannot be downloaded. Pass `geometry` with data you loaded yourself.");let n=await fetch(t,{signal:e});if(!n.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${t} (HTTP ${n.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return n.json()}function $t(t,e){if(!t||typeof t!="object")throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.");let n=t;if(n.type==="FeatureCollection"||"topology"in n&&"object"in n)return t;if(n.type==="Topology"&&n.objects&&typeof n.objects=="object"){let r=n.objects,i=e in r?e:Object.keys(r)[0];if(!i)throw new Error("BharatChoropleth: the TopoJSON topology contains no objects.");return{topology:t,object:i}}throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.")}async function rr(t,e,n){return typeof t=="string"?$t(await nr(t,n),e):t instanceof Promise?$t(await t,e):t}function ir(t){return typeof t=="object"&&t!==null&&!(t instanceof Promise)}async function or(t,e,n){return $t(await nr(Jr(t,e),n),"districts")}var qt=[{id:"in-cs-01-jammu-and-kashmir",name:"Jammu & Kashmir",slug:"jammu-and-kashmir"},{id:"in-cs-02-himachal-pradesh",name:"Himachal Pradesh",slug:"himachal-pradesh"},{id:"in-cs-03-punjab",name:"Punjab",slug:"punjab"},{id:"in-cs-04-chandigarh",name:"Chandigarh",slug:"chandigarh"},{id:"in-cs-05-uttarakhand",name:"Uttarakhand",slug:"uttarakhand"},{id:"in-cs-06-haryana",name:"Haryana",slug:"haryana"},{id:"in-cs-07-delhi",name:"Delhi",slug:"delhi"},{id:"in-cs-08-rajasthan",name:"Rajasthan",slug:"rajasthan"},{id:"in-cs-09-uttar-pradesh",name:"Uttar Pradesh",slug:"uttar-pradesh"},{id:"in-cs-10-bihar",name:"Bihar",slug:"bihar"},{id:"in-cs-11-sikkim",name:"Sikkim",slug:"sikkim"},{id:"in-cs-12-arunachal-pradesh",name:"Arunachal Pradesh",slug:"arunachal-pradesh"},{id:"in-cs-13-nagaland",name:"Nagaland",slug:"nagaland"},{id:"in-cs-14-manipur",name:"Manipur",slug:"manipur"},{id:"in-cs-15-mizoram",name:"Mizoram",slug:"mizoram"},{id:"in-cs-16-tripura",name:"Tripura",slug:"tripura"},{id:"in-cs-17-meghalaya",name:"Meghalaya",slug:"meghalaya"},{id:"in-cs-18-assam",name:"Assam",slug:"assam"},{id:"in-cs-19-west-bengal",name:"West Bengal",slug:"west-bengal"},{id:"in-cs-20-jharkhand",name:"Jharkhand",slug:"jharkhand"},{id:"in-cs-21-odisha",name:"Odisha",slug:"odisha"},{id:"in-cs-22-chhattisgarh",name:"Chhattisgarh",slug:"chhattisgarh"},{id:"in-cs-23-madhya-pradesh",name:"Madhya Pradesh",slug:"madhya-pradesh"},{id:"in-cs-24-gujarat",name:"Gujarat",slug:"gujarat"},{id:"in-cs-26-dadra-and-nagar-haveli-and-daman-and-diu",name:"Dadra and Nagar Haveli and Daman and Diu",slug:"dadra-and-nagar-haveli-and-daman-and-diu"},{id:"in-cs-27-maharashtra",name:"Maharashtra",slug:"maharashtra"},{id:"in-cs-28-andhra-pradesh",name:"Andhra Pradesh",slug:"andhra-pradesh"},{id:"in-cs-29-karnataka",name:"Karnataka",slug:"karnataka"},{id:"in-cs-30-goa",name:"Goa",slug:"goa"},{id:"in-cs-31-lakshadweep",name:"Lakshadweep",slug:"lakshadweep"},{id:"in-cs-32-kerala",name:"Kerala",slug:"kerala"},{id:"in-cs-33-tamil-nadu",name:"Tamil Nadu",slug:"tamil-nadu"},{id:"in-cs-34-puducherry",name:"Puducherry",slug:"puducherry"},{id:"in-cs-35-andaman-and-nicobar",name:"Andaman & Nicobar",slug:"andaman-and-nicobar"},{id:"in-cs-36-telangana",name:"Telangana",slug:"telangana"},{id:"in-cs-37-ladakh",name:"Ladakh",slug:"ladakh"}],Zr={orissa:"odisha",pondicherry:"puducherry",uttaranchal:"uttarakhand","nct-of-delhi":"delhi","new-delhi":"delhi","delhi-nct":"delhi","jammu-kashmir":"jammu-and-kashmir","j-and-k":"jammu-and-kashmir",jk:"jammu-and-kashmir","andaman-nicobar":"andaman-and-nicobar","andaman-and-nicobar-islands":"andaman-and-nicobar","dadra-and-nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu","daman-and-diu":"dadra-and-nagar-haveli-and-daman-and-diu",dnhdd:"dadra-and-nagar-haveli-and-daman-and-diu","nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu"};function Fe(t){return t.toLowerCase().replace(/&/g," and ").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function zt(t){return t.replace(/-/g,"")}var xe=new Map,Oe=new Map;for(let t of qt)for(let e of[t.slug,Fe(t.name),t.id]){xe.has(e)||xe.set(e,t);let n=zt(e);Oe.has(n)||Oe.set(n,t)}for(let[t,e]of Object.entries(Zr)){let n=xe.get(e);if(!n)continue;xe.has(t)||xe.set(t,n);let r=zt(t);Oe.has(r)||Oe.set(r,n)}function ue(t){let e=Fe(t);return xe.get(e)??Oe.get(zt(e))}function ar(t,e){if(!t.includes("_"))return;let n=t.replace(/_([a-z])/g,(r,i)=>i.toUpperCase());return n!==t&&n in e?n:void 0}function lr(t){return typeof t=="object"&&t!==null&&t.nodeType===1}var sr=["#bharat-choropleth","#map"];function Qr(t){if(lr(t))return t;if(typeof t=="string"){let e=document.querySelector(t);if(e)return e;throw new Error(`BharatChoropleth: container "${t}" was not found.`)}for(let e of sr){let n=document.querySelector(e);if(n)return n}throw new Error(`BharatChoropleth: no container given and none of ${sr.join(", ")} exist. Pass an element or selector: new BharatChoropleth("#map").`)}var Ge=class{ready;engineInstance=null;containerEl;options;dataBaseUrl;usingDefaultData;values=new Map;labelByKey=new Map;writtenAs=new Map;statesAccessor;abortController;getId;getLabel;loadingEl=null;destroyed=!1;_fontColor;_borderColor;_borderWidth;_selectionWidth;_colorScale;constructor(e,n={}){let i=typeof e=="object"&&e!==null&&!lr(e)?{...e}:{...n,container:e??n.container};this.options=i,this.containerEl=Qr(i.container),this.dataBaseUrl=i.dataBaseUrl??ct,this.usingDefaultData=i.geometry===void 0,this.getId=i.getId??(o=>String(o.properties?.id??o.properties?.name)),this.getLabel=i.getLabel??(o=>String(o.properties?.name??o.properties?.id));for(let[o,a]of Object.entries(i.values??{})){let l=this.keyFor(o);this.values.set(l,a),this.writtenAs.set(l,o)}return this._colorScale=i.colorScale,this._fontColor=i.fontColor,this._borderColor=i.borderColor,this._borderWidth=i.borderWidth,this._selectionWidth=i.selectionWidth,this.statesAccessor=new Proxy({},{get:(o,a)=>typeof a=="string"?this.getValue(a):void 0,has:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a)),ownKeys:()=>[...this.labelByKey.values()],getOwnPropertyDescriptor:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a))?{enumerable:!0,configurable:!0,value:this.getValue(a)}:void 0,set:(o,a,l)=>typeof a!="string"?!1:(this.setValue(a,l),!0)}),ir(i.geometry)?(this.abortController=null,this.ready=Promise.resolve(this),this.mount(i.geometry)):(this.abortController=typeof AbortController=="function"?new AbortController:null,this.showLoading(),this.ready=rr(i.geometry??tr(this.dataBaseUrl),"states",this.abortController?.signal).then(o=>this.destroyed?this.proxied??this:(this.mount(o),this.proxied??this)).catch(o=>{if(this.destroyed||o.name==="AbortError")return this.proxied??this;throw this.showError(o),o}),this.ready.catch(()=>{})),this.proxied=new Proxy(this,{get:(o,a,l)=>{if(typeof a=="string"&&!(a in o)){let h=ar(a,o);return h?Reflect.get(o,h,l):this.getValue(a)}return Reflect.get(o,a,l)},set:(o,a,l,h)=>{if(typeof a=="string"&&!(a in o)){let d=ar(a,o);return d?Reflect.set(o,d,l,h):(this.setValue(a,l),!0)}return Reflect.set(o,a,l,h)}}),this.proxied}proxied;keyFor(e){return ue(e)?.id??Fe(e)}keyForFeature(e){let n=this.getId(e);return ue(n)?.id??ue(this.getLabel(e))?.id??Fe(this.getLabel(e))}getValue(e){return this.values.get(this.keyFor(e))??null}setValue(e,n){let r=this.keyFor(e);this.values.set(r,n),this.writtenAs.has(r)||this.writtenAs.set(r,e),this.engineInstance&&(this.labelByKey.has(r)?this.engineInstance.update({}):this.warnUnknown(e))}warnUnknown(e){console.warn(`BharatChoropleth: "${e}" is not a recognized state/UT \u2014 its value is ignored.`)}mount(e){this.clearPlaceholder();for(let y of oe(e).features){let x=this.keyForFeature(y);this.labelByKey.set(x,this.getLabel(y)),this.values.has(x)||this.values.set(x,null)}for(let[y,x]of this.values)!this.labelByKey.has(y)&&x!==null&&this.warnUnknown(this.writtenAs.get(y)??y);let{container:n,geometry:r,dataBaseUrl:i,districts:o,getId:a,getLabel:l,values:h,fontColor:d,borderColor:s,borderWidth:c,selectionWidth:u,colorScale:p,onReady:f,onError:m,...v}=this.options,b=o??this.usingDefaultData;this.engineInstance=new de(this.containerEl,{...v,colorScale:p,loadDistricts:v.loadDistricts??(b?this.defaultDistrictLoader:void 0),states:{geometry:e,getId:this.getId,getLabel:this.getLabel,getValue:y=>this.values.get(this.keyForFeature(y))??null}}),this._fontColor&&this.mapRootEl.style.setProperty("--india-map-text",this._fontColor),this._borderColor&&this.mapRootEl.style.setProperty("--india-map-stroke",this._borderColor),this._borderWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-border-width",String(this._borderWidth)),this._selectionWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-selection-width",String(this._selectionWidth)),f?.(this.proxied??this)}defaultDistrictLoader=async e=>({geometry:await or(this.dataBaseUrl,e,this.abortController?.signal),getId:r=>String(r.properties?.id??r.properties?.name),getLabel:r=>String(r.properties?.name??r.properties?.id),getValue:r=>this.values.get(this.keyFor(this.getLabel(r)))??null});showLoading(){this.loadingEl=document.createElement("div"),this.loadingEl.className="bharat-choropleth__status",this.loadingEl.setAttribute("role","status"),this.loadingEl.textContent="Loading map\u2026",this.containerEl.appendChild(this.loadingEl)}showError(e){this.clearPlaceholder();let n=document.createElement("div");n.className="bharat-choropleth__status bharat-choropleth__status--error",n.setAttribute("role","alert"),n.textContent=e.message,this.containerEl.appendChild(n),this.loadingEl=n,this.options.onError?this.options.onError(e):console.error(e)}clearPlaceholder(){this.loadingEl?.remove(),this.loadingEl=null}get engine(){return this.engineInstance}get states(){return this.statesAccessor}setValues(e){for(let[n,r]of Object.entries(e)){let i=this.keyFor(n);this.values.set(i,r),this.writtenAs.has(i)||this.writtenAs.set(i,n),this.engineInstance&&!this.labelByKey.has(i)&&this.warnUnknown(n)}this.engineInstance?.update({})}getValues(){let e={};for(let[n,r]of this.labelByKey)e[r]=this.values.get(n)??null;return e}get mapRootEl(){return this.containerEl.querySelector(".india-choropleth")??this.containerEl}get fontColor(){return this._fontColor}set fontColor(e){this._fontColor=e,this.engineInstance&&(e?this.mapRootEl.style.setProperty("--india-map-text",e):this.mapRootEl.style.removeProperty("--india-map-text"))}get borderColor(){return this._borderColor}set borderColor(e){this._borderColor=e,this.engineInstance&&(e?this.mapRootEl.style.setProperty("--india-map-stroke",e):this.mapRootEl.style.removeProperty("--india-map-stroke"))}get borderWidth(){return this._borderWidth}set borderWidth(e){this._borderWidth=e,this.setWidthVar("--india-map-border-width",e)}get selectionWidth(){return this._selectionWidth}set selectionWidth(e){this._selectionWidth=e,this.setWidthVar("--india-map-selection-width",e)}setWidthVar(e,n){this.engineInstance&&(n===void 0?this.mapRootEl.style.removeProperty(e):this.mapRootEl.style.setProperty(e,String(n)))}get colorScale(){return this._colorScale}set colorScale(e){this._colorScale=e,this.options.colorScale=e,this.engineInstance?.update({colorScale:e})}select(e){this.engineInstance?.select(e)}drillDown(e){let n=e===null?null:ue(e)?.id??e;this.engineInstance?.drillDown(n)}getSelected(){return this.engineInstance?.getSelected()??null}getInspected(){return this.engineInstance?.getInspected()??null}destroy(){this.destroyed=!0,this.abortController?.abort(),this.clearPlaceholder(),this.engineInstance?.destroy(),this.engineInstance=null}};var cr="bharat-choropleth-styles";function dr(){if(typeof document>"u"||document.getElementById(cr))return;let t=document.createElement("style");t.id=cr,t.textContent=Ut,document.head.appendChild(t)}dr();var Ht=globalThis;Ht.BharatChoropleth=Ge;Ht.IndiaChoropleth=de;Ht.BharatChoroplethLib={BharatChoropleth:Ge,IndiaChoropleth:de,STATES:qt,resolveState:ue,ATTRIBUTION:Qn,DEFAULT_DATA_BASE_URL:ct,injectStyles:dr};})();
|
|
125
|
+
`;var K=class{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){let n=this._partials,i=0;for(let r=0;r<this._n&&r<32;r++){let o=n[r],a=t+o,l=Math.abs(t)<Math.abs(o)?t-(a-o):o-(a-t);l&&(n[i++]=l),t=a}return n[i]=t,this._n=i+1,this}valueOf(){let t=this._partials,n=this._n,i,r,o,a=0;if(n>0){for(a=t[--n];n>0&&(i=a,r=t[--n],a=i+r,o=r-(a-i),!o););n>0&&(o<0&&t[n-1]<0||o>0&&t[n-1]>0)&&(r=o*2,i=a+r,r==i-a&&(a=i))}return a}};function*pi(e){for(let t of e)yield*t}function pt(e){return Array.from(pi(e))}var k=1e-6,Ye=1e-12,_=Math.PI,$=_/2,ue=_/4,q=_*2,V=180/_,F=_/180,M=Math.abs,jt=Math.atan,rt=Math.atan2,T=Math.cos;var Xe=Math.exp;var Je=Math.log;var B=Math.sin,Ze=Math.sign||function(e){return e>0?1:e<0?-1:0},Y=Math.sqrt,Qe=Math.tan;function tn(e){return e>1?0:e<-1?_:Math.acos(e)}function ot(e){return e>1?$:e<-1?-$:Math.asin(e)}function z(){}function $t(e,t){e&&nn.hasOwnProperty(e.type)&&nn[e.type](e,t)}var en={Feature:function(e,t){$t(e.geometry,t)},FeatureCollection:function(e,t){for(var n=e.features,i=-1,r=n.length;++i<r;)$t(n[i].geometry,t)}},nn={Sphere:function(e,t){t.sphere()},Point:function(e,t){e=e.coordinates,t.point(e[0],e[1],e[2])},MultiPoint:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)e=n[i],t.point(e[0],e[1],e[2])},LineString:function(e,t){he(e.coordinates,t,0)},MultiLineString:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)he(n[i],t,0)},Polygon:function(e,t){rn(e.coordinates,t)},MultiPolygon:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)rn(n[i],t)},GeometryCollection:function(e,t){for(var n=e.geometries,i=-1,r=n.length;++i<r;)$t(n[i],t)}};function he(e,t,n){var i=-1,r=e.length-n,o;for(t.lineStart();++i<r;)o=e[i],t.point(o[0],o[1],o[2]);t.lineEnd()}function rn(e,t){var n=-1,i=e.length;for(t.polygonStart();++n<i;)he(e[n],t,1);t.polygonEnd()}function at(e,t){e&&en.hasOwnProperty(e.type)?en[e.type](e,t):$t(e,t)}function St(e){return[rt(e[1],e[0]),ot(e[2])]}function Z(e){var t=e[0],n=e[1],i=T(n);return[i*T(t),i*B(t),B(n)]}function Et(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function ft(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function qt(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function Dt(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function _t(e){var t=Y(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}function It(e,t){function n(i,r){return i=e(i,r),t(i[0],i[1])}return e.invert&&t.invert&&(n.invert=function(i,r){return i=t.invert(i,r),i&&e.invert(i[0],i[1])}),n}function pe(e,t){return M(e)>_&&(e-=Math.round(e/q)*q),[e,t]}pe.invert=pe;function fe(e,t,n){return(e%=q)?t||n?It(an(e),sn(t,n)):an(e):t||n?sn(t,n):pe}function on(e){return function(t,n){return t+=e,M(t)>_&&(t-=Math.round(t/q)*q),[t,n]}}function an(e){var t=on(e);return t.invert=on(-e),t}function sn(e,t){var n=T(e),i=B(e),r=T(t),o=B(t);function a(l,u){var d=T(u),s=T(l)*d,c=B(l)*d,h=B(u),f=h*n+s*i;return[rt(c*r-f*o,s*n-h*i),ot(f*r+c*o)]}return a.invert=function(l,u){var d=T(u),s=T(l)*d,c=B(l)*d,h=B(u),f=h*r-c*o;return[rt(c*r+h*o,s*n+f*i),ot(f*n-s*i)]},a}function ln(e){e=fe(e[0]*F,e[1]*F,e.length>2?e[2]*F:0);function t(n){return n=e(n[0]*F,n[1]*F),n[0]*=V,n[1]*=V,n}return t.invert=function(n){return n=e.invert(n[0]*F,n[1]*F),n[0]*=V,n[1]*=V,n},t}function dn(e,t,n,i,r,o){if(n){var a=T(t),l=B(t),u=i*n;r==null?(r=t+i*q,o=t-u/2):(r=cn(a,r),o=cn(a,o),(i>0?r<o:r>o)&&(r+=i*q));for(var d,s=r;i>0?s>o:s<o;s-=u)d=St([a,-l*T(s),-l*B(s)]),e.point(d[0],d[1])}}function cn(e,t){t=Z(t),t[0]-=e,_t(t);var n=tn(-t[1]);return((-t[2]<0?-n:n)+q-k)%q}function zt(){var e=[],t;return{point:function(n,i,r){t.push([n,i,r])},lineStart:function(){e.push(t=[])},lineEnd:z,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function mt(e,t){return M(e[0]-t[0])<k&&M(e[1]-t[1])<k}function Ht(e,t,n,i){this.x=e,this.z=t,this.o=n,this.e=i,this.v=!1,this.n=this.p=null}function Ut(e,t,n,i,r){var o=[],a=[],l,u;if(e.forEach(function(m){if(!((S=m.length-1)<=0)){var S,w=m[0],g=m[S],v;if(mt(w,g)){if(!w[2]&&!g[2]){for(r.lineStart(),l=0;l<S;++l)r.point((w=m[l])[0],w[1]);r.lineEnd();return}g[0]+=2*k}o.push(v=new Ht(w,m,null,!0)),a.push(v.o=new Ht(w,null,v,!1)),o.push(v=new Ht(g,m,null,!1)),a.push(v.o=new Ht(g,null,v,!0))}}),!!o.length){for(a.sort(t),un(o),un(a),l=0,u=a.length;l<u;++l)a[l].e=n=!n;for(var d=o[0],s,c;;){for(var h=d,f=!0;h.v;)if((h=h.n)===d)return;s=h.z,r.lineStart();do{if(h.v=h.o.v=!0,h.e){if(f)for(l=0,u=s.length;l<u;++l)r.point((c=s[l])[0],c[1]);else i(h.x,h.n.x,1,r);h=h.n}else{if(f)for(s=h.p.z,l=s.length-1;l>=0;--l)r.point((c=s[l])[0],c[1]);else i(h.x,h.p.x,-1,r);h=h.p}h=h.o,s=h.z,f=!f}while(!h.v);r.lineEnd()}}}function un(e){if(t=e.length){for(var t,n=0,i=e[0],r;++n<t;)i.n=r=e[n],r.p=i,i=r;i.n=r=e[0],r.p=i}}function me(e){return M(e[0])<=_?e[0]:Ze(e[0])*((M(e[0])+_)%q-_)}function hn(e,t){var n=me(t),i=t[1],r=B(i),o=[B(n),-T(n),0],a=0,l=0,u=new K;r===1?i=$+k:r===-1&&(i=-$-k);for(var d=0,s=e.length;d<s;++d)if(h=(c=e[d]).length)for(var c,h,f=c[h-1],m=me(f),S=f[1]/2+ue,w=B(S),g=T(S),v=0;v<h;++v,m=b,w=E,g=C,f=y){var y=c[v],b=me(y),x=y[1]/2+ue,E=B(x),C=T(x),P=b-m,R=P>=0?1:-1,L=R*P,D=L>_,U=w*E;if(u.add(rt(U*R*B(L),g*C+U*T(L))),a+=D?P+R*q:P,D^m>=n^b>=n){var O=ft(Z(f),Z(y));_t(O);var A=ft(o,O);_t(A);var p=(D^P>=0?-1:1)*ot(A[2]);(i>p||i===p&&(O[0]||O[1]))&&(l+=D^P>=0?1:-1)}}return(a<-k||a<k&&u<-Ye)^l&1}function Vt(e,t,n,i){return function(r){var o=t(r),a=zt(),l=t(a),u=!1,d,s,c,h={point:f,lineStart:S,lineEnd:w,polygonStart:function(){h.point=g,h.lineStart=v,h.lineEnd=y,s=[],d=[]},polygonEnd:function(){h.point=f,h.lineStart=S,h.lineEnd=w,s=pt(s);var b=hn(d,i);s.length?(u||(r.polygonStart(),u=!0),Ut(s,mi,b,n,r)):b&&(u||(r.polygonStart(),u=!0),r.lineStart(),n(null,null,1,r),r.lineEnd()),u&&(r.polygonEnd(),u=!1),s=d=null},sphere:function(){r.polygonStart(),r.lineStart(),n(null,null,1,r),r.lineEnd(),r.polygonEnd()}};function f(b,x){e(b,x)&&r.point(b,x)}function m(b,x){o.point(b,x)}function S(){h.point=m,o.lineStart()}function w(){h.point=f,o.lineEnd()}function g(b,x){c.push([b,x]),l.point(b,x)}function v(){l.lineStart(),c=[]}function y(){g(c[0][0],c[0][1]),l.lineEnd();var b=l.clean(),x=a.result(),E,C=x.length,P,R,L;if(c.pop(),d.push(c),c=null,!!C){if(b&1){if(R=x[0],(P=R.length-1)>0){for(u||(r.polygonStart(),u=!0),r.lineStart(),E=0;E<P;++E)r.point((L=R[E])[0],L[1]);r.lineEnd()}return}C>1&&b&2&&x.push(x.pop().concat(x.shift())),s.push(x.filter(fi))}}return h}}function fi(e){return e.length>1}function mi(e,t){return((e=e.x)[0]<0?e[1]-$-k:$-e[1])-((t=t.x)[0]<0?t[1]-$-k:$-t[1])}var ge=Vt(function(){return!0},gi,bi,[-_,-$]);function gi(e){var t=NaN,n=NaN,i=NaN,r;return{lineStart:function(){e.lineStart(),r=1},point:function(o,a){var l=o>0?_:-_,u=M(o-t);M(u-_)<k?(e.point(t,n=(n+a)/2>0?$:-$),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(l,n),e.point(o,n),r=0):i!==l&&u>=_&&(M(t-i)<k&&(t-=i*k),M(o-l)<k&&(o-=l*k),n=vi(t,n,o,a),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(l,n),r=0),e.point(t=o,n=a),i=l},lineEnd:function(){e.lineEnd(),t=n=NaN},clean:function(){return 2-r}}}function vi(e,t,n,i){var r,o,a=B(e-n);return M(a)>k?jt((B(t)*(o=T(i))*B(n)-B(i)*(r=T(t))*B(e))/(r*o*a)):(t+i)/2}function bi(e,t,n,i){var r;if(e==null)r=n*$,i.point(-_,r),i.point(0,r),i.point(_,r),i.point(_,0),i.point(_,-r),i.point(0,-r),i.point(-_,-r),i.point(-_,0),i.point(-_,r);else if(M(e[0]-t[0])>k){var o=e[0]<t[0]?_:-_;r=n*o/2,i.point(-o,r),i.point(0,r),i.point(o,r)}else i.point(t[0],t[1])}function pn(e){var t=T(e),n=2*F,i=t>0,r=M(t)>k;function o(s,c,h,f){dn(f,e,n,h,s,c)}function a(s,c){return T(s)*T(c)>t}function l(s){var c,h,f,m,S;return{lineStart:function(){m=f=!1,S=1},point:function(w,g){var v=[w,g],y,b=a(w,g),x=i?b?0:d(w,g):b?d(w+(w<0?_:-_),g):0;if(!c&&(m=f=b)&&s.lineStart(),b!==f&&(y=u(c,v),(!y||mt(c,y)||mt(v,y))&&(v[2]=1)),b!==f)S=0,b?(s.lineStart(),y=u(v,c),s.point(y[0],y[1])):(y=u(c,v),s.point(y[0],y[1],2),s.lineEnd()),c=y;else if(r&&c&&i^b){var E;!(x&h)&&(E=u(v,c,!0))&&(S=0,i?(s.lineStart(),s.point(E[0][0],E[0][1]),s.point(E[1][0],E[1][1]),s.lineEnd()):(s.point(E[1][0],E[1][1]),s.lineEnd(),s.lineStart(),s.point(E[0][0],E[0][1],3)))}b&&(!c||!mt(c,v))&&s.point(v[0],v[1]),c=v,f=b,h=x},lineEnd:function(){f&&s.lineEnd(),c=null},clean:function(){return S|(m&&f)<<1}}}function u(s,c,h){var f=Z(s),m=Z(c),S=[1,0,0],w=ft(f,m),g=Et(w,w),v=w[0],y=g-v*v;if(!y)return!h&&s;var b=t*g/y,x=-t*v/y,E=ft(S,w),C=Dt(S,b),P=Dt(w,x);qt(C,P);var R=E,L=Et(C,R),D=Et(R,R),U=L*L-D*(Et(C,C)-1);if(!(U<0)){var O=Y(U),A=Dt(R,(-L-O)/D);if(qt(A,C),A=St(A),!h)return A;var p=s[0],I=c[0],j=s[1],W=c[1],X;I<p&&(X=p,p=I,I=X);var wt=I-p,nt=M(wt-_)<k,lt=nt||wt<k;if(!nt&&W<j&&(X=j,j=W,W=X),lt?nt?j+W>0^A[1]<(M(A[0]-p)<k?j:W):j<=A[1]&&A[1]<=W:wt>_^(p<=A[0]&&A[0]<=I)){var it=Dt(R,(-L+O)/D);return qt(it,C),[A,St(it)]}}}function d(s,c){var h=i?e:_-e,f=0;return s<-h?f|=1:s>h&&(f|=2),c<-h?f|=4:c>h&&(f|=8),f}return Vt(a,l,o,i?[0,-e]:[-_,e-_])}function fn(e,t,n,i,r,o){var a=e[0],l=e[1],u=t[0],d=t[1],s=0,c=1,h=u-a,f=d-l,m;if(m=n-a,!(!h&&m>0)){if(m/=h,h<0){if(m<s)return;m<c&&(c=m)}else if(h>0){if(m>c)return;m>s&&(s=m)}if(m=r-a,!(!h&&m<0)){if(m/=h,h<0){if(m>c)return;m>s&&(s=m)}else if(h>0){if(m<s)return;m<c&&(c=m)}if(m=i-l,!(!f&&m>0)){if(m/=f,f<0){if(m<s)return;m<c&&(c=m)}else if(f>0){if(m>c)return;m>s&&(s=m)}if(m=o-l,!(!f&&m<0)){if(m/=f,f<0){if(m>c)return;m>s&&(s=m)}else if(f>0){if(m<s)return;m<c&&(c=m)}return s>0&&(e[0]=a+s*h,e[1]=l+s*f),c<1&&(t[0]=a+c*h,t[1]=l+c*f),!0}}}}}var kt=1e9,Wt=-kt;function ve(e,t,n,i){function r(d,s){return e<=d&&d<=n&&t<=s&&s<=i}function o(d,s,c,h){var f=0,m=0;if(d==null||(f=a(d,c))!==(m=a(s,c))||u(d,s)<0^c>0)do h.point(f===0||f===3?e:n,f>1?i:t);while((f=(f+c+4)%4)!==m);else h.point(s[0],s[1])}function a(d,s){return M(d[0]-e)<k?s>0?0:3:M(d[0]-n)<k?s>0?2:1:M(d[1]-t)<k?s>0?1:0:s>0?3:2}function l(d,s){return u(d.x,s.x)}function u(d,s){var c=a(d,1),h=a(s,1);return c!==h?c-h:c===0?s[1]-d[1]:c===1?d[0]-s[0]:c===2?d[1]-s[1]:s[0]-d[0]}return function(d){var s=d,c=zt(),h,f,m,S,w,g,v,y,b,x,E,C={point:P,lineStart:U,lineEnd:O,polygonStart:L,polygonEnd:D};function P(p,I){r(p,I)&&s.point(p,I)}function R(){for(var p=0,I=0,j=f.length;I<j;++I)for(var W=f[I],X=1,wt=W.length,nt=W[0],lt,it,Nt=nt[0],ht=nt[1];X<wt;++X)lt=Nt,it=ht,nt=W[X],Nt=nt[0],ht=nt[1],it<=i?ht>i&&(Nt-lt)*(i-it)>(ht-it)*(e-lt)&&++p:ht<=i&&(Nt-lt)*(i-it)<(ht-it)*(e-lt)&&--p;return p}function L(){s=c,h=[],f=[],E=!0}function D(){var p=R(),I=E&&p,j=(h=pt(h)).length;(I||j)&&(d.polygonStart(),I&&(d.lineStart(),o(null,null,1,d),d.lineEnd()),j&&Ut(h,l,p,o,d),d.polygonEnd()),s=d,h=f=m=null}function U(){C.point=A,f&&f.push(m=[]),x=!0,b=!1,v=y=NaN}function O(){h&&(A(S,w),g&&b&&c.rejoin(),h.push(c.result())),C.point=P,b&&s.lineEnd()}function A(p,I){var j=r(p,I);if(f&&m.push([p,I]),x)S=p,w=I,g=j,x=!1,j&&(s.lineStart(),s.point(p,I));else if(j&&b)s.point(p,I);else{var W=[v=Math.max(Wt,Math.min(kt,v)),y=Math.max(Wt,Math.min(kt,y))],X=[p=Math.max(Wt,Math.min(kt,p)),I=Math.max(Wt,Math.min(kt,I))];fn(W,X,e,t,n,i)?(b||(s.lineStart(),s.point(W[0],W[1])),s.point(X[0],X[1]),j||s.lineEnd(),E=!1):j&&(s.lineStart(),s.point(p,I),E=!1)}v=p,y=I,b=j}return C}}var Rt=e=>e;var be=new K,ye=new K,mn,gn,xe,we,st={point:z,lineStart:z,lineEnd:z,polygonStart:function(){st.lineStart=yi,st.lineEnd=wi},polygonEnd:function(){st.lineStart=st.lineEnd=st.point=z,be.add(M(ye)),ye=new K},result:function(){var e=be/2;return be=new K,e}};function yi(){st.point=xi}function xi(e,t){st.point=vn,mn=xe=e,gn=we=t}function vn(e,t){ye.add(we*e-xe*t),xe=e,we=t}function wi(){vn(mn,gn)}var Se=st;var gt=1/0,Kt=gt,Pt=-gt,Yt=Pt,Si={point:Ei,lineStart:z,lineEnd:z,polygonStart:z,polygonEnd:z,result:function(){var e=[[gt,Kt],[Pt,Yt]];return Pt=Yt=-(Kt=gt=1/0),e}};function Ei(e,t){e<gt&&(gt=e),e>Pt&&(Pt=e),t<Kt&&(Kt=t),t>Yt&&(Yt=t)}var vt=Si;var Ee=0,De=0,Ct=0,Xt=0,Jt=0,bt=0,_e=0,Ie=0,Mt=0,xn,wn,Q,tt,J={point:ct,lineStart:bn,lineEnd:yn,polygonStart:function(){J.lineStart=Ii,J.lineEnd=ki},polygonEnd:function(){J.point=ct,J.lineStart=bn,J.lineEnd=yn},result:function(){var e=Mt?[_e/Mt,Ie/Mt]:bt?[Xt/bt,Jt/bt]:Ct?[Ee/Ct,De/Ct]:[NaN,NaN];return Ee=De=Ct=Xt=Jt=bt=_e=Ie=Mt=0,e}};function ct(e,t){Ee+=e,De+=t,++Ct}function bn(){J.point=Di}function Di(e,t){J.point=_i,ct(Q=e,tt=t)}function _i(e,t){var n=e-Q,i=t-tt,r=Y(n*n+i*i);Xt+=r*(Q+e)/2,Jt+=r*(tt+t)/2,bt+=r,ct(Q=e,tt=t)}function yn(){J.point=ct}function Ii(){J.point=Ri}function ki(){Sn(xn,wn)}function Ri(e,t){J.point=Sn,ct(xn=Q=e,wn=tt=t)}function Sn(e,t){var n=e-Q,i=t-tt,r=Y(n*n+i*i);Xt+=r*(Q+e)/2,Jt+=r*(tt+t)/2,bt+=r,r=tt*e-Q*t,_e+=r*(Q+e),Ie+=r*(tt+t),Mt+=r*3,ct(Q=e,tt=t)}var ke=J;function Zt(e){this._context=e}Zt.prototype={_radius:4.5,pointRadius:function(e){return this._radius=e,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(e,t){switch(this._point){case 0:{this._context.moveTo(e,t),this._point=1;break}case 1:{this._context.lineTo(e,t);break}default:{this._context.moveTo(e+this._radius,t),this._context.arc(e,t,this._radius,0,q);break}}},result:z};var Pe=new K,Re,En,Dn,Lt,At,Qt={point:z,lineStart:function(){Qt.point=Pi},lineEnd:function(){Re&&_n(En,Dn),Qt.point=z},polygonStart:function(){Re=!0},polygonEnd:function(){Re=null},result:function(){var e=+Pe;return Pe=new K,e}};function Pi(e,t){Qt.point=_n,En=Lt=e,Dn=At=t}function _n(e,t){Lt-=e,At-=t,Pe.add(Y(Lt*Lt+At*At)),Lt=e,At=t}var Ce=Qt;var In,te,kn,Rn,yt=class{constructor(t){this._append=t==null?Pn:Ci(t),this._radius=4.5,this._=""}pointRadius(t){return this._radius=+t,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(t,n){switch(this._point){case 0:{this._append`M${t},${n}`,this._point=1;break}case 1:{this._append`L${t},${n}`;break}default:{if(this._append`M${t},${n}`,this._radius!==kn||this._append!==te){let i=this._radius,r=this._;this._="",this._append`m0,${i}a${i},${i} 0 1,1 0,${-2*i}a${i},${i} 0 1,1 0,${2*i}z`,kn=i,te=this._append,Rn=this._,this._=r}this._+=Rn;break}}}result(){let t=this._;return this._="",t.length?t:null}};function Pn(e){let t=1;this._+=e[0];for(let n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function Ci(e){let t=Math.floor(e);if(!(t>=0))throw new RangeError(`invalid digits: ${e}`);if(t>15)return Pn;if(t!==In){let n=10**t;In=t,te=function(r){let o=1;this._+=r[0];for(let a=r.length;o<a;++o)this._+=Math.round(arguments[o]*n)/n+r[o]}}return te}function ee(e,t){let n=3,i=4.5,r,o;function a(l){return l&&(typeof i=="function"&&o.pointRadius(+i.apply(this,arguments)),at(l,r(o))),o.result()}return a.area=function(l){return at(l,r(Se)),Se.result()},a.measure=function(l){return at(l,r(Ce)),Ce.result()},a.bounds=function(l){return at(l,r(vt)),vt.result()},a.centroid=function(l){return at(l,r(ke)),ke.result()},a.projection=function(l){return arguments.length?(r=l==null?(e=null,Rt):(e=l).stream,a):e},a.context=function(l){return arguments.length?(o=l==null?(t=null,new yt(n)):new Zt(t=l),typeof i!="function"&&o.pointRadius(i),a):t},a.pointRadius=function(l){return arguments.length?(i=typeof l=="function"?l:(o.pointRadius(+l),+l),a):i},a.digits=function(l){if(!arguments.length)return n;if(l==null)n=null;else{let u=Math.floor(l);if(!(u>=0))throw new RangeError(`invalid digits: ${l}`);n=u}return t===null&&(o=new yt(n)),a},a.projection(e).digits(n).context(t)}function Tt(e){return function(t){var n=new Me;for(var i in e)n[i]=e[i];return n.stream=t,n}}function Me(){}Me.prototype={constructor:Me,point:function(e,t){this.stream.point(e,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()}};function Le(e,t,n){var i=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),i!=null&&e.clipExtent(null),at(n,e.stream(vt)),t(vt.result()),i!=null&&e.clipExtent(i),e}function Ae(e,t,n){return Le(e,function(i){var r=t[1][0]-t[0][0],o=t[1][1]-t[0][1],a=Math.min(r/(i[1][0]-i[0][0]),o/(i[1][1]-i[0][1])),l=+t[0][0]+(r-a*(i[1][0]+i[0][0]))/2,u=+t[0][1]+(o-a*(i[1][1]+i[0][1]))/2;e.scale(150*a).translate([l,u])},n)}function Cn(e,t,n){return Ae(e,[[0,0],t],n)}function Mn(e,t,n){return Le(e,function(i){var r=+t,o=r/(i[1][0]-i[0][0]),a=(r-o*(i[1][0]+i[0][0]))/2,l=-o*i[0][1];e.scale(150*o).translate([a,l])},n)}function Ln(e,t,n){return Le(e,function(i){var r=+t,o=r/(i[1][1]-i[0][1]),a=-o*i[0][0],l=(r-o*(i[1][1]+i[0][1]))/2;e.scale(150*o).translate([a,l])},n)}var An=16,Mi=T(30*F);function Te(e,t){return+t?Ai(e,t):Li(e)}function Li(e){return Tt({point:function(t,n){t=e(t,n),this.stream.point(t[0],t[1])}})}function Ai(e,t){function n(i,r,o,a,l,u,d,s,c,h,f,m,S,w){var g=d-i,v=s-r,y=g*g+v*v;if(y>4*t&&S--){var b=a+h,x=l+f,E=u+m,C=Y(b*b+x*x+E*E),P=ot(E/=C),R=M(M(E)-1)<k||M(o-c)<k?(o+c)/2:rt(x,b),L=e(R,P),D=L[0],U=L[1],O=D-i,A=U-r,p=v*O-g*A;(p*p/y>t||M((g*O+v*A)/y-.5)>.3||a*h+l*f+u*m<Mi)&&(n(i,r,o,a,l,u,D,U,R,b/=C,x/=C,E,S,w),w.point(D,U),n(D,U,R,b,x,E,d,s,c,h,f,m,S,w))}}return function(i){var r,o,a,l,u,d,s,c,h,f,m,S,w={point:g,lineStart:v,lineEnd:b,polygonStart:function(){i.polygonStart(),w.lineStart=x},polygonEnd:function(){i.polygonEnd(),w.lineStart=v}};function g(P,R){P=e(P,R),i.point(P[0],P[1])}function v(){c=NaN,w.point=y,i.lineStart()}function y(P,R){var L=Z([P,R]),D=e(P,R);n(c,h,s,f,m,S,c=D[0],h=D[1],s=P,f=L[0],m=L[1],S=L[2],An,i),i.point(c,h)}function b(){w.point=g,i.lineEnd()}function x(){v(),w.point=E,w.lineEnd=C}function E(P,R){y(r=P,R),o=c,a=h,l=f,u=m,d=S,w.point=y}function C(){n(c,h,s,f,m,S,o,a,r,l,u,d,An,i),w.lineEnd=b,b()}return w}}var Ti=Tt({point:function(e,t){this.stream.point(e*F,t*F)}});function Bi(e){return Tt({point:function(t,n){var i=e(t,n);return this.stream.point(i[0],i[1])}})}function Fi(e,t,n,i,r){function o(a,l){return a*=i,l*=r,[t+e*a,n-e*l]}return o.invert=function(a,l){return[(a-t)/e*i,(n-l)/e*r]},o}function Tn(e,t,n,i,r,o){if(!o)return Fi(e,t,n,i,r);var a=T(o),l=B(o),u=a*e,d=l*e,s=a/e,c=l/e,h=(l*n-a*t)/e,f=(l*t+a*n)/e;function m(S,w){return S*=i,w*=r,[u*S-d*w+t,n-d*S-u*w]}return m.invert=function(S,w){return[i*(s*S-c*w+h),r*(f-c*S-s*w)]},m}function Be(e){return Oi(function(){return e})()}function Oi(e){var t,n=150,i=480,r=250,o=0,a=0,l=0,u=0,d=0,s,c=0,h=1,f=1,m=null,S=ge,w=null,g,v,y,b=Rt,x=.5,E,C,P,R,L;function D(p){return P(p[0]*F,p[1]*F)}function U(p){return p=P.invert(p[0],p[1]),p&&[p[0]*V,p[1]*V]}D.stream=function(p){return R&&L===p?R:R=Ti(Bi(s)(S(E(b(L=p)))))},D.preclip=function(p){return arguments.length?(S=p,m=void 0,A()):S},D.postclip=function(p){return arguments.length?(b=p,w=g=v=y=null,A()):b},D.clipAngle=function(p){return arguments.length?(S=+p?pn(m=p*F):(m=null,ge),A()):m*V},D.clipExtent=function(p){return arguments.length?(b=p==null?(w=g=v=y=null,Rt):ve(w=+p[0][0],g=+p[0][1],v=+p[1][0],y=+p[1][1]),A()):w==null?null:[[w,g],[v,y]]},D.scale=function(p){return arguments.length?(n=+p,O()):n},D.translate=function(p){return arguments.length?(i=+p[0],r=+p[1],O()):[i,r]},D.center=function(p){return arguments.length?(o=p[0]%360*F,a=p[1]%360*F,O()):[o*V,a*V]},D.rotate=function(p){return arguments.length?(l=p[0]%360*F,u=p[1]%360*F,d=p.length>2?p[2]%360*F:0,O()):[l*V,u*V,d*V]},D.angle=function(p){return arguments.length?(c=p%360*F,O()):c*V},D.reflectX=function(p){return arguments.length?(h=p?-1:1,O()):h<0},D.reflectY=function(p){return arguments.length?(f=p?-1:1,O()):f<0},D.precision=function(p){return arguments.length?(E=Te(C,x=p*p),A()):Y(x)},D.fitExtent=function(p,I){return Ae(D,p,I)},D.fitSize=function(p,I){return Cn(D,p,I)},D.fitWidth=function(p,I){return Mn(D,p,I)},D.fitHeight=function(p,I){return Ln(D,p,I)};function O(){var p=Tn(n,0,0,h,f,c).apply(null,t(o,a)),I=Tn(n,i-p[0],r-p[1],h,f,c);return s=fe(l,u,d),C=It(t,I),P=It(s,C),E=Te(C,x),A()}function A(){return R=L=null,D}return function(){return t=e.apply(this,arguments),D.invert=t.invert&&U,O()}}function ne(e,t){return[e,Je(Qe(($+t)/2))]}ne.invert=function(e,t){return[e,2*jt(Xe(t))-$]};function Fe(){return Gi(ne).scale(961/q)}function Gi(e){var t=Be(e),n=t.center,i=t.scale,r=t.translate,o=t.clipExtent,a=null,l,u,d;t.scale=function(c){return arguments.length?(i(c),s()):i()},t.translate=function(c){return arguments.length?(r(c),s()):r()},t.center=function(c){return arguments.length?(n(c),s()):n()},t.clipExtent=function(c){return arguments.length?(c==null?a=l=u=d=null:(a=+c[0][0],l=+c[0][1],u=+c[1][0],d=+c[1][1]),s()):a==null?null:[[a,l],[u,d]]};function s(){var c=_*i(),h=t(ln(t.rotate()).invert([0,0]));return o(a==null?[[h[0]-c,h[1]-c],[h[0]+c,h[1]+c]]:e===ne?[[Math.max(h[0]-c,a),l],[Math.min(h[0]+c,u),d]]:[[a,Math.max(h[1]-c,l)],[u,Math.min(h[1]+c,d)]])}return s()}function Oe(e){return e}function ie(e){if(e==null)return Oe;var t,n,i=e.scale[0],r=e.scale[1],o=e.translate[0],a=e.translate[1];return function(l,u){u||(t=n=0);var d=2,s=l.length,c=new Array(s);for(c[0]=(t+=l[0])*i+o,c[1]=(n+=l[1])*r+a;d<s;)c[d]=l[d],++d;return c}}function Bn(e,t){for(var n,i=e.length,r=i-t;r<--i;)n=e[r],e[r++]=e[i],e[i]=n}function Ge(e,t){return typeof t=="string"&&(t=e.objects[t]),t.type==="GeometryCollection"?{type:"FeatureCollection",features:t.geometries.map(function(n){return Fn(e,n)})}:Fn(e,t)}function Fn(e,t){var n=t.id,i=t.bbox,r=t.properties==null?{}:t.properties,o=Ne(e,t);return n==null&&i==null?{type:"Feature",properties:r,geometry:o}:i==null?{type:"Feature",id:n,properties:r,geometry:o}:{type:"Feature",id:n,bbox:i,properties:r,geometry:o}}function Ne(e,t){var n=ie(e.transform),i=e.arcs;function r(s,c){c.length&&c.pop();for(var h=i[s<0?~s:s],f=0,m=h.length;f<m;++f)c.push(n(h[f],f));s<0&&Bn(c,m)}function o(s){return n(s)}function a(s){for(var c=[],h=0,f=s.length;h<f;++h)r(s[h],c);return c.length<2&&c.push(c[0]),c}function l(s){for(var c=a(s);c.length<4;)c.push(c[0]);return c}function u(s){return s.map(l)}function d(s){var c=s.type,h;switch(c){case"GeometryCollection":return{type:c,geometries:s.geometries.map(d)};case"Point":h=o(s.coordinates);break;case"MultiPoint":h=s.coordinates.map(o);break;case"LineString":h=a(s.arcs);break;case"MultiLineString":h=s.arcs.map(a);break;case"Polygon":h=u(s.arcs);break;case"MultiPolygon":h=s.arcs.map(u);break;default:return null}return{type:c,coordinates:h}}return d(t)}function et(e){if("type"in e&&e.type==="FeatureCollection")return e;let t=e,n=typeof t.object=="string"?t.topology.objects[t.object]:t.object;if(!n)throw new Error("The named TopoJSON object does not exist in this topology.");let i=Ge(t.topology,n);return i.type==="FeatureCollection"?i:{type:"FeatureCollection",features:[i]}}function On(e){return e.reduce((t,n)=>t+(n??0),0)}function re(e,t,n,i){if(e===null||i<=0)return null;if(i===1||n===t)return i-1;let r=Math.round((e-t)/(n-t)*(i-1));return Math.min(Math.max(r,0),i-1)}function Gn(e,t,n,i){let r=e.length;return e.map((o,a)=>{let l=t.filter(u=>re(u,n,i,r)===a);return{index:a,color:o,from:l.length?Math.min(...l):null,to:l.length?Math.max(...l):null,matches:l.length}})}function Nn(e,t){if(e.matches===0||e.from===null||e.to===null)return"No regions in this band";let n=e.from===e.to?t(e.from):`${t(e.from)} to ${t(e.to)}`;return`Highlight ${e.matches} ${e.matches===1?"region":"regions"}, ${n}`}function jn(e,t,n,i=4){let r=0;e.right>t.right-i&&(r=t.right-i-e.right),e.left+r<t.left+i&&(r=t.left+i-e.left);let o=e.top<t.top+i?"below":"above";return{dx:r,side:o}}var qi=["puducherry"];function zn(e){let t=e.toLowerCase();return qi.some(n=>t.includes(n))}function oe(e){let t=1/0,n=1/0,i=-1/0,r=-1/0;for(let[o,a]of e)o<t&&(t=o),o>i&&(i=o),a<n&&(n=a),a>r&&(r=a);return[t,n,i,r]}function ae(e){let t=0;for(let n of e){if(n.length===0)continue;let[i,r,o,a]=oe(n),l=Math.max(o-i,a-r);l>t&&(t=l)}return t}function $n(e){let t=0;for(let n=0;n<e.length;n++){let[i,r]=e[n],[o,a]=e[(n+1)%e.length];t+=i*a-o*r}return t/2}function Hn(e,t){let n=null,i=0;for(let u of e){if(u.length<3)continue;let d=Math.abs($n(u));d>i&&(i=d,n=u)}if(!n||i===0)return t;let r=$n(n),o=0,a=0;for(let u=0;u<n.length;u++){let[d,s]=n[u],[c,h]=n[(u+1)%n.length],f=d*h-c*s;o+=(d+c)*f,a+=(s+h)*f}let l=[o/(6*r),a/(6*r)];return Number.isFinite(l[0])&&Number.isFinite(l[1])?l:t}function zi(e,t){let[n,i]=e,[r,o,a,l]=t,u=Math.max(r-n,0)+Math.max(n-a,0),d=Math.max(o-i,0)+Math.max(i-l,0);return Math.hypot(u,d)}function Un(e,t){let n=1/0;for(let i of t){let r=zi(e,i);r<n&&(n=r)}return n}var Hi=[0,Math.PI/6,-Math.PI/6,Math.PI/3,-Math.PI/3,Math.PI/2,-Math.PI/2,2*Math.PI/3,-(2*Math.PI)/3,5*Math.PI/6,-(5*Math.PI)/6,Math.PI];function Vn(e){let{anchor:t,clearance:n,halfSize:i,viewBox:r,centre:o,isBlocked:a}=e,l=t[0]-o[0],u=t[1]-o[1],d=l===0&&u===0?0:Math.atan2(u,l);for(let s of Hi){let c=d+s,h=[qn(t[0]+Math.cos(c)*n,i[0],r[0]-i[0]),qn(t[1]+Math.sin(c)*n,i[1],r[1]-i[1])];if(!a(h))return h}return null}function qn(e,t,n){return Math.min(Math.max(e,t),n)}function Wn(e,t,n=8){let i=()=>e.map(o=>[...o]);if(t<=0)return i();let r=ae(e);return r<=0||r>=t?i():e.map(o=>{let[a,l,u,d]=oe(o),s=Math.max(u-a,d-l),c=s<=0?1:Math.min(t/s,n),h=(a+u)/2,f=(l+d)/2;return o.map(([m,S])=>[h+(m-h)*c,f+(S-f)*c])})}function Ui(e){let t=[...e].sort((u,d)=>u[0]-d[0]||u[1]-d[1]),n=[];for(let u of t){let d=n.at(-1);(!d||d[0]!==u[0]||d[1]!==u[1])&&n.push(u)}if(n.length<3)return n.map(u=>[...u]);let i=(u,d,s)=>(d[0]-u[0])*(s[1]-u[1])-(d[1]-u[1])*(s[0]-u[0]),r=u=>{let d=[];for(let s of u){for(;d.length>=2&&i(d[d.length-2],d[d.length-1],s)<=0;)d.pop();d.push(s)}return d},o=r(n),a=r([...n].reverse()),l=[...o.slice(0,-1),...a.slice(0,-1)];return l.length>=3?l:n.map(u=>[...u])}function Kn(e,t){if(e.length<2||t<=0)return null;let n=ae(e);if(n<=0||n>=t)return null;let i=Ui(e.flat());return i.length>=3?i:null}function je(e){let t="";for(let n of e)if(n.length!==0){t+=`M${n[0][0]},${n[0][1]}`;for(let i=1;i<n.length;i++)t+=`L${n[i][0]},${n[i][1]}`;t+="Z"}return t}var Vi="http://www.w3.org/2000/svg",H={width:960,height:640,padding:28},Bt=["#d9f1ed","#b9e3dd","#8fd1c8","#5bb9ae","#2f9c90","#147b71","#075b55"],se=new Intl.NumberFormat("en-IN").format,Yn=12,ze=22,Wi=14,le=7;function Xn(e,t){let n=e.geometry;if(!n)return[];let i=n.type==="Polygon"?[n.coordinates]:n.type==="MultiPolygon"?n.coordinates:[],r=[];for(let o of i)for(let a of o){let l=[];for(let u of a){let d=t(u);d&&Number.isFinite(d[0])&&Number.isFinite(d[1])&&l.push([d[0],d[1]])}l.length>0&&r.push(l)}return r}var Ki=0;function Jn(e,t,n,i,r){if(typeof r=="function"){let a={min:n,max:i,feature:t.feature,id:t.id};return r(e,a)}let o=re(e,n,i,r.length);return o===null?"var(--india-map-empty)":r[o]??"var(--india-map-empty)"}function Zn(e){return typeof e.colorScale=="function"?Bt:e.colorScale??Bt}function $e(e){return Fe().fitExtent([[H.padding,H.padding],[H.width-H.padding,H.height-H.padding]],e)}function qe(e,t,n=0){let i=et(e.geometry),r=ee(t);return i.features.map(o=>{let a=r.centroid(o),l=r.bounds(o),u=[(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2],d={id:e.getId(o),label:e.getLabel(o),value:e.getValue(o),meta:e.getMeta?.(o),feature:o},s=n>0&&!zn(d.id),c=s?Wn(Xn(o,t),n):Xn(o,t),h=Kn(c,ze);return{...d,path:s?je(c):r(o)??"",hitPath:h?je([h]):null,centroid:c.length>0?Hn(c,a.every(Number.isFinite)?a:u):a.every(Number.isFinite)?a:u,partBounds:c.map(oe),extent:ae(c)}})}function Qn(e,t){let n=ee(t);return et(e.geometry).features.map(i=>({id:e.getId(i),label:e.getLabel(i),description:e.getDescription(i),path:n(i)??""}))}function Yi(e){let t=e%100;return t>=11&&t<=13?`${e}th`:`${e}${["th","st","nd","rd"][e%10]??"th"}`}function Xi(e,t){let n=document.createDocumentFragment(),i=document.createElement("strong");i.textContent=e.label;let r=document.createElement("b");if(r.textContent=e.value===null?"No data":t(e.value),n.append(i,r),e.share!==null){let o=document.createElement("span");o.className="india-choropleth__tooltip-bar",o.setAttribute("aria-hidden","true");let a=document.createElement("span");a.style.width=`${Math.max(e.share,1.5)}%`,o.append(a);let l=document.createElement("small"),u=[`${e.share.toFixed(1)}% of total`];e.rank!==null&&u.push(`${Yi(e.rank)} of ${e.rankedCount}`),l.textContent=u.join(" \xB7 "),n.append(o,l)}return n}function G(e,t){let n=document.createElement(e);for(let[i,r]of Object.entries(t??{}))n.setAttribute(i,r);return n}function N(e,t){let n=document.createElementNS(Vi,e);for(let[i,r]of Object.entries(t??{}))n.setAttribute(i,r);return n}function Ji(e,t){typeof t=="string"?e.textContent=t:e.appendChild(t)}var dt=class{containerEl;options;instanceId=`india-choropleth-${++Ki}`;tooltipId=`${this.instanceId}-tooltip`;hatchId=`${this.instanceId}-hatch`;activeDrillDownId;activeSubDrillDownId;activeSelectedId;inspectedId=null;loadedDistricts=null;loadedSubDistricts=null;leafDistrictIds=new Set;loadedDistrictReferenceOverlay=null;loadingState=null;loadingDistrict=null;loadError=null;subLoadError=null;districtGeneration=0;subDistrictGeneration=0;overlayGeneration=0;restoreFocusId=null;destroyed=!1;attemptedDistrictLoadForId=null;attemptedSubDistrictLoadForId=null;attemptedOverlayLoadForId=null;pathRefs=new Map;derived;rootEl;toolbarEl;canvasEl;legendEl=null;swatchEls=[];bucketEls=[];activeBucket=null;bandsKey=null;insightsEl=null;tooltipAnchorEl=null;tooltipContentEl=null;svgRootEl=null;selectionGroupEl=null;selectionPathEls=[];constructor(t,n){let i=typeof t=="string"?document.querySelector(t):t;if(!i)throw new Error(`IndiaChoropleth: container ${typeof t=="string"?`"${t}"`:""} was not found.`);this.containerEl=i,this.options=n,this.activeDrillDownId=n.drillDownId!==void 0?n.drillDownId:n.defaultDrillDownId??null,this.activeSubDrillDownId=n.subDistrictDrillDownId!==void 0?n.subDistrictDrillDownId:n.defaultSubDistrictDrillDownId??null,this.activeSelectedId=n.selectedId!==void 0?n.selectedId:n.defaultSelectedId??null,this.buildShell(),this.renderStructure()}update(t){"loadDistricts"in t&&t.loadDistricts!==this.options.loadDistricts&&(this.attemptedDistrictLoadForId=null),"loadSubDistricts"in t&&t.loadSubDistricts!==this.options.loadSubDistricts&&(this.attemptedSubDistrictLoadForId=null,this.leafDistrictIds.clear()),"loadDistrictReferenceOverlay"in t&&t.loadDistrictReferenceOverlay!==this.options.loadDistrictReferenceOverlay&&(this.attemptedOverlayLoadForId=null),this.options={...this.options,...t},"drillDownId"in t&&t.drillDownId!==void 0&&(t.drillDownId!==this.activeDrillDownId&&this.setActiveSubDrillDownId(null),this.activeDrillDownId=t.drillDownId),"subDistrictDrillDownId"in t&&t.subDistrictDrillDownId!==void 0&&(this.activeSubDrillDownId=t.subDistrictDrillDownId),"selectedId"in t&&t.selectedId!==void 0&&(this.activeSelectedId=t.selectedId),this.renderStructure()}select(t){let n=this.derived.regions.find(i=>i.id===t)??null;this.setActiveSelectedId(n?.id??null),n&&this.options.onSelectedChange?.(n,this.derived.level),this.applyInteractionState()}drillDown(t){if(t===null){this.goToStates();return}let n=this.derived.stateRegions.find(i=>i.id===t);n&&(t!==this.activeDrillDownId&&this.setActiveSubDrillDownId(null),this.setActiveDrillDownId(t),this.options.onDrillDownChange?.(t,n),this.renderStructure())}drillDownSubDistrict(t){if(t===null){this.derived.level==="subdistrict"&&this.goBack();return}let n=this.derived.districtRegions.find(i=>i.id===t);n&&(this.setActiveSubDrillDownId(t),this.options.onSubDistrictDrillDownChange?.(t,n),this.renderStructure())}getSelected(){return this.derived.selected}getInspected(){return this.derived.inspected}destroy(){this.destroyed=!0,this.districtGeneration+=1,this.subDistrictGeneration+=1,this.overlayGeneration+=1,this.pathRefs.clear(),this.containerEl.textContent=""}setActiveDrillDownId(t){this.options.drillDownId===void 0&&(this.activeDrillDownId=t)}setActiveSubDrillDownId(t){this.options.subDistrictDrillDownId===void 0&&(this.activeSubDrillDownId=t)}setActiveSelectedId(t){this.options.selectedId===void 0&&(this.activeSelectedId=t)}buildShell(){this.rootEl=G("section"),this.toolbarEl=G("div",{class:"india-choropleth__toolbar"}),this.canvasEl=G("div",{class:"india-choropleth__canvas"}),this.canvasEl.addEventListener("mouseleave",()=>{this.options.interactive!==!1&&this.inspect(null)}),this.rootEl.append(this.toolbarEl,this.canvasEl),this.containerEl.textContent="",this.containerEl.appendChild(this.rootEl)}recompute(){let t=this.options,n=et(t.states.geometry),i=t.referenceOverlay?et(t.referenceOverlay.geometry):null,r=$e({type:"FeatureCollection",features:[...n.features,...i?.features??[]]}),o=qe(t.states,r,t.minPartExtent??0),a=t.referenceOverlay?Qn(t.referenceOverlay,r):[],l=o.find(p=>p.id===this.activeDrillDownId)??null,u=!!(l&&this.activeDrillDownId),d=this.loadedDistricts?.stateId===this.activeDrillDownId?this.loadedDistricts.layer:null,s=this.loadedDistrictReferenceOverlay?.stateId===this.activeDrillDownId?this.loadedDistrictReferenceOverlay.overlay:null,c=d?et(d.geometry):null,h=s?et(s.geometry):null,f=c?$e({type:"FeatureCollection",features:[...c.features,...h?.features??[]]}):null,m=d&&f?qe(d,f,t.minDistrictPartExtent??t.minPartExtent??0):[],S=m.find(p=>p.id===this.activeSubDrillDownId)??null,g=!!(u&&S&&this.activeSubDrillDownId)?"subdistrict":u?"district":"state",v=this.loadedSubDistricts?.districtId===this.activeSubDrillDownId?this.loadedSubDistricts.layer:null,y=v?et(v.geometry):null,b=y?$e(y):null,x=v&&b?qe(v,b,t.minDistrictPartExtent??t.minPartExtent??0):[],E=g==="subdistrict"?x:g==="district"?m:o,C=g==="district"&&s&&f?Qn(s,f):[],P=E.find(p=>p.id===this.activeSelectedId)??null,R=E.find(p=>p.id===this.inspectedId)??null;this.inspectedId&&!R&&(this.inspectedId=null);let L=E.map(p=>p.value).filter(p=>p!==null),D=On(L),U=L.length?Math.min(...L):0,O=L.length?Math.max(...L):0;this.derived={stateRegions:o,referenceRegions:a,drilledState:l,drilledDistrict:S,districtRegions:m,level:g,regions:E,visibleReferenceRegions:g==="state"?a:C,selected:P,inspected:R,total:D,min:U,max:O,canDrill:g==="state"?!!t.loadDistricts:g==="district"?!!t.loadSubDistricts:!1,mergedReferenceIds:new Set(t.referenceOverlayMergeIds??[]),buckets:Gn(Zn(t),E.map(p=>p.value),U,O)};let A=[g,this.activeDrillDownId??"",this.activeSubDrillDownId??"",typeof t.colorScale=="function"?"function":(t.colorScale??Bt).join(",")].join("|");A!==this.bandsKey&&(this.bandsKey=A,this.activeBucket=null),this.activeBucket!==null&&this.activeBucket>=this.derived.buckets.length&&(this.activeBucket=null)}loadDistrictsFor(t){let n=this.options;if(!n.loadDistricts){this.loadedDistricts=null,this.loadingState=null,this.loadError=null;return}let i=this.derived.stateRegions.find(o=>o.id===t);if(!i)return;let r=++this.districtGeneration;this.loadingState=t,this.loadError=null,this.loadedDistricts=null,n.loadDistricts(t,i).then(o=>{this.destroyed||r!==this.districtGeneration||(this.loadedDistricts={stateId:t,layer:o},this.loadingState=null,this.renderStructure())}).catch(o=>{this.destroyed||r!==this.districtGeneration||(this.loadError=o instanceof Error?o:new Error("Unable to load districts."),this.loadingState=null,this.renderStructure())})}loadSubDistrictsFor(t){let n=this.options;if(!n.loadSubDistricts){this.loadedSubDistricts=null,this.loadingDistrict=null,this.subLoadError=null;return}let i=this.derived.districtRegions.find(o=>o.id===t);if(!i||!this.activeDrillDownId)return;let r=++this.subDistrictGeneration;this.loadingDistrict=t,this.subLoadError=null,this.loadedSubDistricts=null,n.loadSubDistricts(t,i,this.activeDrillDownId).then(o=>{if(!(this.destroyed||r!==this.subDistrictGeneration)){if(this.loadingDistrict=null,!o){this.leafDistrictIds.add(t),this.setActiveSubDrillDownId(null),this.setActiveSelectedId(i.id),n.onSubDistrictDrillDownChange?.(null,i),this.renderStructure();return}this.loadedSubDistricts={districtId:t,layer:o},this.renderStructure()}}).catch(o=>{this.destroyed||r!==this.subDistrictGeneration||(this.subLoadError=o instanceof Error?o:new Error("Unable to load sub-districts."),this.loadingDistrict=null,this.renderStructure())})}loadDistrictReferenceOverlayFor(t){let n=this.options;if(!n.loadDistrictReferenceOverlay){this.loadedDistrictReferenceOverlay=null;return}let i=this.derived.stateRegions.find(o=>o.id===t);if(!i)return;let r=++this.overlayGeneration;this.loadedDistrictReferenceOverlay=null,n.loadDistrictReferenceOverlay(t,i).then(o=>{this.destroyed||r!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:t,overlay:o},this.renderStructure())}).catch(()=>{this.destroyed||r!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:t,overlay:null},this.renderStructure())})}inspect(t){let n=t?.id??null;n===null&&this.inspectedId===null||(this.inspectedId=n,this.derived.inspected=t,this.options.onInspect?.(t??null,this.derived.level),this.applyInteractionState())}toViewBox(t){let n=this.canvasEl.querySelector("svg");if(!n)return null;let i=n.getBoundingClientRect();if(i.width===0||i.height===0)return null;let r=Math.min(i.width/H.width,i.height/H.height),o=(i.width-H.width*r)/2,a=(i.height-H.height*r)/2;return[(t.clientX-i.left-o)/r,(t.clientY-i.top-a)/r]}smallRegionNear(t){let n=null,i=1/0;for(let r of this.derived.regions){if(r.extent<=0||r.extent>=ze)continue;let o=Un(t,r.partBounds);o<=Wi&&o<i&&(i=o,n=r)}return n}activate(t){let n=this.options;if(n.onRegionClick?.(t,this.derived.level),this.setActiveSelectedId(t.id),n.onSelectedChange?.(t,this.derived.level),this.derived.level==="state"&&n.loadDistricts){this.setActiveSelectedId(null),this.setActiveDrillDownId(t.id),n.onDrillDownChange?.(t.id,t),this.renderStructure();return}if(this.derived.level==="district"&&n.loadSubDistricts&&!this.leafDistrictIds.has(t.id)){this.setActiveSelectedId(null),this.setActiveSubDrillDownId(t.id),n.onSubDistrictDrillDownChange?.(t.id,t),this.renderStructure();return}this.applyInteractionState()}goBack(){if(this.derived.level==="subdistrict"){let t=this.derived.drilledDistrict??void 0;this.setActiveSubDrillDownId(null),this.setActiveSelectedId(t?.id??null),this.inspectedId=t?.id??null,this.restoreFocusId=t?.id??null,this.options.onSubDistrictDrillDownChange?.(null,t),this.renderStructure();return}this.goToStates()}goToStates(){let t=this.derived.drilledState??void 0,n=this.derived.drilledDistrict??void 0;this.setActiveSubDrillDownId(null),this.setActiveDrillDownId(null),this.setActiveSelectedId(t?.id??null),this.inspectedId=t?.id??null,this.restoreFocusId=t?.id??null,n&&this.options.onSubDistrictDrillDownChange?.(null,n),this.options.onDrillDownChange?.(null,t),this.renderStructure()}renderStructure(){if(this.destroyed)return;this.recompute();let t=this.options;this.activeDrillDownId&&t.loadDistricts&&this.attemptedDistrictLoadForId!==this.activeDrillDownId&&(this.attemptedDistrictLoadForId=this.activeDrillDownId,this.loadDistrictsFor(this.activeDrillDownId)),this.activeDrillDownId||(this.loadedDistricts=null,this.loadingState=null,this.loadError=null,this.attemptedDistrictLoadForId=null),this.activeDrillDownId&&t.loadDistrictReferenceOverlay&&this.attemptedOverlayLoadForId!==this.activeDrillDownId&&(this.attemptedOverlayLoadForId=this.activeDrillDownId,this.loadDistrictReferenceOverlayFor(this.activeDrillDownId)),(!this.activeDrillDownId||!t.loadDistrictReferenceOverlay)&&(this.loadedDistrictReferenceOverlay=null,this.attemptedOverlayLoadForId=null),this.activeSubDrillDownId&&t.loadSubDistricts&&this.attemptedSubDistrictLoadForId!==this.activeSubDrillDownId&&this.derived.districtRegions.some(i=>i.id===this.activeSubDrillDownId)&&(this.attemptedSubDistrictLoadForId=this.activeSubDrillDownId,this.loadSubDistrictsFor(this.activeSubDrillDownId)),this.activeSubDrillDownId||(this.loadedSubDistricts=null,this.loadingDistrict=null,this.subLoadError=null,this.attemptedSubDistrictLoadForId=null);let n=t.interactive!==!1;if(this.rootEl.className=["india-choropleth",!n&&"india-choropleth--static",t.className].filter(Boolean).join(" "),this.loadingState||this.loadingDistrict?this.rootEl.setAttribute("aria-busy","true"):this.rootEl.removeAttribute("aria-busy"),this.renderToolbar(),this.renderCanvas(),this.renderLegend(),this.restoreFocusId&&this.derived.regions.some(i=>i.id===this.restoreFocusId)){let i=this.restoreFocusId;this.restoreFocusId=null,this.pathRefs.get(i)?.focus()}}renderToolbar(){let t=this.options;if(this.toolbarEl.textContent="",t.showBreadcrumb===!1)return;let n=G("nav",{class:"india-choropleth__breadcrumb","aria-label":"Map hierarchy"}),i=()=>{let a=G("span",{"aria-hidden":"true"});return a.textContent="/",a};if(!this.derived.drilledState){let a=G("span");a.textContent="All states",n.append(a),this.toolbarEl.append(n);return}let r=G("button",{class:"india-choropleth__back",type:"button"});if(r.textContent="All states",r.addEventListener("click",()=>this.goToStates()),n.append(r,i()),this.derived.level==="subdistrict"&&this.derived.drilledDistrict){let a=G("button",{class:"india-choropleth__back",type:"button"});a.textContent=this.derived.drilledState.label,a.addEventListener("click",()=>this.goBack());let l=G("span",{"aria-current":"page"});l.textContent=this.derived.drilledDistrict.label,n.append(a,i(),l)}else{let a=G("span",{"aria-current":"page"});a.textContent=this.derived.drilledState.label,n.append(a)}this.toolbarEl.append(n)}renderCanvas(){let t=this.options,n=t.interactive!==!1;this.canvasEl.textContent="",this.pathRefs.clear(),this.bucketEls=[],this.svgRootEl=null,this.tooltipAnchorEl=null,this.tooltipContentEl=null,this.selectionGroupEl=null,this.selectionPathEls=[];let i=!!(this.derived.drilledState&&this.activeDrillDownId),r=this.derived.level==="subdistrict",o=r&&(!this.loadedSubDistricts||this.loadedSubDistricts.districtId!==this.activeSubDrillDownId||this.subLoadError),a=!o&&i&&(!this.loadedDistricts||this.loadedDistricts.stateId!==this.activeDrillDownId||this.loadError),l=!o&&!a&&this.derived.regions.length===0;if(o||a||l){let g=o&&this.subLoadError||a&&this.loadError,v=G("div",{class:"india-choropleth__status",role:g?"alert":"status"});v.textContent=o?this.subLoadError?this.subLoadError.message:this.loadingDistrict?"Loading sub-districts\u2026":"Sub-district data is unavailable for this district.":l?r?"No sub-district data is available for this district.":"No district data is available for this state.":this.loadError?this.loadError.message:this.loadingState?"Loading districts\u2026":"District data is unavailable for this state.",this.canvasEl.append(v),this.applyInteractionState();return}let u=N("svg",{class:"india-choropleth__svg",viewBox:`0 0 ${H.width} ${H.height}`,role:"group","aria-label":t.ariaLabel??"Interactive choropleth map"});if(this.svgRootEl=u,n&&(u.addEventListener("keydown",g=>{g.key==="Escape"&&(g.preventDefault(),this.inspect(null))}),u.addEventListener("click",g=>{if(g.target!==u)return;let v=this.toViewBox(g),y=v?this.smallRegionNear(v):null;if(y){this.activate(y);return}this.options.onBackgroundClick?.(),this.activeSelectedId!==null&&(this.setActiveSelectedId(null),this.options.onSelectedChange?.(null,this.derived.level),this.applyInteractionState())})),this.derived.visibleReferenceRegions.length>0){let g=N("defs"),v=N("pattern",{id:this.hatchId,width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)"});v.append(N("rect",{width:"8",height:"8",fill:"var(--india-map-reference-bg)"}),N("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:"var(--india-map-reference-hatch)","stroke-width":"2"})),g.append(v),u.append(g);let y=N("g",{class:"india-choropleth__reference-fill",role:"group","aria-label":"Non-statistical reference context."});for(let b of this.derived.visibleReferenceRegions)y.append(N("path",{d:b.path,fill:t.referenceOverlayFill==="solid"?"var(--india-map-reference-bg)":`url(#${this.hatchId})`,"aria-label":`${b.label}.${b.description?` ${b.description}`:""}`,role:"img"}));u.append(y)}let d=n?this.derived.regions.filter(g=>g.hitPath):[];if(d.length>0){let g=N("g",{class:"india-choropleth__hit-areas","aria-hidden":"true"});for(let v of d){let y=N("path",{d:v.hitPath,fill:"none","pointer-events":"all",tabindex:"-1"});y.addEventListener("mouseenter",()=>this.inspect(v)),y.addEventListener("mouseleave",()=>this.inspect(null)),y.addEventListener("click",()=>this.activate(v)),g.append(y)}u.append(g)}let s=g=>re(g.value,this.derived.min,this.derived.max,Zn(t).length);for(let g of this.derived.regions){let y=this.derived.canDrill&&!(this.derived.level==="district"&&this.leafDistrictIds.has(g.id))?this.derived.level==="state"?"Activate to view districts.":"Activate to view sub-districts.":"Activate to select.",b=g.value===null?"No data":(t.formatValue??se)(g.value),x=N("path",{class:"india-choropleth__region",d:g.path,fill:Jn(g.value,g,this.derived.min,this.derived.max,t.colorScale??Bt),tabindex:n?"0":"-1","aria-label":`${g.label}, ${b}. ${y}`});n&&x.setAttribute("role","button"),this.derived.mergedReferenceIds.has(g.id)&&x.classList.add("india-choropleth__region--reference-merged"),n&&(x.setAttribute("aria-pressed",g.id===this.derived.selected?.id?"true":"false"),x.addEventListener("mouseenter",()=>this.inspect(g)),x.addEventListener("mouseleave",()=>this.inspect(null)),x.addEventListener("focus",()=>this.inspect(g)),x.addEventListener("blur",()=>this.inspect(null)),x.addEventListener("click",()=>this.activate(g)),x.addEventListener("keydown",E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),this.activate(g))})),u.append(x),this.pathRefs.set(g.id,x),this.bucketEls.push({el:x,bucket:s(g)})}let c=this.derived.regions.filter(g=>g.extent>0&&g.extent<le);if(c.length>0){let g=N("g",{class:"india-choropleth__small-markers","aria-hidden":"true"});for(let v of c){let y=N("circle",{cx:String(v.centroid[0]),cy:String(v.centroid[1]),r:String(le/2),fill:Jn(v.value,v,this.derived.min,this.derived.max,t.colorScale??Bt)});n&&(y.addEventListener("mouseenter",()=>this.inspect(v)),y.addEventListener("mouseleave",()=>this.inspect(null)),y.addEventListener("click",()=>this.activate(v))),this.bucketEls.push({el:y,bucket:s(v)}),g.append(y)}u.append(g)}if(t.showRegionValues){let g=N("g",{class:`india-choropleth__region-values${this.derived.level==="state"?"":" india-choropleth__region-values--district"}`,"aria-hidden":"true"}),v=N("g",{class:"india-choropleth__value-leaders","aria-hidden":"true"});for(let y of this.derived.regions){if(!y.centroid.every(Number.isFinite))continue;let b=y.value===null?"\u2014":(t.formatValue??se)(y.value),x=this.placeRegionValue(y,b);if(!x)continue;let E=N("text",{x:String(x.at[0]),y:String(x.at[1]),"text-anchor":"middle","dominant-baseline":"central"});if(E.textContent=b,g.append(E),this.bucketEls.push({el:E,bucket:s(y)}),x.leader){let C=N("line",{x1:String(x.leader[0][0]),y1:String(x.leader[0][1]),x2:String(x.leader[1][0]),y2:String(x.leader[1][1])});this.bucketEls.push({el:C,bucket:s(y)}),v.append(C)}}u.append(v,g)}if(this.derived.visibleReferenceRegions.length>0){let g=N("g",{class:"india-choropleth__reference-outline","aria-hidden":"true"});for(let v of this.derived.visibleReferenceRegions)g.append(N("path",{d:v.path,fill:"none"}));u.append(g)}let h=N("g",{class:"india-choropleth__selection","aria-hidden":"true"}),f=N("path",{class:"india-choropleth__selection-halo",fill:"none"}),m=N("path",{class:"india-choropleth__selection-ring",fill:"none"});h.append(f,m),u.append(h),this.selectionGroupEl=h,this.selectionPathEls=[f,m],this.canvasEl.append(u);let S=G("div",{class:"india-choropleth__tooltip-anchor"});S.style.display="none";let w=G("div",{id:this.tooltipId,class:"india-choropleth__tooltip"});S.append(w),this.canvasEl.append(S),this.tooltipAnchorEl=S,this.tooltipContentEl=w,this.applyInteractionState()}placeRegionValue(t,n){let i=t.extent>0&&t.extent<ze,r=Math.max(n.length*3.1,3),o=5.5,a=t.partBounds.some(([m,S,w,g])=>w-m>=r*2&&g-S>=o*2);if(!i&&a)return{at:t.centroid};let l=i?Vn({anchor:t.centroid,clearance:Math.max(t.extent,le)/2+4+r,halfSize:[r,o],viewBox:[H.width,H.height],centre:[H.width/2,H.height/2],isBlocked:m=>this.coversAnotherRegion(t,m,r,o)}):null;if(!l)return a?{at:t.centroid}:null;let u=Math.max(t.extent,le)/2+1,d=l[0]-t.centroid[0],s=l[1]-t.centroid[1],c=Math.hypot(d,s);if(c<=u+r)return{at:l};let h=[t.centroid[0]+d/c*u,t.centroid[1]+s/c*u],f=[l[0]-d/c*(r+1.5),l[1]-s/c*(r+1.5)];return{at:l,leader:[h,f]}}coversAnotherRegion(t,n,i,r){let o=[n,[n[0]-i,n[1]-r],[n[0]+i,n[1]+r],[n[0]+i,n[1]-r],[n[0]-i,n[1]+r]];for(let a of this.derived.regions)if(a.id!==t.id){for(let l of o)if(a.partBounds.some(([u,d,s,c])=>l[0]>=u&&l[0]<=s&&l[1]>=d&&l[1]<=c))return!0}return!1}renderLegend(){let t=this.options;if(this.legendEl&&(this.legendEl.remove(),this.legendEl=null),t.showLegend===!1)return;let[n,i]=t.legendLabels??["Lower","Higher"],r=G("div",{class:"india-choropleth__legend",role:"group","aria-label":`Color scale: ${n} to ${i} values`}),o=G("span");o.textContent=n;let a=t.interactive!==!1,l=G("div",{class:"india-choropleth__swatches"});a||l.setAttribute("aria-hidden","true"),this.swatchEls=[];for(let d of this.derived.buckets){let s=G(a?"button":"i",{class:"india-choropleth__swatch"});if(s.style.backgroundColor=d.color,a){s.setAttribute("type","button");let c=Nn(d,t.formatValue??se);s.setAttribute("aria-label",c),s.setAttribute("title",c),d.matches===0&&s.setAttribute("aria-disabled","true"),s.addEventListener("click",()=>{d.matches!==0&&(this.activeBucket=this.activeBucket===d.index?null:d.index,this.applyInteractionState())}),this.swatchEls.push(s)}l.append(s)}let u=G("span");if(u.textContent=i,r.append(o,l,u),this.derived.visibleReferenceRegions.length>0){let d=G("i",{class:`india-choropleth__reference-key${t.referenceOverlayFill==="solid"?" india-choropleth__reference-key--solid":""}`,"aria-hidden":"true"}),s=G("span");s.textContent=t.referenceOverlayLegendLabel??"Reference context \xB7 data unavailable",r.append(d,s)}this.insightsEl?this.rootEl.insertBefore(r,this.insightsEl):this.rootEl.append(r),this.legendEl=r,a&&r.addEventListener("keydown",d=>{d.key==="Escape"&&(d.preventDefault(),this.activeBucket=null,this.applyInteractionState())}),this.applyLegendState()}renderInsights(){let t=this.options;if(this.insightsEl&&(this.insightsEl.remove(),this.insightsEl=null),!t.renderInsights)return;let n=G("aside",{class:"india-choropleth__insights","aria-live":"polite"});t.renderInsights(this.computeInsightContext(),n),this.rootEl.append(n),this.insightsEl=n}applyInteractionState(){if(this.destroyed)return;this.derived.selected=this.derived.regions.find(n=>n.id===this.activeSelectedId)??null,this.derived.inspected=this.derived.regions.find(n=>n.id===this.inspectedId)??null;let t=this.options.interactive!==!1;for(let[n,i]of this.pathRefs){let r=n===this.derived.inspected?.id,o=n===this.derived.selected?.id;i.classList.toggle("india-choropleth__region--inspected",r),i.classList.toggle("india-choropleth__region--selected",o),t&&(i.setAttribute("aria-pressed",o?"true":"false"),r?i.setAttribute("aria-describedby",this.tooltipId):i.removeAttribute("aria-describedby"))}for(let{el:n,bucket:i}of this.bucketEls)n.classList.toggle("india-choropleth__dimmed",this.activeBucket!==null&&i!==this.activeBucket);this.svgRootEl?.classList.toggle("india-choropleth__svg--filtered",this.activeBucket!==null),this.applyLegendState(),this.renderSelectionRing(),this.renderTooltip(),this.renderInsights(),this.options.onInsight?.(this.computeInsightContext())}applyLegendState(){if(this.legendEl)for(let[t,n]of this.swatchEls.entries()){let i=this.activeBucket===t;n.classList.toggle("india-choropleth__swatch--active",i),n.classList.toggle("india-choropleth__swatch--muted",this.activeBucket!==null&&!i),n.setAttribute("aria-pressed",i?"true":"false")}}renderTooltip(){if(!this.tooltipAnchorEl||!this.tooltipContentEl)return;let t=this.derived.inspected;if(!t){this.tooltipAnchorEl.style.display="none";return}let n=this.toTooltipContext(t);this.tooltipAnchorEl.style.display="",this.tooltipAnchorEl.style.left=`${t.centroid[0]/H.width*100}%`,this.tooltipAnchorEl.style.top=`${t.centroid[1]/H.height*100}%`,this.tooltipContentEl.textContent="";let i=this.options.renderTooltip?this.options.renderTooltip(n):Xi(n,this.options.formatValue??se);Ji(this.tooltipContentEl,i),this.positionTooltip()}renderSelectionRing(){let t=this.selectionGroupEl;if(!t)return;let n=this.derived.selected;if(!n){t.style.display="none";return}t.style.display="";for(let i of this.selectionPathEls)i.setAttribute("d",n.path);t.classList.toggle("india-choropleth__selection--lifted",n.id===this.derived.inspected?.id)}positionTooltip(){let t=this.tooltipAnchorEl;if(!t)return;t.style.removeProperty("--india-map-tooltip-dx"),t.style.removeProperty("--india-map-tooltip-dy");let n=t.getBoundingClientRect(),i=this.canvasEl.getBoundingClientRect();if(n.width===0||i.width===0)return;let{dx:r,side:o}=jn(n,i,Yn);r!==0&&t.style.setProperty("--india-map-tooltip-dx",`${Math.round(r)}px`),o==="below"&&t.style.setProperty("--india-map-tooltip-dy",`${Yn}px`)}toTooltipContext(t){let n=this.derived.regions.filter(r=>r.value!==null),i=t.value===null?null:n.filter(r=>(r.value??0)>(t.value??0)).length+1;return{...t,level:this.derived.level,total:this.derived.total,share:t.value===null||this.derived.total===0?null:t.value/this.derived.total*100,rank:i,rankedCount:n.length}}computeInsightContext(){let t=this.derived.inspected??this.derived.selected;return t?{...this.toTooltipContext(t),selected:t.id===this.derived.selected?.id}:null}};var de="https://cdn.jsdelivr.net/gh/shashankbudem/bharat-choropleth@v0.1.0/data/generated",ti="State/UT, district and sub-district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).";function He(e){return e.replace(/\/+$/,"")}function ei(e){return`${He(e)}/current-2019-states/states.topo.json`}function Zi(e,t){return`${He(e)}/current-2019-districts/districts/${t}.topo.json`}function Qi(e,t){return`${He(e)}/current-2019-subdistricts/subdistricts/${t}.topo.json`}async function ni(e,t){if(typeof fetch!="function")throw new Error("BharatChoropleth: no global fetch is available, so boundary data cannot be downloaded. Pass `geometry` with data you loaded yourself.");let n=await fetch(e,{signal:t});if(!n.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${e} (HTTP ${n.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return n.json()}function ce(e,t){if(!e||typeof e!="object")throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.");let n=e;if(n.type==="FeatureCollection"||"topology"in n&&"object"in n)return e;if(n.type==="Topology"&&n.objects&&typeof n.objects=="object"){let i=n.objects,r=t in i?t:Object.keys(i)[0];if(!r)throw new Error("BharatChoropleth: the TopoJSON topology contains no objects.");return{topology:e,object:r}}throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.")}async function ii(e,t,n){return typeof e=="string"?ce(await ni(e,n),t):e instanceof Promise?ce(await e,t):e}function ri(e){return typeof e=="object"&&e!==null&&!(e instanceof Promise)}async function oi(e,t,n){return ce(await ni(Zi(e,t),n),"districts")}async function ai(e,t,n){let i=Qi(e,t);if(typeof fetch!="function")throw new Error("BharatChoropleth: no global fetch is available, so boundary data cannot be downloaded. Pass `geometry` with data you loaded yourself.");let r=await fetch(i,{signal:n});if(r.status===404)return null;if(!r.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${i} (HTTP ${r.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return ce(await r.json(),"subdistricts")}var Ue=[{id:"in-cs-01-jammu-and-kashmir",name:"Jammu & Kashmir",slug:"jammu-and-kashmir"},{id:"in-cs-02-himachal-pradesh",name:"Himachal Pradesh",slug:"himachal-pradesh"},{id:"in-cs-03-punjab",name:"Punjab",slug:"punjab"},{id:"in-cs-04-chandigarh",name:"Chandigarh",slug:"chandigarh"},{id:"in-cs-05-uttarakhand",name:"Uttarakhand",slug:"uttarakhand"},{id:"in-cs-06-haryana",name:"Haryana",slug:"haryana"},{id:"in-cs-07-delhi",name:"Delhi",slug:"delhi"},{id:"in-cs-08-rajasthan",name:"Rajasthan",slug:"rajasthan"},{id:"in-cs-09-uttar-pradesh",name:"Uttar Pradesh",slug:"uttar-pradesh"},{id:"in-cs-10-bihar",name:"Bihar",slug:"bihar"},{id:"in-cs-11-sikkim",name:"Sikkim",slug:"sikkim"},{id:"in-cs-12-arunachal-pradesh",name:"Arunachal Pradesh",slug:"arunachal-pradesh"},{id:"in-cs-13-nagaland",name:"Nagaland",slug:"nagaland"},{id:"in-cs-14-manipur",name:"Manipur",slug:"manipur"},{id:"in-cs-15-mizoram",name:"Mizoram",slug:"mizoram"},{id:"in-cs-16-tripura",name:"Tripura",slug:"tripura"},{id:"in-cs-17-meghalaya",name:"Meghalaya",slug:"meghalaya"},{id:"in-cs-18-assam",name:"Assam",slug:"assam"},{id:"in-cs-19-west-bengal",name:"West Bengal",slug:"west-bengal"},{id:"in-cs-20-jharkhand",name:"Jharkhand",slug:"jharkhand"},{id:"in-cs-21-odisha",name:"Odisha",slug:"odisha"},{id:"in-cs-22-chhattisgarh",name:"Chhattisgarh",slug:"chhattisgarh"},{id:"in-cs-23-madhya-pradesh",name:"Madhya Pradesh",slug:"madhya-pradesh"},{id:"in-cs-24-gujarat",name:"Gujarat",slug:"gujarat"},{id:"in-cs-26-dadra-and-nagar-haveli-and-daman-and-diu",name:"Dadra and Nagar Haveli and Daman and Diu",slug:"dadra-and-nagar-haveli-and-daman-and-diu"},{id:"in-cs-27-maharashtra",name:"Maharashtra",slug:"maharashtra"},{id:"in-cs-28-andhra-pradesh",name:"Andhra Pradesh",slug:"andhra-pradesh"},{id:"in-cs-29-karnataka",name:"Karnataka",slug:"karnataka"},{id:"in-cs-30-goa",name:"Goa",slug:"goa"},{id:"in-cs-31-lakshadweep",name:"Lakshadweep",slug:"lakshadweep"},{id:"in-cs-32-kerala",name:"Kerala",slug:"kerala"},{id:"in-cs-33-tamil-nadu",name:"Tamil Nadu",slug:"tamil-nadu"},{id:"in-cs-34-puducherry",name:"Puducherry",slug:"puducherry"},{id:"in-cs-35-andaman-and-nicobar",name:"Andaman & Nicobar",slug:"andaman-and-nicobar"},{id:"in-cs-36-telangana",name:"Telangana",slug:"telangana"},{id:"in-cs-37-ladakh",name:"Ladakh",slug:"ladakh"}],tr={orissa:"odisha",pondicherry:"puducherry",uttaranchal:"uttarakhand","nct-of-delhi":"delhi","new-delhi":"delhi","delhi-nct":"delhi","jammu-kashmir":"jammu-and-kashmir","j-and-k":"jammu-and-kashmir",jk:"jammu-and-kashmir","andaman-nicobar":"andaman-and-nicobar","andaman-and-nicobar-islands":"andaman-and-nicobar","dadra-and-nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu","daman-and-diu":"dadra-and-nagar-haveli-and-daman-and-diu",dnhdd:"dadra-and-nagar-haveli-and-daman-and-diu","nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu"};function Ot(e){return e.toLowerCase().replace(/&/g," and ").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ve(e){return e.replace(/-/g,"")}var xt=new Map,Ft=new Map;for(let e of Ue)for(let t of[e.slug,Ot(e.name),e.id]){xt.has(t)||xt.set(t,e);let n=Ve(t);Ft.has(n)||Ft.set(n,e)}for(let[e,t]of Object.entries(tr)){let n=xt.get(t);if(!n)continue;xt.has(e)||xt.set(e,n);let i=Ve(e);Ft.has(i)||Ft.set(i,n)}function ut(e){let t=Ot(e);return xt.get(t)??Ft.get(Ve(t))}function si(e,t){if(!e.includes("_"))return;let n=e.replace(/_([a-z])/g,(i,r)=>r.toUpperCase());return n!==e&&n in t?n:void 0}function ci(e){return typeof e=="object"&&e!==null&&e.nodeType===1}var li=["#bharat-choropleth","#map"];function er(e){if(ci(e))return e;if(typeof e=="string"){let t=document.querySelector(e);if(t)return t;throw new Error(`BharatChoropleth: container "${e}" was not found.`)}for(let t of li){let n=document.querySelector(t);if(n)return n}throw new Error(`BharatChoropleth: no container given and none of ${li.join(", ")} exist. Pass an element or selector: new BharatChoropleth("#map").`)}var Gt=class{ready;engineInstance=null;containerEl;options;dataBaseUrl;usingDefaultData;values=new Map;labelByKey=new Map;writtenAs=new Map;statesAccessor;abortController;getId;getLabel;loadingEl=null;destroyed=!1;_fontColor;_borderColor;_borderWidth;_selectionWidth;_colorScale;constructor(t,n={}){let r=typeof t=="object"&&t!==null&&!ci(t)?{...t}:{...n,container:t??n.container};this.options=r,this.containerEl=er(r.container),this.dataBaseUrl=r.dataBaseUrl??de,this.usingDefaultData=r.geometry===void 0,this.getId=r.getId??(o=>String(o.properties?.id??o.properties?.name)),this.getLabel=r.getLabel??(o=>String(o.properties?.name??o.properties?.id));for(let[o,a]of Object.entries(r.values??{})){let l=this.keyFor(o);this.values.set(l,a),this.writtenAs.set(l,o)}return this._colorScale=r.colorScale,this._fontColor=r.fontColor,this._borderColor=r.borderColor,this._borderWidth=r.borderWidth,this._selectionWidth=r.selectionWidth,this.statesAccessor=new Proxy({},{get:(o,a)=>typeof a=="string"?this.getValue(a):void 0,has:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a)),ownKeys:()=>[...this.labelByKey.values()],getOwnPropertyDescriptor:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a))?{enumerable:!0,configurable:!0,value:this.getValue(a)}:void 0,set:(o,a,l)=>typeof a!="string"?!1:(this.setValue(a,l),!0)}),ri(r.geometry)?(this.abortController=null,this.ready=Promise.resolve(this),this.mount(r.geometry)):(this.abortController=typeof AbortController=="function"?new AbortController:null,this.showLoading(),this.ready=ii(r.geometry??ei(this.dataBaseUrl),"states",this.abortController?.signal).then(o=>this.destroyed?this.proxied??this:(this.mount(o),this.proxied??this)).catch(o=>{if(this.destroyed||o.name==="AbortError")return this.proxied??this;throw this.showError(o),o}),this.ready.catch(()=>{})),this.proxied=new Proxy(this,{get:(o,a,l)=>{if(typeof a=="string"&&!(a in o)){let u=si(a,o);return u?Reflect.get(o,u,l):this.getValue(a)}return Reflect.get(o,a,l)},set:(o,a,l,u)=>{if(typeof a=="string"&&!(a in o)){let d=si(a,o);return d?Reflect.set(o,d,l,u):(this.setValue(a,l),!0)}return Reflect.set(o,a,l,u)}}),this.proxied}proxied;keyFor(t){return ut(t)?.id??Ot(t)}keyForFeature(t){let n=this.getId(t);return ut(n)?.id??ut(this.getLabel(t))?.id??Ot(this.getLabel(t))}getValue(t){return this.values.get(this.keyFor(t))??null}setValue(t,n){let i=this.keyFor(t);this.values.set(i,n),this.writtenAs.has(i)||this.writtenAs.set(i,t),this.engineInstance&&(this.labelByKey.has(i)?this.engineInstance.update({}):this.warnUnknown(t))}warnUnknown(t){console.warn(`BharatChoropleth: "${t}" is not a recognized state/UT \u2014 its value is ignored.`)}mount(t){this.clearPlaceholder();for(let b of et(t).features){let x=this.keyForFeature(b);this.labelByKey.set(x,this.getLabel(b)),this.values.has(x)||this.values.set(x,null)}for(let[b,x]of this.values)!this.labelByKey.has(b)&&x!==null&&this.warnUnknown(this.writtenAs.get(b)??b);let{container:n,geometry:i,dataBaseUrl:r,districts:o,subDistricts:a,getId:l,getLabel:u,values:d,fontColor:s,borderColor:c,borderWidth:h,selectionWidth:f,colorScale:m,onReady:S,onError:w,...g}=this.options,v=o??this.usingDefaultData,y=a??this.usingDefaultData;this.engineInstance=new dt(this.containerEl,{...g,colorScale:m,loadDistricts:g.loadDistricts??(v?this.defaultDistrictLoader:void 0),loadSubDistricts:g.loadSubDistricts??(y?this.defaultSubDistrictLoader:void 0),states:{geometry:t,getId:this.getId,getLabel:this.getLabel,getValue:b=>this.values.get(this.keyForFeature(b))??null}}),this._fontColor&&this.mapRootEl.style.setProperty("--india-map-text",this._fontColor),this._borderColor&&this.mapRootEl.style.setProperty("--india-map-stroke",this._borderColor),this._borderWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-border-width",String(this._borderWidth)),this._selectionWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-selection-width",String(this._selectionWidth)),S?.(this.proxied??this)}defaultDistrictLoader=async t=>({geometry:await oi(this.dataBaseUrl,t,this.abortController?.signal),getId:i=>String(i.properties?.id??i.properties?.name),getLabel:i=>String(i.properties?.name??i.properties?.id),getValue:i=>this.values.get(this.keyFor(this.getLabel(i)))??null});defaultSubDistrictLoader=async t=>{let n=await ai(this.dataBaseUrl,t,this.abortController?.signal);return n?{geometry:n,getId:i=>String(i.properties?.id??i.properties?.name),getLabel:i=>String(i.properties?.name??i.properties?.id),getValue:i=>this.values.get(this.keyFor(this.getLabel(i)))??null}:null};showLoading(){this.loadingEl=document.createElement("div"),this.loadingEl.className="bharat-choropleth__status",this.loadingEl.setAttribute("role","status"),this.loadingEl.textContent="Loading map\u2026",this.containerEl.appendChild(this.loadingEl)}showError(t){this.clearPlaceholder();let n=document.createElement("div");n.className="bharat-choropleth__status bharat-choropleth__status--error",n.setAttribute("role","alert"),n.textContent=t.message,this.containerEl.appendChild(n),this.loadingEl=n,this.options.onError?this.options.onError(t):console.error(t)}clearPlaceholder(){this.loadingEl?.remove(),this.loadingEl=null}get engine(){return this.engineInstance}get states(){return this.statesAccessor}setValues(t){for(let[n,i]of Object.entries(t)){let r=this.keyFor(n);this.values.set(r,i),this.writtenAs.has(r)||this.writtenAs.set(r,n),this.engineInstance&&!this.labelByKey.has(r)&&this.warnUnknown(n)}this.engineInstance?.update({})}getValues(){let t={};for(let[n,i]of this.labelByKey)t[i]=this.values.get(n)??null;return t}get mapRootEl(){return this.containerEl.querySelector(".india-choropleth")??this.containerEl}get fontColor(){return this._fontColor}set fontColor(t){this._fontColor=t,this.engineInstance&&(t?this.mapRootEl.style.setProperty("--india-map-text",t):this.mapRootEl.style.removeProperty("--india-map-text"))}get borderColor(){return this._borderColor}set borderColor(t){this._borderColor=t,this.engineInstance&&(t?this.mapRootEl.style.setProperty("--india-map-stroke",t):this.mapRootEl.style.removeProperty("--india-map-stroke"))}get borderWidth(){return this._borderWidth}set borderWidth(t){this._borderWidth=t,this.setWidthVar("--india-map-border-width",t)}get selectionWidth(){return this._selectionWidth}set selectionWidth(t){this._selectionWidth=t,this.setWidthVar("--india-map-selection-width",t)}setWidthVar(t,n){this.engineInstance&&(n===void 0?this.mapRootEl.style.removeProperty(t):this.mapRootEl.style.setProperty(t,String(n)))}get colorScale(){return this._colorScale}set colorScale(t){this._colorScale=t,this.options.colorScale=t,this.engineInstance?.update({colorScale:t})}select(t){this.engineInstance?.select(t)}drillDown(t){let n=t===null?null:ut(t)?.id??t;this.engineInstance?.drillDown(n)}drillDownSubDistrict(t){this.engineInstance?.drillDownSubDistrict(t)}getSelected(){return this.engineInstance?.getSelected()??null}getInspected(){return this.engineInstance?.getInspected()??null}destroy(){this.destroyed=!0,this.abortController?.abort(),this.clearPlaceholder(),this.engineInstance?.destroy(),this.engineInstance=null}};var di="bharat-choropleth-styles";function ui(){if(typeof document>"u"||document.getElementById(di))return;let e=document.createElement("style");e.id=di,e.textContent=Ke,document.head.appendChild(e)}ui();var We=globalThis;We.BharatChoropleth=Gt;We.IndiaChoropleth=dt;We.BharatChoroplethLib={BharatChoropleth:Gt,IndiaChoropleth:dt,STATES:Ue,resolveState:ut,ATTRIBUTION:ti,DEFAULT_DATA_BASE_URL:de,injectStyles:ui};})();
|
|
126
126
|
//# sourceMappingURL=bharat-choropleth.min.js.map
|