@nivo/bullet
Version:
<a href="https://nivo.rocks"><img alt="nivo" src="https://raw.githubusercontent.com/plouc/nivo/master/nivo.png" width="216" height="68"/></a>
3 lines (2 loc) • 10.6 kB
JavaScript
"use strict";var e=require("@nivo/core"),r=require("@react-spring/web"),t=require("react/jsx-runtime"),o=require("@nivo/tooltip"),n=require("react"),i=require("@nivo/axes"),a=require("@nivo/colors"),u=require("@nivo/scales");function s(e){var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var l=s(n);function c(){return c=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},c.apply(this,arguments)}var h=function(e){var o=e.animatedProps,n=o.x,i=o.y,a=o.width,u=o.height,s=o.color,l=e.borderColor,c=e.borderWidth,h=e.data,m=e.onMouseEnter,d=e.onMouseMove,f=e.onMouseLeave,g=e.onClick;return t.jsx(r.animated.rect,{x:n,y:i,width:r.to(a,(function(e){return Math.max(e,0)})),height:r.to(u,(function(e){return Math.max(e,0)})),fill:s,strokeWidth:c,stroke:l,onMouseMove:function(e){return d(h,e)},onMouseEnter:function(e){return m(h,e)},onMouseLeave:function(e){return f(h,e)},onClick:function(e){return g(h,e)}})},m={layout:"horizontal",reverse:!1,spacing:30,minValue:0,maxValue:"auto",axisPosition:"after",titlePosition:"before",titleAlign:"middle",titleRotation:0,titleOffsetX:0,titleOffsetY:0,rangeComponent:h,rangeColors:"seq:cool",measureComponent:h,measureColors:"seq:red_purple",markers:[],markerComponent:function(e){var o=e.animatedProps,n=o.color,i=o.transform,a=o.x,u=o.y1,s=o.y2,l=e.data,c=e.onMouseEnter,h=e.onMouseMove,m=e.onMouseLeave,d=e.onClick;return t.jsx(r.animated.line,{transform:i,x1:a,x2:a,y1:u,y2:s,fill:"none",stroke:n,strokeWidth:"5",onMouseMove:function(e){return h(l,e)},onMouseEnter:function(e){return c(l,e)},onMouseLeave:function(e){return m(l,e)},onClick:function(e){return d(l,e)}})},markerColors:"seq:red_purple",rangeBorderWidth:0,rangeBorderColor:{from:"color"},measureSize:.4,measureBorderWidth:0,measureBorderColor:{from:"color"},markerSize:.6,isInteractive:!0,tooltip:function(e){var r=e.color,n=e.v0,i=e.v1;return t.jsx(o.BasicTooltip,{id:i?t.jsxs("span",{children:[t.jsx("strong",{children:n})," to ",t.jsx("strong",{children:i})]}):t.jsx("strong",{children:n}),enableChip:!0,color:r})},animate:e.motionDefaultProps.animate,motionConfig:e.motionDefaultProps.config,margin:e.defaultMargin,role:"img"},d=function(e,r,t,o,n){void 0===n&&(n=!1);var i=r.domain(),a=i[0],u=i[1];return[].concat(e,["measures"===o||e.includes(u)?0:u]).filter((function(e){return 0!==e})).sort((function(e,r){return e-r})).reduce((function(e,r,o){var i,u=e.slice(-1)[0],s=null!=(i=null==u?void 0:u.v1)?i:a,l=!0===n?s+(r-s)/2:r;return[].concat(e,[{index:o,v0:s,v1:r,color:t("sequential"===t.type?l:o)}])}),[])},f=["position"],g=function(o){var i=o.scale,a=o.layout,u=o.reverse,s=o.markers,h=o.height,m=o.markerSize,d=o.component,g=o.onMouseEnter,v=o.onMouseLeave,x=o.onClick,p=n.useMemo((function(){return function(e){var r=e.layout,t=e.reverse,o=e.scale,n=e.height,i=e.markerSize;return"horizontal"===r?function(e){return{x:o(e.value),y:n/2,size:i,rotation:!0===t?180:0}}:function(e){return{x:n/2,y:o(e.value),size:i,rotation:!0===t?270:90}}}({layout:a,reverse:u,scale:i,height:h,markerSize:m})}),[a,u,i,h,m]),y=e.useMotionConfig(),C=y.animate,M=y.config,k=r.useTransition(s.map((function(e){return c({},e,{position:p(e)})})),{keys:function(e){return""+e.index},enter:function(e){var r=e.color,t=e.position;return{color:r,transform:"rotate("+t.rotation+", "+t.x+", "+t.y+")",x:t.x,y1:t.y-t.size/2,y2:t.y+t.size/2}},update:function(e){var r=e.color,t=e.position;return{color:r,transform:"rotate("+t.rotation+", "+t.x+", "+t.y+")",x:t.x,y1:t.y-t.size/2,y2:t.y+t.size/2}},config:M,immediate:!C});return t.jsx(t.Fragment,{children:k((function(e,r){var t=r.position,o=function(e,r){if(null==e)return{};var t,o,n={},i=Object.keys(e);for(o=0;o<i.length;o++)t=i[o],r.indexOf(t)>=0||(n[t]=e[t]);return n}(r,f);return l.createElement(d,c({key:o.index},o,t,{animatedProps:e,data:o,onMouseEnter:g,onMouseMove:g,onMouseLeave:v,onClick:x}))}))})},v=function(o){var i=o.animatedProps,u=o.data,s=o.layout,l=o.y,h=o.borderColor,m=o.borderWidth,d=o.component,f=o.reverse,g=o.scale,v=o.height,x=o.onMouseEnter,p=o.onMouseLeave,y=o.onClick,C=n.useMemo((function(){return function(e){var r=e.data,t=function(e){var r=e.layout,t=e.reverse,o=e.scale,n=e.height;return"horizontal"===r?!0===t?function(e){var r=o(e.v1);return{x:r,y:0,width:o(e.v0)-r,height:n}}:function(e){var r=o(e.v0);return{x:r,y:0,width:o(e.v1)-r,height:n}}:!0===t?function(e){var r=o(e.v0),t=o(e.v1)-r;return{x:0,y:r,width:n,height:t}}:function(e){var r=o(e.v1),t=o(e.v0)-r;return{x:0,y:r,width:n,height:t}}}({layout:e.layout,reverse:e.reverse,scale:e.scale,height:e.height});return r.map((function(e){return c({data:e},t(e))}))}({data:u,layout:s,reverse:f,scale:g,height:v})}),[u,s,f,g,v]),M=e.useTheme(),k=a.useInheritedColor(h,M),j=function(e){return"translate("+("horizontal"===s?0:e)+","+("horizontal"===s?e:0)+")"},z=i?r.to(i.measuresY,j):j(l),b=e.useMotionConfig(),w=b.animate,B=b.config,P=r.useTransition(C,{keys:function(e){return""+e.data.index},enter:function(e){return{x:e.x,y:e.y,width:e.width,height:e.height,color:e.data.color}},update:function(e){return{x:e.x,y:e.y,width:e.width,height:e.height,color:e.data.color}},config:B,immediate:!w});return t.jsx(r.animated.g,{transform:z,children:P((function(e,t){return n.createElement(d,{key:t.data.index,index:t.data.index,animatedProps:e,data:t.data,x:e.x.get(),y:e.y.get(),borderColor:k(t.data),borderWidth:m,width:r.to(e.width,(function(e){return Math.max(e,0)})).get(),height:r.to(e.height,(function(e){return Math.max(e,0)})).get(),color:e.color.get(),onMouseEnter:x,onMouseMove:x,onMouseLeave:p,onClick:y})}))})},x=function(a){var u,s=a.id,l=a.scale,h=a.layout,m=a.reverse,f=a.axisPosition,x=a.x,p=a.y,y=a.width,C=a.height,M=a.title,k=void 0===M?s:M,j=a.titlePosition,z=a.titleAlign,b=a.titleOffsetX,w=a.titleOffsetY,B=a.titleRotation,P=a.tooltip,O=a.rangeBorderColor,W=a.rangeBorderWidth,E=a.rangeComponent,S=a.rangeColors,q=a.ranges,L=a.measureBorderColor,R=a.measureBorderWidth,T=a.measureComponent,V=a.measureHeight,A=a.measureColors,Y=a.measures,H=a.markerComponent,I=a.markerColors,D=a.markerHeight,X=a.markers,F=void 0===X?[]:X,_=a.onRangeClick,G=a.onMeasureClick,J=a.onMarkerClick,K=e.useTheme(),N=o.useTooltip(),Q=N.showTooltipFromEvent,U=N.hideTooltip,Z=n.useMemo((function(){var r=e.getColorScale(S,l,!0);return d(q,l,r,"range")}),[S,q,l]),$=n.useMemo((function(){var r=e.getColorScale(A,l);return d(Y,l,r,"measures")}),[A,Y,l]),ee=n.useMemo((function(){var r=e.getColorScale(I,l);return F.map((function(e,t){return{value:e,index:t,color:r("sequential"===r.type?e:t)}}))}),[I,F,l]),re=P,te=t.jsx(v,{data:Z,scale:l,layout:h,reverse:m,x:0,y:0,width:y,height:C,component:E,borderColor:O,borderWidth:W,onMouseEnter:function(e,r){Q(t.jsx(re,{color:e.color,v0:e.v0,v1:e.v1}),r)},onMouseLeave:U,onClick:function(e,r){null==_||_(c({id:s},e),r)}}),oe=t.jsx(g,{markers:ee,scale:l,layout:h,reverse:m,height:C,markerSize:D,component:H,onMouseEnter:function(e,r){Q(t.jsx(re,{color:e.color,v0:e.value}),r)},onMouseLeave:U,onClick:function(e,r){null==J||J(c({id:s},e),r)}}),ne="vertical"===h&&"after"===f?C:0,ie="horizontal"===h&&"after"===f?C:0,ae=t.jsx("g",{transform:"translate("+ne+","+ie+")",children:t.jsx(i.Axis,{axis:"horizontal"===h?"x":"y",length:"horizontal"===h?y:C,scale:l,ticksPosition:f})}),ue="horizontal"===h?"before"===j?b:y+b:C/2+b,se="horizontal"===h?C/2+w:"before"===j?w:y+w,le=t.jsx("g",{transform:"translate("+ue+","+se+") rotate("+B+")",children:"string"==typeof k?t.jsx("text",{style:c({},null==K||null==(u=K.labels)?void 0:u.text,{dominantBaseline:"central",textAnchor:z}),children:k}):k}),ce=e.useMotionConfig(),he=ce.animate,me=ce.config,de=r.useSpring({measuresY:(C-V)/2,transform:"translate("+x+","+p+")",config:me,immediate:!he});return t.jsxs(r.animated.g,{transform:de.transform,children:[te,t.jsx(v,{animatedProps:de,data:$,scale:l,layout:h,reverse:m,x:0,y:0,width:y,height:V,component:T,borderColor:L,borderWidth:R,onMouseEnter:function(e,r){Q(t.jsx(re,{color:e.color,v0:e.v1}),r)},onMouseLeave:U,onClick:function(e,r){null==G||G(c({id:s},e),r)}}),ae,oe,le]})},p=function(r){var o=c({},m,r),i=o.data,a=o.layout,s=o.spacing,l=o.measureSize,h=o.markerSize,d=o.reverse,f=o.axisPosition,g=o.minValue,v=o.maxValue,p=o.margin,y=o.width,C=o.height,M=o.titlePosition,k=o.titleAlign,j=o.titleOffsetX,z=o.titleOffsetY,b=o.titleRotation,w=o.rangeBorderColor,B=o.rangeBorderWidth,P=o.rangeComponent,O=o.rangeColors,W=o.measureBorderColor,E=o.measureBorderWidth,S=o.measureComponent,q=o.measureColors,L=o.markerComponent,R=o.markerColors,T=o.theme,V=o.tooltip,A=void 0===V?m.tooltip:V,Y=o.animate,H=o.motionConfig,I=o.isInteractive,D=o.onRangeClick,X=o.onMeasureClick,F=o.onMarkerClick,_=o.role,G=e.useDimensions(y,C,p),J=G.margin,K=G.innerWidth,N=G.innerHeight,Q="horizontal"===a?(N-s*(i.length-1))/i.length:(K-s*(i.length-1))/i.length,U=Q*l,Z=Q*h,$=function(e,r){var t=r.layout,o=r.maxValue,i=r.minValue,a=r.reverse,s=r.height,l=r.width;return n.useMemo((function(){return e.map((function(e){var r,n=[].concat(e.ranges,e.measures,null!=(r=e.markers)?r:[]),h=null!=o?o:Math.max.apply(Math,n),m=null!=i?i:Math.min.apply(Math,n);return c({},e,{scale:u.createLinearScale({clamp:!0,min:m,max:h,type:"linear"},{all:n,max:h,min:m},"horizontal"===t?l:s,"horizontal"===t?a?"y":"x":a?"x":"y")})}))}),[e,s,t,o,i,a,l])}(i,{height:N,layout:a,maxValue:"auto"===v?void 0:v,minValue:"auto"===g?void 0:g,reverse:d,width:K});return t.jsx(e.Container,{isInteractive:I,theme:T,animate:Y,motionConfig:H,children:t.jsx(e.SvgWrapper,{width:y,height:C,margin:J,role:_,children:$.map((function(e,r){return t.jsx(x,c({},e,{layout:a,reverse:d,x:"vertical"===a?Q*r+s*r:0,y:"horizontal"===a?Q*r+s*r:0,width:K,height:Q,titlePosition:M,titleAlign:k,titleOffsetX:j,titleOffsetY:z,titleRotation:b,measureHeight:U,markerHeight:Z,rangeBorderColor:w,rangeBorderWidth:B,rangeComponent:P,rangeColors:O,measureBorderColor:W,measureBorderWidth:E,measureComponent:S,measureColors:q,markerComponent:L,markerColors:R,axisPosition:f,onRangeClick:D,onMeasureClick:X,onMarkerClick:F,tooltip:A}),e.id)}))})})};exports.Bullet=p,exports.BulletItem=x,exports.ResponsiveBullet=function(r){return t.jsx(e.ResponsiveWrapper,{children:function(e){var o=e.width,n=e.height;return t.jsx(p,c({width:o,height:n},r))}})},exports.defaultProps=m;
//# sourceMappingURL=nivo-bullet.cjs.js.map