@devgateway/dvz-ui-react 1.9.5 → 1.9.7
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/dist/cjs/embeddable/common/MapTooltip.js +1 -1
- package/dist/cjs/embeddable/map/MapDataFrame.js +1 -1
- package/dist/cjs/embeddable/map/index.js +2 -2
- package/dist/cjs/embeddable/map/legend.js +1 -1
- package/dist/cjs/embeddable/map/map.js +4 -4
- package/dist/cjs/embeddable/map/mapHelpers.js +1 -0
- package/dist/esm/embeddable/common/MapTooltip.js +26 -22
- package/dist/esm/embeddable/map/MapDataFrame.js +152 -18
- package/dist/esm/embeddable/map/index.js +209 -198
- package/dist/esm/embeddable/map/legend.js +31 -35
- package/dist/esm/embeddable/map/map.js +602 -918
- package/dist/esm/embeddable/map/mapHelpers.js +243 -0
- package/dist/types/embeddable/map/map.d.ts +2 -1
- package/dist/types/embeddable/map/mapHelpers.d.ts +55 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");require("react");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");require("react");const g=require("string-template"),b=/(\%)[\(]([A-z0-9,.]+)\)/gi,f=/(\#)[\(]([A-z0-9,.]+)\)/gi,h=/(\#C)[\(]([A-z0-9,.]+)\)/gi,S=/(\$)[\(]([A-z0-9,.]+)\)/gi,x=[{name:"USD Dollar",code:"USD",symbol:"$"},{name:"Naira",code:"NGN",symbol:"₦"},{name:"South Africa Rand",code:"ZAR",symbol:"R"},{name:"Ethiopian Birr",code:"ETB",symbol:"Br"},{name:"Zambian Kwacha",code:"ZMW",symbol:"ZK"},{name:"Kenyan Shilling",code:"KES",symbol:"KSh"}],m=(t,n,o,c,l)=>{let e,r=n;for(;(e=t.exec(n))!==null;){const a=e[2],p=(u,y=2)=>l.formatNumber(c?u/100:u,{maximumFractionDigits:y,...o}),i=a.split(","),d=i.length>0&&i[0]?p.apply(void 0,i):"No Data";r=r.replaceAll(e[0],d)}return r},A=(t,n)=>{let o,c=n;for(;(o=t.exec(n))!==null;)if(o.length>2){const l=o[0],e=o[2],r=x.find(a=>s(a.code)==s(e)||s(a.name)==s(e)||s(a.symbol)==s(e));r&&(c=c.replaceAll(l,r.symbol))}return c},s=t=>t&&t.trim().toLowerCase(),E=(t,n,o)=>{const c={};Object.keys(n).forEach(r=>{c[r]=n[r],c[r.replace(/\s+/g,"_")]=n[r]});let l=t.replace(/\{([^}]+)\}/g,(r,a)=>`{${a.replace(/\s+/g,"_")}}`),e=g(l,c).replace(/(?:\r\n|\r|\n)/g,"<br>");return e=m(b,e,{style:"percent"},!0,o),e=m(f,e,{style:"decimal"},!1,o),e=m(h,e,{notation:"compact"},!1,o),e=A(S,e),e};exports.formatContent=E;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const z=require("react"),Q=M=>{const{data:o,measures:S,customMeasureLabels:g,children:B,source:O,extraDimension:d,allDimensions:D}=M;console.log("MapDataFrame props:",M);const x=(O||"").split("/").filter(Boolean),h=x.length>0?x[0]:null,f={locationsData:[],nationalData:{},measureLabelMap:{}};o.metadata&&o.metadata.measures&&Array.isArray(o.metadata.measures),o.children&&o.children[0]&&o.children[0].children;const p=o.metadata||{},P=["value","count","type","children","label","measure"],E=D&&D.length>0?D:p.types||[],y={};E.forEach(e=>{const n=e.category||e.type;n&&(y[n]=e.items||[])});const F=(e,n)=>{const t=y[e];if(!t)return null;const r=n!=null?String(n):n;return t.find(a=>{const l=a.value!=null?String(a.value):a.value,i=a.id!=null?String(a.id):a.id,s=a.code!=null?String(a.code):a.code;return l===r||i===r||s===r})||null},u=(e,n)=>{const t=F(e,n);return t?t.value??t.label??t.id??t.code??n:n},j=(e={})=>{const n={};return Object.keys(e).forEach(t=>{const r=e[t];r!=null&&(Array.isArray(r)?n[t]=r.map(a=>u(t,a)).join(" ,"):n[t]=u(t,r))}),n},I=e=>{const n=y[e]||[];return n.length===1?u(e,n[0].value??n[0].id??n[0].code):null},c=e=>e!=null&&e!=="",L=e=>{if(e)return c(e.value)?e.value:c(e.id)?e.id:e.code},b=e=>e==null?"":String(e).trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),v=(e,n)=>{if(!e)return;const t=b(n),r=e[n];if(r!=null&&r!=="")return r;const a=Object.keys(e);for(let l=0;l<a.length;l++){const i=a[l];if(b(i)===t){const s=e[i];if(s!=null&&s!=="")return s}}},K=(e,n)=>{const t=[h,"country",e.type].filter(Boolean),r=[v(n,"country"),v(e,"country"),h?v(n,h):void 0,h?v(e,h):void 0,e.label,e.value].filter(a=>c(a));for(let a=0;a<t.length;a++){const l=t[a],i=y[l]||[];if(i.length)for(let s=0;s<r.length;s++){const _=r[s],G=b(_),w=i.findIndex(H=>{const J=L(H);return b(J)===G});if(w>=0)return w}}return-1},N=(e,n,t)=>{const r=K(n,t);if(r<0)return;const a=y[e]||[];if(!a.length||r>=a.length)return;const l=L(a[r]);if(c(l))return u(e,l)},q=(e,n,t)=>{const r=v(t,e);if(c(r))return r;if(c(A[e]))return A[e];const a=v(n,e);if(c(a))return a;const l=N(e,n,t);if(c(l))return l;const i=I(e);if(c(i))return i;const s=n.value;return F(e,s)?u(e,s):""},V=o.appliedFilters||{};let R=null;if(d){const e=V[d]?V[d][0]:void 0;R=u(d,e)}const A=j(V),$=e=>{const n={};return Object.keys(e).forEach(t=>{P.includes(t)||(n[t]=e[t])}),e.type&&e.value!==void 0&&(n[e.type]=u(e.type,e.value)),n},C=e=>{let n=$(e);return e.children&&Array.isArray(e.children)&&e.children.forEach(t=>{n={...n,...C(t)}}),n},T=(e,n)=>{if(!(!e.children||!Array.isArray(e.children)))return e.children.map(t=>({...t,label:t.value,value:t[n],variables:C(t),children:T(t,n)}))};p.measures&&p.measures.forEach(e=>{g&&g[e.value]&&g[e.value].hasCustomLabel&&g[e.value].customLabel?f.measureLabelMap[e.value]=g[e.value].customLabel:f.measureLabelMap[e.value]=e.label});const m=S.split(",");return o&&o.children&&(o.children.forEach(e=>{m.forEach(n=>{const t={...C(e),...A};E.forEach(a=>{const l=a.category||a.type;l&&(t[l]=q(l,e,t))});const r={...e,label:e.value,value:e[n],measure:n,variables:t};r.variables.selectedDataFrameTooltipValue=e[n],d&&(r.variables[d]=R),r.children=T(e,n),f.locationsData.push(r)})}),f.measures=m.length>1?m:null,f.nationalData.value=o[S]||o[m[0]]),z.Children.map(B,e=>z.cloneElement(e,{transformedData:{...f,types:p.types?p.types:[]}}))};exports.default=Q;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
2
|
-
{label}: %({value},2)`,"data-show-no-data-tooltip":
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("react/jsx-runtime"),k=require("react"),C=require("react-redux"),Ke=require("../data/DataProvider.js"),_e=require("../data/DataConsumer.js"),Ye=require("../reducers/data.js"),$e=require("./map.js"),Qe=require("./MapDataFrame.js"),Xe=require("./MapCSVDataFrame.js"),ea=[{label:"KENYA",value:"KEN",center:[35.8166634,.1],scale:2e3},{label:"Nigeria",value:"NGA",center:[7.491302,9.072264],scale:2e3},{label:"South Africa",value:"ZAF",center:[24.676997,-28.48322],scale:2e3},{label:"West Africa",value:"West Africa",center:[-7.293255,13.90572],scale:1500},{label:"Africa",value:"Africa",center:[13.134227,-11.523088],scale:550},{label:"Ethiopia",value:"ETH",center:[35.8166634,1.7],scale:2e3},{label:"Zambia",value:"ZMB",center:[26.459455,-14.668135],scale:2e3},{label:"Democratic Republic of the Congo",value:"DRC",center:[23.174338,-5.837475],scale:1250},{label:"World",value:"World",center:[0,20.050043],scale:150}],aa=n=>i.jsx(ta,{...n}),ta=n=>{var E;const{unique:u,editing:d,"data-filters":q="{}","data-app":o="csv","data-csv":O="","data-dimension1":j="","data-dimension2":W="","data-dimension3":p="","data-measures":f="[]","data-height":V=600,width:G=960,"data-data-source-text":J="","data-data-source-label":Z="Source","data-national-average-label":H="National Average","data-legend-title":K="Legend Title","data-legend-breaks":_="[]","data-zoom-enabled":v=!1,"data-show-legend-labels":y=!1,"data-map-file":Y,"data-mapping-field":$="zone","data-map-label-field":Q="admin","data-has-multiple-measures":F="false",topoJSONField:X="collection","data-map-center":ee="NGA","data-map-label-show-value":L="false","data-show-tooltip":w="true","data-measure-selector-label":ae="","data-value-format":te="","data-show-overall-value":S="false","data-auto-generate-breaks":D="false","data-number-of-breaks":oe=5,"data-scheme":le="reds","data-show-no-data-label":I="false","data-group":x="default","data-map-symbols":re="[]","data-tooltip-theme":ne="map-tooltip-dark","data-label-font-size":se=12,"data-label-font-weight":ie="normal","data-label-font-color":de="#595959","data-legend-font-size":ce=12,"data-legend-font-weight":me="normal","data-custom-tooltips":ue="[]","data-format-style":g="decimal","data-decimals":N="2","data-currency":pe="","data-tooltip-font-size":fe=14,"data-show-admin-unit-label":ge="showAll","data-map-no-data-color":be="#f8f8f8","data-map-boundary-color":he="#000","data-map-focus-boundary-color":Ce="#000","data-highlighted-location":ve="","data-tooltip-format":ye=`{locationName} %({value},2)
|
|
2
|
+
{label}: %({value},2)`,"data-show-no-data-tooltip":T="false","data-map-container-bg-color":Fe="#fff","data-map-position":Le="{}","data-main-layer-id":we="","data-enabled-layers":Se,"data-point-label-color":De="#fff","data-point-label-format":Ie="{locationName} %({value},2)","data-show-no-data-legend-item":z=!1,"data-highlighted-loc-label-format":xe="{locationName} - Score: #({value},2)","data-enable-summary-view":na="false","data-map-type":R="DEFAULT","data-default-point-color":Ne="#FFFF00","data-aggregation-formula":Te="COUNT","data-zoom-level-to-show-points":ze=2,"data-zoom-on-filter":U="false","data-zoom-on-filter-field":Re="","data-no-data-text":Ue="No Data","data-labels-exclusion-list":Ae="","data-custom-measure-labels":Be="{}","data-show-shading-layer-labels":Me="ifUnitHasData","data-dvz-proxy-dataset-id":r,"data-recently-toggled-layer-id":Ee=null,intl:sa,settings:ia}=n;console.log("MapWrapper props",n);const Pe=e=>d?e:decodeURIComponent(e),l=e=>{try{if(e)return JSON.parse(Pe(e))}catch{console.error("error parsing value:"+e)}return null},ke=e=>{let t=l(e)||[];return t=t.map(a=>(a.min&&(a.min=parseFloat(a.min)),a.max&&(a.max=parseFloat(a.max)),a.color=decodeURIComponent(a.color),a)),t},qe=e=>{const t=l(e)||[];let a={};return t&&t.forEach?t.forEach(m=>{m.value!=null&&m.value.filter(P=>P!=null&&P.toString().trim()!="").length>0&&(a[m.param]=m.value)}):a=t,a},Oe={style:g==="compacted"?"decimal":g,notation:g==="compacted"?"compact":"standard",currency:pe,minimumFractionDigits:parseInt(N),maximumFractionDigits:parseInt(N)};let b=l(Se)||[];b=b.map(e=>(e.bgColor=decodeURIComponent(e.bgColor),e.fontColor=decodeURIComponent(e.fontColor),e));const A=ea.find(e=>e.value===ee),B=F==!0||F=="true";let s=[j,W].filter(e=>e!=="none"&&e!==null).join("/");const je=p&&p!=="none"?p:null,c={unique:u,editing:d,source:`/${Y}`,center:A.center,scale:A.scale,measures:f,legendTitle:K,height:V,width:G,topoJSONField:X,mappingField:$,dataSourceText:J,dataSourceLabel:Z,nationalAverageLabel:H,legendBreaks:ke(_),mapLabelField:Q,zoomEnabled:v==!0||v=="true",showLegendLabels:y==!0||y=="true",multipleMeasures:B,app:o,mapLabelShowValue:L==!0||L=="true",showTooltip:w==!0||w=="true",showOverallValue:S==!0||S=="true",measureSelectorLabel:ae,valueFormat:te,autoGenerateBreaks:D==!0||D=="true",showNoDataLabel:I==!0||I=="true",numberOfBreaks:oe,colorScheme:le,group:x,symbols:l(re)||[],tooltipTheme:ne,labelFontSize:se,labelFontColor:decodeURIComponent(de),labelFontWeight:ie,legendFontSize:ce,legendFontWeight:me,customTooltips:l(ue)||[],format:Oe,tooltipFontSize:fe,showAdminUnitLabel:ge,mapNoDataColor:decodeURIComponent(be),mapBoundaryColor:decodeURIComponent(he),mapFocusBoundaryColor:decodeURIComponent(Ce),highlightedLocation:ve,tooltipFormat:ye,showNoDataTooltip:T==!0||T=="true",fields:s.split("/"),mapContainerBgColor:decodeURIComponent(Fe),mapPosition:l(Le),mainLayerId:we,enabledLayers:b,pointLabelColor:decodeURIComponent(De),pointLabelFormat:Ie,showNoDataLegendItem:z==!0||z=="true",highlightedLocLabelFormat:xe,mapType:R,defaultPointColor:decodeURIComponent(Ne),zoomLevelToShowPoints:ze,zoomOnFilter:U==!0||U=="true",zoomOnFilterField:Re,noDataText:Ue,labelsExclusionList:Ae.split(",").map(e=>e.trim()),showShadingLayerLabels:Me,dvzProxyDatasetId:r,recentlyToggledLayerId:Ee};if(c.recentlyToggledLayerId){const e=c.enabledLayers.find(t=>String(t.id)===String(c.recentlyToggledLayerId));e&&(e!=null&&e.apiField)&&(s=(E=e.apiField)==null?void 0:E.toLowerCase())}const We=l(Be)||{},Ve=o==="csv"?Xe.default:Qe.default,Ge=d?(l(f)||[]).join(","):f,M=qe(q);r&&(M.dvzProxyDatasetId=r);const Je=C.useDispatch(),Ze=["data","categories",o,...r?[r]:[],"items"],h=C.useSelector(e=>e.getIn(Ze)),He=k.useMemo(()=>h?h.toJS():[],[h]);return k.useEffect(()=>{o&&o!=="csv"&&Je(Ye.getCategories({app:o,dvzProxyDatasetId:r}))},[o,r]),i.jsx(Ke.default,{params:M,app:o,csv:decodeURIComponent(O),group:x,editing:d,store:[o,u,...s.split("/")],source:s,children:i.jsx(_e.default,{children:i.jsx(Ve,{measures:Ge,multipleMeasures:B,mapType:R,aggregationFormula:Te,customMeasureLabels:We,source:s,extraDimension:je,allDimensions:He,children:i.jsx($e.default,{...c})})})})},oa=(n,u)=>{},la={},ra=C.connect(oa,la)(aa);exports.default=ra;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),g=require("react");class h extends g.Component{constructor(t){super(t)}formatNumber(t){const{intl:i,format:s}=this.props;return i.formatNumber(s.style==="percent"?t/100:t,{style:s.style,notation:s.notation,maximumFractionDigits:s.maximumFractionDigits,minimuFractionDigits:0,currency:s.currency})}render(){const{filteredBreaks:t,formattedLegendTitle:i,showLegendLabels:s,symbols:r,legendFontSize:c,legendFontWeight:d,autoGenerateBreaks:a,intl:N,numberFormat:b,mapNoDataColor:u,showNoDataLegendItem:o,noDataText:x}=this.props,n={fontSize:c+"px",fontWeight:d};return l.jsxs("div",{className:"legend-container",children:[l.jsx("div",{className:"legend-title-container",children:l.jsx("span",{className:"legend-title",children:t&&t.length>0?i:""})}),l.jsx("div",{className:"legend",children:l.jsxs("ul",{className:"legend-items-container",children:[t&&t.map((e,m)=>l.jsxs("li",{className:"legend-item",children:[l.jsx("span",{className:"symbol",style:{backgroundColor:e.color}}),s&&!a&&l.jsx("span",{className:"legend-label",style:n,children:e.label}),(!s||a)&&e.min!=null&&e.max!=null&&l.jsxs("span",{className:"legend-label",style:n,children:[this.formatNumber(e.min)," -"," ",this.formatNumber(e.max)]}),(!s||a)&&e.min==null&&e.max!=null&&l.jsxs("span",{className:"legend-label",style:n,children:[" ","< ",this.formatNumber(e.max)]}),(!s||a)&&e.min!=null&&e.max==null&&l.jsxs("span",{className:"legend-label",style:n,children:[" ","> ",this.formatNumber(e.min)," "]})]},"lg"+m)),console.log("showNoDataLegendItem",o),o&&l.jsxs("li",{className:"legend-item",children:[l.jsx("span",{className:"symbol",style:{backgroundColor:u}}),l.jsx("span",{className:"legend-label",style:n,children:x})]}),r&&r.map((e,m)=>l.jsxs("li",{className:"legend-item",children:[e.image&&l.jsx("img",{style:{width:"40px",height:"40px",marginTop:"-8px",marginRight:"-4px"},src:"/"+e.image}),l.jsx("span",{className:"legend-label",style:n,children:e.label?e.label:""})]},"k"+m))]})})]})}}exports.default=h;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var Z=(x,F,e)=>F in x?q(x,F,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[F]=e;var B=(x,F,e)=>Z(x,typeof F!="symbol"?F+"":F,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("react/jsx-runtime"),U=require("react-intl"),$=require("d3"),M=require("semantic-ui-react"),W=require("react"),J=require("topojson-client"),X=require("./legend.js"),j=require("../common/MapTooltip.js"),T=require("../../utils/deviceType.js"),Y=require("geostats"),K=require("../../conf/index.js");function V(x){const F=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(x){for(const e in x)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(x,e);Object.defineProperty(F,e,s.get?s:{enumerable:!0,get:()=>x[e]})}}return F.default=x,Object.freeze(F)}const b=V($),Q=V(J);function P(x,F,e){var l;if(!(x!=null&&x.length))return F;const s=((l=x[0])==null?void 0:l.items)??[],i=r=>(r==null?void 0:r.trim().toLowerCase())??"",o=i(F),t=i(e).toUpperCase(),a=s.find(r=>i(r.value)===o||r.code.trim().toLowerCase()===o)??null;if(!a)return F;const n=t&&a.labels&&a.labels[t]?a.labels[t]:a.value;return(n==null?void 0:n.trim())||a.value.trim()}const ee="_Color_",_="location",E="showAll",S="ifUnitHasData",te=10,se={mobile:4,tablet:4,midTablet:2,laptop:2,desktop:2,wide:2},ie={mobile:330,tablet:250,midTablet:250,laptop:200,desktop:100,wide:100},R={mobile:250,tablet:250,midTablet:250,laptop:0,desktop:0,wide:0},oe={greens:["#ccffdd","#b3ffcc","#99ffbb","#80ffaa","#66ff99","#4dff88","#33ff77","#1aff66","#00ff55","#00e64d"],greys:["#f2f2f2","#e6e6e6","#d9d9d9","#cccccc","#bfbfbf","#b3b3b3","#a6a6a6","#999999","#8c8c8c","#808080"],oranges:["#fff0e6","#ffe0cc","#ffd1b3","#ffc299","#ffb380","#ffa366","#ff944d","#ff8533","#ff751a","#ff6600"],purples:["#ffe6ff","#ffccff","#ffb3ff","#ff99ff","#ff80ff","#ff66ff","#ff4dff","#ff33ff","#ff1aff","#ff00ff"],reds:["#ffe6e6","#ffcccc","#ffb3b3","#ff9999","#ff8080","#ff6666","#ff4d4d","#ff3333","#ff1a1a","#ff0000"],blues:["#e6eeff","#ccddff","#b3ccff","#99bbff","#80aaff","#6699ff","#4d88ff","#3377ff","#1a66ff","#0055ff"]},ae=["mobile","tablet","midTablet"].includes(T.default()),H=["mobile","tablet"].includes(T.default());class re extends W.Component{constructor(e){var s;super(e);B(this,"handleScroll",()=>{let e=null;clearTimeout(e),e=setTimeout(()=>{b.select(this.getMapId()).selectAll(".map-labels-container").size()>0||this.updateFeatures(this.getFeatures(),!1)},300)});this.mapContainer=W.createRef(),this.state={mainLayer:null,layers:null},this.classColor=this.classColor.bind(this),this.featuresZoom=this.featuresZoom.bind(this),this.fullView=this.fullView.bind(this),this.onZoomIn=this.onZoomIn.bind(this),this.onZoomOut=this.onZoomOut.bind(this),this.onReset=this.onReset.bind(this),this.onClick=this.onClick.bind(this),this.showTooltip=this.showTooltip.bind(this),this.mousemove=this.mousemove.bind(this),this.mouseout=this.mouseout.bind(this),this.updateFeatures=this.updateFeatures.bind(this),this.d3Map=this.d3Map.bind(this),this.getFeatures=this.getFeatures.bind(this),this.boundingExtent=this.boundingExtent.bind(this),this.getMapId=this.getMapId.bind(this),this.zoomed=this.zoomed.bind(this),this.zoomEnd=this.zoomEnd.bind(this),this.drawPoints=this.drawPoints.bind(this),this.extractFeatures=this.extractFeatures.bind(this),this.getLayers=this.getLayers.bind(this),this.onPointClick=this.onPointClick.bind(this),this.onPolygonClick=this.onPolygonClick.bind(this),this.getCenter=this.getCenter.bind(this),this.mapPosition=null,this.zooming=!1,this.translateValue=se[T.default()],this.projection=b.geoMercator().scale(e.scale).center(e.center).translate([this.getWidth()/this.translateValue,this.getHeight()/2]),this.path=b.geoPath().projection(this.projection),this.zoom=b.zoom().scaleExtent([1,16]).on("zoom",this.zoomed).on("end",this.zoomEnd),this.centered=null,this.state={selectedMeasure:e.transformedData&&e.transformedData.measures&&e.transformedData.measures.length>1?e.transformedData.measures[0]:null,generatedBreaks:[],selectedPolygon:null,layersLoading:!1},this.metadataTypes=((s=e.transformedData)==null?void 0:s.types)||[]}componentDidMount(){window.addEventListener("scroll",this.handleScroll,{passive:!0}),window.addEventListener("touchmove",this.handleScroll,{passive:!0}),this.loadLayers(),this.tooltip=b.select("body").append("div").style("position","absolute").style("visibility","hidden").style("pointer-events","none"),console.log("Map props",this.metadataTypes)}componentDidCatch(e,s){console.log(e)}componentWillUnmount(){window.removeEventListener("scroll",this.handleScroll)}loadLayers(){const{source:e,mainLayerId:s,enabledLayers:i}=this.props;if(this.setState({layers:[],layersLoading:!0}),i&&i.length>0){const o=[];i.forEach(t=>{o.push(new Promise((a,n)=>{b.json(K.Config.REACT_APP_WP_API+"/wp/v2/media/"+t.id).then(l=>{a({id:t.id,url:l.source_url,index:t.index,layerMappingField:t.layerMappingField,layerDatasource:t.datasource,layerApiField:t.apiField,layerLocale:t.locale,displayLayerLabels:t.displayLayerLabels})}).catch(function(l){a({id:t.id,url:null,index:t.index,layerMappingField:t.layerMappingField,layerDatasource:t.datasource,layerApiField:t.apiField,layerLocale:t.locale,displayLayerLabels:t.displayLayerLabels})})}))}),Promise.all(o).then(t=>{const a=[];t.forEach(n=>{n.url&&a.push(new Promise((l,r)=>{b.json(n.url).then(h=>{l({id:n.id,data:h,index:n.index,layerMappingField:n.layerMappingField,layerDatasource:n.layerDatasource,layerApiField:n.layerApiField,layerLocale:n.layerLocale,displayLayerLabels:n.displayLayerLabels})})}))}),Promise.all(a).then(n=>{this.setState({layers:n,layersLoading:!1})})})}else b.json(e).then(o=>{this.setState({layers:[{id:null,url:e,data:o,index:0,layerMappingField:null,layerDatasource:null,layerApiField:null,layerLocale:null,displayLayerLabels:!1}],layersLoading:!1})})}getMainLayer(){const e=this.getLayers(),{mainLayerId:s,enabledLayers:i}=this.props;let o;return e&&(o=e.filter(t=>t.id==s||t.id==null)[0]||e[0]),o?o.data:null}componentDidUpdate(e,s,i){const{selectedMeasure:o,layers:t,selectedPolygon:a}=this.state,n=this.getMainLayer(),{transformedData:l,intl:r,zoomOnFilterField:h,appliedFilters:p}=this.props,{appliedFilters:d}=e;if(h){const v=[],c=[];d&&Object.keys(d).forEach(f=>{d[f]!=null&&d[f]instanceof Array&&v.push(...d[f].filter(y=>y!=Number.MIN_SAFE_INTEGER))}),p&&Object.keys(p).forEach(f=>{p[f]!=null&&p[f]instanceof Array&&c.push(...p[f].filter(y=>y!=Number.MIN_SAFE_INTEGER))}),v.length>0&&c.length==0&&this.onReset()}this.tooltip.style("visibility","hidden"),e.enabledLayers.length!=this.props.enabledLayers.length&&this.loadLayers();const u=this.getFeatures();e.center!==this.props.center&&(this.mapPosition=null,this.projection.scale(this.props.scale).center(this.props.center).translate([this.getWidth()/2,this.getHeight()/2]));const m=this.filterUpdated(e,s);this.d3Map(u,m),t&&l&&(l!=e.transformedData||t!=s.layers||o!=s.selectedMeasure||a!=s.selectedPolygon||n!=s.mainLayer||e.mainLayerId!==this.props.mainLayerId||JSON.stringify(e.enabledLayers)!=JSON.stringify(this.props.enabledLayers))&&this.updateFeatures(this.getFeatures(),m)}getHeight(){return this.props.height}getWidth(){return this.mapContainer.current?this.mapContainer.current.offsetWidth:this.props.width}boundingExtent(e){let s,i,o,t;for(const a in e){const[[n,l],[r,h]]=this.path.bounds(e[a]);(n<s||s==null)&&(s=n),(r>i||i==null)&&(i=r),(l<o||o==null)&&(o=l),(h>t||t==null)&&(t=h)}return[[s,o],[i,t]]}onReset(){this.mapPosition=null,this.tooltip.style("visibility","hidden"),this.fullView()}resizeLabels(e){const{labelFontSize:s,mapLabelField:i}=this.props;b.select(this.getMapId()).selectAll(".map-labels-container").each((o,t,a)=>{const n=b.select(a[t]),l=n.select("div"),r=e.k>1?e.k:1,h=s/r;l.style("font-size",`${h}px`);const p=this.getLabelPosition(o),d=this.getLabelBoxWidth(o)/r,u=p[0]-d/2,m=e.k>1?10/e.k:10,v=p[1]-m;n.attr("x",u).attr("y",v).attr("width",this.getLabelBoxWidth(o)/r).attr("height",this.getLabelBoxHeight(o)/r)})}resizePointLabels(e){const{labelFontSize:s}=this.props;b.select(this.getMapId()).selectAll(".point-labels-container").each((i,o,t)=>{const a=b.select(t[o]),n=a.select("div"),l=e.k>1?e.k:1,r=s/l;n.style("font-size",`${r}px`);const h=this.projection([i.geometry.coordinates[1],i.geometry.coordinates[0]]),p=(this.getLabelBoxWidth(i)+20)/l,d=this.getLabelBoxHeight(i)/l,u=h[0]-p/2,m=h[1]-d/2;a.attr("x",u).attr("y",m).attr("width",p).attr("height",d)})}resizeCircles(e){b.select(this.getMapId()).select("svg").selectAll("circle").attr("r",e.k>1?6/e.k:6)}zoomed(e){this.tooltip.style("visibility","hidden");const s=e.transform;b.select(this.getMapId()).select("svg").select("g").attr("transform",s),this.resizeCircles(s),this.resizeLabels(s),this.resizePointLabels(s)}zoomEnd(e){const{editing:s}=this.props,i=e.transform;this.mapPosition={k:i.k,x:i.x,y:i.y},s&&window.parent.postMessage({type:"map",value:JSON.stringify(this.mapPosition)},"*")}classColor(e){let{zoomEnabled:s}=this.props;return s||(s=!!["mobile","tablet","midTablet"].includes(T.default())),s?"active zoom-enabled":"active"}generateBreaks(e){const{autoGenerateBreaks:s,numberOfBreaks:i,colorScheme:o}=this.props,t=[];if(s&&e&&e.length>0){const a=e.filter(r=>r.properties&&r.properties.value!=null).map(r=>r.properties.value.toFixed(2)),n=[];a.forEach(r=>{if(r>0){const h=r*.99,p=r*1.01;n.indexOf(h)===-1&&n.push(h),n.indexOf(p)===-1&&n.push(p)}});const l=oe[o];if(n.length>0){const r=new Y(n);r.setPrecision(2);const h=n.length>1?n.length-1:n.length;return r.getJenks(Math.min(i,h)),r.ranges.forEach((p,d)=>{const u={};u.min=parseFloat(p.substr(0,p.indexOf("-")-1))+(d>0?.01:0),u.max=parseFloat(p.substr(p.indexOf("-")+2,p.length)),u.color=l[d],t.push(u)}),t}}return t}getBreaks(){const{legendBreaks:e,autoGenerateBreaks:s}=this.props;if(s){const i=this.getFeatures();return this.generateBreaks(i)}else{let i=e;return this.getSelectedMeasure()&&(i=e.filter(o=>o.measure===this.getSelectedMeasure()).filter(o=>{if(o.filters&&o.filters.length>0&&this.props.appliedFilters&&JSON.stringify(this.props.appliedFilters)!=="{}"){const a=Object.keys(this.props.appliedFilters);return o.filters.filter(l=>{if(a.indexOf(l.field)!=-1){const r=this.props.appliedFilters[l.field],h=l.values;return r.join(",").indexOf(h)!=-1}return!1}).length>0}return!0})),i}}fillColor(e,s){const{mapNoDataColor:i,mainLayerId:o}=this.props;let t;if(e.properties&&e.properties.variables&&this.state.selectedMeasure&&e.properties.value!=null){const n=ee+this.state.selectedMeasure;if(t=e.properties.variables[n.trim()],t)return t}if(e.properties.value!=null&&(o&&e.properties.layerId===o||!o)){const n=s.find(l=>{if(l.min!=null&&l.max!=null)return e.properties.value>=l.min&&e.properties.value<=l.max;if(l.min!=null)return e.properties.value>=l.min;if(l.max!=null)return e.properties.value<=l.max});return n&&n.color?n.color:i}const a=this.props.enabledLayers.filter(n=>n.id===e.properties.layerId)[0];return a&&a.bgColor&&a.bgColor!="undefined"?a.bgColor:i}setValues(){const e=this.getFeatures();b.select(this.getMapId()).select("svg").select("g").selectAll("path").data(e).join("path").attr("d",this.path)}getLabelPosition(e){return e.properties.LABEL_LATITUDE&&e.properties.LABEL_LONGITUDE?this.projection([e.properties.LABEL_LONGITUDE,e.properties.LABEL_LATITUDE]):this.path.centroid(e)}updateFeatures(e,s){const{mapLabelField:i,symbols:o,highlightedLocation:t}=this.props,a=[...e.filter(n=>t!=n.properties[i]),...e.filter(n=>t==n.properties[i])];this.drawPolygons(a),this.drawLabels(a),this.drawPoints(a,s),o.length>0&&this.addSymbols(o,a)}drawLabels(e){const{mapLabelField:s,mapLabelShowValue:i,intl:o,valueFormat:t,showNoDataLabel:a,labelFontColor:n,labelFontWeight:l,labelFontSize:r,showAdminUnitLabel:h,mapType:p,noDataText:d,labelsExclusionList:u}=this.props,m=b.select(this.getMapId()).select("svg").select("g");if(m.selectAll(".map-labels-container").size()>0){console.log("Labels already exist, skipping redraw...");return}m.selectAll(".map-labels").data(e.filter(c=>u&&u.length>0?!u.includes(c.properties[s]):!0)).enter().append("foreignObject").attr("class","map-labels-container").attr("x",c=>{const f=this.getLabelPosition(c);if(c.properties[s]){const y=this.getLabelBoxWidth(c);return f[0]-y/2}return f[0]}).attr("y",c=>this.getLabelPosition(c)[1]-10).attr("width",c=>this.getLabelBoxWidth(c)).attr("height",c=>this.getLabelBoxHeight(c)).attr("font-size",(c,f)=>`${r}px`).attr("overflow","visible").attr("opacity",1).style("display",c=>h===E||h===S&&c.properties.hasDataRow||c.properties.displayLayerLabels?"block":"none").attr("pointer-events",p=="POINTS_MAP"?"none":"all").on("mouseover",this.showTooltip).on("mousemove",this.mousemove).on("mouseout",this.mouseout).append("xhtml:div").style("font-size",c=>`${r}px`).style("color",(c,f)=>n).style("font-weight",c=>l).style("background-color",c=>c.properties.hasDataRow&&i&&(c.properties.value!=null||c.properties.value==null&&a)?"#fff6e1":"none").style("border-radius",c=>"4px").style("line-height","95%").style("text-align","center").html((c,f)=>this.createLabel(c))}getTranslatedLocationName(e,s,i){if(e.properties.displayLayerLabels&&e.properties.layerLocale){const o=e.properties.layerMappingField||s,t=e.properties[o];return P(this.metadataTypes,t,e.properties.layerLocale)}return e.properties[s]}createLabel(e){const{mapLabelField:s,mapLabelShowValue:i,intl:o,valueFormat:t,showNoDataLabel:a,showAdminUnitLabel:n,noDataText:l}=this.props;let r="";if(n==E||n==S&&e.properties.hasDataRow||e.properties.displayLayerLabels){const h=e.properties.displayLayerLabels&&e.properties.layerMappingField?e.properties.layerMappingField:s,p=e.properties[h],d=e.properties.layerLocale||(o==null?void 0:o.locale);r=P(this.metadataTypes,p,d);const u=e.properties.abbrev;if(r&&r.length>te&&u&&(r=u),i)if(e.properties.value!=null){const m=e.properties.variables||{};r+="<br><span class='map-label-value'>"+j.formatContent(t,{value:e.properties.value,measure:this.getSelectedMeasure(),...m},o)+"</span>"}else a==!0&&e.properties.value==null&&e.properties.hasDataRow&&(r+="<br><span class='map-label-value'>"+l+"</span>")}return r}drawPolygons(e){const{mapLabelField:s,mapBoundaryColor:i,mapFocusBoundaryColor:o,highlightedLocation:t}=this.props,a=this.getBreaks(),n=b.select(this.getMapId()).select("svg").select("g"),l=e.filter(r=>r.geometry&&r.geometry&&(r.geometry.type=="Polygon"||r.geometry.type=="MultiPolygon"));l.length>0&&n.selectAll("path").data(l).join("path").attr("d",this.path).attr("fill",r=>this.fillColor(r,a)).attr("stroke-width",r=>t==r.properties[s]?1.2:.4).attr("stroke",r=>t==r.properties[s]?o:i).on("click",this.onPolygonClick)}drawPoints(e,s){const{intl:i,pointLabelColor:o,pointLabelFormat:t,transformedData:a,defaultPointColor:n,appliedFilters:l,zoomOnFilterField:r,noDataText:h,showShadingLayerLabels:p}=this.props,d=b.select(this.getMapId()).select("svg").select("g");let u=[];if(a.pointsData){let c=this.state.selectedPolygon;s&&l&&l[r]&&(c=l[r]),u=a.pointsData.filter(f=>f.lat&&f.lng&&f.label==c).map(f=>({properties:{label:f.label,lat:f.lat,lng:f.lng,value:f.value,variables:f.variables}})),d.selectAll(".circle").data(u).enter().append("circle").attr("id",(f,y)=>"circle"+y).attr("cx",f=>this.projection([f.properties.lng,f.properties.lat])[0]).attr("cy",f=>this.projection([f.properties.lng,f.properties.lat])[1]).attr("r",(f,y)=>2).style("stroke-width",.5).style("fill",(f,y)=>n).on("mouseover",(f,y)=>this.onPointClick(f,y)).on("mouseout",this.mouseout)}const m=this.getBreaks();let v=[];p==E?v=e.filter(c=>c.geometry&&c.geometry.type=="Point"):p==S&&(v=e.filter(c=>c.geometry&&c.geometry.type=="Point"&&c.properties.hasDataRow)),v.length>0&&d.selectAll(".point-labels").data(v).enter().append("foreignObject").attr("id",(c,f)=>"point-label"+f).attr("class","point-labels-container").attr("x",c=>{const f=this.getLabelBoxWidth(c)+20;return this.projection([c.geometry.coordinates[1],c.geometry.coordinates[0]])[0]-f/2}).attr("y",c=>this.projection([c.geometry.coordinates[1],c.geometry.coordinates[0]])[1]-this.getLabelBoxHeight(c)/2).attr("width",c=>this.getLabelBoxWidth(c)+20).attr("height",c=>"1px").attr("overflow","visible").attr("font-size","12px").style("opacity",1).append("xhtml:div").style("color",(c,f)=>o).style("font-weight",c=>"bold").style("background-color",c=>this.fillColor(c,m)).style("padding",c=>"5px 3px 5px 3px").style("border-radius",c=>"4px").style("line-height","100%").style("text-align","center").html((c,f)=>j.formatContent(t,{value:c.properties.value,locationName:c.properties[this.props.mapLabelField]},i)).on("mouseover",(c,f,y)=>{b.select(this.getMapId()).select("svg").select("g").select("#point-label"+y).raise(),this.showTooltip(c,f)}).on("mousemove",this.mousemove).on("mouseout",this.mouseout)}addSymbols(e,s){const{mappingField:i}=this.props,o=b.select(this.getMapId()).select("svg").select("g");e.forEach(t=>{if(t.field&&t.image&&t.values){const a=s.filter(l=>{const r=_==t.field?i:"value",h=(l.properties[r]||(l.properties.variables?l.properties.variables[r]:""))+"",d=(t.values+"").split(",");return l.properties.LATITUDE&&l.properties.LONGITUDE&&d.filter(u=>u.trim().toLowerCase()==h.trim().toLowerCase()).length>0}),n=s.filter(l=>{const r=_==t.field?i:"value",h=(l.properties[r]||(l.properties.variables?l.properties.variables[r]:""))+"",d=(t.values+"").split(",");return!l.properties.LATITUDE&&!l.properties.LONGITUDE&&d.filter(u=>u.trim().toLowerCase()==h.trim().toLowerCase()).length>0});o.selectAll("image").data(a).enter().append("image").attr("width",40).attr("height",40).attr("class","map-symbol").attr("xlink:href","/"+t.image).attr("transform",l=>"translate("+this.projection([l.properties.LONGITUDE,l.properties.LATITUDE])+")").on("mouseover",this.showTooltip).on("mousemove",this.mousemove).on("mouseout",this.mouseout),o.selectAll("image").data(n).enter().append("image").attr("width",40).attr("height",40).attr("class","map-symbol").attr("xlink:href","/"+t.image).attr("x",l=>this.path.centroid(l)[0]-20).attr("y",l=>this.path.centroid(l)[1]).on("mouseover",this.showTooltip).on("mousemove",this.mousemove).on("mouseout",this.mouseout)}})}getLabelBoxHeight(){const{mapLabelShowValue:e}=this.props;return e?30:25}getLabelBoxWidth(e){const{mapLabelField:s}=this.props,i=80;if(e.properties[s]){const o=e.properties[s].length;return o<10?i:o*8}return 0}featuresZoom(e,s,i){const o=b.select(this.getMapId()).select("svg"),t=this.boundingExtent(e),[[a,n],[l,r]]=t,h=this.getWidth(),p=this.getHeight(),d=Math.min(8,.9/Math.max((l-a)/h,(r-n)/p)),u=[h/2-(a+l)/2,p/2-(n+r)/2];s?o.call(this.zoom.transform,b.zoomIdentity.translate(u[0],u[1]).scale(d)):o.transition().duration(450).call(this.zoom.transform,b.zoomIdentity.translate(u[0],u[1]).scale(d)).on("end",i)}fullView(){const{mapPosition:e,editing:s}=this.props,i=b.select(this.getMapId()).select("svg");i.select("g").selectAll(".active").attr("class",function(){return b.select(this).attr("class").replace(/background/gi,"")});let t=b.zoomIdentity;e&&!s?t=t.translate(e.x,e.y).scale(e.k):t=t.translate(0,0).scale(1),i.transition().duration(300).call(this.zoom.transform,t)}showTooltip(e,s){let{showTooltip:i,zoomEnabled:o,tooltipTheme:t,customTooltips:a,tooltipFontSize:n,tooltipFormat:l,intl:r,mappingField:h,showNoDataTooltip:p,fields:d,mapType:u,noDataText:m}=this.props;if(o=!!["mobile","tablet","midTablet"].includes(T.default()),i&&s.properties.value!=null||i&&p){b.select(this.getMapId()).select("svg").select("g").selectAll(".active").attr("class",k=>k.properties[h]===s.properties[h]?"focus"+(o?" zoom-enabled":""):"active"+(o?" zoom-enabled":""));const f=l||`{locationName} %({value},2)
|
|
2
|
-
{label}: %({value},2)`,
|
|
3
|
-
`),
|
|
4
|
-
{label}: %({value},2)`,D={value:null,measure:this.getSelectedMeasure(),measureLabel:s.properties.measureLabel,locationName:this.getTranslatedLocationName(s,h,r),...y};L+=j.formatContent(w,D,r),L+="</div>"}return L})}}positionTooltip(e){const i=this.tooltip.node(),o=i?i.offsetWidth:0,t=window.scrollX+document.documentElement.clientWidth;let a=e.pageX;o&&a+o>t&&(a=e.pageX-o,a<window.scrollX&&(a=window.scrollX)),this.tooltip.style("top",e.pageY+"px").style("left",a+"px").style("margin-left","8px")}mousemove(e,s){this.positionTooltip(e)}mouseout(e,s){const{showTooltip:i}=this.props;i&&(b.select(this.getMapId()).select("svg").select("g").selectAll(".focus").attr("class","active"),this.tooltip.style("visibility","hidden"))}onClick(e,s){s.properties&&(this.tooltip.style("visibility","visible"),this.positionTooltip(e)),e.stopPropagation(),e.preventDefault()}onPointClick(e,s,i){this.showTooltip(e,s),this.tooltip.style("visibility","visible"),this.positionTooltip(e);const o=b.select(this.getMapId()).select("svg").select("g");o.selectAll("circle").style("fill",this.props.defaultPointColor).style("stroke","none"),o.select("#circle"+i).raise().style("fill","#fff")}onPolygonClick(e,s){const{mappingField:i}=this.props;this.state.selectedPolygon!==s.properties[i]&&s.properties.value!==null&&this.setState({selectedPolygon:s.properties[i]})}onZoomIn(e){b.select(this.getMapId()).select("svg").transition().call(this.zoom.scaleBy,1.5)}onZoomOut(){b.select(this.getMapId()).select("svg").transition().call(this.zoom.scaleBy,.6667)}getSelectedMeasure(){let e=this.state.selectedMeasure;return!e&&this.props.transformedData&&this.props.transformedData.measures&&this.props.transformedData.measures.length>1&&(e=this.props.transformedData.measures[0]),e}getCollectionField(e){const{topoJSONField:s}=this.props;if(e&&e.objects){const i=Object.keys(e.objects);for(const o in i){const t=i[o];if(e.objects[t].type=="GeometryCollection")return t}}return s}extractFeatures(e){const s=this.getCollectionField(e);return e&&e.objects&&e.objects[s]?Q.feature(e,e.objects[s]).features:e&&e.features?e.features:[]}getLayers(){const{layers:e}=this.state,{enabledLayers:s}=this.props;return e&&e.length>0?e.map(o=>{const t=s.find(a=>a.id==o.id);return o.index=t?t.index:0,o}).sort((o,t)=>parseInt(o.index)<parseInt(t.index)?1:parseInt(o.index)>parseInt(t.index)?-1:0):[]}getFeatures(){const e=this.getMainLayer(),s=this.getLayers();if(e){const{transformedData:i,mappingField:o,app:t,mainLayerId:a,enabledLayers:n}=this.props;let l=[];try{l=this.extractFeatures(e),l.map(p=>{p.properties.layerId=a;const d=s.find(u=>String(u.id)===String(a));return d&&(p.properties.layerMappingField=d.layerMappingField,p.properties.layerDatasource=d.layerDatasource,p.properties.layerApiField=d.layerApiField,p.properties.layerLocale=d.layerLocale,p.properties.displayLayerLabels=d.displayLayerLabels),n.forEach(u=>{String(u.id)==a&&Object.keys(u||{}).forEach(m=>{p.properties[m]=u[m]})}),p}),s&&s.forEach(p=>{if(p.id!=a){let d=this.extractFeatures(p.data);d=d.map(u=>(u.properties.layerId=p.id,u.properties.layerMappingField=p.layerMappingField,u.properties.layerDatasource=p.layerDatasource,u.properties.layerApiField=p.layerApiField,u.properties.layerLocale=p.layerLocale,u.properties.displayLayerLabels=p.displayLayerLabels,u)),l=[...d,...l]}})}catch(p){console.log("error updating features .."+p)}const r=l.filter(p=>p.properties!=null);let h=i.locationsData;return i.measures&&i.measures.length>1&&(h=i.locationsData.filter(p=>p.measure===this.getSelectedMeasure())),r.map(p=>{if(h){const d=h.find(u=>{const m=u.label?(""+u.label).toLowerCase():"",v=p.properties[o]?p.properties[o].toLowerCase():"";return m===v});if(d){let u=d.measure;i.measureLabelMap&&d.measure&&i.measureLabelMap[d.measure]&&(u=i.measureLabelMap[d.measure]),p.properties.value=d.value,p.properties.measure=d.measure,p.properties.measureLabel=u,p.properties.children=d.children,p.properties.variables=d.variables,p.properties.hasDataRow=!0,Object.keys(d).forEach(m=>{p.properties[m]=d[m]})}else p.properties.value=null,p.properties.measure=null,p.properties.children=null,p.properties.measureLabel=null,p.properties.hasDataRow=!1}}),r}return[]}getMapId(){const{unique:e}=this.props;return".map.wrapper."+e}filterUpdated(e,s){const{zoomOnFilterField:i}=this.props,o=e&&e.appliedFilters||{},t=this.props.appliedFilters||{};let a=!1;return o[i]!=t[i]&&(a=!0),a}getCenter(e,s){const{zoomOnFilter:i,zoomOnFilterField:o,mappingField:t,appliedFilters:a}=this.props;let n=null;if(i&&o){let l=this.state.selectedPolygon;s&&a&&a[o]&&(l=a[o]);const r=e.filter(h=>h.properties!=null&&h.properties[t]==l)[0];r&&r.properties!=null&&r.properties.value&&(n=r)}return n}area(e){let s=0;const i=e.coordinates.length>1?e.coordinates[0][0]:e.coordinates[0];for(let o=0;o<i.length-1;o++)s+=i[o][0]*i[o+1][1]-i[o+1][0]*i[o][1];return .5*s}centroid(e){const s=[0,0],i=e.coordinates.length>1?e.coordinates[0][0]:e.coordinates[0];for(let t=0;t<i.length-1;t++)s[0]+=(i[t][0]+i[t+1][0])*(i[t][0]*i[t+1][1]-i[t+1][0]*i[t][1]),s[1]+=(i[t][1]+i[t+1][1])*(i[t][0]*i[t+1][1]-i[t+1][0]*i[t][1]);const o=this.area(e);return s[0]/=o*6,s[1]/=o*6,s}d3Map(e,s){let{zoomEnabled:i,mapContainerBgColor:o,mapPosition:t,editing:a,mapType:n}=this.props;i||(i=!!["mobile","tablet"].includes(T.default()));const l=this.getBreaks(),r=b.select(this.getMapId());let h=r.select("svg"),p=this.getWidth();p===0?p=window.innerWidth+R[T.default()]:p+=R[T.default()];const d=this.getHeight()-100;if(h.empty()?h=r.append("svg"):h.selectAll("*").remove(),h.attr("style",`background-color:${o};`).attr("viewBox",`0 0 ${p} ${d}`).attr("preserveAspectRatio","xMidYMid meet"),h.append("g").selectAll("path").data(e).enter().append("path").attr("fill",m=>this.fillColor(m,l)).attr("d",b.geoPath().projection(this.projection)).attr("class",m=>this.classColor(m)).on("mouseover",n!=="POINTS_MAP"?this.showTooltip:null).on("mousemove",n!=="POINTS_MAP"?this.mousemove:null).on("mouseout",n!=="POINTS_MAP"?this.mouseout:null),this.mapPosition&&h.transition().duration(300).call(this.zoom.transform,b.zoomIdentity.translate(this.mapPosition.x,this.mapPosition.y).scale(this.mapPosition.k)),!this.mapPosition&&t&&t.x&&t.y&&t.k&&(h.transition().duration(300).call(this.zoom.transform,b.zoomIdentity.translate(t.x,t.y).scale(t.k)),n==="POINTS_MAP")){const v={mobile:100,tablet:0,midTablet:0,desktop:0,laptop:0,wide:0}[T.default()];h.transition().duration(300).call(this.zoom.transform,b.zoomIdentity.translate(t.x+v,t.y).scale(t.k))}i||a?h.call(this.zoom):h.on("dblclick.zoom",null);const u=this.getCenter(e,s);if(u){const m=this.path.bounds(u),v=[(m[0][0]+m[1][0])/2,(m[0][1]+m[1][1])/2];h.transition().duration(750).call(this.zoom.transform,b.zoomIdentity.translate(p/2,d/2).scale(12).translate(-v[0],-v[1]))}}getAvg(){const{transformedData:e}=this.props;return e.nationalData.value}selectedMeasureChanged(e){this.state.selectedMeasure!=e&&this.setState({selectedMeasure:e})}getFilters(){const{appliedFilters:e}=this.props,s={};return e&&Object.keys(e).forEach(o=>{const t=e[o];t&&(s[o]=Array.isArray(t)?t.join(" ,"):t)}),s}getHighlightedLocationData(){const{highlightedLocation:e,transformedData:s}=this.props;let i=s.locationsData;return s.measures&&s.measures.length>1&&(i=s.locationsData.filter(t=>t.measure===this.getSelectedMeasure())),i.find(t=>t.label===e)}getTranslatedHighlightedLocationName(){const{highlightedLocation:e,mapLabelField:s,intl:i}=this.props;if(!e)return null;const t=this.getFeatures().find(a=>a.properties[s]===e);if(t&&t.properties.displayLayerLabels&&t.properties.layerLocale){const a=t.properties.layerMappingField||s,n=t.properties[a];return P(this.metadataTypes,n,t.properties.layerLocale)}return e}getHighlightedLocationColor(e){const s=this.getBreaks(),{mapNoDataColor:i}=this.props,o=e?e.value:null;if(o!=null){const t=s.find(a=>{if(a.min!=null&&a.max!=null)return o>=a.min&&o<=a.max;if(a.min!=null)return o>=a.min;if(a.max!=null)return o<=a.max});return t&&t.color?t.color:i}return i}renderLoader(){return g.jsx(M.Container,{className:"loading",children:g.jsx(M.Segment,{basic:!0,padded:!0,textAlign:"center",style:{margin:"30px"},children:g.jsx(M.Dimmer,{active:!0,inverted:!0,children:g.jsx(M.Loader,{size:"medium"})})})})}noMapSelected(){return g.jsxs(M.Message,{icon:!0,warning:!0,children:[g.jsx(M.Icon,{name:"map outline"}),g.jsxs(M.Message.Content,{children:[g.jsx(M.Message.Header,{children:"No map selected"}),"Pick one from the list in the ",g.jsx("strong",{children:"Map Layers"})," section."]})]})}render(){let{app:e,legendTitle:s,nationalAverageLabel:i,intl:o,zoomEnabled:t,transformedData:a,measureSelectorLabel:n,valueFormat:l,showOverallValue:r,unique:h,highlightedLocation:p,labelFontColor:d,legendFontSize:u,editing:m,highlightedLocLabelFormat:v,noDataText:c}=this.props;t||(t=!!["mobile","tablet","midTablet"].includes(T.default()));const f=this.getAvg(),y=this.getFilters(),C=this.getHighlightedLocationData(),k={backgroundColor:this.getHighlightedLocationColor(C),color:d,fontSize:u+"px"};m&&(k.marginTop="25px");const L=()=>g.jsxs(M.Container,{fluid:!0,className:"footnote ",children:[g.jsxs(M.Grid,{columns:2,children:[e!=="csv"&&r&&g.jsx(M.Grid.Column,{textAlign:"left",width:4,children:g.jsxs("div",{className:"national-average-div",children:[g.jsx("span",{className:"national-avg-label",children:i}),g.jsx("span",{className:"national-avg-value",children:j.formatContent(l,{value:f},o)})]})}),g.jsx(M.Grid.Column,{textAlign:"right",width:e!=="csv"&&r?12:16,children:g.jsx(X.default,{filteredBreaks:this.getBreaks(),formattedLegendTitle:j.formatContent(s,{...y},o),selectedMeasure:this.state.selectedMeasure,...this.props})})]}),g.jsx("div",{className:"measure-selector",children:g.jsxs("ul",{children:[n&&g.jsx("li",{children:g.jsx("span",{className:"label",children:n})}),a&&a.measures&&a.measures.length>1&&a.measures.map(w=>g.jsxs("li",{onClick:this.selectedMeasureChanged.bind(this,w),children:[g.jsx("input",{checked:this.getSelectedMeasure()===w,type:"radio",value:w}),g.jsx("label",{children:a.measureLabelMap[w]||w})]}))]})})]});return g.jsxs("div",{className:"map component wp-data-viz-map",ref:this.mapContainer,children:[this.state.layersLoading&&(m?this.noMapSelected():this.renderLoader()),!this.state.layersLoading&&g.jsxs(g.Fragment,{children:[!H&&g.jsx(L,{}),g.jsxs("div",{className:"map wrapper scaling-svg-container "+h,style:{height:this.props.height-ie[T.default()]+"px"},children:[C?g.jsx("div",{className:"highlighted-loc-info",style:k,children:g.jsxs("span",{children:[" ",j.formatContent(v,{value:C.value,locationName:this.getTranslatedHighlightedLocationName()||C.label,measureName:C.measure},o)]})}):g.jsx(g.Fragment,{children:" "}),(m||t)&&!ae&&g.jsxs("div",{className:"control panel ignore",children:[g.jsx("div",{className:"zoom plus",onClick:this.onZoomIn,children:g.jsx(M.Icon,{name:"plus",size:"large"})}),g.jsx("div",{className:"zoom minus",onClick:this.onZoomOut,children:g.jsx(M.Icon,{name:"minus",size:"large"})}),g.jsx(M.Popup,{content:g.jsx(U.FormattedMessage,{id:"map.reset.tooltip",defaultMessage:"Reset zoom"}),trigger:g.jsx("div",{className:"reset",onClick:this.onReset,children:g.jsx(M.Icon,{name:"repeat",size:"large"})})})]})]}),H&&g.jsx(L,{})]})]})}}const le=U.injectIntl(re);exports.default=le;exports.getTranslatedItemLabel=P;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("react/jsx-runtime"),Je=require("react-intl"),$t=require("d3"),b=require("semantic-ui-react"),h=require("react"),Jt=require("./legend.js"),k=require("../common/MapTooltip.js"),I=require("../../utils/deviceType.js"),f=require("./mapHelpers.js"),Xt=require("../../conf/index.js");function Zt(L){const U=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(L){for(const w in L)if(w!=="default"){const X=Object.getOwnPropertyDescriptor(L,w);Object.defineProperty(U,w,X.get?X:{enumerable:!0,get:()=>L[w]})}}return U.default=L,Object.freeze(U)}const u=Zt($t),Yt=["mobile","tablet","midTablet"].includes(I.default()),$e=["mobile","tablet"].includes(I.default());function Kt(L){const{unique:U,editing:w,source:X,center:ne,scale:Fe,height:we,width:Xe,topoJSONField:Ze,mappingField:x,transformedData:p,legendBreaks:Ae,mapLabelField:A,mapLabelShowValue:se,showOverallValue:Te,measureSelectorLabel:Me,valueFormat:je,autoGenerateBreaks:Ne,showNoDataLabel:Ce,numberOfBreaks:Ye,colorScheme:Ke,symbols:ke,tooltipTheme:Qe,labelFontSize:te,labelFontColor:Ie,labelFontWeight:et,legendFontSize:tt,customTooltips:rt,tooltipFontSize:lt,showAdminUnitLabel:ae,mapNoDataColor:Ee,mapBoundaryColor:nt,mapFocusBoundaryColor:st,highlightedLocation:z,tooltipFormat:Se,showNoDataTooltip:at,fields:ot,mapContainerBgColor:it,mapPosition:v,mainLayerId:_,enabledLayers:D,pointLabelColor:ct,pointLabelFormat:ut,highlightedLocLabelFormat:pt,mapType:G,defaultPointColor:Oe,zoomOnFilter:dt,zoomOnFilterField:P,noDataText:ft,labelsExclusionList:oe,showShadingLayerLabels:ze,appliedFilters:m,intl:T,legendTitle:mt,nationalAverageLabel:gt,zoomEnabled:ie,showTooltip:ce}=L;console.log("Map props:",L);const[W,ht]=h.useState(()=>p&&p.measures&&p.measures.length>1?p.measures[0]:null),[q,yt]=h.useState(null),[De,ue]=h.useState(!1),[B,pe]=h.useState(null),de=h.useRef(null),M=h.useRef(null),F=h.useRef(null),V=h.useRef(null),j=h.useRef(null),Pe=h.useRef(null),E=h.useRef(null),Re=h.useRef(!1),fe=h.useRef(null),me=h.useRef(null),N=h.useRef({}),ge=h.useRef(null),Z=(p==null?void 0:p.types)||[];function he(){return de.current?de.current.offsetWidth:Xe}function ye(){return we}j.current===null&&(j.current=u.zoom().scaleExtent([1,16]).on("zoom",e=>N.current.zoomed(e)).on("end",e=>N.current.zoomEnd(e))),F.current===null&&(Pe.current=f.deviceTranslateMap[I.default()],F.current=u.geoMercator().scale(Fe).center(ne).translate([he()/Pe.current,ye()/2]),V.current=u.geoPath().projection(F.current));function y(){return".map.wrapper."+U}function S(){let e=W;return!e&&p&&p.measures&&p.measures.length>1&&(e=p.measures[0]),e}function _e(){return B&&B.length>0?B.map(t=>{const a=D.find(n=>n.id==t.id);return t.index=a?a.index:0,t}).sort((t,a)=>parseInt(t.index)<parseInt(a.index)?1:parseInt(t.index)>parseInt(a.index)?-1:0):[]}function bt(){const e=_e();let t;return e&&(t=e.filter(a=>a.id==_||a.id==null)[0]||e[0]),t?t.data:null}function We(e){return f.extractFeatures(e,Ze)}function Y(){const e=bt(),t=_e();if(e){let a=[];try{a=We(e),a.map(l=>{l.properties.layerId=_;const r=t.find(s=>String(s.id)===String(_));return r&&(l.properties.layerMappingField=r.layerMappingField,l.properties.layerDatasource=r.layerDatasource,l.properties.layerApiField=r.layerApiField,l.properties.layerLocale=r.layerLocale,l.properties.displayLayerLabels=r.displayLayerLabels),D.forEach(s=>{String(s.id)==_&&Object.keys(s||{}).forEach(o=>{l.properties[o]=s[o]})}),l}),t&&t.forEach(l=>{if(l.id!=_){let r=We(l.data);r=r.map(s=>(s.properties.layerId=l.id,s.properties.layerMappingField=l.layerMappingField,s.properties.layerDatasource=l.layerDatasource,s.properties.layerApiField=l.layerApiField,s.properties.layerLocale=l.layerLocale,s.properties.displayLayerLabels=l.displayLayerLabels,s)),a=[...r,...a]}})}catch(l){console.log("error updating features .."+l)}const n=a.filter(l=>l.properties!=null);let i=p.locationsData;return p.measures&&p.measures.length>1&&(i=p.locationsData.filter(l=>l.measure===S())),n.map(l=>{if(i){const r=i.find(s=>{const o=s.label?(""+s.label).toLowerCase():"",d=l.properties[x]?l.properties[x].toLowerCase():"";return o===d});if(r){let s=r.measure;p.measureLabelMap&&r.measure&&p.measureLabelMap[r.measure]&&(s=p.measureLabelMap[r.measure]),l.properties.value=r.value,l.properties.measure=r.measure,l.properties.measureLabel=s,l.properties.children=r.children,l.properties.variables=r.variables,l.properties.hasDataRow=!0,Object.keys(r).forEach(o=>{l.properties[o]=r[o]})}else l.properties.value=null,l.properties.measure=null,l.properties.children=null,l.properties.measureLabel=null,l.properties.hasDataRow=!1}}),n}return[]}function Be(){if(pe([]),ue(!0),D&&D.length>0){const e=[];D.forEach(t=>{e.push(new Promise(a=>{u.json(Xt.Config.REACT_APP_WP_API+"/wp/v2/media/"+t.id).then(n=>{a({id:t.id,url:n.source_url,index:t.index,layerMappingField:t.layerMappingField,layerDatasource:t.datasource,layerApiField:t.apiField,layerLocale:t.locale,displayLayerLabels:t.displayLayerLabels})}).catch(function(){a({id:t.id,url:null,index:t.index,layerMappingField:t.layerMappingField,layerDatasource:t.datasource,layerApiField:t.apiField,layerLocale:t.locale,displayLayerLabels:t.displayLayerLabels})})}))}),Promise.all(e).then(t=>{const a=[];t.forEach(n=>{n.url&&a.push(new Promise(i=>{u.json(n.url).then(l=>{i({id:n.id,data:l,index:n.index,layerMappingField:n.layerMappingField,layerDatasource:n.layerDatasource,layerApiField:n.layerApiField,layerLocale:n.layerLocale,displayLayerLabels:n.displayLayerLabels})})}))}),Promise.all(a).then(n=>{pe(n),ue(!1)})})}else u.json(X).then(e=>{pe([{id:null,url:X,data:e,index:0,layerMappingField:null,layerDatasource:null,layerApiField:null,layerLocale:null,displayLayerLabels:!1}]),ue(!1)})}function vt(e){u.select(y()).select("svg").selectAll("circle").attr("r",e.k>1?6/e.k:6)}function H(e){return f.getLabelBoxWidth(e,A)}function re(){return f.getLabelBoxHeight(se)}function be(e){return e.properties.LABEL_LATITUDE&&e.properties.LABEL_LONGITUDE?F.current([e.properties.LABEL_LONGITUDE,e.properties.LABEL_LATITUDE]):V.current.centroid(e)}function Lt(e){u.select(y()).selectAll(".map-labels-container").each((t,a,n)=>{const i=u.select(n[a]),l=i.select("div"),r=e.k>1?e.k:1,s=te/r;l.style("font-size",`${s}px`);const o=be(t),d=H(t)/r,g=o[0]-d/2,C=e.k>1?10/e.k:10,R=o[1]-C;i.attr("x",g).attr("y",R).attr("width",H(t)/r).attr("height",re()/r)})}function xt(e){u.select(y()).selectAll(".point-labels-container").each((t,a,n)=>{const i=u.select(n[a]),l=i.select("div"),r=e.k>1?e.k:1,s=te/r;l.style("font-size",`${s}px`);const o=F.current([t.geometry.coordinates[1],t.geometry.coordinates[0]]),d=(H(t)+20)/r,g=re()/r,C=o[0]-d/2,R=o[1]-g/2;i.attr("x",C).attr("y",R).attr("width",d).attr("height",g)})}function Ft(e){M.current.style("visibility","hidden");const t=e.transform;u.select(y()).select("svg").select("g").attr("transform",t),vt(t),Lt(t),xt(t)}function wt(e){const t=e.transform;E.current={k:t.k,x:t.x,y:t.y},w&&window.parent.postMessage({type:"map",value:JSON.stringify(E.current)},"*")}function At(){const e=u.select(y()).select("svg");e.select("g").selectAll(".active").attr("class",function(){return u.select(this).attr("class").replace(/background/gi,"")});let a=u.zoomIdentity;v&&!w?a=a.translate(v.x,v.y).scale(v.k):a=a.translate(0,0).scale(1),e.transition().duration(300).call(j.current.transform,a)}function He(){E.current=null,M.current.style("visibility","hidden"),At()}function Tt(){u.select(y()).select("svg").transition().call(j.current.scaleBy,1.5)}function Mt(){u.select(y()).select("svg").transition().call(j.current.scaleBy,.6667)}function K(){if(Ne){const e=Y();return f.generateBreaks(e,{autoGenerateBreaks:Ne,numberOfBreaks:Ye,colorScheme:Ke})}else{let e=Ae;return S()&&(e=Ae.filter(t=>t.measure===S()).filter(t=>{if(t.filters&&t.filters.length>0&&m&&JSON.stringify(m)!=="{}"){const n=Object.keys(m);return t.filters.filter(l=>{if(n.indexOf(l.field)!=-1){const r=m[l.field],s=l.values;return r.join(",").indexOf(s)!=-1}return!1}).length>0}return!0})),e}}function ve(e,t){return f.fillColor(e,t,{mapNoDataColor:Ee,mainLayerId:_,enabledLayers:D,selectedMeasure:W})}function jt(e){return f.createLabel(e,{mapLabelField:A,mapLabelShowValue:se,intl:T,valueFormat:je,showNoDataLabel:Ce,showAdminUnitLabel:ae,noDataText:ft,selectedMeasure:S()},Z,k.formatContent)}function Ue(e,t){const a=[...e.filter(n=>z!=n.properties[A]),...e.filter(n=>z==n.properties[A])];Ct(a),Nt(a),kt(a,t),ke.length>0&&It(ke,a)}function Nt(e){const t=u.select(y()).select("svg").select("g");if(t.selectAll(".map-labels-container").size()>0){console.log("Labels already exist, skipping redraw...");return}t.selectAll(".map-labels").data(e.filter(n=>oe&&oe.length>0?!oe.includes(n.properties[A]):!0)).enter().append("foreignObject").attr("class","map-labels-container").attr("x",n=>{const i=be(n);if(n.properties[A]){const l=H(n);return i[0]-l/2}return i[0]}).attr("y",n=>be(n)[1]-10).attr("width",n=>H(n)).attr("height",n=>re()).attr("font-size",()=>`${te}px`).attr("overflow","visible").attr("opacity",1).style("display",n=>ae===f.SHOW_ALL||ae===f.SHOW_IF_HAS_DATA&&n.properties.hasDataRow||n.properties.displayLayerLabels?"block":"none").attr("pointer-events",G=="POINTS_MAP"?"none":"all").on("mouseover",$).on("mousemove",Q).on("mouseout",J).append("xhtml:div").style("font-size",()=>`${te}px`).style("color",()=>Ie).style("font-weight",()=>et).style("background-color",n=>n.properties.hasDataRow&&se&&(n.properties.value!=null||n.properties.value==null&&Ce)?"#fff6e1":"none").style("border-radius",()=>"4px").style("line-height","95%").style("text-align","center").html(n=>jt(n))}function Ct(e){const t=K(),a=u.select(y()).select("svg").select("g"),n=e.filter(i=>i.geometry&&i.geometry&&(i.geometry.type=="Polygon"||i.geometry.type=="MultiPolygon"));n.length>0&&a.selectAll("path").data(n).join("path").attr("d",V.current).attr("fill",i=>ve(i,t)).attr("stroke-width",i=>z==i.properties[A]?1.2:.4).attr("stroke",i=>z==i.properties[A]?st:nt).on("click",St)}function kt(e,t){const a=u.select(y()).select("svg").select("g");let n=[];if(p.pointsData){let r=q;t&&m&&m[P]&&(r=m[P]),n=p.pointsData.filter(s=>s.lat&&s.lng&&s.label==r).map(s=>({properties:{label:s.label,lat:s.lat,lng:s.lng,value:s.value,variables:s.variables}})),a.selectAll(".circle").data(n).enter().append("circle").attr("id",(s,o)=>"circle"+o).attr("cx",s=>F.current([s.properties.lng,s.properties.lat])[0]).attr("cy",s=>F.current([s.properties.lng,s.properties.lat])[1]).attr("r",()=>2).style("stroke-width",.5).style("fill",()=>Oe).on("mouseover",(s,o)=>Et(s,o)).on("mouseout",J)}const i=K();let l=[];ze==f.SHOW_ALL?l=e.filter(r=>r.geometry&&r.geometry.type=="Point"):ze==f.SHOW_IF_HAS_DATA&&(l=e.filter(r=>r.geometry&&r.geometry.type=="Point"&&r.properties.hasDataRow)),l.length>0&&a.selectAll(".point-labels").data(l).enter().append("foreignObject").attr("id",(r,s)=>"point-label"+s).attr("class","point-labels-container").attr("x",r=>{const s=H(r)+20;return F.current([r.geometry.coordinates[1],r.geometry.coordinates[0]])[0]-s/2}).attr("y",r=>F.current([r.geometry.coordinates[1],r.geometry.coordinates[0]])[1]-re()/2).attr("width",r=>H(r)+20).attr("height",()=>"1px").attr("overflow","visible").attr("font-size","12px").style("opacity",1).append("xhtml:div").style("color",()=>ct).style("font-weight",()=>"bold").style("background-color",r=>ve(r,i)).style("padding",()=>"5px 3px 5px 3px").style("border-radius",()=>"4px").style("line-height","100%").style("text-align","center").html(r=>k.formatContent(ut,{value:r.properties.value,locationName:r.properties[A]},T)).on("mouseover",(r,s,o)=>{u.select(y()).select("svg").select("g").select("#point-label"+o).raise(),$(r,s)}).on("mousemove",Q).on("mouseout",J)}function It(e,t){const a=u.select(y()).select("svg").select("g");e.forEach(n=>{if(n.field&&n.image&&n.values){const i=t.filter(r=>{const s=f.LOCATION==n.field?x:"value",o=(r.properties[s]||(r.properties.variables?r.properties.variables[s]:""))+"",g=(n.values+"").split(",");return r.properties.LATITUDE&&r.properties.LONGITUDE&&g.filter(C=>C.trim().toLowerCase()==o.trim().toLowerCase()).length>0}),l=t.filter(r=>{const s=f.LOCATION==n.field?x:"value",o=(r.properties[s]||(r.properties.variables?r.properties.variables[s]:""))+"",g=(n.values+"").split(",");return!r.properties.LATITUDE&&!r.properties.LONGITUDE&&g.filter(C=>C.trim().toLowerCase()==o.trim().toLowerCase()).length>0});a.selectAll("image").data(i).enter().append("image").attr("width",40).attr("height",40).attr("class","map-symbol").attr("xlink:href","/"+n.image).attr("transform",r=>"translate("+F.current([r.properties.LONGITUDE,r.properties.LATITUDE])+")").on("mouseover",$).on("mousemove",Q).on("mouseout",J),a.selectAll("image").data(l).enter().append("image").attr("width",40).attr("height",40).attr("class","map-symbol").attr("xlink:href","/"+n.image).attr("x",r=>V.current.centroid(r)[0]-20).attr("y",r=>V.current.centroid(r)[1]).on("mouseover",$).on("mousemove",Q).on("mouseout",J)}})}function $(e,t){console.log("Showing tooltip for data:",t);const a=["mobile","tablet","midTablet"].includes(I.default());if(ce&&t.properties.value!==null||ce&&at){u.select(y()).select("svg").select("g").selectAll(".active").attr("class",o=>o.properties[x]===t.properties[x]?"focus"+(a?" zoom-enabled":""):"active"+(a?" zoom-enabled":""));const l=Se||`{locationName} %({value},2)
|
|
2
|
+
{label}: %({value},2)`,r=t.properties.variables||{},s={...t.properties,value:t.properties.value,measure:S(),measureLabel:t.properties.measureLabel,locationName:f.getTranslatedLocationName(t,x,Z),label:f.getTranslatedLocationName(t,x,Z),...r,...f.getFilters(m)};M.current.attr("class",Qe).style("position","absolute").style("visibility","hidden").style("visibility","visible").html(()=>{let o=`<div style='font-size:${lt}px;' class='tooltip-content' >`;if(t.properties.value!=null){const d=l.split(`
|
|
3
|
+
`),g=d[0],C=d.length>1?d[1]:null;let R=1,le;ot.length>1&&G!="POINTS_MAP"?(R=d.length>2?2:1,le=d[R]):le=null,g&&(o+=k.formatContent(g,s,T)),C&&(o.endsWith("<hr>")||(o+="<hr>"),o+=k.formatContent(C,s,T)),le&&t.properties.children&&t.properties.children.forEach(O=>{const xe={value:O.value,label:O.label,measure:S(),measureLabel:t.properties.measureLabel,...r,...O.variables,...f.getFilters(m)};o.endsWith("<hr>")||(o+="<hr>"),o+=k.formatContent(le,xe,T)}),d.length>R+1&&(o.endsWith("<hr>")||(o+="<hr>"),d.forEach((O,xe)=>{xe>R&&(o.endsWith("<hr>")||(o+="<hr>"),o+=k.formatContent(O,s,T))})),rt.filter(O=>O.location===t.properties[x]).forEach(O=>{o.endsWith("<hr>")||(o+="<hr>"),o+=O.tooltip})}else{const d=Se||`{locationName} %({value},2)
|
|
4
|
+
{label}: %({value},2)`,g={value:null,measure:S(),measureLabel:t.properties.measureLabel,locationName:f.getTranslatedLocationName(t,x,Z),...r};o+=k.formatContent(d,g,T),o+="</div>"}return o})}}function Ge(e){const a=M.current.node(),n=a?a.offsetWidth:0,i=window.scrollX+document.documentElement.clientWidth;let l=e.pageX;n&&l+n>i&&(l=e.pageX-n,l<window.scrollX&&(l=window.scrollX)),M.current.style("top",e.pageY+"px").style("left",l+"px").style("margin-left","8px")}function Q(e){Ge(e)}function J(){ce&&(u.select(y()).select("svg").select("g").selectAll(".focus").attr("class","active"),M.current.style("visibility","hidden"))}function Et(e,t,a){$(e,t),M.current.style("visibility","visible"),Ge(e);const n=u.select(y()).select("svg").select("g");n.selectAll("circle").style("fill",Oe).style("stroke","none"),n.select("#circle"+a).raise().style("fill","#fff")}function St(e,t){q!==t.properties[x]&&t.properties.value!==null&&yt(t.properties[x])}function Ot(e){const t=e&&e.appliedFilters||{},a=m||{};return t[P]!=a[P]}function zt(e,t){let a=null;if(dt&&P){let n=q;t&&m&&m[P]&&(n=m[P]);const i=e.filter(l=>l.properties!=null&&l.properties[x]==n)[0];i&&i.properties!=null&&i.properties.value&&(a=i)}return a}function Dt(){return f.classColor(ie)}function Pt(e,t){let a=ie;a||(a=["mobile","tablet"].includes(I.default()));const n=K(),i=u.select(y());let l=i.select("svg"),r=he();r===0?r=window.innerWidth+f.deviceMapWidth[I.default()]:r+=f.deviceMapWidth[I.default()];const s=ye()-100;if(l.empty()?l=i.append("svg"):l.selectAll("*").remove(),l.attr("style",`background-color:${it};`).attr("viewBox",`0 0 ${r} ${s}`).attr("preserveAspectRatio","xMidYMid meet"),l.append("g").selectAll("path").data(e).enter().append("path").attr("fill",d=>ve(d,n)).attr("d",u.geoPath().projection(F.current)).attr("class",()=>Dt()).on("mouseover",G!=="POINTS_MAP"?$:null).on("mousemove",G!=="POINTS_MAP"?Q:null).on("mouseout",G!=="POINTS_MAP"?J:null),E.current&&l.transition().duration(300).call(j.current.transform,u.zoomIdentity.translate(E.current.x,E.current.y).scale(E.current.k)),!E.current&&v&&v.x&&v.y&&v.k&&(l.transition().duration(300).call(j.current.transform,u.zoomIdentity.translate(v.x,v.y).scale(v.k)),G==="POINTS_MAP")){const g={mobile:100,tablet:0,midTablet:0,desktop:0,laptop:0,wide:0}[I.default()];l.transition().duration(300).call(j.current.transform,u.zoomIdentity.translate(v.x+g,v.y).scale(v.k))}a||w?l.call(j.current):l.on("dblclick.zoom",null);const o=zt(e,t);if(o){const d=V.current.bounds(o),g=[(d[0][0]+d[1][0])/2,(d[0][1]+d[1][1])/2];l.transition().duration(750).call(j.current.transform,u.zoomIdentity.translate(r/2,s/2).scale(12).translate(-g[0],-g[1]))}}function Rt(){return p.nationalData.value}function _t(e){W!=e&&ht(e)}function Wt(){let e=p.locationsData;return p.measures&&p.measures.length>1&&(e=p.locationsData.filter(t=>t.measure===S())),e.find(t=>t.label===z)}function Bt(){if(!z)return null;const t=Y().find(a=>a.properties[A]===z);if(t&&t.properties.displayLayerLabels&&t.properties.layerLocale){const a=t.properties.layerMappingField||A,n=t.properties[a];return f.getTranslatedItemLabel(Z,n,t.properties.layerLocale)}return z}function Ht(e){return f.getHighlightedLocationColor(e,K(),Ee)}function Ut(){return c.jsx(b.Container,{className:"loading",children:c.jsx(b.Segment,{basic:!0,padded:!0,textAlign:"center",style:{margin:"30px"},children:c.jsx(b.Dimmer,{active:!0,inverted:!0,children:c.jsx(b.Loader,{size:"medium"})})})})}function Gt(){return c.jsxs(b.Message,{icon:!0,warning:!0,children:[c.jsx(b.Icon,{name:"map outline"}),c.jsxs(b.Message.Content,{children:[c.jsx(b.Message.Header,{children:"No map selected"}),"Pick one from the list in the ",c.jsx("strong",{children:"Map Layers"})," section."]})]})}N.current.zoomed=Ft,N.current.zoomEnd=wt,N.current.getFeatures=Y,N.current.updateFeatures=Ue,N.current.getMapId=y,ge.current||(ge.current=()=>{let e=null;clearTimeout(e),e=setTimeout(()=>{u.select(N.current.getMapId()).selectAll(".map-labels-container").size()>0||N.current.updateFeatures(N.current.getFeatures(),!1)},300)}),h.useEffect(()=>{const e=ge.current;return window.addEventListener("scroll",e,{passive:!0}),window.addEventListener("touchmove",e,{passive:!0}),Be(),M.current=u.select("body").append("div").style("position","absolute").style("visibility","hidden").style("pointer-events","none"),()=>{var t;window.removeEventListener("scroll",e),window.removeEventListener("touchmove",e),(t=M.current)==null||t.remove()}},[]),h.useEffect(()=>{if(!Re.current){Re.current=!0,fe.current=L,me.current={selectedMeasure:W,layers:B,selectedPolygon:q};return}const e=fe.current,t=me.current;if(P){const i=[],l=[],r=e.appliedFilters;r&&Object.keys(r).forEach(s=>{r[s]!=null&&r[s]instanceof Array&&i.push(...r[s].filter(o=>o!=Number.MIN_SAFE_INTEGER))}),m&&Object.keys(m).forEach(s=>{m[s]!=null&&m[s]instanceof Array&&l.push(...m[s].filter(o=>o!=Number.MIN_SAFE_INTEGER))}),i.length>0&&l.length==0&&He()}M.current.style("visibility","hidden"),e.enabledLayers.length!=D.length&&Be();const a=Y();e.center!==ne&&(E.current=null,F.current.scale(Fe).center(ne).translate([he()/2,ye()/2]));const n=Ot(e);Pt(a,n),B&&p&&(p!=e.transformedData||B!=t.layers||W!=t.selectedMeasure||q!=t.selectedPolygon||e.mainLayerId!==_||JSON.stringify(e.enabledLayers)!=JSON.stringify(D))&&Ue(Y(),n),fe.current=L,me.current={selectedMeasure:W,layers:B,selectedPolygon:q}});let Le=ie;Le||(Le=!!["mobile","tablet","midTablet"].includes(I.default()));const qt=Rt(),Vt=f.getFilters(m),ee=Wt(),qe={backgroundColor:Ht(ee),color:Ie,fontSize:tt+"px"};w&&(qe.marginTop="25px");const Ve=()=>c.jsxs(b.Container,{fluid:!0,className:"footnote ",children:[c.jsxs(b.Grid,{columns:2,children:[L.app!=="csv"&&Te&&c.jsx(b.Grid.Column,{textAlign:"left",width:4,children:c.jsxs("div",{className:"national-average-div",children:[c.jsx("span",{className:"national-avg-label",children:gt}),c.jsx("span",{className:"national-avg-value",children:k.formatContent(je,{value:qt},T)})]})}),c.jsx(b.Grid.Column,{textAlign:"right",width:L.app!=="csv"&&Te?12:16,children:c.jsx(Jt.default,{filteredBreaks:K(),formattedLegendTitle:k.formatContent(mt,{...Vt},T),selectedMeasure:W,...L})})]}),c.jsx("div",{className:"measure-selector",children:c.jsxs("ul",{children:[Me&&c.jsx("li",{children:c.jsx("span",{className:"label",children:Me})}),p&&p.measures&&p.measures.length>1&&p.measures.map(e=>c.jsxs("li",{onClick:()=>_t(e),children:[c.jsx("input",{checked:S()===e,type:"radio",value:e,readOnly:!0}),c.jsx("label",{children:p.measureLabelMap[e]||e})]},e))]})})]});return c.jsxs("div",{className:"map component wp-data-viz-map",ref:de,children:[De&&(w?Gt():Ut()),!De&&c.jsxs(c.Fragment,{children:[!$e&&c.jsx(Ve,{}),c.jsxs("div",{className:"map wrapper scaling-svg-container "+U,style:{height:we-f.deviceMapHeight[I.default()]+"px"},children:[ee?c.jsx("div",{className:"highlighted-loc-info",style:qe,children:c.jsxs("span",{children:[" ",k.formatContent(pt,{value:ee.value,locationName:Bt()||ee.label,measureName:ee.measure},T)]})}):c.jsx(c.Fragment,{children:" "}),(w||Le)&&!Yt&&c.jsxs("div",{className:"control panel ignore",children:[c.jsx("div",{className:"zoom plus",onClick:Tt,children:c.jsx(b.Icon,{name:"plus",size:"large"})}),c.jsx("div",{className:"zoom minus",onClick:Mt,children:c.jsx(b.Icon,{name:"minus",size:"large"})}),c.jsx(b.Popup,{content:c.jsx(Je.FormattedMessage,{id:"map.reset.tooltip",defaultMessage:"Reset zoom"}),trigger:c.jsx("div",{className:"reset",onClick:He,children:c.jsx(b.Icon,{name:"repeat",size:"large"})})})]})]}),$e&&c.jsx(Ve,{})]})]})}const Qt=Je.injectIntl(Kt);exports.getTranslatedItemLabel=f.getTranslatedItemLabel;exports.default=Qt;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("topojson-client"),j=require("geostats"),C=require("../../utils/deviceType.js");function T(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(t,l,o.get?o:{enumerable:!0,get:()=>e[l]})}}return t.default=e,Object.freeze(t)}const M=T(_),v="_Color_",k="location",L="showAll",m="ifUnitHasData",O=10,w={mobile:4,tablet:4,midTablet:2,laptop:2,desktop:2,wide:2},F={mobile:330,tablet:250,midTablet:250,laptop:200,desktop:100,wide:100},B={mobile:250,tablet:250,midTablet:250,laptop:0,desktop:0,wide:0},H={greens:["#ccffdd","#b3ffcc","#99ffbb","#80ffaa","#66ff99","#4dff88","#33ff77","#1aff66","#00ff55","#00e64d"],greys:["#f2f2f2","#e6e6e6","#d9d9d9","#cccccc","#bfbfbf","#b3b3b3","#a6a6a6","#999999","#8c8c8c","#808080"],oranges:["#fff0e6","#ffe0cc","#ffd1b3","#ffc299","#ffb380","#ffa366","#ff944d","#ff8533","#ff751a","#ff6600"],purples:["#ffe6ff","#ffccff","#ffb3ff","#ff99ff","#ff80ff","#ff66ff","#ff4dff","#ff33ff","#ff1aff","#ff00ff"],reds:["#ffe6e6","#ffcccc","#ffb3b3","#ff9999","#ff8080","#ff6666","#ff4d4d","#ff3333","#ff1a1a","#ff0000"],blues:["#e6eeff","#ccddff","#b3ccff","#99bbff","#80aaff","#6699ff","#4d88ff","#3377ff","#1a66ff","#0055ff"]};function d(e,t,l){var r;if(!(e!=null&&e.length))return t;const o=((r=e[0])==null?void 0:r.items)??[],n=i=>(i==null?void 0:i.trim().toLowerCase())??"",s=n(t),c=n(l).toUpperCase(),f=o.find(i=>n(i.value)===s||n(i.code)===s)??null;if(!f)return t;const a=c&&f.labels&&f.labels[c]?f.labels[c]:f.value;return(a==null?void 0:a.trim())||f.value.trim()}function I(e){let t=e;return t||(t=["mobile","tablet","midTablet"].includes(C.default())),t?"active zoom-enabled":"active"}function S(e,t){const{autoGenerateBreaks:l,numberOfBreaks:o,colorScheme:n}=t,s=[];if(l&&e&&e.length>0){const c=e.filter(r=>r.properties&&r.properties.value!=null).map(r=>r.properties.value.toFixed(2)),f=[];c.forEach(r=>{if(r>0){const i=r*.99,u=r*1.01;f.indexOf(i)===-1&&f.push(i),f.indexOf(u)===-1&&f.push(u)}});const a=H[n];if(f.length>0){const r=new j(f);r.setPrecision(2);const i=f.length>1?f.length-1:f.length;return r.getJenks(Math.min(o,i)),r.ranges.forEach((u,p)=>{const b={};b.min=parseFloat(u.substr(0,u.indexOf("-")-1))+(p>0?.01:0),b.max=parseFloat(u.substr(u.indexOf("-")+2,u.length)),b.color=a[p],s.push(b)}),s}}return s}function D(e,t,l){const{mapNoDataColor:o,mainLayerId:n,enabledLayers:s,selectedMeasure:c}=l;if(e.properties&&e.properties.variables&&c&&e.properties.value!=null){const a=v+c,r=e.properties.variables[a.trim()];if(r)return r}if(e.properties.value!=null&&(n&&e.properties.layerId===n||!n)){const a=t.find(r=>r.min!=null&&r.max!=null?e.properties.value>=r.min&&e.properties.value<=r.max:r.min!=null?e.properties.value>=r.min:r.max!=null?e.properties.value<=r.max:!1);return a&&a.color?a.color:o}const f=s.filter(a=>a.id===e.properties.layerId)[0];return f&&f.bgColor&&f.bgColor!="undefined"?f.bgColor:o}function E(e,t){if(e.properties[t]){const o=e.properties[t].length;return o<10?80:o*8}return 0}function W(e){return e?30:25}function x(e,t){if(e&&e.objects){const l=Object.keys(e.objects);for(const o in l){const n=l[o];if(e.objects[n].type=="GeometryCollection")return n}}return t}function R(e,t){const l=x(e,t);return e&&e.objects&&e.objects[l]?M.feature(e,e.objects[l]).features:e&&e.features?e.features:[]}function N(e,t,l){if(e.properties.displayLayerLabels&&e.properties.layerLocale){const o=e.properties.layerMappingField||t,n=e.properties[o];return d(l,n,e.properties.layerLocale)}return e.properties[t]}function P(e,t,l,o){const{mapLabelField:n,mapLabelShowValue:s,intl:c,valueFormat:f,showNoDataLabel:a,showAdminUnitLabel:r,noDataText:i,selectedMeasure:u}=t;let p="";if(r==L||r==m&&e.properties.hasDataRow||e.properties.displayLayerLabels){const b=e.properties.displayLayerLabels&&e.properties.layerMappingField?e.properties.layerMappingField:n,g=e.properties[b],A=e.properties.layerLocale||(c==null?void 0:c.locale);p=d(l,g,A);const h=e.properties.abbrev;if(p&&p.length>O&&h&&(p=h),s)if(e.properties.value!=null){const y=e.properties.variables||{};p+="<br><span class='map-label-value'>"+o(f,{value:e.properties.value,measure:u,...y},c)+"</span>"}else a==!0&&e.properties.value==null&&e.properties.hasDataRow&&(p+="<br><span class='map-label-value'>"+i+"</span>")}return p}function q(e){const t={};return e&&Object.keys(e).forEach(l=>{const o=e[l];o&&(t[l]=Array.isArray(o)?o.join(" ,"):o)}),t}function z(e,t,l){const o=e?e.value:null;if(o!=null){const n=t.find(s=>s.min!=null&&s.max!=null?o>=s.min&&o<=s.max:s.min!=null?o>=s.min:s.max!=null?o<=s.max:!1);return n&&n.color?n.color:l}return l}exports.COLOR_VARIABLE=v;exports.LOCATION=k;exports.MAX_LABEL_LEN=O;exports.SHOW_ALL=L;exports.SHOW_IF_HAS_DATA=m;exports.classColor=I;exports.createLabel=P;exports.deviceMapHeight=F;exports.deviceMapWidth=B;exports.deviceTranslateMap=w;exports.extractFeatures=R;exports.fillColor=D;exports.generateBreaks=S;exports.getCollectionField=x;exports.getFilters=q;exports.getHighlightedLocationColor=z;exports.getLabelBoxHeight=W;exports.getLabelBoxWidth=E;exports.getTranslatedItemLabel=d;exports.getTranslatedLocationName=N;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import
|
|
4
|
-
const f = /(\%)[\(]([A-z0-9,.]+)\)/gi,
|
|
3
|
+
import g from "string-template";
|
|
4
|
+
const f = /(\%)[\(]([A-z0-9,.]+)\)/gi, b = /(\#)[\(]([A-z0-9,.]+)\)/gi, h = /(\#C)[\(]([A-z0-9,.]+)\)/gi, x = /(\$)[\(]([A-z0-9,.]+)\)/gi, A = [
|
|
5
5
|
{
|
|
6
6
|
name: "USD Dollar",
|
|
7
7
|
code: "USD",
|
|
@@ -32,28 +32,32 @@ const f = /(\%)[\(]([A-z0-9,.]+)\)/gi, g = /(\#)[\(]([A-z0-9,.]+)\)/gi, h = /(\#
|
|
|
32
32
|
code: "KES",
|
|
33
33
|
symbol: "KSh"
|
|
34
34
|
}
|
|
35
|
-
],
|
|
36
|
-
let
|
|
37
|
-
for (; (
|
|
38
|
-
const
|
|
39
|
-
maximumFractionDigits:
|
|
40
|
-
...
|
|
41
|
-
}),
|
|
42
|
-
|
|
35
|
+
], m = (t, n, r, c, l) => {
|
|
36
|
+
let e, o = n;
|
|
37
|
+
for (; (e = t.exec(n)) !== null; ) {
|
|
38
|
+
const a = e[2], p = (u, y = 2) => l.formatNumber(c ? u / 100 : u, {
|
|
39
|
+
maximumFractionDigits: y,
|
|
40
|
+
...r
|
|
41
|
+
}), i = a.split(","), d = i.length > 0 && i[0] ? p.apply(void 0, i) : "No Data";
|
|
42
|
+
o = o.replaceAll(e[0], d);
|
|
43
43
|
}
|
|
44
|
-
return
|
|
45
|
-
},
|
|
46
|
-
let
|
|
47
|
-
for (; (
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
|
|
44
|
+
return o;
|
|
45
|
+
}, E = (t, n) => {
|
|
46
|
+
let r, c = n;
|
|
47
|
+
for (; (r = t.exec(n)) !== null; )
|
|
48
|
+
if (r.length > 2) {
|
|
49
|
+
const l = r[0], e = r[2], o = A.find((a) => s(a.code) == s(e) || s(a.name) == s(e) || s(a.symbol) == s(e));
|
|
50
|
+
o && (c = c.replaceAll(l, o.symbol));
|
|
51
51
|
}
|
|
52
|
-
return
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
return c;
|
|
53
|
+
}, s = (t) => t && t.trim().toLowerCase(), N = (t, n, r) => {
|
|
54
|
+
const c = {};
|
|
55
|
+
Object.keys(n).forEach((o) => {
|
|
56
|
+
c[o] = n[o], c[o.replace(/\s+/g, "_")] = n[o];
|
|
57
|
+
});
|
|
58
|
+
let l = t.replace(/\{([^}]+)\}/g, (o, a) => `{${a.replace(/\s+/g, "_")}}`), e = g(l, c).replace(/(?:\r\n|\r|\n)/g, "<br>");
|
|
59
|
+
return e = m(f, e, { style: "percent" }, !0, r), e = m(b, e, { style: "decimal" }, !1, r), e = m(h, e, { notation: "compact" }, !1, r), e = E(x, e), e;
|
|
56
60
|
};
|
|
57
61
|
export {
|
|
58
|
-
|
|
62
|
+
N as formatContent
|
|
59
63
|
};
|
|
@@ -1,31 +1,165 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
const { data:
|
|
1
|
+
import T from "react";
|
|
2
|
+
const U = (x) => {
|
|
3
|
+
const { data: o, measures: M, customMeasureLabels: g, children: O, source: _, extraDimension: d, allDimensions: D } = x;
|
|
4
|
+
console.log("MapDataFrame props:", x);
|
|
5
|
+
const E = (_ || "").split("/").filter(Boolean), p = E.length > 0 ? E[0] : null, f = {
|
|
4
6
|
locationsData: [],
|
|
5
7
|
nationalData: {},
|
|
6
8
|
measureLabelMap: {}
|
|
7
9
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
o.metadata && o.metadata.measures && Array.isArray(o.metadata.measures), o.children && o.children[0] && o.children[0].children;
|
|
11
|
+
const h = o.metadata || {}, I = ["value", "count", "type", "children", "label", "measure"], F = D && D.length > 0 ? D : h.types || [], y = {};
|
|
12
|
+
F.forEach((e) => {
|
|
13
|
+
const n = e.category || e.type;
|
|
14
|
+
n && (y[n] = e.items || []);
|
|
10
15
|
});
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
const L = (e, n) => {
|
|
17
|
+
const a = y[e];
|
|
18
|
+
if (!a)
|
|
19
|
+
return null;
|
|
20
|
+
const r = n != null ? String(n) : n;
|
|
21
|
+
return a.find((t) => {
|
|
22
|
+
const l = t.value != null ? String(t.value) : t.value, i = t.id != null ? String(t.id) : t.id, s = t.code != null ? String(t.code) : t.code;
|
|
23
|
+
return l === r || i === r || s === r;
|
|
24
|
+
}) || null;
|
|
25
|
+
}, u = (e, n) => {
|
|
26
|
+
const a = L(e, n);
|
|
27
|
+
return a ? a.value ?? a.label ?? a.id ?? a.code ?? n : n;
|
|
28
|
+
}, K = (e = {}) => {
|
|
29
|
+
const n = {};
|
|
30
|
+
return Object.keys(e).forEach((a) => {
|
|
31
|
+
const r = e[a];
|
|
32
|
+
r != null && (Array.isArray(r) ? n[a] = r.map((t) => u(a, t)).join(" ,") : n[a] = u(a, r));
|
|
33
|
+
}), n;
|
|
34
|
+
}, N = (e) => {
|
|
35
|
+
const n = y[e] || [];
|
|
36
|
+
return n.length === 1 ? u(e, n[0].value ?? n[0].id ?? n[0].code) : null;
|
|
37
|
+
}, c = (e) => e != null && e !== "", S = (e) => {
|
|
38
|
+
if (e)
|
|
39
|
+
return c(e.value) ? e.value : c(e.id) ? e.id : e.code;
|
|
40
|
+
}, b = (e) => e == null ? "" : String(e).trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, ""), v = (e, n) => {
|
|
41
|
+
if (!e)
|
|
42
|
+
return;
|
|
43
|
+
const a = b(n), r = e[n];
|
|
44
|
+
if (r != null && r !== "")
|
|
45
|
+
return r;
|
|
46
|
+
const t = Object.keys(e);
|
|
47
|
+
for (let l = 0; l < t.length; l++) {
|
|
48
|
+
const i = t[l];
|
|
49
|
+
if (b(i) === a) {
|
|
50
|
+
const s = e[i];
|
|
51
|
+
if (s != null && s !== "")
|
|
52
|
+
return s;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, P = (e, n) => {
|
|
56
|
+
const a = [
|
|
57
|
+
p,
|
|
58
|
+
"country",
|
|
59
|
+
e.type
|
|
60
|
+
].filter(Boolean), r = [
|
|
61
|
+
v(n, "country"),
|
|
62
|
+
v(e, "country"),
|
|
63
|
+
p ? v(n, p) : void 0,
|
|
64
|
+
p ? v(e, p) : void 0,
|
|
65
|
+
e.label,
|
|
66
|
+
e.value
|
|
67
|
+
].filter((t) => c(t));
|
|
68
|
+
for (let t = 0; t < a.length; t++) {
|
|
69
|
+
const l = a[t], i = y[l] || [];
|
|
70
|
+
if (i.length)
|
|
71
|
+
for (let s = 0; s < r.length; s++) {
|
|
72
|
+
const z = r[s], G = b(z), B = i.findIndex((H) => {
|
|
73
|
+
const J = S(H);
|
|
74
|
+
return b(J) === G;
|
|
75
|
+
});
|
|
76
|
+
if (B >= 0)
|
|
77
|
+
return B;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return -1;
|
|
81
|
+
}, j = (e, n, a) => {
|
|
82
|
+
const r = P(n, a);
|
|
83
|
+
if (r < 0)
|
|
84
|
+
return;
|
|
85
|
+
const t = y[e] || [];
|
|
86
|
+
if (!t.length || r >= t.length)
|
|
87
|
+
return;
|
|
88
|
+
const l = S(t[r]);
|
|
89
|
+
if (c(l))
|
|
90
|
+
return u(e, l);
|
|
91
|
+
}, $ = (e, n, a) => {
|
|
92
|
+
const r = v(a, e);
|
|
93
|
+
if (c(r))
|
|
94
|
+
return r;
|
|
95
|
+
if (c(A[e]))
|
|
96
|
+
return A[e];
|
|
97
|
+
const t = v(n, e);
|
|
98
|
+
if (c(t))
|
|
99
|
+
return t;
|
|
100
|
+
const l = j(e, n, a);
|
|
101
|
+
if (c(l))
|
|
102
|
+
return l;
|
|
103
|
+
const i = N(e);
|
|
104
|
+
if (c(i))
|
|
105
|
+
return i;
|
|
106
|
+
const s = n.value;
|
|
107
|
+
return L(e, s) ? u(e, s) : "";
|
|
108
|
+
}, V = o.appliedFilters || {};
|
|
109
|
+
let R = null;
|
|
110
|
+
if (d) {
|
|
111
|
+
const e = V[d] ? V[d][0] : void 0;
|
|
112
|
+
R = u(d, e);
|
|
113
|
+
}
|
|
114
|
+
const A = K(V), q = (e) => {
|
|
115
|
+
const n = {};
|
|
116
|
+
return Object.keys(e).forEach((a) => {
|
|
117
|
+
I.includes(a) || (n[a] = e[a]);
|
|
118
|
+
}), e.type && e.value !== void 0 && (n[e.type] = u(e.type, e.value)), n;
|
|
119
|
+
}, C = (e) => {
|
|
120
|
+
let n = q(e);
|
|
121
|
+
return e.children && Array.isArray(e.children) && e.children.forEach((a) => {
|
|
122
|
+
n = { ...n, ...C(a) };
|
|
123
|
+
}), n;
|
|
124
|
+
}, w = (e, n) => {
|
|
125
|
+
if (!(!e.children || !Array.isArray(e.children)))
|
|
126
|
+
return e.children.map((a) => ({
|
|
15
127
|
...a,
|
|
16
128
|
label: a.value,
|
|
17
|
-
value: a[
|
|
18
|
-
|
|
129
|
+
value: a[n],
|
|
130
|
+
variables: C(a),
|
|
131
|
+
children: w(a, n)
|
|
132
|
+
}));
|
|
133
|
+
};
|
|
134
|
+
h.measures && h.measures.forEach((e) => {
|
|
135
|
+
g && g[e.value] && g[e.value].hasCustomLabel && g[e.value].customLabel ? f.measureLabelMap[e.value] = g[e.value].customLabel : f.measureLabelMap[e.value] = e.label;
|
|
136
|
+
});
|
|
137
|
+
const m = M.split(",");
|
|
138
|
+
return o && o.children && (o.children.forEach((e) => {
|
|
139
|
+
m.forEach((n) => {
|
|
140
|
+
const a = {
|
|
141
|
+
...C(e),
|
|
142
|
+
// Dynamic fields for both formats, including nested dimensions
|
|
143
|
+
...A
|
|
144
|
+
};
|
|
145
|
+
F.forEach((t) => {
|
|
146
|
+
const l = t.category || t.type;
|
|
147
|
+
l && (a[l] = $(l, e, a));
|
|
148
|
+
});
|
|
149
|
+
const r = {
|
|
150
|
+
...e,
|
|
151
|
+
label: e.value,
|
|
152
|
+
value: e[n],
|
|
153
|
+
measure: n,
|
|
154
|
+
variables: a
|
|
19
155
|
};
|
|
20
|
-
|
|
21
|
-
u.children.push({ ...n, label: n.value, value: n[r] });
|
|
22
|
-
})), l.locationsData.push(u);
|
|
156
|
+
r.variables.selectedDataFrameTooltipValue = e[n], d && (r.variables[d] = R), r.children = w(e, n), f.locationsData.push(r);
|
|
23
157
|
});
|
|
24
|
-
}),
|
|
25
|
-
...
|
|
26
|
-
types:
|
|
158
|
+
}), f.measures = m.length > 1 ? m : null, f.nationalData.value = o[M] || o[m[0]]), T.Children.map(O, (e) => T.cloneElement(e, { transformedData: {
|
|
159
|
+
...f,
|
|
160
|
+
types: h.types ? h.types : []
|
|
27
161
|
} }));
|
|
28
162
|
};
|
|
29
163
|
export {
|
|
30
|
-
|
|
164
|
+
U as default
|
|
31
165
|
};
|