react-grid-heatmapjs
Version:
React for the user interface, Tailwind CSS for styling, and CSS Grid for layout. A heatmap is a data visualization technique that uses color to represent the magnitude of values within a two-dimensional grid or matrix.
28 lines (24 loc) • 16.8 kB
JavaScript
(function(P,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],k):(P=typeof globalThis<"u"?globalThis:P||self,k(P["react-grid-heatmapjs"]={},P.require$$0))})(this,function(P,k){"use strict";const pr="";var B={exports:{}},I={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var ee;function Ce(){if(ee)return I;ee=1;var R=k,m=Symbol.for("react.element"),O=Symbol.for("react.fragment"),g=Object.prototype.hasOwnProperty,b=R.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,j={key:!0,ref:!0,__self:!0,__source:!0};function h(o,s,f){var d,y={},_=null,w=null;f!==void 0&&(_=""+f),s.key!==void 0&&(_=""+s.key),s.ref!==void 0&&(w=s.ref);for(d in s)g.call(s,d)&&!j.hasOwnProperty(d)&&(y[d]=s[d]);if(o&&o.defaultProps)for(d in s=o.defaultProps,s)y[d]===void 0&&(y[d]=s[d]);return{$$typeof:m,type:o,key:_,ref:w,props:y,_owner:b.current}}return I.Fragment=O,I.jsx=h,I.jsxs=h,I}var $={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var re;function Se(){return re||(re=1,process.env.NODE_ENV!=="production"&&function(){var R=k,m=Symbol.for("react.element"),O=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),h=Symbol.for("react.provider"),o=Symbol.for("react.context"),s=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),w=Symbol.for("react.offscreen"),ne=Symbol.iterator,Fe="@@iterator";function Ne(e){if(e===null||typeof e!="object")return null;var r=ne&&e[ne]||e[Fe];return typeof r=="function"?r:null}var F=R.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function E(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Ae("error",e,t)}}function Ae(e,r,t){{var n=F.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var l=t.map(function(i){return String(i)});l.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,l)}}var Ie=!1,$e=!1,Me=!1,We=!1,Ye=!1,ae;ae=Symbol.for("react.module.reference");function Le(e){return!!(typeof e=="string"||typeof e=="function"||e===g||e===j||Ye||e===b||e===f||e===d||We||e===w||Ie||$e||Me||typeof e=="object"&&e!==null&&(e.$$typeof===_||e.$$typeof===y||e.$$typeof===h||e.$$typeof===o||e.$$typeof===s||e.$$typeof===ae||e.getModuleId!==void 0))}function Ve(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function ie(e){return e.displayName||"Context"}function C(e){if(e==null)return null;if(typeof e.tag=="number"&&E("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case g:return"Fragment";case O:return"Portal";case j:return"Profiler";case b:return"StrictMode";case f:return"Suspense";case d:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case o:var r=e;return ie(r)+".Consumer";case h:var t=e;return ie(t._context)+".Provider";case s:return Ve(e,e.render,"ForwardRef");case y:var n=e.displayName||null;return n!==null?n:C(e.type)||"Memo";case _:{var u=e,l=u._payload,i=u._init;try{return C(i(l))}catch{return null}}}return null}var D=Object.assign,M=0,oe,se,ue,le,ce,fe,de;function ve(){}ve.__reactDisabledLog=!0;function Ue(){{if(M===0){oe=console.log,se=console.info,ue=console.warn,le=console.error,ce=console.group,fe=console.groupCollapsed,de=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ve,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}M++}}function He(){{if(M--,M===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:oe}),info:D({},e,{value:se}),warn:D({},e,{value:ue}),error:D({},e,{value:le}),group:D({},e,{value:ce}),groupCollapsed:D({},e,{value:fe}),groupEnd:D({},e,{value:de})})}M<0&&E("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var q=F.ReactCurrentDispatcher,J;function Y(e,r,t){{if(J===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);J=n&&n[1]||""}return`
`+J+e}}var z=!1,L;{var Be=typeof WeakMap=="function"?WeakMap:Map;L=new Be}function pe(e,r){if(!e||z)return"";{var t=L.get(e);if(t!==void 0)return t}var n;z=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var l;l=q.current,q.current=null,Ue();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(S){n=S}Reflect.construct(e,[],i)}else{try{i.call()}catch(S){n=S}e.call(i.prototype)}}else{try{throw Error()}catch(S){n=S}e()}}catch(S){if(S&&n&&typeof S.stack=="string"){for(var a=S.stack.split(`
`),x=n.stack.split(`
`),v=a.length-1,p=x.length-1;v>=1&&p>=0&&a[v]!==x[p];)p--;for(;v>=1&&p>=0;v--,p--)if(a[v]!==x[p]){if(v!==1||p!==1)do if(v--,p--,p<0||a[v]!==x[p]){var T=`
`+a[v].replace(" at new "," at ");return e.displayName&&T.includes("<anonymous>")&&(T=T.replace("<anonymous>",e.displayName)),typeof e=="function"&&L.set(e,T),T}while(v>=1&&p>=0);break}}}finally{z=!1,q.current=l,He(),Error.prepareStackTrace=u}var A=e?e.displayName||e.name:"",Oe=A?Y(A):"";return typeof e=="function"&&L.set(e,Oe),Oe}function qe(e,r,t){return pe(e,!1)}function Je(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function V(e,r,t){if(e==null)return"";if(typeof e=="function")return pe(e,Je(e));if(typeof e=="string")return Y(e);switch(e){case f:return Y("Suspense");case d:return Y("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case s:return qe(e.render);case y:return V(e.type,r,t);case _:{var n=e,u=n._payload,l=n._init;try{return V(l(u),r,t)}catch{}}}return""}var U=Object.prototype.hasOwnProperty,me={},he=F.ReactDebugCurrentFrame;function H(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);he.setExtraStackFrame(t)}else he.setExtraStackFrame(null)}function ze(e,r,t,n,u){{var l=Function.call.bind(U);for(var i in e)if(l(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var x=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw x.name="Invariant Violation",x}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(v){a=v}a&&!(a instanceof Error)&&(H(u),E("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof a),H(null)),a instanceof Error&&!(a.message in me)&&(me[a.message]=!0,H(u),E("Failed %s type: %s",t,a.message),H(null))}}}var Ge=Array.isArray;function G(e){return Ge(e)}function Ke(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Xe(e){try{return be(e),!1}catch{return!0}}function be(e){return""+e}function ye(e){if(Xe(e))return E("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ke(e)),be(e)}var W=F.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},ge,_e,K;K={};function Qe(e){if(U.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function er(e){if(U.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function rr(e,r){if(typeof e.ref=="string"&&W.current&&r&&W.current.stateNode!==r){var t=C(W.current.type);K[t]||(E('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',C(W.current.type),e.ref),K[t]=!0)}}function tr(e,r){{var t=function(){ge||(ge=!0,E("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function nr(e,r){{var t=function(){_e||(_e=!0,E("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var ar=function(e,r,t,n,u,l,i){var a={$$typeof:m,type:e,key:r,ref:t,props:i,_owner:l};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function ir(e,r,t,n,u){{var l,i={},a=null,x=null;t!==void 0&&(ye(t),a=""+t),er(r)&&(ye(r.key),a=""+r.key),Qe(r)&&(x=r.ref,rr(r,u));for(l in r)U.call(r,l)&&!Ze.hasOwnProperty(l)&&(i[l]=r[l]);if(e&&e.defaultProps){var v=e.defaultProps;for(l in v)i[l]===void 0&&(i[l]=v[l])}if(a||x){var p=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&tr(i,p),x&&nr(i,p)}return ar(e,a,x,u,n,W.current,i)}}var X=F.ReactCurrentOwner,Ee=F.ReactDebugCurrentFrame;function N(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);Ee.setExtraStackFrame(t)}else Ee.setExtraStackFrame(null)}var Z;Z=!1;function Q(e){return typeof e=="object"&&e!==null&&e.$$typeof===m}function xe(){{if(X.current){var e=C(X.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function or(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
Check your code at `+r+":"+t+"."}return""}}var Re={};function sr(e){{var r=xe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function je(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=sr(r);if(Re[t])return;Re[t]=!0;var n="";e&&e._owner&&e._owner!==X.current&&(n=" It was passed a child from "+C(e._owner.type)+"."),N(e),E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),N(null)}}function Te(e,r){{if(typeof e!="object")return;if(G(e))for(var t=0;t<e.length;t++){var n=e[t];Q(n)&&je(n,r)}else if(Q(e))e._store&&(e._store.validated=!0);else if(e){var u=Ne(e);if(typeof u=="function"&&u!==e.entries)for(var l=u.call(e),i;!(i=l.next()).done;)Q(i.value)&&je(i.value,r)}}}function ur(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===s||r.$$typeof===y))t=r.propTypes;else return;if(t){var n=C(r);ze(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!Z){Z=!0;var u=C(r);E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function lr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){N(e),E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),N(null);break}}e.ref!==null&&(N(e),E("Invalid attribute `ref` supplied to `React.Fragment`."),N(null))}}function we(e,r,t,n,u,l){{var i=Le(e);if(!i){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var x=or(u);x?a+=x:a+=xe();var v;e===null?v="null":G(e)?v="array":e!==void 0&&e.$$typeof===m?(v="<"+(C(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):v=typeof e,E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",v,a)}var p=ir(e,r,t,u,l);if(p==null)return p;if(i){var T=r.children;if(T!==void 0)if(n)if(G(T)){for(var A=0;A<T.length;A++)Te(T[A],e);Object.freeze&&Object.freeze(T)}else E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Te(T,e)}return e===g?lr(p):ur(p),p}}function cr(e,r,t){return we(e,r,t,!0)}function fr(e,r,t){return we(e,r,t,!1)}var dr=fr,vr=cr;$.Fragment=g,$.jsx=dr,$.jsxs=vr}()),$}process.env.NODE_ENV==="production"?B.exports=Ce():B.exports=Se();var c=B.exports;function te({label:R,variant:m}){return c.jsxs("div",{className:"flex gap-1 items-center",children:[c.jsx("span",{className:"w-2 h-2 rounded-full",style:{background:m}}),c.jsx("p",{className:"text-gray-500 text-sm whitespace-nowrap",children:R})]})}function Pe(R){const m=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(R);if(!m)throw new Error("Could not parse Hex Color");const O=parseInt(m[1],16),g=parseInt(m[2],16),b=parseInt(m[3],16),j=O/255,h=g/255,o=b/255,s=Math.max(j,h,o),f=Math.min(j,h,o);let d=(s+f)/2,y=d,_=d;if(s===f)return{h:0,s:0,l:_};const w=s-f;switch(y=_>.5?w/(2-s-f):w/(s+f),s){case j:d=(h-o)/w+(h<o?6:0);break;case h:d=(o-j)/w+2;break;case o:d=(j-h)/w+4;break}return d/=6,y=y*100,y=Math.round(y),_=_*100,_=Math.round(_),d=Math.round(360*d),{h:d,s:y,l:_}}function ke(R,m,O,g){const b=Pe(g),j=m-R,h=100-(O-R)/j*100;return`hsl(${b.h},${b.s}%,${h<20?20:h}%)`}const De=({series:R,xaxis:m,title:O,legends:g,colorRange:b,chartStyle:j})=>{var h;return c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h2",{className:"font-sans text-base font-bold",children:O}),c.jsx("div",{className:"flex gap-3",children:g?g==null?void 0:g.map(o=>c.jsx(te,{variant:o.color,label:o.name},o.name)):b==null?void 0:b.map(o=>c.jsx(te,{variant:o.color,label:o.name},o.name))})]}),c.jsx("div",{className:"grid place-items-center w-full mt-9 px-12",children:c.jsxs("div",{className:"grid items-center justify-items-end gap-x-2 grid-cols-[minmax(auto,_5.125rem)_minmax(auto,_46.875rem)_minmax(auto,_5.125rem)]",style:{...j},children:[R==null?void 0:R.map(o=>c.jsxs(k.Fragment,{children:[c.jsx("div",{className:"flex",children:c.jsx("p",{className:"text-xs text-end",children:o.name})}),c.jsx("div",{className:"flex w-full",children:o.data.map(s=>{const f=(b==null?void 0:b.find(d=>d.from<=s&&d.to>=s))||{from:0,to:s,color:"#000000",name:"error"};return c.jsxs("div",{className:"flex flex-1 p-1 border relative cursor-pointer group",children:[c.jsx("div",{className:"absolute bottom-0 right-0 -translate-x-3 -translate-y-3 pointer-events-none z-10 transition-opacity rounded-full bg-white p-1 grid min-w-[30px] place-items-center border-2 text-sm text-gray-500 shadow-lg aspect-square md:opacity-0 group-hover:opacity-100 ",style:{borderColor:f.color||"#afafaf"},children:s}),c.jsx("div",{className:"aspect-square rounded-sm w-full",style:{background:ke(f==null?void 0:f.from,f==null?void 0:f.to,s,f==null?void 0:f.color)}})]},s+o.name)})}),c.jsx("div",{className:"flex justify-self-start",children:c.jsx("p",{className:"text-xs ",children:o.total})})]},JSON.stringify(o))),c.jsx("div",{}),c.jsx("div",{className:"mt-2 w-full flex justify-between gap-1",children:(h=m.labels)==null?void 0:h.map((o,s)=>{var f;return c.jsxs("div",{className:"w-full mt-1 text-center",children:[c.jsx("p",{children:o}),c.jsx("p",{children:(f=m==null?void 0:m.totals)==null?void 0:f[s]})]},o)})}),c.jsx("div",{})]})})]})};P.HeatMap=De,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});