react-jsx-highmaps
Version:
Highmaps built using React components
2 lines • 16 kB
JavaScript
/*! For license information please see react-jsx-highmaps.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactHighcharts=t(require("react")):e.ReactHighcharts=t(e.React)}("undefined"!=typeof self?self:this,(e=>(()=>{"use strict";var t={197:(e,t)=>{var n=Symbol.for("react.transitional.element");Symbol.for("react.fragment"),t.jsx=function(e,t,r){var i=null;if(void 0!==r&&(i=""+r),void 0!==t.key&&(i=""+t.key),"key"in t)for(var o in r={},t)"key"!==o&&(r[o]=t[o]);else r=t;return t=r.ref,{$$typeof:n,type:e,key:i,ref:void 0!==t?t:null,props:r}}},85:(e,t,n)=>{e.exports=n(197)},12:t=>{t.exports=e}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var o=n[e]={exports:{}};return t[e](o,o.exports,r),o.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};r.r(i),r.d(i,{Chart:()=>_,ColorAxis:()=>q,Credits:()=>Y,Debug:()=>G,HighchartsMapChart:()=>Ae,HighmapsProvider:()=>K,Legend:()=>ce,Loading:()=>ee,MapBubbleSeries:()=>Ge,MapLineSeries:()=>Je,MapNavigation:()=>Me,MapPointSeries:()=>Ke,MapSeries:()=>Qe,Series:()=>B,Subtitle:()=>de,Title:()=>be,Tooltip:()=>he,XAxis:()=>_e,YAxis:()=>Ze,useAxis:()=>P,useChart:()=>w,useHighcharts:()=>j,useSeries:()=>ge,withHighmaps:()=>J,withSeriesType:()=>V});var o=r(12);const s={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let a;const c=new Uint8Array(16);function l(){if(!a){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");a=crypto.getRandomValues.bind(crypto)}return a(c)}const u=[];for(let e=0;e<256;++e)u.push((e+256).toString(16).slice(1));const d=function(e,t,n){if(s.randomUUID&&!t&&!e)return s.randomUUID();const r=(e=e||{}).random||(e.rng||l)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return(u[e[t+0]]+u[e[t+1]]+u[e[t+2]]+u[e[t+3]]+"-"+u[e[t+4]]+u[e[t+5]]+"-"+u[e[t+6]]+u[e[t+7]]+"-"+u[e[t+8]]+u[e[t+9]]+"-"+u[e[t+10]]+u[e[t+11]]+u[e[t+12]]+u[e[t+13]]+u[e[t+14]]+u[e[t+15]]).toLowerCase()}(r)},f=(0,o.createContext)();f.displayName="SeriesContext";const p=f;function b(e,t){let n={};return e&&Object.keys(e).filter((n=>t(n,e[n]))).forEach((t=>{n[t]=e[t]})),n}const m=e=>b(e,((e,t)=>!h(e,t))),y=e=>{const t=(e=>b(e,h))(e),n={};return Object.keys(t).forEach((e=>{const r=e.slice(2)[0].toLowerCase()+e.slice(3);n[r]=t[e]})),n},h=(e,t)=>0===e.indexOf("on")&&e.length>2&&"function"==typeof t;function g(e,t,n=!1){let{children:r,...i}=t;const o=b(i,((t,n)=>!e||!1===Object.is(n,e[t])));return!n||e&&!1!==Object.is(e.children,r)||(o.text=r),Object.keys(o).length>0&&o}function v(e){const t=(0,o.useRef)();return(0,o.useEffect)((()=>{t.current=e})),t.current}const x=(0,o.createContext)();x.displayName="HighchartsContext";const O=x;function j(){return(0,o.useContext)(O)}const E=(0,o.createContext)();E.displayName="ChartContext";const C=E;function w(){return(0,o.useContext)(C)}const A=(0,o.createContext)();A.displayName="AxisContext";const S=A,T=e=>e?{object:e,id:e.userOptions&&e.userOptions.id,type:e.coll,update:e.update.bind(e),remove:e.remove.bind(e),addPlotBandOrLine:e.addPlotBandOrLine.bind(e),removePlotBandOrLine:e.removePlotBandOrLine.bind(e),getExtremes:e.getExtremes.bind(e),setExtremes:e.setExtremes.bind(e),setTitle:e.setTitle.bind(e)}:null;function P(e){const t=w(),n=(0,o.useContext)(S),r=()=>{if(n)return n;if(e){const n=t.get(e);return T(n)}return null},[i,s]=(0,o.useState)(r);return(0,o.useEffect)((()=>{i||s(r())}),[]),(0,o.useDebugValue)(i?i.id:null),i}const R=(0,o.createContext)();R.displayName="ColorAxisContext";const k=R,N=e=>e?{object:e,id:e.userOptions&&e.userOptions.id}:null;function L(e){return e?{object:e,id:e.userOptions&&e.userOptions.id,type:e.type,update:e.update.bind(e),remove:e.remove.bind(e),setData:e.setData.bind(e),setVisible:e.setVisible.bind(e)}:null}var M=r(85);const D=[],I=(0,o.memo)((({id:e=d,data:t=D,isDataEqual:n=Object.is,type:r="line",visible:i=!0,children:s=null,axisId:a,requiresAxis:c=!0,jsxOptions:l,...u})=>{const f={id:e,data:t,type:r,visible:i,...u},b=j(),{addSeries:h,needsRedraw:x}=w(),O=(0,o.useRef)(null),[,E]=(0,o.useState)(!1),C=(0,o.useRef)(null),A=P(a),S=function(){w();const e=(0,o.useContext)(k),t=()=>e||null,[n,r]=(0,o.useState)(t);return(0,o.useEffect)((()=>{n||r(t())}),[]),(0,o.useDebugValue)(n?n.id:null),n}();(0,o.useEffect)((()=>{if(c&&!A)return;const e=U(f,A,S,c),t=h(e,!1);return O.current=t,C.current=L(O.current),E(!0),x(),()=>{if(t&&t.remove){try{t.remove.bind(t)(!1),O.current=null}catch{}x()}}}),[A]);const T=v(f);return(0,o.useEffect)((()=>{if(!T)return;if(!O.current)return;const e=O.current,{visible:t,data:r,...i}=f;let o=!1;if(!1===n(r,T.data)){const t=l&&l.animation,n=l&&l.updatePoints;e.setData(r,!1,t,n),o=!0}t!==T.visible&&(e.setVisible(t,!1),o=!0);const s=g(T,i);if(!1!==s){const t=m(s);e.update(t,!1);const n=y(s),r=y(T);Object.keys(n).forEach((t=>{const i=r[t];i&&b.removeEvent(e,t,i);const o=n[t];o&&b.addEvent(e,t,o)})),o=!0}o&&x()})),O.current?(0,M.jsx)(p.Provider,{value:C.current,children:s}):null})),U=(e,t,n,r)=>{const{id:i,data:o,...s}=e,a="function"==typeof i?i():i,c=m(s),l={id:a,data:o,events:y(s),...c};return n&&(l.colorAxis=n.id),r&&(l[t.type]=t.id),l};I.displayName="Series";const B=I;function V(e,t={}){const n=n=>(0,M.jsx)(B,{...n,...t,type:e.toLowerCase()});return n.displayName=`${e}Series`,n}function H(e,t=!1){const n=(0,o.useRef)();(0,o.useEffect)((()=>{n.current=e}));const r=g(n.current,e,t);return(0,o.useDebugValue)(r?"Modified":"Not modified"),r}const z=(0,o.memo)((({type:e="line",width:t,height:n,...r})=>{const i=w(),s=(0,o.useRef)(!1),a=H({type:e,...r});return(0,o.useEffect)((()=>{void 0===t&&void 0===n||i.setSize(t,n)}),[t,n]),(0,o.useEffect)((()=>{if(!1!==a&&s.current){const e=m(a);Object.getOwnPropertyNames(e).length>0&&F(a,i,i.needsRedraw)}})),(0,o.useEffect)((()=>{const t=m({type:e,...r});F(t,i),s.current=!0}),[]),function(e,t){const n=j(),r=y(e),i=v(r),o=g(i,r);!1!==o&&Object.keys(o).forEach((e=>{if(i){const r=i[e];r&&n.removeEvent(t,e,r)}const r=o[e];r&&n.addEvent(t,e,r)}))}(r,i.object),null})),F=(e,t)=>{t.update({chart:e},!1),t.needsRedraw()};z.displayName="Chart";const _=z,q=({children:e=null,...t})=>{const n=w(),r=(0,o.useRef)(null),i=(0,o.useRef)(null),[s,a]=(0,o.useState)(!1);(0,o.useEffect)((()=>{const e=((e,t)=>{const n=(e=>{const{id:t=d,...n}=e,r="function"==typeof t?t():t,i=m(n);return{id:r,events:y(n),...i}})(t);return e.addColorAxis(n,!1)})(n,t);return r.current=e,i.current=N(r.current),a(!0),n.needsRedraw(),()=>{if(e&&e.remove){try{e.remove.bind(e)(!1)}catch{}n.needsRedraw()}}}),[]);const c=H(t);return(0,o.useEffect)((()=>{null!==r.current&&!1!==c&&(r.current.update(c,!1),n.needsRedraw())})),s?(0,M.jsx)(k.Provider,{value:i.current,children:e}):null},$=e=>e,X=(e,t=$,n=$,r=!0)=>{const i=w(),s=H(e,r);(0,o.useEffect)((()=>{!1!==s&&(t(i,s),i.needsRedraw())})),(0,o.useEffect)((()=>()=>{try{n(i)}catch{}i.needsRedraw()}),[])},Z=(e,t)=>{"text"in t&&!t.text&&delete t.text,e.addCredits(t,!0)},Y=({enabled:e=!0,...t})=>(X({enabled:e,...t},Z,(e=>Z(e,{enabled:!1}))),null),G=({varName:e="chart"})=>{const t=w();return(0,o.useEffect)((()=>(window[e]=t.object,console.log(`Chart instance available as global variable as window.${e}`),()=>{window[e]=void 0})),[e]),null};function J(e,t){return function(n){return(0,M.jsx)(K,{Highcharts:t,children:(0,M.jsx)(e,{...n})})}}const K=({Highcharts:e,children:t})=>(0,M.jsx)(O.Provider,{value:e,children:t}),Q=(0,o.memo)((({children:e,isLoading:t=!0,...n})=>{const r=w(),i=H(n);return(0,o.useEffect)((()=>{!1!==i&&W(i,r),t?r.showLoading(e):r.hideLoading()})),(0,o.useEffect)((()=>()=>{try{r.hideLoading()}catch{}}),[]),null})),W=(e,t)=>{t.update({loading:e},!0)};Q.displayName="Loading";const ee=Q,te=(0,o.memo)((({children:e=null,enabled:t=!0,...n})=>(X({enabled:t,...n},ne,(e=>ne(e,{enabled:!1})),!1),e))),ne=(e,t)=>{e.update({legend:t},!1)};te.displayName="Legend";const re=te,ie=(0,o.memo)((e=>(X(e,oe,(e=>oe(e,{text:null}))),null))),oe=(e,t)=>{e.update({legend:{title:t}},!1)};ie.displayName="LegendTitle";const se=ie,ae=re;ae.Title=se;const ce=ae,le=(0,o.memo)((e=>(X(e,ue,(e=>ue(e,{text:null}))),null))),ue=(e,t)=>{e.setTitle(void 0,t,!1)};le.displayName="Subtitle";const de=le,fe=(0,o.memo)((e=>(X(e,pe,(e=>pe(e,{text:null}))),null))),pe=(e,t)=>{e.setTitle(t,null,!1)};fe.displayName="Title";const be=fe,me=(0,o.memo)((e=>{var t;const{children:n=null,...r}=e,i=w(),s=j();r.enabled=null===(t=e.enabled)||void 0===t||t,(0,o.useEffect)((()=>(ye(i,{...s.defaultOptions&&s.defaultOptions.tooltip,...r}),()=>{try{ye(i,{enabled:!1})}catch{}})),[]);const a=H(r);return(0,o.useEffect)((()=>{!1!==a&&ye(i,a)})),null})),ye=(e,t)=>{e.update({tooltip:t})};me.displayName="Tooltip";const he=me;function ge(e){const t=(0,o.useContext)(p),n=w(),r=()=>t||(e?L(n.get(e)):null),[i,s]=(0,o.useState)(r);return(0,o.useEffect)((()=>{i||s(r())}),[]),(0,o.useDebugValue)(i?i.id:null),i}function ve(e){const t=window.cancelAnimationFrame,n=window.requestAnimationFrame;var r;return function(...i){r&&t(r),r=n(e.bind(e,...i))}}const xe=e=>e,Oe=({children:e=null,callback:t=xe,className:n="",containerProps:r=null,...i})=>{const[s,a]=(0,o.useState)(!1),c=(0,o.useRef)(null),l=(0,o.useRef)(null),u=(0,o.useRef)(null);(0,o.useLayoutEffect)((()=>{const e=((e,t)=>{if(!t)return;const{chartCreationFunc:n,callback:r,chart:i,polar:o,gauge:s,styledMode:a=!1,children:c,...l}=e,u=n(t,{chart:{styledMode:a,...i},title:{text:null},subtitle:{text:null},legend:{enabled:!1},rangeSelector:{enabled:!1},navigator:{enabled:!1},scrollbar:{enabled:!1},tooltip:{enabled:!1},credits:{enabled:!1},series:[],xAxis:[],yAxis:[],...l});return u.polar=o,u.angular=s,u})(i,c.current);var n,r;l.current=e,u.current=(n=e,r=i.chartType,{object:n,type:r,get:n.get.bind(n),setSize:n.setSize.bind(n),update:n.update.bind(n),addAxis:n.addAxis.bind(n),addColorAxis:n.addColorAxis.bind(n),addSeries:n.addSeries.bind(n),setTitle:n.setTitle.bind(n),setCaption:n.setCaption.bind(n),showLoading:n.showLoading.bind(n),hideLoading:n.hideLoading.bind(n),addCredits:n.addCredits.bind(n),addAnnotation:n.addAnnotation?n.addAnnotation.bind(n):null,removeAnnotation:n.removeAnnotation?n.removeAnnotation.bind(n):null,needsRedraw:ve((()=>{if(!n.__destroyed)try{n.redraw.bind(n)()}catch{}}))}),t(e),a(!0)}),[]),(0,o.useEffect)((()=>{const e=l.current;return()=>{e&&(e.destroy.bind(e)(),e.__destroyed=!0)}}),[]);const d=v(i);return(0,o.useEffect)((()=>{if(!s)return;const{plotOptions:e}=i,t=l.current;!1===Object.is(d.plotOptions,e)&&t&&(t.update({plotOptions:e},!1),u.current.needsRedraw())})),(0,M.jsx)("div",{...r,className:`chart ${n}`,ref:c,children:s&&(0,M.jsx)(C.Provider,{value:u.current,children:e})})};function je(){return je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},je.apply(null,arguments)}const Ee={id:"xAxis"},Ce={id:"yAxis"},we={enabled:!1},Ae=({map:e,chart:t,callback:n,...r})=>{const i=j(),s=(0,o.useMemo)((()=>((e,t)=>{if(e)return"string"==typeof e?t.maps[e]:e})(e,i)),[e]),a=(0,o.useMemo)((()=>({...t,map:s})),[s,t]),c=(0,o.useCallback)((e=>{if(s){const t=i.format,{mapText:n,mapTextFull:r}=e.options.credits;e.mapCredits=t(n,{geojson:s}),e.mapCreditsFull=t(r,{geojson:s})}n&&n(e)}),[n]);return o.createElement(Oe,je({chart:a,mapNavigation:we,xAxis:Ee,yAxis:Ce},r,{callback:c,chartCreationFunc:i.mapChart,chartType:"mapChart"}))},Se=(e,t)=>{t.update({mapNavigation:e},!0)},Te=e=>{const t=j(),n=w();return(0,o.useEffect)((()=>{const{type:r,...i}=e,o=((e,t)=>{const{children:n,onClick:r,...i}=e;return{...t.defaultOptions&&t.defaultOptions.mapNavigation.buttonOptions,onclick:r,...i,text:n}})(i,t);return((e,t,n)=>{const r=Object.keys(t).length>0;n.update({mapNavigation:{enableButtons:r,buttons:{[e]:t}}})})(r,o,n),()=>{}}),[]),null};function Pe(){return Pe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Pe.apply(null,arguments)}const Re=function(){this.mapZoom(.5)};function ke(){return ke=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},ke.apply(null,arguments)}const Ne=function(){this.mapZoom(2)},Le=({children:e,enabled:t=!0,...n})=>{const[r,i]=(0,o.useState)(!1),s=w(),a=j();(0,o.useEffect)((()=>{const e=s.object;e.options.mapNavigation.enabled=!0,a.fireEvent(e,"beforeRender");const r=((e,t)=>({...t.defaultOptions&&t.defaultOptions.mapNavigation,...e,enableButtons:!1,buttons:{zoomIn:{},zoomOut:{}}}))({enabled:t,...n},a);return Se(r,s),i(!0),()=>{try{Se({enabled:!1},s)}catch{}}}),[]);const c=H({enabled:t,...n});return(0,o.useEffect)((()=>{r&&!1!==c&&Se(c,s)})),e&&r?o.createElement(o.Fragment,null,e):null};Le.ZoomIn=({children:e="+",onClick:t=Re,y:n=0,...r})=>o.createElement(Te,Pe({type:"zoomIn",onClick:t,y:n},r),e),Le.ZoomOut=({children:e="-",onClick:t=Ne,y:n=28,...r})=>o.createElement(Te,ke({type:"zoomOut",onClick:t,y:n},r),e);const Me=Le,De=(0,o.memo)((({children:e,axisId:t,...n})=>{const r=P(t);return(0,o.useEffect)((()=>{r&&Ie({text:e,...n},r)})),(0,o.useEffect)((()=>()=>{if(r)try{Ie({text:null},r)}catch{}}),[r]),null})),Ie=(e,t)=>{t.setTitle(e,!0)};De.displayName="AxisTitle";const Ue=De,Be=({children:e=null,dynamicAxis:t=!0,...n})=>{const r=w(),i=(0,o.useRef)(null),s=(0,o.useRef)(null),[a,c]=(0,o.useState)(!1);(0,o.useEffect)((()=>{const e=((e,t,n)=>{const{id:r=d,isX:i}=t,o=(e=>{const{id:t=d,...n}=e,r="function"==typeof t?t():t,i=m(n);return{id:r,title:{text:null},events:y(n),...i}})(t);let s;if(n)s=e.addAxis(o,i,!1);else{const t="function"==typeof r?r():r;s=e.get(t),s.update.call(s,o,!1)}return s})(r,n,t);return i.current=e,s.current=T(i.current),c(!0),r.needsRedraw(),()=>{if(e.remove&&t){try{e.remove.bind(e)(!1)}catch{}r.needsRedraw()}}}),[]);const l=H(n);return(0,o.useEffect)((()=>{if(a&&!1!==l){const e=i.current,t=m(l),o={events:y(n),...t};e.plotLinesAndBands&&e.plotLinesAndBands.length>0?e.update(o,!0):(e.update(o,!1),r.needsRedraw())}})),a?(0,M.jsx)(S.Provider,{value:s.current,children:e}):null};Be.Title=Ue;const Ve=Be,He=({id:e,...t})=>{const n="stockChart"===w().type,r=n?"datetime":"linear",i=n?"xAxis":e;return(0,M.jsx)(Ve,{type:r,...t,id:i,isX:!0})};He.Title=Ve.Title;const ze=He;function Fe(){return Fe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Fe.apply(null,arguments)}const _e=({endOnTick:e=!1,visible:t=!1,minPadding:n=0,maxPadding:r=0,startOnTick:i=!1,...s})=>o.createElement(ze,Fe({endOnTick:e,visible:t,minPadding:n,maxPadding:r,startOnTick:i},s,{id:"xAxis",dynamicAxis:!1})),qe=({type:e="linear",...t})=>(0,M.jsx)(Ve,{type:e,...t,isX:!1});qe.displayName="YAxis",qe.Title=Ve.Title;const $e=qe;function Xe(){return Xe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Xe.apply(null,arguments)}const Ze=({endOnTick:e=!1,visible:t=!1,minPadding:n=0,maxPadding:r=0,startOnTick:i=!1,reversed:s=!0,...a})=>o.createElement($e,Xe({endOnTick:e,visible:t,minPadding:n,maxPadding:r,startOnTick:i,reversed:s},a,{id:"yAxis",dynamicAxis:!1})),Ye={axisId:"yAxis"},Ge=V("MapBubble",Ye),Je=V("MapLine",Ye),Ke=V("MapPoint",Ye),Qe=V("Map",Ye);return i})()));