UNPKG

@nivo/polar-bar

Version:
3 lines (2 loc) 8.83 kB
"use strict";var e=require("react"),r=require("@nivo/core"),a=require("@nivo/legends"),n=require("@nivo/arcs"),i=require("@nivo/polar-axes"),o=require("@nivo/tooltip"),t=require("react/jsx-runtime"),l=require("d3-scale"),s=require("d3-shape"),d=require("@nivo/scales"),u=require("@nivo/colors");function c(){return c=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var n in a)({}).hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},c.apply(null,arguments)}function v(e,r){if(null==e)return{};var a={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==r.indexOf(n))continue;a[n]=e[n]}return a}var g={indexBy:"id",keys:["value"],adjustValueRange:!0,startAngle:0,endAngle:360,innerRadius:0,cornerRadius:0,layers:["grid","arcs","axes","labels","legends"],colors:{scheme:"nivo"},borderWidth:0,borderColor:{theme:"background"},enableArcLabels:!1,arcLabel:"formattedValue",arcLabelsSkipAngle:0,arcLabelsSkipRadius:0,arcLabelsRadiusOffset:.5,arcLabelsTextColor:{theme:"labels.text.fill"},enableRadialGrid:!0,enableCircularGrid:!0,radialAxis:null,circularAxisInner:null,circularAxisOuter:{},legends:[],isInteractive:!0,tooltip:function(e){var r=e.arc;return t.jsx(o.BasicTooltip,{enableChip:!0,id:t.jsxs("span",{children:[r.index," - ",r.key]}),value:r.formattedValue,color:r.color})},role:"img"},f=c({},g,{animate:!0,motionConfig:"gentle",transitionMode:"outerRadius"}),b=function(a){var n=a.data,i=a.indexBy,o=void 0===i?g.indexBy:i,t=a.keys,c=void 0===t?g.keys:t,v=a.valueSteps,f=a.adjustValueRange,b=void 0===f?g.adjustValueRange:f,p=a.valueFormat,h=a.width,m=a.height,R=a.startAngle,x=void 0===R?g.startAngle:R,A=a.endAngle,y=void 0===A?g.endAngle:A,L=a.innerRadius,M=void 0===L?g.innerRadius:L,C=a.cornerRadius,k=void 0===C?g.cornerRadius:C,j=a.colors,S=void 0===j?g.colors:j,w=a.forwardLegendData,W=r.usePropertyAccessor(o),B=e.useMemo((function(){return n.map(W)}),[n,W]),G=e.useMemo((function(){var e=s.stack().keys(c)(n),r=Math.max.apply(Math,e.flatMap((function(e){return e.map((function(e){return e[1]}))})));return[e,r]}),[n,c]),I=G[0],O=G[1],q=e.useMemo((function(){return[h/2,m/2]}),[h,m]),P=Math.min.apply(Math,q),T=P*Math.min(M,1),V=e.useMemo((function(){return d.castBandScale(l.scaleBand().domain(B).range([x,y]))}),[B,x,y]),D=e.useMemo((function(){var e=d.castLinearScale(l.scaleLinear().domain([0,O]).range([T,P]).clamp(!0));return b&&e.nice("number"==typeof v?v:void 0),e}),[T,P,O,b,v]),E=r.useValueFormatter(p),F=u.useOrdinalColorScale(S,"key"),z=e.useMemo((function(){return I.map((function(e){var a=e.key;return e.map((function(e,n){var i,o=B[n],t=e.data[a],l=r.degreesToRadians(null!=(i=V(o))?i:0),s={index:o,key:a,id:o+"."+a,value:t,formattedValue:E(t),color:"",arc:{startAngle:l,endAngle:l+r.degreesToRadians(V.bandwidth()),innerRadius:D(e[0]),outerRadius:D(e[1])}};return s.color=F(s),s}))})).flat()}),[B,I,V,D,E,F]),H=e.useMemo((function(){return s.arc().startAngle((function(e){return e.startAngle})).endAngle((function(e){return e.endAngle})).innerRadius((function(e){return e.innerRadius})).outerRadius((function(e){return e.outerRadius})).cornerRadius(k)}),[k]),J=e.useMemo((function(){return c.map((function(e){var r=z.find((function(r){return r.key===e})),a=r?r.color:"transparent";return{id:e,label:e,color:a}}))}),[c,z]),K=e.useRef(w);e.useEffect((function(){"function"==typeof K.current&&K.current(J)}),[K,J]);var N=e.useMemo((function(){return{center:q,innerRadius:T,outerRadius:P,arcs:z,arcGenerator:H,radiusScale:D,angleScale:V}}),[q,T,P,z,H,D,V]);return{center:q,innerRadius:T,outerRadius:P,angleScale:V,radiusScale:D,arcGenerator:H,arcs:z,legendData:J,customLayerProps:N}},p=function(r){var a=r.center,i=r.arcs,l=r.borderWidth,s=r.borderColor,d=r.arcGenerator,u=r.isInteractive,c=r.tooltip,v=r.onClick,g=r.onMouseEnter,f=r.onMouseMove,b=r.onMouseLeave,p=r.transitionMode,h=o.useTooltip(),m=h.showTooltipFromEvent,R=h.hideTooltip,x=e.useCallback((function(e,r){null==v||v(e,r)}),[v]),A=e.useCallback((function(r,a){m(e.createElement(c,{arc:r}),a),null==g||g(r,a)}),[m,c,g]),y=e.useCallback((function(r,a){m(e.createElement(c,{arc:r}),a),null==f||f(r,a)}),[m,c,f]),L=e.useCallback((function(e,r){R(),null==b||b(e,r)}),[R,b]);return t.jsx(n.ArcsLayer,{center:a,data:i,arcGenerator:d,borderWidth:l,borderColor:s,transitionMode:p,onClick:u?x:void 0,onMouseEnter:u?A:void 0,onMouseMove:u?y:void 0,onMouseLeave:u?L:void 0})},h=["isInteractive","animate","motionConfig","theme","renderWrapper"],m=function(o){var l=o.data,s=o.indexBy,d=void 0===s?f.indexBy:s,u=o.keys,v=void 0===u?f.keys:u,g=o.valueSteps,h=o.adjustValueRange,m=void 0===h?f.adjustValueRange:h,R=o.valueFormat,x=o.layers,A=void 0===x?f.layers:x,y=o.width,L=o.height,M=o.margin,C=o.startAngle,k=void 0===C?f.startAngle:C,j=o.endAngle,S=void 0===j?f.endAngle:j,w=o.innerRadius,W=void 0===w?f.innerRadius:w,B=o.cornerRadius,G=void 0===B?f.cornerRadius:B,I=o.colors,O=void 0===I?f.colors:I,q=o.borderWidth,P=void 0===q?f.borderWidth:q,T=o.borderColor,V=void 0===T?f.borderColor:T,D=o.enableArcLabels,E=void 0===D?f.enableArcLabels:D,F=o.arcLabel,z=void 0===F?f.arcLabel:F,H=o.arcLabelsSkipAngle,J=void 0===H?f.arcLabelsSkipAngle:H,K=o.arcLabelsSkipRadius,N=void 0===K?f.arcLabelsSkipRadius:K,Q=o.arcLabelsTextColor,U=void 0===Q?f.arcLabelsTextColor:Q,X=o.arcLabelsRadiusOffset,Y=void 0===X?f.arcLabelsRadiusOffset:X,Z=o.arcLabelsComponent,$=o.enableRadialGrid,_=void 0===$?f.enableRadialGrid:$,ee=o.enableCircularGrid,re=void 0===ee?f.enableCircularGrid:ee,ae=o.radialAxis,ne=void 0===ae?f.radialAxis:ae,ie=o.circularAxisInner,oe=void 0===ie?f.circularAxisInner:ie,te=o.circularAxisOuter,le=void 0===te?f.circularAxisOuter:te,se=o.legends,de=void 0===se?f.legends:se,ue=o.forwardLegendData,ce=o.isInteractive,ve=void 0===ce?f.isInteractive:ce,ge=o.tooltip,fe=void 0===ge?f.tooltip:ge,be=o.onClick,pe=o.onMouseEnter,he=o.onMouseMove,me=o.onMouseLeave,Re=o.transitionMode,xe=void 0===Re?f.transitionMode:Re,Ae=o.role,ye=void 0===Ae?f.role:Ae,Le=o.ariaLabel,Me=o.ariaLabelledBy,Ce=o.ariaDescribedBy,ke=o.forwardedRef,je=r.useDimensions(y,L,M),Se=je.innerWidth,we=je.innerHeight,We=je.outerWidth,Be=je.outerHeight,Ge=je.margin,Ie=b({data:l,indexBy:d,keys:v,valueSteps:g,adjustValueRange:m,valueFormat:R,width:Se,height:we,startAngle:k,endAngle:S,innerRadius:W,cornerRadius:G,colors:O,forwardLegendData:ue}),Oe=Ie.center,qe=Ie.innerRadius,Pe=Ie.outerRadius,Te=Ie.angleScale,Ve=Ie.radiusScale,De=Ie.arcGenerator,Ee=Ie.arcs,Fe=Ie.legendData,ze=Ie.customLayerProps,He={grid:null,arcs:null,axes:null,labels:null,legends:null};return A.includes("grid")&&(He.grid=t.jsx(i.PolarGrid,{center:Oe,enableRadialGrid:_,angleScale:Te,startAngle:k,endAngle:S,enableCircularGrid:re,radiusScale:Ve,circularGridTicks:g},"grid")),A.includes("arcs")&&(He.arcs=t.jsx(p,{arcs:Ee,center:Oe,arcGenerator:De,isInteractive:ve,borderColor:V,borderWidth:P,tooltip:fe,onClick:be,onMouseEnter:pe,onMouseMove:he,onMouseLeave:me,transitionMode:xe},"arcs")),A.includes("axes")&&(He.axes=t.jsxs(e.Fragment,{children:[oe&&qe>0&&t.jsx(i.CircularAxis,c({type:"inner",center:Oe,radius:qe,startAngle:k,endAngle:S,scale:Te},oe)),le&&t.jsx(i.CircularAxis,c({type:"outer",center:Oe,radius:Pe,startAngle:k,endAngle:S,scale:Te},le)),ne&&t.jsx(i.RadialAxis,c({center:Oe,scale:Ve,ticks:g},ne))]},"axes")),E&&A.includes("labels")&&(He.labels=t.jsx(n.ArcLabelsLayer,{center:Oe,data:Ee,label:z,radiusOffset:Y,skipAngle:J,skipRadius:N,textColor:U,transitionMode:xe,component:Z},"labels")),A.includes("legends")&&de.length>0&&(He.legends=t.jsx(e.Fragment,{children:de.map((function(e,r){return t.jsx(a.BoxLegendSvg,c({},e,{containerWidth:Se,containerHeight:we,data:Fe}),r)}))},"legends")),t.jsx(r.SvgWrapper,{width:We,height:Be,margin:Ge,role:ye,ariaLabel:Le,ariaLabelledBy:Me,ariaDescribedBy:Ce,ref:ke,children:A.map((function(r,a){var n;return"function"==typeof r?t.jsx(e.Fragment,{children:e.createElement(r,ze)},a):null!=(n=null==He?void 0:He[r])?n:null}))})},R=e.forwardRef((function(e,a){var n=e.isInteractive,i=void 0===n?f.isInteractive:n,o=e.animate,l=void 0===o?f.animate:o,s=e.motionConfig,d=void 0===s?f.motionConfig:s,u=e.theme,g=e.renderWrapper,b=v(e,h);return t.jsx(r.Container,{animate:l,isInteractive:i,motionConfig:d,renderWrapper:g,theme:u,children:t.jsx(m,c({isInteractive:i},b,{forwardedRef:a}))})})),x=["defaultWidth","defaultHeight","onResize","debounceResize"],A=e.forwardRef((function(e,a){var n=e.defaultWidth,i=e.defaultHeight,o=e.onResize,l=e.debounceResize,s=v(e,x);return t.jsx(r.ResponsiveWrapper,{defaultWidth:n,defaultHeight:i,onResize:o,debounceResize:l,children:function(e){var r=e.width,n=e.height;return t.jsx(R,c({width:r,height:n},s,{ref:a}))}})}));exports.PolarBar=R,exports.ResponsivePolarBar=A,exports.defaultProps=g,exports.svgDefaultProps=f; //# sourceMappingURL=nivo-polar-bar.cjs.js.map