@nivo/heatmap
Version:
3 lines (2 loc) • 20 kB
JavaScript
import{memo as e,useMemo as i,useState as t,useCallback as o,createElement as n,forwardRef as r,Fragment as a,useRef as l,useEffect as d}from"react";import{useValueFormatter as c,usePropertyAccessor as u,useMotionConfig as s,Container as h,useDimensions as f,SvgWrapper as v,ResponsiveWrapper as g,getRelativeCursor as b,isCursorInRect as m,mergeRefs as p}from"@nivo/core";import{Grid as y,Axes as x,renderGridLinesToCanvas as C,renderAxesToCanvas as w}from"@nivo/axes";import{AnchoredContinuousColorsLegendSvg as P,renderContinuousColorLegendToCanvas as O}from"@nivo/legends";import{useTheme as I}from"@nivo/theming";import{getContinuousColorScale as M,useInheritedColor as S}from"@nivo/colors";import{useAnnotations as T,Annotation as W,useComputedAnnotations as R,renderAnnotationsToCanvas as L}from"@nivo/annotations";import{BasicTooltip as k,useTooltip as z}from"@nivo/tooltip";import{jsx as V,jsxs as B,Fragment as q}from"react/jsx-runtime";import{scaleBand as E,scaleLinear as A}from"d3-scale";import{castBandScale as H}from"@nivo/scales";import{animated as X,to as Y,useTransition as G}from"@react-spring/web";import{Text as F,setCanvasFont as j,drawCanvasText as D}from"@nivo/text";function _(){return _=Object.assign?Object.assign.bind():function(e){for(var i=1;i<arguments.length;i++){var t=arguments[i];for(var o in t)({}).hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},_.apply(null,arguments)}function J(e,i){if(null==e)return{};var t={};for(var o in e)if({}.hasOwnProperty.call(e,o)){if(-1!==i.indexOf(o))continue;t[o]=e[o]}return t}var K={layers:["grid","axes","cells","legends","annotations"],forceSquare:!1,xInnerPadding:0,xOuterPadding:0,yInnerPadding:0,yOuterPadding:0,sizeVariation:!1,opacity:1,activeOpacity:1,inactiveOpacity:.15,borderWidth:0,borderColor:{from:"color",modifiers:[["darker",.8]]},enableGridX:!1,enableGridY:!1,enableLabels:!0,label:"formattedValue",labelTextColor:{from:"color",modifiers:[["darker",2]]},colors:{type:"sequential",scheme:"brown_blueGreen"},emptyColor:"#000000",legends:[],annotations:[],isInteractive:!0,hoverTarget:"rowColumn",tooltip:e((function(e){var i=e.cell;return null===i.formattedValue?null:V(k,{id:i.serieId+" - "+i.data.x,value:i.formattedValue,enableChip:!0,color:i.color})})),animate:!0,motionConfig:"gentle"},N=_({},K,{axisTop:{},axisRight:null,axisBottom:null,axisLeft:{},borderRadius:0,cellComponent:"rect"}),Q=_({},K,{axisTop:{},axisRight:null,axisBottom:null,axisLeft:{},renderCell:"rect",pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1}),U=function(e){var i=e.width,t=e.height,o=e.rows,n=e.columns,r=i,a=t,l=0,d=0;if(e.forceSquare){var c=Math.max(i/n,0),u=Math.max(t/o,0),s=Math.min(c,u);l=(i-(r=s*n))/2,d=(t-(a=s*o))/2}return{offsetX:l,offsetY:d,width:r,height:a}},Z=function(e){var i=e.data,t=e.width,o=e.height,n=e.xInnerPadding,r=e.xOuterPadding,a=e.yInnerPadding,l=e.yOuterPadding,d=e.forceSquare,c=new Set,u=[],s=[],h=[];i.forEach((function(e){u.push(e.id),e.data.forEach((function(i){c.add(i.x);var t=null;void 0!==i.y&&null!==i.y&&(s.push(i.y),t=i.y),h.push({id:e.id+"."+i.x,serieId:e.id,value:t,data:i})}))}));var f=Array.from(c),v=U({width:t,height:o,columns:f.length,rows:u.length,forceSquare:d}),g=v.width,b=v.height,m=v.offsetX,p=v.offsetY,y=H(E().domain(f).range([0,g]).paddingOuter(r).paddingInner(n)),x=H(E().domain(u).range([0,b]).paddingOuter(l).paddingInner(a)),C=y.bandwidth(),w=x.bandwidth(),P=h.map((function(e){return _({},e,{x:y(e.data.x)+C/2,y:x(e.serieId)+w/2,width:C,height:w})}));return{width:g,height:b,offsetX:m,offsetY:p,xScale:y,yScale:x,minValue:Math.min.apply(Math,s),maxValue:Math.max.apply(Math,s),cells:P}},$=function(e,i,t){if(!e)return function(){return 1};var o=A().domain(e.values?e.values:[i,t]).range(e.sizes);return function(e){return null===e?1:o(e)}},ee=function(e){return{x:e.x,y:e.y}},ie=function(e){return{size:Math.max(e.width,e.height),width:e.width,height:e.height}},te=function(e){var t=e.data,o=e.width,n=e.height,r=e.xInnerPadding,a=e.xOuterPadding,l=e.yInnerPadding,d=e.yOuterPadding,c=e.forceSquare;return i((function(){return Z({data:t,width:o,height:n,xInnerPadding:r,xOuterPadding:a,yInnerPadding:l,yOuterPadding:d,forceSquare:c})}),[t,o,n,r,a,l,d,c])},oe={cell:function(e,i){return e.id===i.id},row:function(e,i){return e.serieId===i.serieId},column:function(e,i){return e.data.x===i.data.x},rowColumn:function(e,i){return e.serieId===i.serieId||e.data.x===i.data.x}},ne=function(e){var t,n,r,a=e.cells,l=e.minValue,d=e.maxValue,s=e.sizeVariation,h=e.colors,f=e.emptyColor,v=e.opacity,g=e.activeOpacity,b=e.inactiveOpacity,m=e.borderColor,p=e.label,y=e.labelTextColor,x=e.valueFormat,C=e.activeIds,w=i((function(){return $(t,n,r)}),[t=s,n=l,r=d]),P=i((function(){return"function"==typeof h?null:M(h,{min:l,max:d})}),[h,l,d]),O=o((function(e){if(null!==e.value){if("function"==typeof h)return h(e);if(null!==P)return P(e.value)}return f}),[h,P,f]),T=I(),W=S(m,T),R=S(y,T),L=c(x),k=u(p);return{cells:i((function(){return a.map((function(e){var i=v;C.length>0&&(i=C.includes(e.id)?g:b);var t=w(e.value),o=_({},e,{width:e.width*t,height:e.height*t,formattedValue:null!==e.value?L(e.value):null,opacity:i});return o.label=k(o),o.color=O(o),o.borderColor=W(o),o.labelTextColor=R(o),o}))}),[a,w,O,W,R,L,k,C,v,g,b]),colorScale:P}},re=function(e){var o=e.data,n=e.valueFormat,r=e.width,a=e.height,l=e.xOuterPadding,d=void 0===l?K.xOuterPadding:l,c=e.xInnerPadding,u=void 0===c?K.xInnerPadding:c,s=e.yOuterPadding,h=void 0===s?K.yOuterPadding:s,f=e.yInnerPadding,v=void 0===f?K.yInnerPadding:f,g=e.forceSquare,b=void 0===g?K.forceSquare:g,m=e.sizeVariation,p=void 0===m?K.sizeVariation:m,y=e.colors,x=void 0===y?K.colors:y,C=e.emptyColor,w=void 0===C?K.emptyColor:C,P=e.opacity,O=void 0===P?K.opacity:P,I=e.activeOpacity,M=void 0===I?K.activeOpacity:I,S=e.inactiveOpacity,T=void 0===S?K.inactiveOpacity:S,W=e.borderColor,R=void 0===W?K.borderColor:W,L=e.label,k=void 0===L?K.label:L,z=e.labelTextColor,V=void 0===z?K.labelTextColor:z,B=e.hoverTarget,q=void 0===B?K.hoverTarget:B,E=t(null),A=E[0],H=E[1],X=te({data:o,width:r,height:a,xOuterPadding:d,xInnerPadding:u,yOuterPadding:h,yInnerPadding:v,forceSquare:b}),Y=X.width,G=X.height,F=X.offsetX,j=X.offsetY,D=X.cells,_=X.xScale,J=X.yScale,N=X.minValue,Q=X.maxValue,U=i((function(){if(!A)return[];var e=oe[q];return D.filter((function(i){return e(i,A)})).map((function(e){return e.id}))}),[D,A,q]),Z=ne({cells:D,minValue:N,maxValue:Q,sizeVariation:p,colors:x,emptyColor:w,opacity:O,activeOpacity:M,inactiveOpacity:T,borderColor:R,label:k,labelTextColor:V,valueFormat:n,activeIds:U});return{width:Y,height:G,offsetX:F,offsetY:j,cells:Z.cells,xScale:_,yScale:J,colorScale:Z.colorScale,activeCell:A,setActiveCell:H}},ae=function(e,i){return T({data:e,annotations:i,getPosition:ee,getDimensions:ie})},le=e((function(e){var t=e.cell,o=e.borderWidth,n=e.borderRadius,r=e.animatedProps,a=e.onMouseEnter,l=e.onMouseMove,d=e.onMouseLeave,c=e.onClick,u=e.enableLabels,s=I(),h=i((function(){return{onMouseEnter:a?a(t):void 0,onMouseMove:l?l(t):void 0,onMouseLeave:d?d(t):void 0,onClick:c?c(t):void 0}}),[t,a,l,d,c]);return B(X.g,_({"data-testid":"cell."+t.id,style:{cursor:"pointer"},opacity:r.opacity},h,{transform:Y([r.x,r.y,r.scale],(function(e,i,t){return"translate("+e+", "+i+") scale("+t+")"})),children:[V(X.rect,{transform:Y([r.width,r.height],(function(e,i){return"translate("+-.5*e+", "+-.5*i+")"})),fill:r.color,width:r.width,height:r.height,stroke:r.borderColor,strokeWidth:o,rx:n,ry:n},t.id),u&&V(F,{textAnchor:"middle",dominantBaseline:"central",fill:r.labelTextColor,style:_({},s.labels.text,{fill:void 0,userSelect:"none"}),children:t.label})]}))})),de=e((function(e){var t=e.cell,o=e.borderWidth,n=e.animatedProps,r=e.onMouseEnter,a=e.onMouseMove,l=e.onMouseLeave,d=e.onClick,c=e.enableLabels,u=I(),s=i((function(){return{onMouseEnter:r?r(t):void 0,onMouseMove:a?a(t):void 0,onMouseLeave:l?l(t):void 0,onClick:d?d(t):void 0}}),[t,r,a,l,d]);return B(X.g,_({"data-testid":"cell."+t.id,style:{cursor:"pointer"},opacity:n.opacity},s,{transform:Y([n.x,n.y],(function(e,i){return"translate("+e+", "+i+")"})),children:[V(X.circle,{r:Y([n.width,n.height],(function(e,i){return Math.min(e,i)/2})),fill:n.color,fillOpacity:n.opacity,strokeWidth:o,stroke:n.borderColor}),c&&V(F,{dominantBaseline:"central",textAnchor:"middle",fill:n.labelTextColor,style:_({},u.labels.text,{fill:void 0}),children:t.label})]}))})),ce=function(e){return{x:e.x,y:e.y,width:e.width,height:e.height,color:e.color,opacity:0,borderColor:e.borderColor,labelTextColor:e.labelTextColor,scale:0}},ue=function(e){return{x:e.x,y:e.y,width:e.width,height:e.height,color:e.color,opacity:e.opacity,borderColor:e.borderColor,labelTextColor:e.labelTextColor,scale:1}},se=function(e){return{x:e.x,y:e.y,width:e.width,height:e.height,color:e.color,opacity:0,borderColor:e.borderColor,labelTextColor:e.labelTextColor,scale:0}},he=function(e){var t,o=e.cells,r=e.cellComponent,a=e.borderRadius,l=e.borderWidth,d=e.isInteractive,c=e.setActiveCell,u=e.onMouseEnter,h=e.onMouseMove,f=e.onMouseLeave,v=e.onClick,g=e.tooltip,b=e.enableLabels,m=s(),p=m.animate,y=m.config,x=G(o,{keys:function(e){return e.id},initial:ue,from:ce,enter:ue,update:ue,leave:se,config:y,immediate:!p}),C=z(),w=C.showTooltipFromEvent,P=C.hideTooltip,O=i((function(){if(d)return function(e){return function(i){w(n(g,{cell:e}),i),c(e),null==u||u(e,i)}}}),[d,w,g,c,u]),I=i((function(){if(d)return function(e){return function(i){w(n(g,{cell:e}),i),null==h||h(e,i)}}}),[d,w,g,h]),M=i((function(){if(d)return function(e){return function(i){P(),c(null),null==f||f(e,i)}}}),[d,P,c,f]),S=i((function(){if(d)return function(e){return function(i){null==v||v(e,i)}}}),[d,v]);return t="rect"===r?le:"circle"===r?de:r,V(q,{children:x((function(e,i){return n(t,{cell:i,borderRadius:a,borderWidth:l,animatedProps:e,enableLabels:b,onMouseEnter:O,onMouseMove:I,onMouseLeave:M,onClick:S})}))})},fe=function(e){var i=e.cells,t=e.annotations,o=ae(i,t);return V(q,{children:o.map((function(e,i){return V(W,_({},e),i)}))})},ve=["isInteractive","animate","motionConfig","theme","renderWrapper"],ge=function(e){var t=e.data,o=e.layers,r=void 0===o?N.layers:o,l=e.valueFormat,d=e.width,c=e.height,u=e.margin,s=e.forceSquare,h=void 0===s?N.forceSquare:s,g=e.xInnerPadding,b=void 0===g?N.xInnerPadding:g,m=e.xOuterPadding,p=void 0===m?N.xOuterPadding:m,C=e.yInnerPadding,w=void 0===C?N.yInnerPadding:C,O=e.yOuterPadding,I=void 0===O?N.yOuterPadding:O,M=e.sizeVariation,S=void 0===M?N.sizeVariation:M,T=e.cellComponent,W=void 0===T?N.cellComponent:T,R=e.opacity,L=void 0===R?N.opacity:R,k=e.activeOpacity,z=void 0===k?N.activeOpacity:k,B=e.inactiveOpacity,q=void 0===B?N.inactiveOpacity:B,E=e.borderRadius,A=void 0===E?N.borderRadius:E,H=e.borderWidth,X=void 0===H?N.borderWidth:H,Y=e.borderColor,G=void 0===Y?N.borderColor:Y,F=e.enableGridX,j=void 0===F?N.enableGridX:F,D=e.enableGridY,J=void 0===D?N.enableGridY:D,K=e.axisTop,Q=void 0===K?N.axisTop:K,U=e.axisRight,Z=void 0===U?N.axisRight:U,$=e.axisBottom,ee=void 0===$?N.axisBottom:$,ie=e.axisLeft,te=void 0===ie?N.axisLeft:ie,oe=e.enableLabels,ne=void 0===oe?N.enableLabels:oe,ae=e.label,le=void 0===ae?N.label:ae,de=e.labelTextColor,ce=void 0===de?N.labelTextColor:de,ue=e.colors,se=void 0===ue?N.colors:ue,ve=e.emptyColor,ge=void 0===ve?N.emptyColor:ve,be=e.legends,me=void 0===be?N.legends:be,pe=e.annotations,ye=void 0===pe?N.annotations:pe,xe=e.isInteractive,Ce=void 0===xe?N.isInteractive:xe,we=e.onMouseEnter,Pe=e.onMouseMove,Oe=e.onMouseLeave,Ie=e.onClick,Me=e.hoverTarget,Se=void 0===Me?N.hoverTarget:Me,Te=e.tooltip,We=void 0===Te?N.tooltip:Te,Re=e.role,Le=e.ariaLabel,ke=e.ariaLabelledBy,ze=e.ariaDescribedBy,Ve=e.forwardedRef,Be=f(d,c,u),qe=Be.margin,Ee=Be.innerWidth,Ae=Be.innerHeight,He=Be.outerWidth,Xe=Be.outerHeight,Ye=re({data:t,valueFormat:l,width:Ee,height:Ae,forceSquare:h,xInnerPadding:b,xOuterPadding:p,yInnerPadding:w,yOuterPadding:I,sizeVariation:S,colors:se,emptyColor:ge,opacity:L,activeOpacity:z,inactiveOpacity:q,borderColor:G,label:le,labelTextColor:ce,hoverTarget:Se}),Ge=Ye.width,Fe=Ye.height,je=Ye.offsetX,De=Ye.offsetY,_e=Ye.xScale,Je=Ye.yScale,Ke=Ye.cells,Ne=Ye.colorScale,Qe=Ye.activeCell,Ue=Ye.setActiveCell,Ze=i((function(){return _({},qe,{top:qe.top+De,left:qe.left+je})}),[qe,je,De]),$e={grid:null,axes:null,cells:null,legends:null,annotations:null};r.includes("grid")&&($e.grid=V(y,{width:Ge,height:Fe,xScale:j?_e:null,yScale:J?Je:null},"grid")),r.includes("axes")&&($e.axes=V(x,{xScale:_e,yScale:Je,width:Ge,height:Fe,top:Q,right:Z,bottom:ee,left:te},"axes")),r.includes("cells")&&($e.cells=V(a,{children:V(he,{cells:Ke,cellComponent:W,borderRadius:A,borderWidth:X,isInteractive:Ce,setActiveCell:Ue,onMouseEnter:we,onMouseMove:Pe,onMouseLeave:Oe,onClick:Ie,tooltip:We,enableLabels:ne})},"cells")),r.includes("legends")&&null!==Ne&&($e.legends=V(a,{children:me.map((function(e,i){return n(P,_({},e,{key:i,containerWidth:Ge,containerHeight:Fe,scale:Ne}))}))},"legends")),r.includes("annotations")&&ye.length>0&&($e.annotations=V(fe,{cells:Ke,annotations:ye},"annotations"));var ei={cells:Ke,activeCell:Qe,setActiveCell:Ue};return V(v,{width:He,height:Xe,margin:Object.assign({},Ze,{top:Ze.top,left:Ze.left}),role:Re,ariaLabel:Le,ariaLabelledBy:ke,ariaDescribedBy:ze,ref:Ve,children:r.map((function(e,i){var t;return"function"==typeof e?V(a,{children:n(e,ei)},i):null!=(t=null==$e?void 0:$e[e])?t:null}))})},be=r((function(e,i){var t=e.isInteractive,o=void 0===t?N.isInteractive:t,n=e.animate,r=void 0===n?N.animate:n,a=e.motionConfig,l=void 0===a?N.motionConfig:a,d=e.theme,c=e.renderWrapper,u=J(e,ve);return V(h,{animate:r,isInteractive:o,motionConfig:l,renderWrapper:c,theme:d,children:V(ge,_({isInteractive:o},u,{forwardedRef:i}))})})),me=["defaultWidth","defaultHeight","onResize","debounceResize"],pe=r((function(e,i){var t=e.defaultWidth,o=e.defaultHeight,n=e.onResize,r=e.debounceResize,a=J(e,me);return V(g,{defaultWidth:t,defaultHeight:o,onResize:n,debounceResize:r,children:function(e){var t=e.width,o=e.height;return V(be,_({width:t,height:o},a,{ref:i}))}})})),ye=function(e,i){var t=i.cell,o=t.x,n=t.y,r=t.width,a=t.height,l=t.color,d=t.borderColor,c=t.opacity,u=t.labelTextColor,s=t.label,h=i.borderWidth,f=i.enableLabels,v=i.theme;e.save(),e.globalAlpha=c,e.fillStyle=l,h>0&&(e.strokeStyle=d,e.lineWidth=h),e.fillRect(o-r/2,n-a/2,r,a),h>0&&e.strokeRect(o-r/2,n-a/2,r,a),f&&(j(e,v.labels.text),e.textAlign="center",e.textBaseline="middle",D(e,_({},v.labels.text,{fill:u}),s,o,n)),e.restore()},xe=function(e,i){var t=i.cell,o=t.x,n=t.y,r=t.width,a=t.height,l=t.color,d=t.borderColor,c=t.opacity,u=t.labelTextColor,s=t.label,h=i.borderWidth,f=i.enableLabels,v=i.theme;e.save(),e.globalAlpha=c;var g=Math.min(r,a)/2;e.fillStyle=l,h>0&&(e.strokeStyle=d,e.lineWidth=h),e.beginPath(),e.arc(o,n,g,0,2*Math.PI),e.fill(),h>0&&e.stroke(),f&&(j(e,v.labels.text),e.textAlign="center",e.textBaseline="middle",D(e,_({},v.labels.text,{fill:u}),s,o,n)),e.restore()},Ce=["theme","isInteractive","animate","motionConfig","renderWrapper"],we=function(e){var t,r=e.data,a=e.layers,c=void 0===a?Q.layers:a,u=e.valueFormat,s=e.width,h=e.height,v=e.margin,g=e.xInnerPadding,y=void 0===g?Q.xInnerPadding:g,x=e.xOuterPadding,P=void 0===x?Q.xOuterPadding:x,M=e.yInnerPadding,S=void 0===M?Q.yInnerPadding:M,T=e.yOuterPadding,W=void 0===T?Q.yOuterPadding:T,k=e.forceSquare,B=void 0===k?Q.forceSquare:k,q=e.sizeVariation,E=void 0===q?Q.sizeVariation:q,A=e.renderCell,H=void 0===A?Q.renderCell:A,X=e.opacity,Y=void 0===X?Q.opacity:X,G=e.activeOpacity,F=void 0===G?Q.activeOpacity:G,j=e.inactiveOpacity,D=void 0===j?Q.inactiveOpacity:j,J=e.borderWidth,K=void 0===J?Q.borderWidth:J,N=e.borderColor,U=void 0===N?Q.borderColor:N,Z=e.enableGridX,$=void 0===Z?Q.enableGridX:Z,ee=e.enableGridY,ie=void 0===ee?Q.enableGridY:ee,te=e.axisTop,oe=void 0===te?Q.axisTop:te,ne=e.axisRight,le=void 0===ne?Q.axisRight:ne,de=e.axisBottom,ce=void 0===de?Q.axisBottom:de,ue=e.axisLeft,se=void 0===ue?Q.axisLeft:ue,he=e.enableLabels,fe=void 0===he?Q.enableLabels:he,ve=e.label,ge=void 0===ve?Q.label:ve,be=e.labelTextColor,me=void 0===be?Q.labelTextColor:be,pe=e.colors,Ce=void 0===pe?Q.colors:pe,we=e.emptyColor,Pe=void 0===we?Q.emptyColor:we,Oe=e.legends,Ie=void 0===Oe?Q.legends:Oe,Me=e.annotations,Se=void 0===Me?Q.annotations:Me,Te=e.isInteractive,We=void 0===Te?Q.isInteractive:Te,Re=e.onClick,Le=e.hoverTarget,ke=void 0===Le?Q.hoverTarget:Le,ze=e.tooltip,Ve=void 0===ze?Q.tooltip:ze,Be=e.role,qe=e.ariaLabel,Ee=e.ariaLabelledBy,Ae=e.ariaDescribedBy,He=e.pixelRatio,Xe=void 0===He?Q.pixelRatio:He,Ye=e.forwardedRef,Ge=l(null),Fe=f(s,h,v),je=Fe.margin,De=Fe.innerWidth,_e=Fe.innerHeight,Je=Fe.outerWidth,Ke=Fe.outerHeight,Ne=re({data:r,valueFormat:u,width:De,height:_e,xInnerPadding:y,xOuterPadding:P,yInnerPadding:S,yOuterPadding:W,forceSquare:B,sizeVariation:E,colors:Ce,emptyColor:Pe,opacity:Y,activeOpacity:F,inactiveOpacity:D,borderColor:U,label:ge,labelTextColor:me,hoverTarget:ke}),Qe=Ne.width,Ue=Ne.height,Ze=Ne.offsetX,$e=Ne.offsetY,ei=Ne.xScale,ii=Ne.yScale,ti=Ne.cells,oi=Ne.colorScale,ni=Ne.activeCell,ri=Ne.setActiveCell,ai=i((function(){return _({},je,{top:je.top+$e,left:je.left+Ze})}),[je,Ze,$e]),li=ae(ti,Se),di=R({annotations:li});t="function"==typeof H?H:"circle"===H?xe:ye;var ci=I(),ui=i((function(){return{cells:ti,activeCell:ni,setActiveCell:ri}}),[ti,ni,ri]);d((function(){if(null!==Ge.current){var e=Ge.current.getContext("2d");e&&(Ge.current.width=Je*Xe,Ge.current.height=Ke*Xe,e.scale(Xe,Xe),e.fillStyle=ci.background,e.fillRect(0,0,Je,Ke),e.translate(ai.left,ai.top),c.forEach((function(i){"grid"===i?(e.lineWidth=ci.grid.line.strokeWidth,e.strokeStyle=ci.grid.line.stroke,$&&C(e,{width:Qe,height:Ue,scale:ei,axis:"x"}),ie&&C(e,{width:Qe,height:Ue,scale:ii,axis:"y"})):"axes"===i?w(e,{xScale:ei,yScale:ii,width:Qe,height:Ue,top:oe,right:le,bottom:ce,left:se,theme:ci}):"cells"===i?(e.textAlign="center",e.textBaseline="middle",ti.forEach((function(i){t(e,{cell:i,borderWidth:K,enableLabels:fe,theme:ci})}))):"legends"===i&&null!==oi?Ie.forEach((function(i){O(e,_({},i,{containerWidth:Qe,containerHeight:Ue,scale:oi,theme:ci}))})):"annotations"===i?L(e,{annotations:di,theme:ci}):"function"==typeof i&&i(e,ui)})))}}),[Ge,Xe,Je,Ke,Qe,Ue,ai,c,ui,ti,t,$,ie,oe,le,ce,se,ei,ii,ci,K,fe,oi,Ie,di]);var si=z(),hi=si.showTooltipFromEvent,fi=si.hideTooltip,vi=o((function(e){if(null!==Ge.current){var i=b(Ge.current,e),t=i[0],o=i[1],r=ti.find((function(e){return m(e.x+ai.left-e.width/2,e.y+ai.top-e.height/2,e.width,e.height,t,o)}));void 0!==r?(ri(r),hi(n(Ve,{cell:r}),e)):(ri(null),fi())}}),[Ge,ti,ai,ri,hi,fi,Ve]),gi=o((function(){ri(null),fi()}),[ri,fi]),bi=o((function(e){null!==ni&&(null==Re||Re(ni,e))}),[ni,Re]);return V("canvas",{ref:p(Ge,Ye),width:Je*Xe,height:Ke*Xe,style:{width:Je,height:Ke},onMouseEnter:We?vi:void 0,onMouseMove:We?vi:void 0,onMouseLeave:We?gi:void 0,onClick:We?bi:void 0,role:Be,"aria-label":qe,"aria-labelledby":Ee,"aria-describedby":Ae})},Pe=r((function(e,i){var t=e.theme,o=e.isInteractive,n=void 0===o?Q.isInteractive:o,r=e.animate,a=void 0===r?Q.animate:r,l=e.motionConfig,d=void 0===l?Q.motionConfig:l,c=e.renderWrapper,u=J(e,Ce);return V(h,{isInteractive:n,animate:a,motionConfig:d,theme:t,renderWrapper:c,children:V(we,_({isInteractive:n},u,{forwardedRef:i}))})})),Oe=["defaultWidth","defaultHeight","onResize","debounceResize"],Ie=r((function(e,i){var t=e.defaultWidth,o=e.defaultHeight,n=e.onResize,r=e.debounceResize,a=J(e,Oe);return V(g,{defaultWidth:t,defaultHeight:o,onResize:n,debounceResize:r,children:function(e){var t=e.width,o=e.height;return V(Pe,_({width:t,height:o},a,{ref:i}))}})}));export{be as HeatMap,Pe as HeatMapCanvas,pe as ResponsiveHeatMap,Ie as ResponsiveHeatMapCanvas,Q as canvasDefaultProps,K as commonDefaultProps,Z as computeCells,U as computeLayout,$ as computeSizeScale,ie as getCellAnnotationDimensions,ee as getCellAnnotationPosition,N as svgDefaultProps,ae as useCellAnnotations,te as useComputeCells,re as useHeatMap};
//# sourceMappingURL=nivo-heatmap.mjs.map