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