@nivo/calendar
Version:
3 lines (2 loc) • 24.1 kB
JavaScript
import*as e from"react";import{memo as t,useCallback as o,useMemo as n,forwardRef as i,createElement as r,useRef as a,useState as d,useEffect as l}from"react";import{alignBox as c,Container as h,useDimensions as u,useValueFormatter as s,SvgWrapper as f,ResponsiveWrapper as g,degreesToRadians as v,mergeRefs as m,getRelativeCursor as y,isCursorInRect as p}from"@nivo/core";import{useTheme as b}from"@nivo/theming";import{BoxLegendSvg as x,renderLegendToCanvas as w}from"@nivo/legends";import{Text as S,setCanvasFont as W,drawCanvasText as L}from"@nivo/text";import{jsx as k,Fragment as M,jsxs as z}from"react/jsx-runtime";import{useTooltip as C,BasicTooltip as R}from"@nivo/tooltip";import{timeFormat as H}from"d3-time-format";import{scaleQuantize as V}from"d3-scale";import O from"lodash/isDate.js";import I from"lodash/memoize.js";import D from"lodash/range.js";import{timeWeek as P,timeYear as B,timeWeeks as E,timeDays as F,timeMonths as T,timeDay as Y,timeSunday as j,timeMonday as q,timeTuesday as A,timeWednesday as X,timeThursday as N,timeFriday as Z,timeSaturday as G}from"d3-time";function J(){return J=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)({}).hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},J.apply(null,arguments)}function K(e,t){if(null==e)return{};var o={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;o[n]=e[n]}return o}var Q,U=t((function(e){var t=e.years,o=e.legend,n=e.theme;return k(M,{children:t.map((function(e){return k(S,{transform:"translate("+e.x+","+e.y+") rotate("+e.rotation+")",textAnchor:"middle",style:n.labels.text,children:o(e.year)},e.year)}))})})),$=t((function(e){var t=e.path,o=e.borderWidth,n=e.borderColor;return k("path",{d:t,style:{fill:"none",strokeWidth:o,stroke:n,pointerEvents:"none"}})})),_=t((function(e){var t=e.months,o=e.legend,n=e.theme;return k(M,{children:t.map((function(e){return k(S,{transform:"translate("+e.x+","+e.y+") rotate("+e.rotation+")",textAnchor:"middle",style:n.labels.text,children:o(e.year,e.month,e.date)},e.date.toString()+".legend")}))})})),ee=t((function(t){var n=t.data,i=t.x,r=t.y,a=t.size,d=t.color,l=t.borderWidth,c=t.borderColor,h=t.isInteractive,u=t.tooltip,s=t.onMouseEnter,f=t.onMouseMove,g=t.onMouseLeave,v=t.onClick,m=t.formatValue,y=C(),p=y.showTooltipFromEvent,b=y.hideTooltip,x=o((function(t){if("value"in n){var o=J({},n,{value:m(n.value),data:J({},n.data)});p(e.createElement(u,J({},o)),t),null==s||s(n,t)}}),[p,u,n,s,m]),w=o((function(t){if("value"in n){var o=J({},n,{value:m(n.value),data:J({},n.data)});p(e.createElement(u,J({},o)),t),null==f||f(n,t)}}),[p,u,n,f,m]),S=o((function(e){"value"in n&&(b(),null==g||g(n,e))}),[b,n,g]),W=o((function(e){return null==v?void 0:v(n,e)}),[n,v]);return k("rect",{x:i,y:r,width:a,height:a,style:{fill:d,strokeWidth:l,stroke:c},onMouseEnter:h?x:void 0,onMouseMove:h?w:void 0,onMouseLeave:h?S:void 0,onClick:h?W:void 0})})),te=t((function(e){var t=e.value,o=e.day,n=e.color;return void 0===t||isNaN(Number(t))?null:k(R,{id:o,value:t,color:n,enableChip:!0})})),oe=H("%b"),ne={colors:["#61cdbb","#97e3d5","#e8c1a0","#f47560"],align:"center",direction:"horizontal",emptyColor:"#fff",minValue:0,maxValue:"auto",yearSpacing:30,yearLegend:function(e){return e},yearLegendPosition:"before",yearLegendOffset:10,monthBorderWidth:2,monthBorderColor:"#000",monthSpacing:0,monthLegend:function(e,t,o){return oe(o)},monthLegendPosition:"before",monthLegendOffset:10,daySpacing:0,dayBorderWidth:1,dayBorderColor:"#000",isInteractive:!0,legends:[],tooltip:te},ie=J({},ne,{role:"img"}),re=J({},ne,{pixelRatio:"undefined"!=typeof window&&null!=(Q=window.devicePixelRatio)?Q:1}),ae=J({},ie,{dayBorderColor:"#fff",dayRadius:0,square:!0,weekdayLegendOffset:75,firstWeekday:"sunday",weekdays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]}),de=function(e,t,o){var n=e.map((function(e){return e.value}));return["auto"===t?Math.min.apply(Math,n):t,"auto"===o?Math.max.apply(Math,n):o]},le=I((function(e){var t,o=e.date,n=e.cellSize,i=e.yearIndex,r=e.yearSpacing,a=e.monthSpacing,d=e.daySpacing,l=e.direction,c=e.originX,h=e.originY,u=new Date(o.getFullYear(),o.getMonth()+1,0),s=P.count(B(o),o),f=P.count(B(u),u),g=o.getDay(),v=u.getDay(),m=c,y=h,p=i*(7*(n+d)+r),b=o.getMonth()*a;"horizontal"===l?(y+=p,m+=b):(y+=b,m+=p);var x={x:m,y:y,width:0,height:0};return"horizontal"===l?(t=["M"+(m+(s+1)*(n+d))+","+(y+g*(n+d)),"H"+(m+s*(n+d))+"V"+(y+7*(n+d)),"H"+(m+f*(n+d))+"V"+(y+(v+1)*(n+d)),"H"+(m+(f+1)*(n+d))+"V"+y,"H"+(m+(s+1)*(n+d))+"Z"].join(""),x.x=m+s*(n+d),x.width=m+(f+1)*(n+d)-x.x,x.height=7*(n+d)):(t=["M"+(m+g*(n+d))+","+(y+(s+1)*(n+d)),"H"+m+"V"+(y+(f+1)*(n+d)),"H"+(m+(v+1)*(n+d))+"V"+(y+f*(n+d)),"H"+(m+7*(n+d))+"V"+(y+s*(n+d)),"H"+(m+g*(n+d))+"Z"].join(""),x.y=y+s*(n+d),x.width=7*(n+d),x.height=y+(f+1)*(n+d)-x.y),{path:t,bbox:x}}),(function(e){var t=e.date,o=e.cellSize,n=e.yearIndex,i=e.yearSpacing,r=e.monthSpacing,a=e.daySpacing,d=e.direction,l=e.originX,c=e.originY;return t.toString()+"."+o+"."+n+"."+i+"."+r+"."+a+"."+d+"."+l+"."+c})),ce=H("%Y-%m-%d"),he=function(e){var t,o=e.width,n=e.height,i=e.from,r=e.to,a=e.direction,d=e.yearSpacing,l=e.monthSpacing,h=e.daySpacing,u=e.align,s=O(i)?i:new Date(i),f=O(r)?r:new Date(r),g=D(s.getFullYear(),f.getFullYear()+1),v=Math.max.apply(Math,g.map((function(e){return E(new Date(e,0,1),new Date(e+1,0,1)).length})))+1,m=function(e){var t,o,n=e.width,i=e.height,r=e.direction,a=e.yearRange,d=e.yearSpacing,l=e.monthSpacing,c=e.daySpacing,h=e.maxWeeks;return"horizontal"===r?(t=(n-12*l-c*h)/h,o=(i-(a.length-1)*d-a.length*(8*c))/(7*a.length)):(t=(n-(a.length-1)*d-a.length*(8*c))/(7*a.length),o=(i-12*l-c*h)/h),Math.min(t,o)}({width:o,height:n,direction:a,yearRange:g,yearSpacing:d,monthSpacing:l,daySpacing:h,maxWeeks:v}),y=m*v+h*v+12*l,p=7*(m+h)*g.length+d*(g.length-1),b="horizontal"===a?y:p,x="horizontal"===a?p:y,w=c({x:0,y:0,width:b,height:x},{x:0,y:0,width:o,height:n},u),S=w[0],W=w[1];t="horizontal"===a?function(e,t,o,n){return function(i,r,a,d){return{x:i+P.count(B(a),a)*(e+n)+n/2+a.getMonth()*o,y:r+a.getDay()*(e+n)+n/2+d*(t+7*(e+n))}}}(m,d,l,h):function(e,t,o,n){return function(i,r,a,d){var l=P.count(B(a),a);return{x:i+a.getDay()*(e+n)+n/2+d*(t+7*(e+n)),y:r+l*(e+n)+n/2+a.getMonth()*o}}}(m,d,l,h);var L=[],k=[],M=[];return g.forEach((function(e,o){var n=new Date(e,0,1),i=new Date(e+1,0,1);M=M.concat(F(n,i).map((function(e){return J({date:e,day:ce(e),size:m},t(S,W,e,o))})));var r=T(n,i).map((function(e){return J({date:e,year:e.getFullYear(),month:e.getMonth()},le({originX:S,originY:W,date:e,direction:a,yearIndex:o,yearSpacing:d,monthSpacing:l,daySpacing:h,cellSize:m}))}));k=k.concat(r),L.push({year:e,bbox:{x:r[0].bbox.x,y:r[0].bbox.y,width:r[11].bbox.x-r[0].bbox.x+r[11].bbox.width,height:r[11].bbox.y-r[0].bbox.y+r[11].bbox.height}})})),{years:L,months:k,days:M,cellSize:m,calendarWidth:b,calendarHeight:x,originX:S,originY:W}},ue=function(e){var t=e.days,o=e.data,n=e.colorScale,i=e.emptyColor;return t.map((function(e){var t=o.find((function(t){return t.day===e.day}));return J({},e,t?{color:n(t.value),data:t,value:t.value}:{color:i})}))},se=function(e){var t=e.years,o=e.direction,n=e.position,i=e.offset;return t.map((function(e){var t=0,r=0,a=0;return"horizontal"===o&&"before"===n?(t=e.bbox.x-i,r=e.bbox.y+e.bbox.height/2,a=-90):"horizontal"===o&&"after"===n?(t=e.bbox.x+e.bbox.width+i,r=e.bbox.y+e.bbox.height/2,a=-90):"vertical"===o&&"before"===n?(t=e.bbox.x+e.bbox.width/2,r=e.bbox.y-i):(t=e.bbox.x+e.bbox.width/2,r=e.bbox.y+e.bbox.height+i),J({},e,{x:t,y:r,rotation:a})}))},fe=function(e){var t=e.months,o=e.direction,n=e.position,i=e.offset;return t.map((function(e){var t=0,r=0,a=0;return"horizontal"===o&&"before"===n?(t=e.bbox.x+e.bbox.width/2,r=e.bbox.y-i):"horizontal"===o&&"after"===n?(t=e.bbox.x+e.bbox.width/2,r=e.bbox.y+e.bbox.height+i):"vertical"===o&&"before"===n?(t=e.bbox.x-i,r=e.bbox.y+e.bbox.height/2,a=-90):(t=e.bbox.x+e.bbox.width+i,r=e.bbox.y+e.bbox.height/2,a=-90),J({},e,{x:t,y:r,rotation:a})}))},ge=function(e){var t=e.width,o=e.height,i=e.from,r=e.to,a=e.direction,d=e.yearSpacing,l=e.monthSpacing,c=e.daySpacing,h=e.align;return n((function(){return he({width:t,height:o,from:i,to:r,direction:a,yearSpacing:d,monthSpacing:l,daySpacing:c,align:h})}),[t,o,i,r,a,d,l,c,h])},ve=function(e){var t=e.data,o=e.minValue,i=e.maxValue,r=e.colors,a=e.colorScale;return n((function(){if(a)return a;var e=de(t,o,i);return V().domain(e).range(r)}),[t,o,i,r,a])},me=function(e){var t=e.years,o=e.direction,i=e.yearLegendPosition,r=e.yearLegendOffset;return n((function(){return se({years:t,direction:o,position:i,offset:r})}),[t,o,i,r])},ye=function(e){var t=e.months,o=e.direction,i=e.monthLegendPosition,r=e.monthLegendOffset;return n((function(){return fe({months:t,direction:o,position:i,offset:r})}),[t,o,i,r])},pe=function(e){var t=e.days,o=e.data,i=e.colorScale,r=e.emptyColor;return n((function(){return ue({days:t,data:o,colorScale:i,emptyColor:r})}),[t,o,i,r])},be=["months","years"],xe=["isInteractive","renderWrapper","theme"],we=function(e){var t=e.margin,o=e.width,n=e.height,i=e.align,r=void 0===i?ie.align:i,a=e.colors,d=void 0===a?ie.colors:a,l=e.colorScale,c=e.data,h=e.direction,g=void 0===h?ie.direction:h,v=e.emptyColor,m=void 0===v?ie.emptyColor:v,y=e.from,p=e.to,w=e.minValue,S=void 0===w?ie.minValue:w,W=e.maxValue,L=void 0===W?ie.maxValue:W,M=e.valueFormat,C=e.legendFormat,R=e.yearLegend,H=void 0===R?ie.yearLegend:R,V=e.yearLegendOffset,O=void 0===V?ie.yearLegendOffset:V,I=e.yearLegendPosition,D=void 0===I?ie.yearLegendPosition:I,P=e.yearSpacing,B=void 0===P?ie.yearSpacing:P,E=e.monthBorderColor,F=void 0===E?ie.monthBorderColor:E,T=e.monthBorderWidth,Y=void 0===T?ie.monthBorderWidth:T,j=e.monthLegend,q=void 0===j?ie.monthLegend:j,A=e.monthLegendOffset,X=void 0===A?ie.monthLegendOffset:A,N=e.monthLegendPosition,Z=void 0===N?ie.monthLegendPosition:N,G=e.monthSpacing,Q=void 0===G?ie.monthSpacing:G,te=e.dayBorderColor,oe=void 0===te?ie.dayBorderColor:te,ne=e.dayBorderWidth,re=void 0===ne?ie.dayBorderWidth:ne,ae=e.daySpacing,de=void 0===ae?ie.daySpacing:ae,le=e.isInteractive,ce=void 0===le?ie.isInteractive:le,he=e.tooltip,ue=void 0===he?ie.tooltip:he,se=e.onClick,fe=e.onMouseEnter,xe=e.onMouseLeave,we=e.onMouseMove,Se=e.legends,We=void 0===Se?ie.legends:Se,Le=e.role,ke=void 0===Le?ie.role:Le,Me=e.forwardedRef,ze=b(),Ce=u(o,n,t),Re=Ce.margin,He=Ce.innerWidth,Ve=Ce.innerHeight,Oe=Ce.outerWidth,Ie=Ce.outerHeight,De=ge({width:He,height:Ve,from:y,to:p,direction:g,yearSpacing:B,monthSpacing:Q,daySpacing:de,align:r}),Pe=De.months,Be=De.years,Ee=K(De,be),Fe=ve({data:c,minValue:S,maxValue:L,colors:d,colorScale:l}),Te=ye({months:Pe,direction:g,monthLegendPosition:Z,monthLegendOffset:X}),Ye=me({years:Be,direction:g,yearLegendPosition:D,yearLegendOffset:O}),je=pe({days:Ee.days,data:c,colorScale:Fe,emptyColor:m}),qe=s(C),Ae=s(M);return z(f,{width:Oe,height:Ie,margin:Re,role:ke,ref:Me,children:[je.map((function(e){return k(ee,{data:e,x:e.x,y:e.y,size:e.size,color:e.color,borderWidth:re,borderColor:oe,onMouseEnter:fe,onMouseLeave:xe,onMouseMove:we,isInteractive:ce,tooltip:ue,onClick:se,formatValue:Ae},e.date.toString())})),Pe.map((function(e){return k($,{path:e.path,borderWidth:Y,borderColor:F},e.date.toString())})),k(_,{months:Te,legend:q,theme:ze}),k(U,{years:Ye,legend:H,theme:ze}),We.map((function(e,t){var i=Fe.ticks(e.itemCount).map((function(e){return{id:e,label:qe(e),color:Fe(e)}}));return k(x,J({},e,{containerWidth:o,containerHeight:n,data:i}),t)}))]})},Se=i((function(e,t){var o=e.isInteractive,n=void 0===o?ie.isInteractive:o,i=e.renderWrapper,r=e.theme,a=K(e,xe);return k(h,{isInteractive:n,renderWrapper:i,theme:r,children:k(we,J({isInteractive:n},a,{forwardedRef:t}))})})),We=H("%Y-%m-%d"),Le=function(e){var t,o,n=e.direction,i=e.daySpacing,r=e.offset,a=e.square,d=e.totalDays,l=e.width,c=e.height;"horizontal"===n?(l-=r,t=7,o=Math.ceil(d/7)):(c-=r,o=7,t=Math.ceil(d/7));var h=(c-i*(t+1))/t,u=(l-i*(o+1))/o,s=Math.min(h,u);return{columns:o,rows:t,cellHeight:a?s:h,cellWidth:a?s:u}},ke=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function Me(e){return ke.findIndex((function(t){return t.toLowerCase()===e}))}var ze=function(e,t){var o=e.getDay()-Me(t);return[0,1,2,3,4,5,6].slice(o)[0]};function Ce(e){var t=e.startDate,o=e.date,n=e.direction,i=e.firstWeekday,r=function(e){return[j,q,A,X,N,Z,G][Me(e)]}(i),a=r.count(t,o),d=o.getMonth(),l=o.getFullYear(),c=0,h=0;return"horizontal"===n?(c=a,h=ze(o,i)):(c=ze(o,i),h=a),{currentColumn:c,year:l,currentRow:h,firstWeek:a,month:d,date:o}}var Re=function(e){var t=e.direction,o=e.colorScale,n=e.emptyColor,i=e.from,r=e.to,a=e.data,d=e.cellWidth,l=e.cellHeight,c=e.daySpacing,h=e.offset,u=e.firstWeekday,s=c,f=c;"horizontal"===t?s+=h:f+=h;var g=i||a[0].date,v=r||a[a.length-1].date,m=O(g)?g:new Date(g),y=O(v)?v:new Date(v);return F(m,y).map((function(e){return{date:e,day:We(e)}})).map((function(e){var i=a.find((function(t){return t.day===e.day})),r=Ce({startDate:m,date:e.date,direction:t,firstWeekday:u}),h=r.currentColumn,g=r.currentRow,v=r.firstWeek,y=r.year,p=r.month,b=r.date,x={x:s+c*h+d*h,y:f+c*g+l*g};return i?J({},i,{coordinates:x,firstWeek:v,month:p,year:y,date:b,color:o(i.value),width:d,height:l}):J({},e,{coordinates:x,firstWeek:v,month:p,year:y,date:b,color:n,width:d,height:l})}))},He=function(e){var t,o,n=e.cellHeight,i=e.cellWidth,r=e.direction,a=e.daySpacing,d=e.ticks,l=void 0===d?[1,3,5]:d,c=e.firstWeekday,h=e.arrayOfWeekdays,u=i+a,s=n+a,f=(t=void 0===h?ke:h,o=Me(c),t.length&&o?(o%=t.length,t.slice(o,t.length).concat(t.slice(0,o))):t);return l.map((function(e){return{value:f[e],rotation:"horizontal"===r?0:-90,y:"horizontal"===r?s*(e+1)-s/3:0,x:"horizontal"===r?0:u*(e+1)-u/3}}))},Ve=function(e){var t=e.direction,o=e.daySpacing,n=e.days,i=e.cellHeight,r=e.cellWidth;return n.reduce((function(e,n){if(e.weeks.length===n.firstWeek||!e.weeks.length&&1===n.firstWeek){e.weeks.push(n);var a=n.year+"-"+n.month;if(Object.keys(e.months).includes(a))"horizontal"===t?e.months[a].bbox.width=(n.firstWeek-e.months[a].firstWeek)*(r+o):e.months[a].bbox.height=(n.firstWeek-e.months[a].firstWeek)*(i+o);else{var d={x:0,y:0,width:0,height:0};"horizontal"===t?(d.x=n.coordinates.x-o,d.height=i+o,d.width=r+2*o):(d.y=n.coordinates.y-o,d.height=i+2*o,d.width=r+2*o),e.months[a]={date:n.date,bbox:d,firstWeek:n.firstWeek,month:0,year:0}}}return e}),{months:{},weeks:[]})},Oe=function(e){var t,o,n=e.from,i=e.to,r=e.data;return t=n?O(n)?n:new Date(n):r[0].date,o=n&&i?O(i)?i:new Date(i):r[r.length-1].date,t.getDay()+Y.count(t,o)},Ie=t((function(e){var t=e.data,n=e.x,i=e.ry,a=void 0===i?5:i,d=e.rx,l=void 0===d?5:d,c=e.y,h=e.width,u=e.height,s=e.color,f=e.borderWidth,g=e.borderColor,v=e.isInteractive,m=e.tooltip,y=e.onMouseEnter,p=e.onMouseMove,b=e.onMouseLeave,x=e.onClick,w=e.formatValue,S=C(),W=S.showTooltipFromEvent,L=S.hideTooltip,M=o((function(e){if("value"in t){var o=J({},t,{value:w(t.value)});W(r(m,J({},o)),e),null==y||y(t,e)}}),[W,m,t,y,w]),z=o((function(e){if("value"in t){var o=J({},t,{value:w(t.value)});W(r(m,J({},o)),e),null==p||p(t,e)}}),[W,m,t,p,w]),R=o((function(e){"value"in t&&(L(),null==b||b(t,e))}),[L,t,b]),H=o((function(e){return null==x?void 0:x(t,e)}),[t,x]);return k("rect",{x:n,y:c,rx:l,ry:a,width:h,height:u,style:{fill:s,strokeWidth:f,stroke:g},onMouseEnter:v?M:void 0,onMouseMove:v?z:void 0,onMouseLeave:v?R:void 0,onClick:v?H:void 0})})),De=["isInteractive","renderWrapper","theme"],Pe=function(e){var t=e.margin,o=e.width,i=e.height,r=e.square,a=void 0===r?ae.square:r,d=e.colors,l=void 0===d?ae.colors:d,c=e.colorScale,h=e.emptyColor,g=void 0===h?ae.emptyColor:h,v=e.from,m=e.to,y=e.data,p=e.direction,w=void 0===p?ae.direction:p,W=e.minValue,L=void 0===W?ae.minValue:W,M=e.maxValue,C=void 0===M?ae.maxValue:M,R=e.valueFormat,H=e.legendFormat,V=e.monthLegend,O=void 0===V?ae.monthLegend:V,I=e.monthLegendOffset,D=void 0===I?ae.monthLegendOffset:I,P=e.monthLegendPosition,B=void 0===P?ae.monthLegendPosition:P,E=e.weekdayLegendOffset,F=void 0===E?ae.weekdayLegendOffset:E,T=e.weekdayTicks,Y=e.weekdays,j=void 0===Y?ae.weekdays:Y,q=e.dayBorderColor,A=void 0===q?ae.dayBorderColor:q,X=e.dayBorderWidth,N=void 0===X?ae.dayBorderWidth:X,Z=e.daySpacing,G=void 0===Z?ae.daySpacing:Z,K=e.dayRadius,Q=void 0===K?ae.dayRadius:K,U=e.isInteractive,$=void 0===U?ae.isInteractive:U,ee=e.tooltip,te=void 0===ee?ae.tooltip:ee,oe=e.onClick,ne=e.onMouseEnter,ie=e.onMouseLeave,re=e.onMouseMove,de=e.legends,le=void 0===de?ae.legends:de,ce=e.role,he=void 0===ce?ae.role:ce,ue=e.firstWeekday,se=void 0===ue?ae.firstWeekday:ue,fe=e.forwardedRef,ge=u(o,i,t),me=ge.margin,pe=ge.innerWidth,be=ge.innerHeight,xe=ge.outerWidth,we=ge.outerHeight,Se=n((function(){return y.map((function(e){return J({},e,{date:new Date(e.day+"T00:00:00")})})).sort((function(e,t){return e.day.localeCompare(t.day)}))}),[y]),We=b(),ke=ve({data:Se,minValue:L,maxValue:C,colors:l,colorScale:c}),Me=Oe({from:v,to:m,data:Se}),ze=Le({square:a,offset:F,totalDays:Me,width:pe,height:be,daySpacing:G,direction:w}),Ce=ze.cellHeight,De=ze.cellWidth,Pe=Re({offset:F,colorScale:ke,emptyColor:g,cellHeight:Ce,cellWidth:De,from:v,to:m,data:Se,direction:w,daySpacing:G,firstWeekday:se}),Be=Object.values(Ve({daySpacing:G,direction:w,cellHeight:Ce,cellWidth:De,days:Pe}).months),Ee=He({direction:w,cellHeight:Ce,cellWidth:De,daySpacing:G,ticks:T,firstWeekday:se,arrayOfWeekdays:j}),Fe=ye({months:Be,direction:w,monthLegendPosition:B,monthLegendOffset:D}),Te=s(R),Ye=s(H);return z(f,{width:xe,height:we,margin:me,role:he,ref:fe,children:[Ee.map((function(e){return k(S,{transform:"translate("+e.x+","+e.y+") rotate("+e.rotation+")",textAnchor:"left",style:We.labels.text,children:e.value},e.value+"-"+e.x+"-"+e.y)})),Pe.map((function(e){return k(Ie,{data:e,x:e.coordinates.x,rx:Q,y:e.coordinates.y,ry:Q,width:De,height:Ce,color:e.color,borderWidth:N,borderColor:A,onMouseEnter:ne,onMouseLeave:ie,onMouseMove:re,isInteractive:$,tooltip:te,onClick:oe,formatValue:Te},e.date.toString())})),k(_,{months:Fe,legend:O,theme:We}),le.map((function(e,t){var n=ke.ticks(e.itemCount).map((function(e){return{id:e,label:Ye(e),color:ke(e)}}));return k(x,J({},e,{containerWidth:o,containerHeight:i,data:n}),t)}))]})},Be=i((function(e,t){var o=e.isInteractive,n=void 0===o?ae.isInteractive:o,i=e.renderWrapper,r=e.theme,a=K(e,De);return k(h,{isInteractive:n,renderWrapper:i,theme:r,children:k(Pe,J({isInteractive:n},a,{forwardedRef:t}))})})),Ee=["defaultWidth","defaultHeight","onResize","debounceResize"],Fe=i((function(e,t){var o=e.defaultWidth,n=e.defaultHeight,i=e.onResize,r=e.debounceResize,a=K(e,Ee);return k(g,{defaultWidth:o,defaultHeight:n,onResize:i,debounceResize:r,children:function(e){var o=e.width,n=e.height;return k(Be,J({width:o,height:n},a,{ref:t}))}})})),Te=["defaultWidth","defaultHeight","onResize","debounceResize"],Ye=i((function(e,t){var o=e.defaultWidth,n=e.defaultHeight,i=e.onResize,r=e.debounceResize,a=K(e,Te);return k(g,{defaultWidth:o,defaultHeight:n,onResize:i,debounceResize:r,children:function(e){var o=e.width,n=e.height;return k(Se,J({width:o,height:n},a,{ref:t}))}})})),je=["months","years"],qe=["isInteractive","renderWrapper","theme"],Ae=function(e,t,o,n,i,r){var a=y(t,e),d=a[0],l=a[1];return o.find((function(e){return"value"in e&&p(e.x+r.left-i/2,e.y+r.top-i/2,n+i,n+i,d,l)}))},Xe=t((function(t){var n=t.margin,i=t.width,r=t.height,c=t.pixelRatio,h=void 0===c?re.pixelRatio:c,f=t.align,g=void 0===f?re.align:f,y=t.colors,p=void 0===y?re.colors:y,x=t.colorScale,S=t.data,M=t.direction,z=void 0===M?re.direction:M,R=t.emptyColor,H=void 0===R?re.emptyColor:R,V=t.from,O=t.to,I=t.minValue,D=void 0===I?re.minValue:I,P=t.maxValue,B=void 0===P?re.maxValue:P,E=t.valueFormat,F=t.legendFormat,T=t.yearLegend,Y=void 0===T?re.yearLegend:T,j=t.yearLegendOffset,q=void 0===j?re.yearLegendOffset:j,A=t.yearLegendPosition,X=void 0===A?re.yearLegendPosition:A,N=t.yearSpacing,Z=void 0===N?re.yearSpacing:N,G=t.monthLegend,Q=void 0===G?re.monthLegend:G,U=t.monthLegendOffset,$=void 0===U?re.monthLegendOffset:U,_=t.monthLegendPosition,ee=void 0===_?re.monthLegendPosition:_,te=t.monthSpacing,oe=void 0===te?re.monthSpacing:te,ne=t.dayBorderColor,ie=void 0===ne?re.dayBorderColor:ne,ae=t.dayBorderWidth,de=void 0===ae?re.dayBorderWidth:ae,le=t.daySpacing,ce=void 0===le?re.daySpacing:le,he=t.isInteractive,ue=void 0===he?re.isInteractive:he,se=t.tooltip,fe=void 0===se?re.tooltip:se,be=t.onClick,xe=t.onMouseEnter,we=t.onMouseLeave,Se=t.onMouseMove,We=t.legends,Le=void 0===We?re.legends:We,ke=t.forwardedRef,Me=a(null),ze=u(i,r,n),Ce=ze.innerWidth,Re=ze.innerHeight,He=ze.outerWidth,Ve=ze.outerHeight,Oe=ze.margin,Ie=ge({width:Ce,height:Re,from:V,to:O,direction:z,yearSpacing:Z,monthSpacing:oe,daySpacing:ce,align:g}),De=Ie.months,Pe=Ie.years,Be=K(Ie,je),Ee=ve({data:S,minValue:D,maxValue:B,colors:p,colorScale:x}),Fe=ye({months:De,direction:z,monthLegendPosition:ee,monthLegendOffset:$}),Te=me({years:Pe,direction:z,yearLegendPosition:X,yearLegendOffset:q}),Ye=pe({days:Be.days,data:S,colorScale:Ee,emptyColor:H}),qe=d(null),Xe=qe[0],Ne=qe[1],Ze=b(),Ge=s(E),Je=s(F),Ke=C(),Qe=Ke.showTooltipFromEvent,Ue=Ke.hideTooltip;l((function(){if(Me.current){Me.current.width=He*h,Me.current.height=Ve*h;var e=Me.current.getContext("2d");e&&(e.scale(h,h),e.fillStyle=Ze.background,e.fillRect(0,0,He,Ve),e.translate(Oe.left,Oe.top),Ye.forEach((function(t){e.fillStyle=t.color,de>0&&(e.strokeStyle=ie,e.lineWidth=de),e.beginPath(),e.rect(t.x,t.y,t.size,t.size),e.fill(),de>0&&e.stroke()})),e.textAlign="center",e.textBaseline="middle",W(e,Ze.labels.text),Fe.forEach((function(t){e.save(),e.translate(t.x,t.y),e.rotate(v(t.rotation)),L(e,Ze.labels.text,String(Q(t.year,t.month,t.date))),e.restore()})),Te.forEach((function(t){e.save(),e.translate(t.x,t.y),e.rotate(v(t.rotation)),L(e,Ze.labels.text,String(Y(t.year))),e.restore()})),Le.forEach((function(t){var o=Ee.ticks(t.itemCount).map((function(e){return{id:e,label:Je(e),color:Ee(e)}}));w(e,J({},t,{data:o,containerWidth:Ce,containerHeight:Re,theme:Ze}))})))}}),[Me,Re,Ce,He,Ve,h,Oe,Ye,ie,de,x,Y,Te,Q,Fe,Le,Ze,Je,Ee]);var $e=o((function(t){if(Me.current){var o=Ae(t,Me.current,Ye,Ye[0].size,de,Oe);if(o){if(Ne(o),!("value"in o))return;var n=J({},o,{value:Ge(o.value),data:J({},o.data)});Qe(e.createElement(fe,J({},n)),t),Xe||null==xe||xe(o,t),null==Se||Se(o,t),Xe&&(null==we||we(o,t))}else Ue(),o&&(null==we||we(o,t))}}),[Me,Xe,Oe,Ye,Ne,Ge,de,Qe,Ue,xe,Se,we,fe]),_e=o((function(){Ne(null),Ue()}),[Ne,Ue]),et=o((function(e){if(be&&Me.current){var t=Ae(e,Me.current,Ye,Ye[0].size,ce,Oe);t&&be(t,e)}}),[Me,ce,Oe,Ye,be]);return k("canvas",{ref:m(Me,ke),width:He*h,height:Ve*h,style:{width:He,height:Ve},onMouseEnter:ue?$e:void 0,onMouseMove:ue?$e:void 0,onMouseLeave:ue?_e:void 0,onClick:ue?et:void 0})})),Ne=i((function(e,t){var o=e.isInteractive,n=void 0===o?re.isInteractive:o,i=e.renderWrapper,r=e.theme,a=K(e,qe);return k(h,{isInteractive:n,renderWrapper:i,theme:r,children:k(Xe,J({isInteractive:n},a,{forwardedRef:t}))})})),Ze=["defaultWidth","defaultHeight","onResize","debounceResize"],Ge=i((function(e,t){var o=e.defaultWidth,n=e.defaultHeight,i=e.onResize,r=e.debounceResize,a=K(e,Ze);return k(g,{defaultWidth:o,defaultHeight:n,onResize:i,debounceResize:r,children:function(e){var o=e.width,n=e.height;return k(Ne,J({width:o,height:n},a,{ref:t}))}})}));export{ke as ARRAY_OF_WEEKDAYS,Se as Calendar,Ne as CalendarCanvas,Ye as ResponsiveCalendar,Ge as ResponsiveCalendarCanvas,Fe as ResponsiveTimeRange,Be as TimeRange,ue as bindDaysData,re as calendarCanvasDefaultProps,ie as calendarDefaultProps,Re as computeCellPositions,Le as computeCellSize,de as computeDomain,he as computeLayout,fe as computeMonthLegendPositions,Ve as computeMonthLegends,Oe as computeTotalDays,He as computeWeekdays,se as computeYearLegendPositions,ze as getDayIndex,Me as getFirstWeekdayIndex,ae as timeRangeDefaultProps,ge as useCalendarLayout,ve as useColorScale,pe as useDays,ye as useMonthLegends,me as useYearLegends};
//# sourceMappingURL=nivo-calendar.mjs.map