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