UNPKG

@nivo/calendar

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