bharat-choropleth-js 0.2.0 → 0.3.1
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 +67 -0
- package/README.md +13 -2
- package/dist/bharat-choropleth.min.js +10 -4
- package/dist/bharat-choropleth.min.js.map +1 -1
- package/dist/index.d.ts +78 -2
- package/dist/index.js +169 -19
- package/dist/index.js.map +1 -1
- package/dist/style.css +8 -2
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.1 - 2026-09-13
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Drilling in no longer loses keyboard focus. Stepping back out had an obvious
|
|
8
|
+
target — the region just left — and going in had none, so focus fell to
|
|
9
|
+
`<body>` on every drill-down, dropping a keyboard user at the top of the
|
|
10
|
+
document. Focus now lands on the first region of the level entered; on the
|
|
11
|
+
message when that level holds nothing; and back on the district itself when
|
|
12
|
+
an optimistic drill turns out to be a leaf, which had unmounted the region
|
|
13
|
+
under the cursor.
|
|
14
|
+
- Changing the state now tells the host that the sub-district level was dropped.
|
|
15
|
+
The map clears that level itself and fired no `onSubDistrictDrillDownChange`,
|
|
16
|
+
so anything mirroring the level kept pointing at a district of the state just
|
|
17
|
+
left — the wrong level, against the wrong map. There is no prior district to
|
|
18
|
+
hand back, because it belonged to the state that is gone, so the callback
|
|
19
|
+
receives `(null, undefined)`.
|
|
20
|
+
- Two spellings of one state in a single batch now warn instead of resolving in
|
|
21
|
+
silence. `{ Orissa: 1, Odisha: 2 }` quietly kept the last; that silence is how
|
|
22
|
+
a mis-shaped dataset becomes a believed wrong number. The last value still
|
|
23
|
+
wins — changing that would move numbers under existing callers — and updating
|
|
24
|
+
a state later is not mistaken for a clash.
|
|
25
|
+
- Legend swatches size from the legend row rather than the viewport. `vw`
|
|
26
|
+
measures the browser window, so in any embed narrower than the page the
|
|
27
|
+
swatches pinned to their maximum and overflowed the map they belong to.
|
|
28
|
+
|
|
29
|
+
## 0.3.0 - 2026-09-05
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Values keyed by a feature id the state registry does not know now match. A
|
|
34
|
+
feature was keyed by its id only if the registry recognised it, and otherwise
|
|
35
|
+
fell back to its *label* — so a dataset keyed by id against geometry outside
|
|
36
|
+
the registry, such as this repo's own historical Census bundle with its
|
|
37
|
+
`in-hs-*` ids, silently rendered as "No data" on every region while looking
|
|
38
|
+
perfectly healthy. Each key a caller writes is now recorded against the
|
|
39
|
+
canonical key it addresses, and a feature is matched by exact id, exact label,
|
|
40
|
+
then either resolved through the registry. Found by building a dashboard on
|
|
41
|
+
the historical bundle.
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- The default data source now points at the `v0.3.0` boundary bundle. A release
|
|
46
|
+
pins the geometry a consumer receives, not only the renderer that draws it.
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- Exported `loadDistrictTopology` and `loadSubDistrictTopology`, so a custom
|
|
51
|
+
loader can fetch the prepared bundles without re-deriving their URL scheme.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- Repainting no longer re-unpacks the topology or refits the projection. The
|
|
56
|
+
zero-config facade calls `update({})` for every value written, and both steps
|
|
57
|
+
ran again each time even though neither reads a value. They are now held
|
|
58
|
+
against `states.geometry`, and the decoded features are passed into layer
|
|
59
|
+
preparation rather than unpacked a second time. Mirrors the React renderer.
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
|
|
63
|
+
- The default data source now points at the `v0.2.0` boundary bundle. It was
|
|
64
|
+
still pinned to `v0.1.0`, which predates `data/generated/current-2019-subdistricts/`,
|
|
65
|
+
so every sub-district request 404'd — and because a 404 means "this district
|
|
66
|
+
has no sub-district level", the level 0.2.0 added was silently unreachable for
|
|
67
|
+
anyone using the default `dataBaseUrl`. Nothing errored; districts simply
|
|
68
|
+
stayed leaves. Self-hosted `dataBaseUrl` deployments were unaffected.
|
|
69
|
+
|
|
3
70
|
## 0.2.0
|
|
4
71
|
|
|
5
72
|
- Added an optional sub-district level below districts — tehsils, taluks,
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ An accessible SVG India state-to-district-to-sub-district choropleth with no fra
|
|
|
9
9
|
```html
|
|
10
10
|
<div id="map"></div>
|
|
11
11
|
|
|
12
|
-
<script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js@0.
|
|
12
|
+
<script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js@0.3.0"></script>
|
|
13
13
|
<script>
|
|
14
14
|
var map = new BharatChoropleth("#map");
|
|
15
15
|
|
|
@@ -145,7 +145,18 @@ const map = new BharatChoropleth("#map");
|
|
|
145
145
|
map.states["Goa"] = 6;
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
The ESM entry also exports the full `IndiaChoropleth` engine, the `STATES` registry, `resolveState`, `ATTRIBUTION` and `
|
|
148
|
+
The ESM entry also exports the full `IndiaChoropleth` engine, the `STATES` registry, `resolveState`, `normalizeStateKey`, `ATTRIBUTION`, `DEFAULT_DATA_BASE_URL`, and the two bundle loaders `loadDistrictTopology` / `loadSubDistrictTopology`, plus every type.
|
|
149
|
+
|
|
150
|
+
The loaders are the ones the zero-config map uses, exported so a custom
|
|
151
|
+
`loadDistricts` or `loadSubDistricts` can fetch the prepared bundles without
|
|
152
|
+
re-deriving their URL scheme:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
import { loadSubDistrictTopology, DEFAULT_DATA_BASE_URL } from "bharat-choropleth-js";
|
|
156
|
+
|
|
157
|
+
const geometry = await loadSubDistrictTopology(DEFAULT_DATA_BASE_URL, districtId);
|
|
158
|
+
// null means the bundle holds no sub-districts for this district — it is a leaf.
|
|
159
|
+
```
|
|
149
160
|
|
|
150
161
|
## `IndiaChoropleth` (full-featured engine)
|
|
151
162
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
1
|
+
"use strict";(()=>{var We=`.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
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
--india-map-focus: #0f766e;
|
|
11
11
|
--india-map-active: #ff725f;
|
|
12
12
|
--india-map-empty: #e7edf0;
|
|
13
|
+
/* Paired with --india-map-text: that variable colours the tooltip as well as the
|
|
14
|
+
map, so a dark theme that sets it must set this too, or it puts light text on
|
|
15
|
+
a white card. */
|
|
13
16
|
--india-map-tooltip-bg: #fff;
|
|
14
17
|
--india-map-tooltip-border: #b8c2ce;
|
|
15
18
|
--india-map-text: #081435;
|
|
@@ -94,8 +97,11 @@
|
|
|
94
97
|
.india-choropleth__tooltip-bar { display: block; height: .3rem; margin: .1rem 0 .15rem; border-radius: .3rem; background: var(--india-map-empty); overflow: hidden; }
|
|
95
98
|
.india-choropleth__tooltip-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--india-map-active); }
|
|
96
99
|
.india-choropleth__legend { margin-top: .75rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .75rem; color: var(--india-map-muted); font: .8125rem/1.3 system-ui, sans-serif; }
|
|
97
|
-
.india-choropleth__swatches { display: flex; gap: .25rem; }
|
|
98
|
-
|
|
100
|
+
.india-choropleth__swatches { display: flex; gap: .25rem; flex: 1 1 auto; min-width: 0; max-width: 100%; }
|
|
101
|
+
/* Sized from the legend row, never the viewport: \`vw\` measures the browser
|
|
102
|
+
window, so in any embed narrower than the page the swatches pinned to
|
|
103
|
+
their maximum and overflowed the map they belong to. */
|
|
104
|
+
.india-choropleth__swatch { flex: 1 1 0; min-width: .5rem; max-width: 4.25rem; height: .75rem; border-radius: .1rem; }
|
|
99
105
|
/* On an interactive map each swatch filters to its own band. The bar stays the
|
|
100
106
|
same 12px it has always been; a transparent border above and below it lifts
|
|
101
107
|
the pointer and touch target to 24px, and the negative margin gives that
|
|
@@ -122,5 +128,5 @@ button.india-choropleth__swatch[aria-disabled="true"] { cursor: default; }
|
|
|
122
128
|
being fetched, and for the message if that fetch fails. */
|
|
123
129
|
.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
130
|
.bharat-choropleth__status--error { background: #fdeceb; color: #8a1c14; }
|
|
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};})();
|
|
131
|
+
`;var W=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,s=Math.abs(t)<Math.abs(o)?t-(a-o):o-(a-t);s&&(n[i++]=s),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 ft(e){return Array.from(pi(e))}var R=1e-6,Ye=1e-12,_=Math.PI,q=_/2,ue=_/4,z=_*2,V=180/_,O=_/180,M=Math.abs,jt=Math.atan,ot=Math.atan2,F=Math.cos;var Xe=Math.exp;var Je=Math.log;var T=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 at(e){return e>1?q:e<-1?-q:Math.asin(e)}function H(){}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 lt(e,t){e&&en.hasOwnProperty(e.type)?en[e.type](e,t):$t(e,t)}function Et(e){return[ot(e[1],e[0]),at(e[2])]}function tt(e){var t=e[0],n=e[1],i=F(n);return[i*F(t),i*T(t),T(n)]}function Dt(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function mt(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 _t(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function It(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 kt(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/z)*z),[e,t]}pe.invert=pe;function fe(e,t,n){return(e%=z)?t||n?kt(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/z)*z),[t,n]}}function an(e){var t=on(e);return t.invert=on(-e),t}function sn(e,t){var n=F(e),i=T(e),r=F(t),o=T(t);function a(s,d){var u=F(d),l=F(s)*u,c=T(s)*u,h=T(d),p=h*n+l*i;return[ot(c*r-p*o,l*n-h*i),at(p*r+c*o)]}return a.invert=function(s,d){var u=F(d),l=F(s)*u,c=T(s)*u,h=T(d),p=h*r-c*o;return[ot(c*r+h*o,l*n+p*i),at(p*n-l*i)]},a}function ln(e){e=fe(e[0]*O,e[1]*O,e.length>2?e[2]*O:0);function t(n){return n=e(n[0]*O,n[1]*O),n[0]*=V,n[1]*=V,n}return t.invert=function(n){return n=e.invert(n[0]*O,n[1]*O),n[0]*=V,n[1]*=V,n},t}function dn(e,t,n,i,r,o){if(n){var a=F(t),s=T(t),d=i*n;r==null?(r=t+i*z,o=t-d/2):(r=cn(a,r),o=cn(a,o),(i>0?r<o:r>o)&&(r+=i*z));for(var u,l=r;i>0?l>o:l<o;l-=d)u=Et([a,-s*F(l),-s*T(l)]),e.point(u[0],u[1])}}function cn(e,t){t=tt(t),t[0]-=e,It(t);var n=tn(-t[1]);return((-t[2]<0?-n:n)+z-R)%z}function zt(){var e=[],t;return{point:function(n,i,r){t.push([n,i,r])},lineStart:function(){e.push(t=[])},lineEnd:H,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function gt(e,t){return M(e[0]-t[0])<R&&M(e[1]-t[1])<R}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=[],s,d;if(e.forEach(function(f){if(!((S=f.length-1)<=0)){var S,x=f[0],g=f[S],v;if(gt(x,g)){if(!x[2]&&!g[2]){for(r.lineStart(),s=0;s<S;++s)r.point((x=f[s])[0],x[1]);r.lineEnd();return}g[0]+=2*R}o.push(v=new Ht(x,f,null,!0)),a.push(v.o=new Ht(x,null,v,!1)),o.push(v=new Ht(g,f,null,!1)),a.push(v.o=new Ht(g,null,v,!0))}}),!!o.length){for(a.sort(t),un(o),un(a),s=0,d=a.length;s<d;++s)a[s].e=n=!n;for(var u=o[0],l,c;;){for(var h=u,p=!0;h.v;)if((h=h.n)===u)return;l=h.z,r.lineStart();do{if(h.v=h.o.v=!0,h.e){if(p)for(s=0,d=l.length;s<d;++s)r.point((c=l[s])[0],c[1]);else i(h.x,h.n.x,1,r);h=h.n}else{if(p)for(l=h.p.z,s=l.length-1;s>=0;--s)r.point((c=l[s])[0],c[1]);else i(h.x,h.p.x,-1,r);h=h.p}h=h.o,l=h.z,p=!p}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])+_)%z-_)}function hn(e,t){var n=me(t),i=t[1],r=T(i),o=[T(n),-F(n),0],a=0,s=0,d=new W;r===1?i=q+R:r===-1&&(i=-q-R);for(var u=0,l=e.length;u<l;++u)if(h=(c=e[u]).length)for(var c,h,p=c[h-1],f=me(p),S=p[1]/2+ue,x=T(S),g=F(S),v=0;v<h;++v,f=b,x=E,g=P,p=y){var y=c[v],b=me(y),w=y[1]/2+ue,E=T(w),P=F(w),k=b-f,L=k>=0?1:-1,B=L*k,D=B>_,$=x*E;if(d.add(ot($*L*T(B),g*P+$*F(B))),a+=D?k+L*z:k,D^f>=n^b>=n){var G=mt(tt(p),tt(y));It(G);var A=mt(o,G);It(A);var m=(D^k>=0?-1:1)*at(A[2]);(i>m||i===m&&(G[0]||G[1]))&&(s+=D^k>=0?1:-1)}}return(a<-R||a<R&&d<-Ye)^s&1}function Vt(e,t,n,i){return function(r){var o=t(r),a=zt(),s=t(a),d=!1,u,l,c,h={point:p,lineStart:S,lineEnd:x,polygonStart:function(){h.point=g,h.lineStart=v,h.lineEnd=y,l=[],u=[]},polygonEnd:function(){h.point=p,h.lineStart=S,h.lineEnd=x,l=ft(l);var b=hn(u,i);l.length?(d||(r.polygonStart(),d=!0),Ut(l,mi,b,n,r)):b&&(d||(r.polygonStart(),d=!0),r.lineStart(),n(null,null,1,r),r.lineEnd()),d&&(r.polygonEnd(),d=!1),l=u=null},sphere:function(){r.polygonStart(),r.lineStart(),n(null,null,1,r),r.lineEnd(),r.polygonEnd()}};function p(b,w){e(b,w)&&r.point(b,w)}function f(b,w){o.point(b,w)}function S(){h.point=f,o.lineStart()}function x(){h.point=p,o.lineEnd()}function g(b,w){c.push([b,w]),s.point(b,w)}function v(){s.lineStart(),c=[]}function y(){g(c[0][0],c[0][1]),s.lineEnd();var b=s.clean(),w=a.result(),E,P=w.length,k,L,B;if(c.pop(),u.push(c),c=null,!!P){if(b&1){if(L=w[0],(k=L.length-1)>0){for(d||(r.polygonStart(),d=!0),r.lineStart(),E=0;E<k;++E)r.point((B=L[E])[0],B[1]);r.lineEnd()}return}P>1&&b&2&&w.push(w.pop().concat(w.shift())),l.push(w.filter(fi))}}return h}}function fi(e){return e.length>1}function mi(e,t){return((e=e.x)[0]<0?e[1]-q-R:q-e[1])-((t=t.x)[0]<0?t[1]-q-R:q-t[1])}var ge=Vt(function(){return!0},gi,yi,[-_,-q]);function gi(e){var t=NaN,n=NaN,i=NaN,r;return{lineStart:function(){e.lineStart(),r=1},point:function(o,a){var s=o>0?_:-_,d=M(o-t);M(d-_)<R?(e.point(t,n=(n+a)/2>0?q:-q),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(s,n),e.point(o,n),r=0):i!==s&&d>=_&&(M(t-i)<R&&(t-=i*R),M(o-s)<R&&(o-=s*R),n=vi(t,n,o,a),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(s,n),r=0),e.point(t=o,n=a),i=s},lineEnd:function(){e.lineEnd(),t=n=NaN},clean:function(){return 2-r}}}function vi(e,t,n,i){var r,o,a=T(e-n);return M(a)>R?jt((T(t)*(o=F(i))*T(n)-T(i)*(r=F(t))*T(e))/(r*o*a)):(t+i)/2}function yi(e,t,n,i){var r;if(e==null)r=n*q,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])>R){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=F(e),n=2*O,i=t>0,r=M(t)>R;function o(l,c,h,p){dn(p,e,n,h,l,c)}function a(l,c){return F(l)*F(c)>t}function s(l){var c,h,p,f,S;return{lineStart:function(){f=p=!1,S=1},point:function(x,g){var v=[x,g],y,b=a(x,g),w=i?b?0:u(x,g):b?u(x+(x<0?_:-_),g):0;if(!c&&(f=p=b)&&l.lineStart(),b!==p&&(y=d(c,v),(!y||gt(c,y)||gt(v,y))&&(v[2]=1)),b!==p)S=0,b?(l.lineStart(),y=d(v,c),l.point(y[0],y[1])):(y=d(c,v),l.point(y[0],y[1],2),l.lineEnd()),c=y;else if(r&&c&&i^b){var E;!(w&h)&&(E=d(v,c,!0))&&(S=0,i?(l.lineStart(),l.point(E[0][0],E[0][1]),l.point(E[1][0],E[1][1]),l.lineEnd()):(l.point(E[1][0],E[1][1]),l.lineEnd(),l.lineStart(),l.point(E[0][0],E[0][1],3)))}b&&(!c||!gt(c,v))&&l.point(v[0],v[1]),c=v,p=b,h=w},lineEnd:function(){p&&l.lineEnd(),c=null},clean:function(){return S|(f&&p)<<1}}}function d(l,c,h){var p=tt(l),f=tt(c),S=[1,0,0],x=mt(p,f),g=Dt(x,x),v=x[0],y=g-v*v;if(!y)return!h&&l;var b=t*g/y,w=-t*v/y,E=mt(S,x),P=_t(S,b),k=_t(x,w);qt(P,k);var L=E,B=Dt(P,L),D=Dt(L,L),$=B*B-D*(Dt(P,P)-1);if(!($<0)){var G=Y($),A=_t(L,(-B-G)/D);if(qt(A,P),A=Et(A),!h)return A;var m=l[0],I=c[0],C=l[1],K=c[1],X;I<m&&(X=m,m=I,I=X);var St=I-m,it=M(St-_)<R,dt=it||St<R;if(!it&&K<C&&(X=C,C=K,K=X),dt?it?C+K>0^A[1]<(M(A[0]-m)<R?C:K):C<=A[1]&&A[1]<=K:St>_^(m<=A[0]&&A[0]<=I)){var rt=_t(L,(-B+G)/D);return qt(rt,P),[A,Et(rt)]}}}function u(l,c){var h=i?e:_-e,p=0;return l<-h?p|=1:l>h&&(p|=2),c<-h?p|=4:c>h&&(p|=8),p}return Vt(a,s,o,i?[0,-e]:[-_,e-_])}function fn(e,t,n,i,r,o){var a=e[0],s=e[1],d=t[0],u=t[1],l=0,c=1,h=d-a,p=u-s,f;if(f=n-a,!(!h&&f>0)){if(f/=h,h<0){if(f<l)return;f<c&&(c=f)}else if(h>0){if(f>c)return;f>l&&(l=f)}if(f=r-a,!(!h&&f<0)){if(f/=h,h<0){if(f>c)return;f>l&&(l=f)}else if(h>0){if(f<l)return;f<c&&(c=f)}if(f=i-s,!(!p&&f>0)){if(f/=p,p<0){if(f<l)return;f<c&&(c=f)}else if(p>0){if(f>c)return;f>l&&(l=f)}if(f=o-s,!(!p&&f<0)){if(f/=p,p<0){if(f>c)return;f>l&&(l=f)}else if(p>0){if(f<l)return;f<c&&(c=f)}return l>0&&(e[0]=a+l*h,e[1]=s+l*p),c<1&&(t[0]=a+c*h,t[1]=s+c*p),!0}}}}}var Rt=1e9,Kt=-Rt;function ve(e,t,n,i){function r(u,l){return e<=u&&u<=n&&t<=l&&l<=i}function o(u,l,c,h){var p=0,f=0;if(u==null||(p=a(u,c))!==(f=a(l,c))||d(u,l)<0^c>0)do h.point(p===0||p===3?e:n,p>1?i:t);while((p=(p+c+4)%4)!==f);else h.point(l[0],l[1])}function a(u,l){return M(u[0]-e)<R?l>0?0:3:M(u[0]-n)<R?l>0?2:1:M(u[1]-t)<R?l>0?1:0:l>0?3:2}function s(u,l){return d(u.x,l.x)}function d(u,l){var c=a(u,1),h=a(l,1);return c!==h?c-h:c===0?l[1]-u[1]:c===1?u[0]-l[0]:c===2?u[1]-l[1]:l[0]-u[0]}return function(u){var l=u,c=zt(),h,p,f,S,x,g,v,y,b,w,E,P={point:k,lineStart:$,lineEnd:G,polygonStart:B,polygonEnd:D};function k(m,I){r(m,I)&&l.point(m,I)}function L(){for(var m=0,I=0,C=p.length;I<C;++I)for(var K=p[I],X=1,St=K.length,it=K[0],dt,rt,Nt=it[0],pt=it[1];X<St;++X)dt=Nt,rt=pt,it=K[X],Nt=it[0],pt=it[1],rt<=i?pt>i&&(Nt-dt)*(i-rt)>(pt-rt)*(e-dt)&&++m:pt<=i&&(Nt-dt)*(i-rt)<(pt-rt)*(e-dt)&&--m;return m}function B(){l=c,h=[],p=[],E=!0}function D(){var m=L(),I=E&&m,C=(h=ft(h)).length;(I||C)&&(u.polygonStart(),I&&(u.lineStart(),o(null,null,1,u),u.lineEnd()),C&&Ut(h,s,m,o,u),u.polygonEnd()),l=u,h=p=f=null}function $(){P.point=A,p&&p.push(f=[]),w=!0,b=!1,v=y=NaN}function G(){h&&(A(S,x),g&&b&&c.rejoin(),h.push(c.result())),P.point=k,b&&l.lineEnd()}function A(m,I){var C=r(m,I);if(p&&f.push([m,I]),w)S=m,x=I,g=C,w=!1,C&&(l.lineStart(),l.point(m,I));else if(C&&b)l.point(m,I);else{var K=[v=Math.max(Kt,Math.min(Rt,v)),y=Math.max(Kt,Math.min(Rt,y))],X=[m=Math.max(Kt,Math.min(Rt,m)),I=Math.max(Kt,Math.min(Rt,I))];fn(K,X,e,t,n,i)?(b||(l.lineStart(),l.point(K[0],K[1])),l.point(X[0],X[1]),C||l.lineEnd(),E=!1):C&&(l.lineStart(),l.point(m,I),E=!1)}v=m,y=I,b=C}return P}}var Pt=e=>e;var ye=new W,be=new W,mn,gn,we,xe,ct={point:H,lineStart:H,lineEnd:H,polygonStart:function(){ct.lineStart=bi,ct.lineEnd=xi},polygonEnd:function(){ct.lineStart=ct.lineEnd=ct.point=H,ye.add(M(be)),be=new W},result:function(){var e=ye/2;return ye=new W,e}};function bi(){ct.point=wi}function wi(e,t){ct.point=vn,mn=we=e,gn=xe=t}function vn(e,t){be.add(xe*e-we*t),we=e,xe=t}function xi(){vn(mn,gn)}var Se=ct;var vt=1/0,Wt=vt,Ct=-vt,Yt=Ct,Si={point:Ei,lineStart:H,lineEnd:H,polygonStart:H,polygonEnd:H,result:function(){var e=[[vt,Wt],[Ct,Yt]];return Ct=Yt=-(Wt=vt=1/0),e}};function Ei(e,t){e<vt&&(vt=e),e>Ct&&(Ct=e),t<Wt&&(Wt=t),t>Yt&&(Yt=t)}var yt=Si;var Ee=0,De=0,Lt=0,Xt=0,Jt=0,bt=0,_e=0,Ie=0,Mt=0,wn,xn,et,nt,J={point:ut,lineStart:yn,lineEnd:bn,polygonStart:function(){J.lineStart=Ii,J.lineEnd=ki},polygonEnd:function(){J.point=ut,J.lineStart=yn,J.lineEnd=bn},result:function(){var e=Mt?[_e/Mt,Ie/Mt]:bt?[Xt/bt,Jt/bt]:Lt?[Ee/Lt,De/Lt]:[NaN,NaN];return Ee=De=Lt=Xt=Jt=bt=_e=Ie=Mt=0,e}};function ut(e,t){Ee+=e,De+=t,++Lt}function yn(){J.point=Di}function Di(e,t){J.point=_i,ut(et=e,nt=t)}function _i(e,t){var n=e-et,i=t-nt,r=Y(n*n+i*i);Xt+=r*(et+e)/2,Jt+=r*(nt+t)/2,bt+=r,ut(et=e,nt=t)}function bn(){J.point=ut}function Ii(){J.point=Ri}function ki(){Sn(wn,xn)}function Ri(e,t){J.point=Sn,ut(wn=et=e,xn=nt=t)}function Sn(e,t){var n=e-et,i=t-nt,r=Y(n*n+i*i);Xt+=r*(et+e)/2,Jt+=r*(nt+t)/2,bt+=r,r=nt*e-et*t,_e+=r*(et+e),Ie+=r*(nt+t),Mt+=r*3,ut(et=e,nt=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,z);break}}},result:H};var Pe=new W,Re,En,Dn,At,Ft,Qt={point:H,lineStart:function(){Qt.point=Pi},lineEnd:function(){Re&&_n(En,Dn),Qt.point=H},polygonStart:function(){Re=!0},polygonEnd:function(){Re=null},result:function(){var e=+Pe;return Pe=new W,e}};function Pi(e,t){Qt.point=_n,En=At=e,Dn=Ft=t}function _n(e,t){At-=e,Ft-=t,Pe.add(Y(At*At+Ft*Ft)),At=e,Ft=t}var Ce=Qt;var In,te,kn,Rn,wt=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(s){return s&&(typeof i=="function"&&o.pointRadius(+i.apply(this,arguments)),lt(s,r(o))),o.result()}return a.area=function(s){return lt(s,r(Se)),Se.result()},a.measure=function(s){return lt(s,r(Ce)),Ce.result()},a.bounds=function(s){return lt(s,r(yt)),yt.result()},a.centroid=function(s){return lt(s,r(ke)),ke.result()},a.projection=function(s){return arguments.length?(r=s==null?(e=null,Pt):(e=s).stream,a):e},a.context=function(s){return arguments.length?(o=s==null?(t=null,new wt(n)):new Zt(t=s),typeof i!="function"&&o.pointRadius(i),a):t},a.pointRadius=function(s){return arguments.length?(i=typeof s=="function"?s:(o.pointRadius(+s),+s),a):i},a.digits=function(s){if(!arguments.length)return n;if(s==null)n=null;else{let d=Math.floor(s);if(!(d>=0))throw new RangeError(`invalid digits: ${s}`);n=d}return t===null&&(o=new wt(n)),a},a.projection(e).digits(n).context(t)}function Tt(e){return function(t){var n=new Le;for(var i in e)n[i]=e[i];return n.stream=t,n}}function Le(){}Le.prototype={constructor:Le,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 Me(e,t,n){var i=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),i!=null&&e.clipExtent(null),lt(n,e.stream(yt)),t(yt.result()),i!=null&&e.clipExtent(i),e}function Ae(e,t,n){return Me(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])),s=+t[0][0]+(r-a*(i[1][0]+i[0][0]))/2,d=+t[0][1]+(o-a*(i[1][1]+i[0][1]))/2;e.scale(150*a).translate([s,d])},n)}function Cn(e,t,n){return Ae(e,[[0,0],t],n)}function Ln(e,t,n){return Me(e,function(i){var r=+t,o=r/(i[1][0]-i[0][0]),a=(r-o*(i[1][0]+i[0][0]))/2,s=-o*i[0][1];e.scale(150*o).translate([a,s])},n)}function Mn(e,t,n){return Me(e,function(i){var r=+t,o=r/(i[1][1]-i[0][1]),a=-o*i[0][0],s=(r-o*(i[1][1]+i[0][1]))/2;e.scale(150*o).translate([a,s])},n)}var An=16,Li=F(30*O);function Fe(e,t){return+t?Ai(e,t):Mi(e)}function Mi(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,s,d,u,l,c,h,p,f,S,x){var g=u-i,v=l-r,y=g*g+v*v;if(y>4*t&&S--){var b=a+h,w=s+p,E=d+f,P=Y(b*b+w*w+E*E),k=at(E/=P),L=M(M(E)-1)<R||M(o-c)<R?(o+c)/2:ot(w,b),B=e(L,k),D=B[0],$=B[1],G=D-i,A=$-r,m=v*G-g*A;(m*m/y>t||M((g*G+v*A)/y-.5)>.3||a*h+s*p+d*f<Li)&&(n(i,r,o,a,s,d,D,$,L,b/=P,w/=P,E,S,x),x.point(D,$),n(D,$,L,b,w,E,u,l,c,h,p,f,S,x))}}return function(i){var r,o,a,s,d,u,l,c,h,p,f,S,x={point:g,lineStart:v,lineEnd:b,polygonStart:function(){i.polygonStart(),x.lineStart=w},polygonEnd:function(){i.polygonEnd(),x.lineStart=v}};function g(k,L){k=e(k,L),i.point(k[0],k[1])}function v(){c=NaN,x.point=y,i.lineStart()}function y(k,L){var B=tt([k,L]),D=e(k,L);n(c,h,l,p,f,S,c=D[0],h=D[1],l=k,p=B[0],f=B[1],S=B[2],An,i),i.point(c,h)}function b(){x.point=g,i.lineEnd()}function w(){v(),x.point=E,x.lineEnd=P}function E(k,L){y(r=k,L),o=c,a=h,s=p,d=f,u=S,x.point=y}function P(){n(c,h,l,p,f,S,o,a,r,s,d,u,An,i),x.lineEnd=b,b()}return x}}var Fi=Tt({point:function(e,t){this.stream.point(e*O,t*O)}});function Ti(e){return Tt({point:function(t,n){var i=e(t,n);return this.stream.point(i[0],i[1])}})}function Bi(e,t,n,i,r){function o(a,s){return a*=i,s*=r,[t+e*a,n-e*s]}return o.invert=function(a,s){return[(a-t)/e*i,(n-s)/e*r]},o}function Fn(e,t,n,i,r,o){if(!o)return Bi(e,t,n,i,r);var a=F(o),s=T(o),d=a*e,u=s*e,l=a/e,c=s/e,h=(s*n-a*t)/e,p=(s*t+a*n)/e;function f(S,x){return S*=i,x*=r,[d*S-u*x+t,n-u*S-d*x]}return f.invert=function(S,x){return[i*(l*S-c*x+h),r*(p-c*S-l*x)]},f}function Te(e){return Oi(function(){return e})()}function Oi(e){var t,n=150,i=480,r=250,o=0,a=0,s=0,d=0,u=0,l,c=0,h=1,p=1,f=null,S=ge,x=null,g,v,y,b=Pt,w=.5,E,P,k,L,B;function D(m){return k(m[0]*O,m[1]*O)}function $(m){return m=k.invert(m[0],m[1]),m&&[m[0]*V,m[1]*V]}D.stream=function(m){return L&&B===m?L:L=Fi(Ti(l)(S(E(b(B=m)))))},D.preclip=function(m){return arguments.length?(S=m,f=void 0,A()):S},D.postclip=function(m){return arguments.length?(b=m,x=g=v=y=null,A()):b},D.clipAngle=function(m){return arguments.length?(S=+m?pn(f=m*O):(f=null,ge),A()):f*V},D.clipExtent=function(m){return arguments.length?(b=m==null?(x=g=v=y=null,Pt):ve(x=+m[0][0],g=+m[0][1],v=+m[1][0],y=+m[1][1]),A()):x==null?null:[[x,g],[v,y]]},D.scale=function(m){return arguments.length?(n=+m,G()):n},D.translate=function(m){return arguments.length?(i=+m[0],r=+m[1],G()):[i,r]},D.center=function(m){return arguments.length?(o=m[0]%360*O,a=m[1]%360*O,G()):[o*V,a*V]},D.rotate=function(m){return arguments.length?(s=m[0]%360*O,d=m[1]%360*O,u=m.length>2?m[2]%360*O:0,G()):[s*V,d*V,u*V]},D.angle=function(m){return arguments.length?(c=m%360*O,G()):c*V},D.reflectX=function(m){return arguments.length?(h=m?-1:1,G()):h<0},D.reflectY=function(m){return arguments.length?(p=m?-1:1,G()):p<0},D.precision=function(m){return arguments.length?(E=Fe(P,w=m*m),A()):Y(w)},D.fitExtent=function(m,I){return Ae(D,m,I)},D.fitSize=function(m,I){return Cn(D,m,I)},D.fitWidth=function(m,I){return Ln(D,m,I)},D.fitHeight=function(m,I){return Mn(D,m,I)};function G(){var m=Fn(n,0,0,h,p,c).apply(null,t(o,a)),I=Fn(n,i-m[0],r-m[1],h,p,c);return l=fe(s,d,u),P=kt(t,I),k=kt(l,P),E=Fe(P,w),A()}function A(){return L=B=null,D}return function(){return t=e.apply(this,arguments),D.invert=t.invert&&$,G()}}function ne(e,t){return[e,Je(Qe((q+t)/2))]}ne.invert=function(e,t){return[e,2*jt(Xe(t))-q]};function Be(){return Gi(ne).scale(961/z)}function Gi(e){var t=Te(e),n=t.center,i=t.scale,r=t.translate,o=t.clipExtent,a=null,s,d,u;t.scale=function(c){return arguments.length?(i(c),l()):i()},t.translate=function(c){return arguments.length?(r(c),l()):r()},t.center=function(c){return arguments.length?(n(c),l()):n()},t.clipExtent=function(c){return arguments.length?(c==null?a=s=d=u=null:(a=+c[0][0],s=+c[0][1],d=+c[1][0],u=+c[1][1]),l()):a==null?null:[[a,s],[d,u]]};function l(){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),s],[Math.min(h[0]+c,d),u]]:[[a,Math.max(h[1]-c,s)],[d,Math.min(h[1]+c,u)]])}return l()}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(s,d){d||(t=n=0);var u=2,l=s.length,c=new Array(l);for(c[0]=(t+=s[0])*i+o,c[1]=(n+=s[1])*r+a;u<l;)c[u]=s[u],++u;return c}}function Tn(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 Bn(e,n)})}:Bn(e,t)}function Bn(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(l,c){c.length&&c.pop();for(var h=i[l<0?~l:l],p=0,f=h.length;p<f;++p)c.push(n(h[p],p));l<0&&Tn(c,f)}function o(l){return n(l)}function a(l){for(var c=[],h=0,p=l.length;h<p;++h)r(l[h],c);return c.length<2&&c.push(c[0]),c}function s(l){for(var c=a(l);c.length<4;)c.push(c[0]);return c}function d(l){return l.map(s)}function u(l){var c=l.type,h;switch(c){case"GeometryCollection":return{type:c,geometries:l.geometries.map(u)};case"Point":h=o(l.coordinates);break;case"MultiPoint":h=l.coordinates.map(o);break;case"LineString":h=a(l.arcs);break;case"MultiLineString":h=l.arcs.map(a);break;case"Polygon":h=d(l.arcs);break;case"MultiPolygon":h=l.arcs.map(d);break;default:return null}return{type:c,coordinates:h}}return u(t)}function Z(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 s=t.filter(d=>re(d,n,i,r)===a);return{index:a,color:o,from:s.length?Math.min(...s):null,to:s.length?Math.max(...s):null,matches:s.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),s=Math.max(o-i,a-r);s>t&&(t=s)}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 d of e){if(d.length<3)continue;let u=Math.abs($n(d));u>i&&(i=u,n=d)}if(!n||i===0)return t;let r=$n(n),o=0,a=0;for(let d=0;d<n.length;d++){let[u,l]=n[d],[c,h]=n[(d+1)%n.length],p=u*h-c*l;o+=(u+c)*p,a+=(l+h)*p}let s=[o/(6*r),a/(6*r)];return Number.isFinite(s[0])&&Number.isFinite(s[1])?s:t}function zi(e,t){let[n,i]=e,[r,o,a,s]=t,d=Math.max(r-n,0)+Math.max(n-a,0),u=Math.max(o-i,0)+Math.max(i-s,0);return Math.hypot(d,u)}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,s=t[0]-o[0],d=t[1]-o[1],u=s===0&&d===0?0:Math.atan2(d,s);for(let l of Hi){let c=u+l,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 Kn(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,s,d,u]=oe(o),l=Math.max(d-a,u-s),c=l<=0?1:Math.min(t/l,n),h=(a+d)/2,p=(s+u)/2;return o.map(([f,S])=>[h+(f-h)*c,p+(S-p)*c])})}function Ui(e){let t=[...e].sort((d,u)=>d[0]-u[0]||d[1]-u[1]),n=[];for(let d of t){let u=n.at(-1);(!u||u[0]!==d[0]||u[1]!==d[1])&&n.push(d)}if(n.length<3)return n.map(d=>[...d]);let i=(d,u,l)=>(u[0]-d[0])*(l[1]-d[1])-(u[1]-d[1])*(l[0]-d[0]),r=d=>{let u=[];for(let l of d){for(;u.length>=2&&i(u[u.length-2],u[u.length-1],l)<=0;)u.pop();u.push(l)}return u},o=r(n),a=r([...n].reverse()),s=[...o.slice(0,-1),...a.slice(0,-1)];return s.length>=3?s:n.map(d=>[...d])}function Wn(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",U={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,Ki=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 s=[];for(let d of a){let u=t(d);u&&Number.isFinite(u[0])&&Number.isFinite(u[1])&&s.push([u[0],u[1]])}s.length>0&&r.push(s)}return r}var Wi=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 Be().fitExtent([[U.padding,U.padding],[U.width-U.padding,U.height-U.padding]],e)}function qe(e,t,n=0,i=Z(e.geometry)){let r=ee(t);return i.features.map(o=>{let a=r.centroid(o),s=r.bounds(o),d=[(s[0][0]+s[1][0])/2,(s[0][1]+s[1][1])/2],u={id:e.getId(o),label:e.getLabel(o),value:e.getValue(o),meta:e.getMeta?.(o),feature:o},l=n>0&&!zn(u.id),c=l?Kn(Xn(o,t),n):Xn(o,t),h=Wn(c,ze);return{...u,path:l?je(c):r(o)??"",hitPath:h?je([h]):null,centroid:c.length>0?Hn(c,a.every(Number.isFinite)?a:d):a.every(Number.isFinite)?a:d,partBounds:c.map(oe),extent:ae(c)}})}function Qn(e,t){let n=ee(t);return Z(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 s=document.createElement("small"),d=[`${e.share.toFixed(1)}% of total`];e.rank!==null&&d.push(`${Yi(e.rank)} of ${e.rankedCount}`),s.textContent=d.join(" \xB7 "),n.append(o,s)}return n}function N(e,t){let n=document.createElement(e);for(let[i,r]of Object.entries(t??{}))n.setAttribute(i,r);return n}function j(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 ht=class{containerEl;options;instanceId=`india-choropleth-${++Wi}`;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;focusFirstFromLevel=null;emptyStatusEl=null;destroyed=!1;projectionCache=null;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){if("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){if(t.drillDownId!==this.activeDrillDownId){let n=this.activeSubDrillDownId!==null;this.setActiveSubDrillDownId(null),this.activeSubDrillDownId=null,n&&this.options.onSubDistrictDrillDownChange?.(null,void 0)}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);if(n){if(t!==this.activeDrillDownId){let i=this.activeSubDrillDownId!==null;this.setActiveSubDrillDownId(null),i&&this.options.onSubDistrictDrillDownChange?.(null,void 0)}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=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 t=this.options,n=t.referenceOverlay?.geometry??null,i=this.projectionCache,r,o;if(i&&i.geometry===t.states.geometry&&i.referenceGeometry===n)r=i.collection,o=i.projection;else{r=Z(t.states.geometry);let C=n?Z(n).features:[];o=$e({type:"FeatureCollection",features:[...r.features,...C]}),this.projectionCache={geometry:t.states.geometry,referenceGeometry:n,collection:r,projection:o}}let a=n?Z(n):null,s=qe(t.states,o,t.minPartExtent??0,r),d=t.referenceOverlay?Qn(t.referenceOverlay,o):[],u=s.find(C=>C.id===this.activeDrillDownId)??null,l=!!(u&&this.activeDrillDownId),c=this.loadedDistricts?.stateId===this.activeDrillDownId?this.loadedDistricts.layer:null,h=this.loadedDistrictReferenceOverlay?.stateId===this.activeDrillDownId?this.loadedDistrictReferenceOverlay.overlay:null,p=c?Z(c.geometry):null,f=h?Z(h.geometry):null,S=p?$e({type:"FeatureCollection",features:[...p.features,...f?.features??[]]}):null,x=c&&S?qe(c,S,t.minDistrictPartExtent??t.minPartExtent??0):[],g=x.find(C=>C.id===this.activeSubDrillDownId)??null,y=!!(l&&g&&this.activeSubDrillDownId)?"subdistrict":l?"district":"state",b=this.loadedSubDistricts?.districtId===this.activeSubDrillDownId?this.loadedSubDistricts.layer:null,w=b?Z(b.geometry):null,E=w?$e(w):null,P=b&&E?qe(b,E,t.minDistrictPartExtent??t.minPartExtent??0):[],k=y==="subdistrict"?P:y==="district"?x:s,L=y==="district"&&h&&S?Qn(h,S):[],B=k.find(C=>C.id===this.activeSelectedId)??null,D=k.find(C=>C.id===this.inspectedId)??null;this.inspectedId&&!D&&(this.inspectedId=null);let $=k.map(C=>C.value).filter(C=>C!==null),G=On($),A=$.length?Math.min(...$):0,m=$.length?Math.max(...$):0;this.derived={stateRegions:s,referenceRegions:d,drilledState:u,drilledDistrict:g,districtRegions:x,level:y,regions:k,visibleReferenceRegions:y==="state"?d:L,selected:B,inspected:D,total:G,min:A,max:m,canDrill:y==="state"?!!t.loadDistricts:y==="district"?!!t.loadSubDistricts:!1,mergedReferenceIds:new Set(t.referenceOverlayMergeIds??[]),buckets:Gn(Zn(t),k.map(C=>C.value),A,m)};let I=[y,this.activeDrillDownId??"",this.activeSubDrillDownId??"",typeof t.colorScale=="function"?"function":(t.colorScale??Bt).join(",")].join("|");I!==this.bandsKey&&(this.bandsKey=I,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.restoreFocusId=i.id,this.focusFirstFromLevel=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/U.width,i.height/U.height),o=(i.width-U.width*r)/2,a=(i.height-U.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<=Ki&&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.focusFirstFromLevel=this.derived.level,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.focusFirstFromLevel=this.derived.level,this.setActiveSubDrillDownId(t.id),n.onSubDistrictDrillDownChange?.(t.id,t),this.renderStructure();return}this.applyInteractionState()}goBack(){if(this.focusFirstFromLevel=null,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(){this.focusFirstFromLevel=null;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;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.applyPendingFocus()}applyPendingFocus(){if(this.restoreFocusId&&this.derived.regions.some(n=>n.id===this.restoreFocusId)){let n=this.restoreFocusId;this.restoreFocusId=null,this.focusFirstFromLevel=null,this.pathRefs.get(n)?.focus();return}if(!this.focusFirstFromLevel||this.focusFirstFromLevel===this.derived.level)return;let t=this.derived.regions[0];if(t){this.focusFirstFromLevel=null,this.pathRefs.get(t.id)?.focus();return}this.emptyStatusEl&&(this.focusFirstFromLevel=null,this.emptyStatusEl.focus())}renderToolbar(){let t=this.options;if(this.toolbarEl.textContent="",t.showBreadcrumb===!1)return;let n=N("nav",{class:"india-choropleth__breadcrumb","aria-label":"Map hierarchy"}),i=()=>{let a=N("span",{"aria-hidden":"true"});return a.textContent="/",a};if(!this.derived.drilledState){let a=N("span");a.textContent="All states",n.append(a),this.toolbarEl.append(n);return}let r=N("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=N("button",{class:"india-choropleth__back",type:"button"});a.textContent=this.derived.drilledState.label,a.addEventListener("click",()=>this.goBack());let s=N("span",{"aria-current":"page"});s.textContent=this.derived.drilledDistrict.label,n.append(a,i(),s)}else{let a=N("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),s=!o&&!a&&this.derived.regions.length===0;if(this.emptyStatusEl=null,o||a||s){let g=o&&this.subLoadError||a&&this.loadError,v=N("div",{class:"india-choropleth__status",role:g?"alert":"status",...s?{tabindex:"-1"}:{}});v.textContent=o?this.subLoadError?this.subLoadError.message:this.loadingDistrict?"Loading sub-districts\u2026":"Sub-district data is unavailable for this district.":s?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.emptyStatusEl=s?v:null,this.applyInteractionState(),this.applyPendingFocus();return}let d=j("svg",{class:"india-choropleth__svg",viewBox:`0 0 ${U.width} ${U.height}`,role:"group","aria-label":t.ariaLabel??"Interactive choropleth map"});if(this.svgRootEl=d,n&&(d.addEventListener("keydown",g=>{g.key==="Escape"&&(g.preventDefault(),this.inspect(null))}),d.addEventListener("click",g=>{if(g.target!==d)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=j("defs"),v=j("pattern",{id:this.hatchId,width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)"});v.append(j("rect",{width:"8",height:"8",fill:"var(--india-map-reference-bg)"}),j("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:"var(--india-map-reference-hatch)","stroke-width":"2"})),g.append(v),d.append(g);let y=j("g",{class:"india-choropleth__reference-fill",role:"group","aria-label":"Non-statistical reference context."});for(let b of this.derived.visibleReferenceRegions)y.append(j("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"}));d.append(y)}let u=n?this.derived.regions.filter(g=>g.hitPath):[];if(u.length>0){let g=j("g",{class:"india-choropleth__hit-areas","aria-hidden":"true"});for(let v of u){let y=j("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)}d.append(g)}let l=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),w=j("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&&w.setAttribute("role","button"),this.derived.mergedReferenceIds.has(g.id)&&w.classList.add("india-choropleth__region--reference-merged"),n&&(w.setAttribute("aria-pressed",g.id===this.derived.selected?.id?"true":"false"),w.addEventListener("mouseenter",()=>this.inspect(g)),w.addEventListener("mouseleave",()=>this.inspect(null)),w.addEventListener("focus",()=>this.inspect(g)),w.addEventListener("blur",()=>this.inspect(null)),w.addEventListener("click",()=>this.activate(g)),w.addEventListener("keydown",E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),this.activate(g))})),d.append(w),this.pathRefs.set(g.id,w),this.bucketEls.push({el:w,bucket:l(g)})}let c=this.derived.regions.filter(g=>g.extent>0&&g.extent<le);if(c.length>0){let g=j("g",{class:"india-choropleth__small-markers","aria-hidden":"true"});for(let v of c){let y=j("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:l(v)}),g.append(y)}d.append(g)}if(t.showRegionValues){let g=j("g",{class:`india-choropleth__region-values${this.derived.level==="state"?"":" india-choropleth__region-values--district"}`,"aria-hidden":"true"}),v=j("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),w=this.placeRegionValue(y,b);if(!w)continue;let E=j("text",{x:String(w.at[0]),y:String(w.at[1]),"text-anchor":"middle","dominant-baseline":"central"});if(E.textContent=b,g.append(E),this.bucketEls.push({el:E,bucket:l(y)}),w.leader){let P=j("line",{x1:String(w.leader[0][0]),y1:String(w.leader[0][1]),x2:String(w.leader[1][0]),y2:String(w.leader[1][1])});this.bucketEls.push({el:P,bucket:l(y)}),v.append(P)}}d.append(v,g)}if(this.derived.visibleReferenceRegions.length>0){let g=j("g",{class:"india-choropleth__reference-outline","aria-hidden":"true"});for(let v of this.derived.visibleReferenceRegions)g.append(j("path",{d:v.path,fill:"none"}));d.append(g)}let h=j("g",{class:"india-choropleth__selection","aria-hidden":"true"}),p=j("path",{class:"india-choropleth__selection-halo",fill:"none"}),f=j("path",{class:"india-choropleth__selection-ring",fill:"none"});h.append(p,f),d.append(h),this.selectionGroupEl=h,this.selectionPathEls=[p,f],this.canvasEl.append(d);let S=N("div",{class:"india-choropleth__tooltip-anchor"});S.style.display="none";let x=N("div",{id:this.tooltipId,class:"india-choropleth__tooltip"});S.append(x),this.canvasEl.append(S),this.tooltipAnchorEl=S,this.tooltipContentEl=x,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(([f,S,x,g])=>x-f>=r*2&&g-S>=o*2);if(!i&&a)return{at:t.centroid};let s=i?Vn({anchor:t.centroid,clearance:Math.max(t.extent,le)/2+4+r,halfSize:[r,o],viewBox:[U.width,U.height],centre:[U.width/2,U.height/2],isBlocked:f=>this.coversAnotherRegion(t,f,r,o)}):null;if(!s)return a?{at:t.centroid}:null;let d=Math.max(t.extent,le)/2+1,u=s[0]-t.centroid[0],l=s[1]-t.centroid[1],c=Math.hypot(u,l);if(c<=d+r)return{at:s};let h=[t.centroid[0]+u/c*d,t.centroid[1]+l/c*d],p=[s[0]-u/c*(r+1.5),s[1]-l/c*(r+1.5)];return{at:s,leader:[h,p]}}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 s of o)if(a.partBounds.some(([d,u,l,c])=>s[0]>=d&&s[0]<=l&&s[1]>=u&&s[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=N("div",{class:"india-choropleth__legend",role:"group","aria-label":`Color scale: ${n} to ${i} values`}),o=N("span");o.textContent=n;let a=t.interactive!==!1,s=N("div",{class:"india-choropleth__swatches"});a||s.setAttribute("aria-hidden","true"),this.swatchEls=[];for(let u of this.derived.buckets){let l=N(a?"button":"i",{class:"india-choropleth__swatch"});if(l.style.backgroundColor=u.color,a){l.setAttribute("type","button");let c=Nn(u,t.formatValue??se);l.setAttribute("aria-label",c),l.setAttribute("title",c),u.matches===0&&l.setAttribute("aria-disabled","true"),l.addEventListener("click",()=>{u.matches!==0&&(this.activeBucket=this.activeBucket===u.index?null:u.index,this.applyInteractionState())}),this.swatchEls.push(l)}s.append(l)}let d=N("span");if(d.textContent=i,r.append(o,s,d),this.derived.visibleReferenceRegions.length>0){let u=N("i",{class:`india-choropleth__reference-key${t.referenceOverlayFill==="solid"?" india-choropleth__reference-key--solid":""}`,"aria-hidden":"true"}),l=N("span");l.textContent=t.referenceOverlayLegendLabel??"Reference context \xB7 data unavailable",r.append(u,l)}this.insightsEl?this.rootEl.insertBefore(r,this.insightsEl):this.rootEl.append(r),this.legendEl=r,a&&r.addEventListener("keydown",u=>{u.key==="Escape"&&(u.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=N("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]/U.width*100}%`,this.tooltipAnchorEl.style.top=`${t.centroid[1]/U.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.3.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 st(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,Ot=new Map;for(let e of Ue)for(let t of[e.slug,st(e.name),e.id]){xt.has(t)||xt.set(t,e);let n=Ve(t);Ot.has(n)||Ot.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);Ot.has(i)||Ot.set(i,n)}function Q(e){let t=st(e);return xt.get(t)??Ot.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;exactKeys=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??(a=>String(a.properties?.id??a.properties?.name)),this.getLabel=r.getLabel??(a=>String(a.properties?.name??a.properties?.id));let o=new Map;for(let[a,s]of Object.entries(r.values??{})){let d=this.keyFor(a),u=o.get(d);u!==void 0?this.warnDuplicate(a,u):o.set(d,a),this.values.set(d,s),this.exactKeys.set(a,d),this.writtenAs.has(d)||this.writtenAs.set(d,a)}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:(a,s)=>typeof s=="string"?this.getValue(s):void 0,has:(a,s)=>typeof s=="string"&&this.values.has(this.keyFor(s)),ownKeys:()=>[...new Set(this.labelByKey.values())],getOwnPropertyDescriptor:(a,s)=>typeof s=="string"&&this.values.has(this.keyFor(s))?{enumerable:!0,configurable:!0,value:this.getValue(s)}:void 0,set:(a,s,d)=>typeof s!="string"?!1:(this.setValue(s,d),!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(a=>this.destroyed?this.proxied??this:(this.mount(a),this.proxied??this)).catch(a=>{if(this.destroyed||a.name==="AbortError")return this.proxied??this;throw this.showError(a),a}),this.ready.catch(()=>{})),this.proxied=new Proxy(this,{get:(a,s,d)=>{if(typeof s=="string"&&!(s in a)){let u=si(s,a);return u?Reflect.get(a,u,d):this.getValue(s)}return Reflect.get(a,s,d)},set:(a,s,d,u)=>{if(typeof s=="string"&&!(s in a)){let l=si(s,a);return l?Reflect.set(a,l,d,u):(this.setValue(s,d),!0)}return Reflect.set(a,s,d,u)}}),this.proxied}proxied;keyFor(t){return Q(t)?.id??st(t)}keysForFeature(t){let n=this.getId(t),i=this.getLabel(t);return[n,i,Q(n)?.id,Q(i)?.id,st(n),st(i)].filter(r=>typeof r=="string"&&r.length>0)}keyForFeature(t){let n=this.getId(t);return Q(n)?.id??Q(this.getLabel(t))?.id??st(this.getLabel(t))}getValue(t){return this.values.get(this.keyFor(t))??null}valueForFeature(t,n){for(let i of[this.exactKeys.get(t),this.exactKeys.get(n),Q(t)?.id,Q(n)?.id,st(t),st(n)])if(i!==void 0&&this.values.has(i))return this.values.get(i)??null;return null}setValue(t,n){let i=this.keyFor(t);this.values.set(i,n),this.exactKeys.set(t,i),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.`)}warnDuplicate(t,n){console.warn(`BharatChoropleth: "${n}" and "${t}" name the same state \u2014 the last one is shown. Use one spelling if that is not what you meant.`)}mount(t){this.clearPlaceholder();for(let b of Z(t).features){let w=this.getLabel(b),E=this.keyForFeature(b);for(let P of this.keysForFeature(b))this.labelByKey.set(P,w);this.labelByKey.set(E,w),this.values.has(E)||this.values.set(E,null)}for(let[b,w]of this.values)!this.labelByKey.has(b)&&w!==null&&this.warnUnknown(this.writtenAs.get(b)??b);let{container:n,geometry:i,dataBaseUrl:r,districts:o,subDistricts:a,getId:s,getLabel:d,values:u,fontColor:l,borderColor:c,borderWidth:h,selectionWidth:p,colorScale:f,onReady:S,onError:x,...g}=this.options,v=o??this.usingDefaultData,y=a??this.usingDefaultData;this.engineInstance=new ht(this.containerEl,{...g,colorScale:f,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.valueForFeature(this.getId(b),this.getLabel(b))}}),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.valueForFeature(String(i.properties?.id??""),this.getLabel(i))});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.valueForFeature(String(i.properties?.id??""),this.getLabel(i))}: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){let n=new Map;for(let[i,r]of Object.entries(t)){let o=this.keyFor(i),a=n.get(o);a!==void 0?this.warnDuplicate(i,a):n.set(o,i),this.values.set(o,r),this.exactKeys.set(i,o),this.writtenAs.has(o)||this.writtenAs.set(o,i),this.engineInstance&&!this.labelByKey.has(o)&&this.warnUnknown(i)}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:Q(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=We,document.head.appendChild(e)}ui();var Ke=globalThis;Ke.BharatChoropleth=Gt;Ke.IndiaChoropleth=ht;Ke.BharatChoroplethLib={BharatChoropleth:Gt,IndiaChoropleth:ht,STATES:Ue,resolveState:Q,ATTRIBUTION:ti,DEFAULT_DATA_BASE_URL:de,injectStyles:ui};})();
|
|
126
132
|
//# sourceMappingURL=bharat-choropleth.min.js.map
|