@nivo/annotations
Advanced tools
Comparing version 0.82.1 to 0.83.0
@@ -1,2 +0,2 @@ | ||
"use strict";var t=require("react"),n=require("lodash"),e=require("@nivo/core"),i=require("lodash/omit"),o=require("@react-spring/web"),a=require("react/jsx-runtime");function s(){return s=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},s.apply(this,arguments)}var r={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},u=function(n){var e=typeof n;return t.isValidElement(n)||"string"===e||"function"===e||"object"===e},l=function(t){var n=typeof t;return"string"===n||"function"===n},h=function(t){return"circle"===t.type},d=function(t){return"dot"===t.type},c=function(t){return"rect"===t.type},x=function(t){var e=t.data,i=t.annotations,o=t.getPosition,a=t.getDimensions;return i.reduce((function(t,i){var r=i.offset||0;return[].concat(t,n.filter(e,i.match).map((function(t){var e=o(t),u=a(t);return(h(i)||c(i))&&(u.size=u.size+2*r,u.width=u.width+2*r,u.height=u.height+2*r),s({},n.omit(i,["match","offset"]),e,u,{size:i.size||u.size,datum:t})})))}),[])},f=function(t,n,i,o){var a=Math.atan2(o-n,i-t);return e.absoluteAngleDegrees(e.radiansToDegrees(a))},m=function(t){var i,o,a=t.x,s=t.y,u=t.noteX,l=t.noteY,d=t.noteWidth,x=void 0===d?r.noteWidth:d,m=t.noteTextOffset,y=void 0===m?r.noteTextOffset:m;if(n.isNumber(u))i=a+u;else{if(void 0===u.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");i=u.abs}if(n.isNumber(l))o=s+l;else{if(void 0===l.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");o=l.abs}var g=a,p=s,k=f(a,s,i,o);if(h(t)){var W=e.positionFromAngle(e.degreesToRadians(k),t.size/2);g+=W.x,p+=W.y}if(c(t)){var v=Math.round((k+90)/45)%8;0===v&&(p-=t.height/2),1===v&&(g+=t.width/2,p-=t.height/2),2===v&&(g+=t.width/2),3===v&&(g+=t.width/2,p+=t.height/2),4===v&&(p+=t.height/2),5===v&&(g-=t.width/2,p+=t.height/2),6===v&&(g-=t.width/2),7===v&&(g-=t.width/2,p-=t.height/2)}var b=i,w=i;return(k+90)%360>180?(b-=x,w-=x):w+=x,{points:[[g,p],[i,o],[w,o]],text:[b,o-y],angle:k+90}},y=function(n){return t.useMemo((function(){return m(n)}),[n])},g=function(n){var r=n.datum,u=n.x,l=n.y,h=n.note,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:u,y:l,config:f,immediate:!x});return"function"==typeof h?t.createElement(h,{x:u,y:l,datum:r}):a.jsxs(a.Fragment,{children:[d.annotations.text.outlineWidth>0&&a.jsx(o.animated.text,{x:m.x,y:m.y,style:s({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:h}),a.jsx(o.animated.text,{x:m.x,y:m.y,style:i(d.annotations.text,["outlineWidth","outlineColor"]),children:h})]})},p=function(n){var i=n.points,r=n.isOutline,u=void 0!==r&&r,l=e.useTheme(),h=t.useMemo((function(){var t=i[0];return i.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[i]),d=e.useAnimatedPath(h);if(u&&l.annotations.link.outlineWidth<=0)return null;var c=s({},l.annotations.link);return u&&(c.strokeLinecap="square",c.strokeWidth=l.annotations.link.strokeWidth+2*l.annotations.link.outlineWidth,c.stroke=l.annotations.link.outlineColor,c.opacity=l.annotations.link.outlineOpacity),a.jsx(o.animated.path,{fill:"none",d:d,style:c})},k=function(t){var n=t.x,i=t.y,r=t.size,u=e.useTheme(),l=e.useMotionConfig(),h=l.animate,d=l.config,c=o.useSpring({x:n,y:i,radius:r/2,config:d,immediate:!h});return a.jsxs(a.Fragment,{children:[u.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:s({},u.annotations.outline,{fill:"none",strokeWidth:u.annotations.outline.strokeWidth+2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:u.annotations.outline})]})},W=function(t){var n=t.x,i=t.y,u=t.size,l=void 0===u?r.dotSize:u,h=e.useTheme(),d=e.useMotionConfig(),c=d.animate,x=d.config,f=o.useSpring({x:n,y:i,radius:l/2,config:x,immediate:!c});return a.jsxs(a.Fragment,{children:[h.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:s({},h.annotations.outline,{fill:"none",strokeWidth:2*h.annotations.outline.outlineWidth,stroke:h.annotations.outline.outlineColor,opacity:h.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:h.annotations.symbol})]})},v=function(t){var n=t.x,i=t.y,r=t.width,u=t.height,l=t.borderRadius,h=void 0===l?6:l,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:n-r/2,y:i-u/2,width:r,height:u,config:f,immediate:!x});return a.jsxs(a.Fragment,{children:[d.annotations.outline.outlineWidth>0&&a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:s({},d.annotations.outline,{fill:"none",strokeWidth:d.annotations.outline.strokeWidth+2*d.annotations.outline.outlineWidth,stroke:d.annotations.outline.outlineColor,opacity:d.annotations.outline.outlineOpacity})}),a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:d.annotations.outline})]})},b=function(t,n){n.forEach((function(n,e){var i=n[0],o=n[1];0===e?t.moveTo(i,o):t.lineTo(i,o)}))};exports.Annotation=function(t){var n=t.datum,e=t.x,i=t.y,o=t.note,s=y(t);if(!u(o))throw new Error("note should be a valid react element");return a.jsxs(a.Fragment,{children:[a.jsx(p,{points:s.points,isOutline:!0}),h(t)&&a.jsx(k,{x:e,y:i,size:t.size}),d(t)&&a.jsx(W,{x:e,y:i,size:t.size}),c(t)&&a.jsx(v,{x:e,y:i,width:t.width,height:t.height,borderRadius:t.borderRadius}),a.jsx(p,{points:s.points}),a.jsx(g,{datum:n,x:s.text[0],y:s.text[1],note:o})]})},exports.bindAnnotations=x,exports.computeAnnotation=m,exports.defaultProps=r,exports.getLinkAngle=f,exports.isCanvasNote=l,exports.isCircleAnnotation=h,exports.isDotAnnotation=d,exports.isRectAnnotation=c,exports.isSvgNote=u,exports.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,i=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!l(n.note))throw new Error("note is invalid for canvas implementation");i.annotations.link.outlineWidth>0&&(t.lineCap="square",t.strokeStyle=i.annotations.link.outlineColor,t.lineWidth=i.annotations.link.strokeWidth+2*i.annotations.link.outlineWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),t.lineCap="butt"),h(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&i.annotations.symbol.outlineWidth>0&&(t.strokeStyle=i.annotations.symbol.outlineColor,t.lineWidth=2*i.annotations.symbol.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),c(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),t.strokeStyle=i.annotations.link.stroke,t.lineWidth=i.annotations.link.strokeWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),h(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&(t.fillStyle=i.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),c(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),"function"==typeof n.note?n.note(t,{datum:n.datum,x:n.computed.text[0],y:n.computed.text[1],theme:i}):(t.font=i.annotations.text.fontSize+"px "+i.annotations.text.fontFamily,t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle=i.annotations.text.fill,t.strokeStyle=i.annotations.text.outlineColor,t.lineWidth=2*i.annotations.text.outlineWidth,i.annotations.text.outlineWidth>0&&(t.lineJoin="round",t.strokeText(n.note,n.computed.text[0],n.computed.text[1]),t.lineJoin="miter"),t.fillText(n.note,n.computed.text[0],n.computed.text[1]))})),t.restore())},exports.useAnnotations=function(n){var e=n.data,i=n.annotations,o=n.getPosition,a=n.getDimensions;return t.useMemo((function(){return x({data:e,annotations:i,getPosition:o,getDimensions:a})}),[e,i,o,a])},exports.useComputedAnnotation=y,exports.useComputedAnnotations=function(n){var e=n.annotations;return t.useMemo((function(){return e.map((function(t){return s({},t,{computed:m(s({},t))})}))}),[e])}; | ||
"use strict";var t=require("react"),n=require("lodash"),e=require("@nivo/core"),i=require("lodash/omit"),o=require("@react-spring/web"),a=require("react/jsx-runtime");function s(){return s=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},s.apply(this,arguments)}var r={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0},u=function(n){var e=typeof n;return t.isValidElement(n)||"string"===e||"function"===e||"object"===e},l=function(t){var n=typeof t;return"string"===n||"function"===n},h=function(t){return"circle"===t.type},d=function(t){return"dot"===t.type},c=function(t){return"rect"===t.type},x=function(t){var e=t.data,i=t.annotations,o=t.getPosition,a=t.getDimensions;return i.reduce((function(t,i){var r=i.offset||0;return[].concat(t,n.filter(e,i.match).map((function(t){var e=o(t),u=a(t);return(h(i)||c(i))&&(u.size=u.size+2*r,u.width=u.width+2*r,u.height=u.height+2*r),s({},n.omit(i,["match","offset"]),e,u,{size:i.size||u.size,datum:t})})))}),[])},f=function(t,n,i,o){var a=Math.atan2(o-n,i-t);return e.absoluteAngleDegrees(e.radiansToDegrees(a))},m=function(t){var i,o,a=t.x,s=t.y,u=t.noteX,l=t.noteY,d=t.noteWidth,x=void 0===d?r.noteWidth:d,m=t.noteTextOffset,y=void 0===m?r.noteTextOffset:m;if(n.isNumber(u))i=a+u;else{if(void 0===u.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");i=u.abs}if(n.isNumber(l))o=s+l;else{if(void 0===l.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");o=l.abs}var g=a,p=s,k=f(a,s,i,o);if(h(t)){var W=e.positionFromAngle(e.degreesToRadians(k),t.size/2);g+=W.x,p+=W.y}if(c(t)){var v=Math.round((k+90)/45)%8;0===v&&(p-=t.height/2),1===v&&(g+=t.width/2,p-=t.height/2),2===v&&(g+=t.width/2),3===v&&(g+=t.width/2,p+=t.height/2),4===v&&(p+=t.height/2),5===v&&(g-=t.width/2,p+=t.height/2),6===v&&(g-=t.width/2),7===v&&(g-=t.width/2,p-=t.height/2)}var b=i,w=i;return(k+90)%360>180?(b-=x,w-=x):w+=x,{points:[[g,p],[i,o],[w,o]],text:[b,o-y],angle:k+90}},y=function(n){return t.useMemo((function(){return m(n)}),[n])},g=function(n){var r=n.datum,u=n.x,l=n.y,h=n.note,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:u,y:l,config:f,immediate:!x});return"function"==typeof h?t.createElement(h,{x:u,y:l,datum:r}):a.jsxs(a.Fragment,{children:[d.annotations.text.outlineWidth>0&&a.jsx(o.animated.text,{x:m.x,y:m.y,style:s({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:h}),a.jsx(o.animated.text,{x:m.x,y:m.y,style:i(d.annotations.text,["outlineWidth","outlineColor"]),children:h})]})},p=function(n){var i=n.points,r=n.isOutline,u=void 0!==r&&r,l=e.useTheme(),h=t.useMemo((function(){var t=i[0];return i.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[i]),d=e.useAnimatedPath(h);if(u&&l.annotations.link.outlineWidth<=0)return null;var c=s({},l.annotations.link);return u&&(c.strokeLinecap="square",c.strokeWidth=l.annotations.link.strokeWidth+2*l.annotations.link.outlineWidth,c.stroke=l.annotations.link.outlineColor,c.opacity=l.annotations.link.outlineOpacity),a.jsx(o.animated.path,{fill:"none",d:d,style:c})},k=function(t){var n=t.x,i=t.y,r=t.size,u=e.useTheme(),l=e.useMotionConfig(),h=l.animate,d=l.config,c=o.useSpring({x:n,y:i,radius:r/2,config:d,immediate:!h});return a.jsxs(a.Fragment,{children:[u.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:s({},u.annotations.outline,{fill:"none",strokeWidth:u.annotations.outline.strokeWidth+2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:u.annotations.outline})]})},W=function(t){var n=t.x,i=t.y,u=t.size,l=void 0===u?r.dotSize:u,h=e.useTheme(),d=e.useMotionConfig(),c=d.animate,x=d.config,f=o.useSpring({x:n,y:i,radius:l/2,config:x,immediate:!c});return a.jsxs(a.Fragment,{children:[h.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:s({},h.annotations.outline,{fill:"none",strokeWidth:2*h.annotations.outline.outlineWidth,stroke:h.annotations.outline.outlineColor,opacity:h.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:h.annotations.symbol})]})},v=function(t){var n=t.x,i=t.y,r=t.width,u=t.height,l=t.borderRadius,h=void 0===l?6:l,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:n-r/2,y:i-u/2,width:r,height:u,config:f,immediate:!x});return a.jsxs(a.Fragment,{children:[d.annotations.outline.outlineWidth>0&&a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:s({},d.annotations.outline,{fill:"none",strokeWidth:d.annotations.outline.strokeWidth+2*d.annotations.outline.outlineWidth,stroke:d.annotations.outline.outlineColor,opacity:d.annotations.outline.outlineOpacity})}),a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:d.annotations.outline})]})},b=function(t,n){n.forEach((function(n,e){var i=n[0],o=n[1];0===e?t.moveTo(i,o):t.lineTo(i,o)}))};exports.Annotation=function(t){var n=t.datum,e=t.x,i=t.y,o=t.note,s=y(t);if(!u(o))throw new Error("note should be a valid react element");return a.jsxs(a.Fragment,{children:[a.jsx(p,{points:s.points,isOutline:!0}),h(t)&&a.jsx(k,{x:e,y:i,size:t.size}),d(t)&&a.jsx(W,{x:e,y:i,size:t.size}),c(t)&&a.jsx(v,{x:e,y:i,width:t.width,height:t.height,borderRadius:t.borderRadius}),a.jsx(p,{points:s.points}),a.jsx(g,{datum:n,x:s.text[0],y:s.text[1],note:o})]})},exports.bindAnnotations=x,exports.computeAnnotation=m,exports.defaultProps=r,exports.getLinkAngle=f,exports.isCanvasNote=l,exports.isCircleAnnotation=h,exports.isDotAnnotation=d,exports.isRectAnnotation=c,exports.isSvgNote=u,exports.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,i=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!l(n.note))throw new Error("note is invalid for canvas implementation");i.annotations.link.outlineWidth>0&&(t.lineCap="square",t.strokeStyle=i.annotations.link.outlineColor,t.lineWidth=i.annotations.link.strokeWidth+2*i.annotations.link.outlineWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),t.lineCap="butt"),h(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&i.annotations.symbol.outlineWidth>0&&(t.strokeStyle=i.annotations.symbol.outlineColor,t.lineWidth=2*i.annotations.symbol.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),c(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),t.strokeStyle=i.annotations.link.stroke,t.lineWidth=i.annotations.link.strokeWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),h(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&(t.fillStyle=i.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),c(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),"function"==typeof n.note?n.note(t,{datum:n.datum,x:n.computed.text[0],y:n.computed.text[1],theme:i}):(t.font=i.annotations.text.fontSize+"px "+i.annotations.text.fontFamily,t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle=i.annotations.text.fill,t.strokeStyle=i.annotations.text.outlineColor,t.lineWidth=2*i.annotations.text.outlineWidth,i.annotations.text.outlineWidth>0&&(t.lineJoin="round",t.strokeText(n.note,n.computed.text[0],n.computed.text[1]),t.lineJoin="miter"),t.fillText(n.note,n.computed.text[0],n.computed.text[1]))})),t.restore())},exports.useAnnotations=function(n){var e=n.data,i=n.annotations,o=n.getPosition,a=n.getDimensions;return t.useMemo((function(){return x({data:e,annotations:i,getPosition:o,getDimensions:a})}),[e,i,o,a])},exports.useComputedAnnotation=y,exports.useComputedAnnotations=function(n){var e=n.annotations;return t.useMemo((function(){return e.map((function(t){return s({},t,{computed:m(s({},t))})}))}),[e])}; | ||
//# sourceMappingURL=nivo-annotations.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var t=require("react"),n=require("lodash"),e=require("@nivo/core"),i=require("lodash/omit"),o=require("@react-spring/web"),a=require("react/jsx-runtime");function s(){return s=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},s.apply(this,arguments)}var r={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},u=function(n){var e=typeof n;return t.isValidElement(n)||"string"===e||"function"===e||"object"===e},l=function(t){var n=typeof t;return"string"===n||"function"===n},h=function(t){return"circle"===t.type},d=function(t){return"dot"===t.type},c=function(t){return"rect"===t.type},x=function(t){var e=t.data,i=t.annotations,o=t.getPosition,a=t.getDimensions;return i.reduce((function(t,i){var r=i.offset||0;return[].concat(t,n.filter(e,i.match).map((function(t){var e=o(t),u=a(t);return(h(i)||c(i))&&(u.size=u.size+2*r,u.width=u.width+2*r,u.height=u.height+2*r),s({},n.omit(i,["match","offset"]),e,u,{size:i.size||u.size,datum:t})})))}),[])},f=function(t,n,i,o){var a=Math.atan2(o-n,i-t);return e.absoluteAngleDegrees(e.radiansToDegrees(a))},m=function(t){var i,o,a=t.x,s=t.y,u=t.noteX,l=t.noteY,d=t.noteWidth,x=void 0===d?r.noteWidth:d,m=t.noteTextOffset,y=void 0===m?r.noteTextOffset:m;if(n.isNumber(u))i=a+u;else{if(void 0===u.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");i=u.abs}if(n.isNumber(l))o=s+l;else{if(void 0===l.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");o=l.abs}var g=a,p=s,k=f(a,s,i,o);if(h(t)){var W=e.positionFromAngle(e.degreesToRadians(k),t.size/2);g+=W.x,p+=W.y}if(c(t)){var v=Math.round((k+90)/45)%8;0===v&&(p-=t.height/2),1===v&&(g+=t.width/2,p-=t.height/2),2===v&&(g+=t.width/2),3===v&&(g+=t.width/2,p+=t.height/2),4===v&&(p+=t.height/2),5===v&&(g-=t.width/2,p+=t.height/2),6===v&&(g-=t.width/2),7===v&&(g-=t.width/2,p-=t.height/2)}var b=i,w=i;return(k+90)%360>180?(b-=x,w-=x):w+=x,{points:[[g,p],[i,o],[w,o]],text:[b,o-y],angle:k+90}},y=function(n){return t.useMemo((function(){return m(n)}),[n])},g=function(n){var r=n.datum,u=n.x,l=n.y,h=n.note,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:u,y:l,config:f,immediate:!x});return"function"==typeof h?t.createElement(h,{x:u,y:l,datum:r}):a.jsxs(a.Fragment,{children:[d.annotations.text.outlineWidth>0&&a.jsx(o.animated.text,{x:m.x,y:m.y,style:s({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:h}),a.jsx(o.animated.text,{x:m.x,y:m.y,style:i(d.annotations.text,["outlineWidth","outlineColor"]),children:h})]})},p=function(n){var i=n.points,r=n.isOutline,u=void 0!==r&&r,l=e.useTheme(),h=t.useMemo((function(){var t=i[0];return i.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[i]),d=e.useAnimatedPath(h);if(u&&l.annotations.link.outlineWidth<=0)return null;var c=s({},l.annotations.link);return u&&(c.strokeLinecap="square",c.strokeWidth=l.annotations.link.strokeWidth+2*l.annotations.link.outlineWidth,c.stroke=l.annotations.link.outlineColor,c.opacity=l.annotations.link.outlineOpacity),a.jsx(o.animated.path,{fill:"none",d:d,style:c})},k=function(t){var n=t.x,i=t.y,r=t.size,u=e.useTheme(),l=e.useMotionConfig(),h=l.animate,d=l.config,c=o.useSpring({x:n,y:i,radius:r/2,config:d,immediate:!h});return a.jsxs(a.Fragment,{children:[u.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:s({},u.annotations.outline,{fill:"none",strokeWidth:u.annotations.outline.strokeWidth+2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:u.annotations.outline})]})},W=function(t){var n=t.x,i=t.y,u=t.size,l=void 0===u?r.dotSize:u,h=e.useTheme(),d=e.useMotionConfig(),c=d.animate,x=d.config,f=o.useSpring({x:n,y:i,radius:l/2,config:x,immediate:!c});return a.jsxs(a.Fragment,{children:[h.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:s({},h.annotations.outline,{fill:"none",strokeWidth:2*h.annotations.outline.outlineWidth,stroke:h.annotations.outline.outlineColor,opacity:h.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:h.annotations.symbol})]})},v=function(t){var n=t.x,i=t.y,r=t.width,u=t.height,l=t.borderRadius,h=void 0===l?6:l,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:n-r/2,y:i-u/2,width:r,height:u,config:f,immediate:!x});return a.jsxs(a.Fragment,{children:[d.annotations.outline.outlineWidth>0&&a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:s({},d.annotations.outline,{fill:"none",strokeWidth:d.annotations.outline.strokeWidth+2*d.annotations.outline.outlineWidth,stroke:d.annotations.outline.outlineColor,opacity:d.annotations.outline.outlineOpacity})}),a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:d.annotations.outline})]})},b=function(t,n){n.forEach((function(n,e){var i=n[0],o=n[1];0===e?t.moveTo(i,o):t.lineTo(i,o)}))};exports.Annotation=function(t){var n=t.datum,e=t.x,i=t.y,o=t.note,s=y(t);if(!u(o))throw new Error("note should be a valid react element");return a.jsxs(a.Fragment,{children:[a.jsx(p,{points:s.points,isOutline:!0}),h(t)&&a.jsx(k,{x:e,y:i,size:t.size}),d(t)&&a.jsx(W,{x:e,y:i,size:t.size}),c(t)&&a.jsx(v,{x:e,y:i,width:t.width,height:t.height,borderRadius:t.borderRadius}),a.jsx(p,{points:s.points}),a.jsx(g,{datum:n,x:s.text[0],y:s.text[1],note:o})]})},exports.bindAnnotations=x,exports.computeAnnotation=m,exports.defaultProps=r,exports.getLinkAngle=f,exports.isCanvasNote=l,exports.isCircleAnnotation=h,exports.isDotAnnotation=d,exports.isRectAnnotation=c,exports.isSvgNote=u,exports.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,i=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!l(n.note))throw new Error("note is invalid for canvas implementation");i.annotations.link.outlineWidth>0&&(t.lineCap="square",t.strokeStyle=i.annotations.link.outlineColor,t.lineWidth=i.annotations.link.strokeWidth+2*i.annotations.link.outlineWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),t.lineCap="butt"),h(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&i.annotations.symbol.outlineWidth>0&&(t.strokeStyle=i.annotations.symbol.outlineColor,t.lineWidth=2*i.annotations.symbol.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),c(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),t.strokeStyle=i.annotations.link.stroke,t.lineWidth=i.annotations.link.strokeWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),h(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&(t.fillStyle=i.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),c(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),"function"==typeof n.note?n.note(t,{datum:n.datum,x:n.computed.text[0],y:n.computed.text[1],theme:i}):(t.font=i.annotations.text.fontSize+"px "+i.annotations.text.fontFamily,t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle=i.annotations.text.fill,t.strokeStyle=i.annotations.text.outlineColor,t.lineWidth=2*i.annotations.text.outlineWidth,i.annotations.text.outlineWidth>0&&(t.lineJoin="round",t.strokeText(n.note,n.computed.text[0],n.computed.text[1]),t.lineJoin="miter"),t.fillText(n.note,n.computed.text[0],n.computed.text[1]))})),t.restore())},exports.useAnnotations=function(n){var e=n.data,i=n.annotations,o=n.getPosition,a=n.getDimensions;return t.useMemo((function(){return x({data:e,annotations:i,getPosition:o,getDimensions:a})}),[e,i,o,a])},exports.useComputedAnnotation=y,exports.useComputedAnnotations=function(n){var e=n.annotations;return t.useMemo((function(){return e.map((function(t){return s({},t,{computed:m(s({},t))})}))}),[e])}; | ||
"use strict";var t=require("react"),n=require("lodash"),e=require("@nivo/core"),i=require("lodash/omit"),o=require("@react-spring/web"),a=require("react/jsx-runtime");function s(){return s=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},s.apply(this,arguments)}var r={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0},u=function(n){var e=typeof n;return t.isValidElement(n)||"string"===e||"function"===e||"object"===e},l=function(t){var n=typeof t;return"string"===n||"function"===n},h=function(t){return"circle"===t.type},d=function(t){return"dot"===t.type},c=function(t){return"rect"===t.type},x=function(t){var e=t.data,i=t.annotations,o=t.getPosition,a=t.getDimensions;return i.reduce((function(t,i){var r=i.offset||0;return[].concat(t,n.filter(e,i.match).map((function(t){var e=o(t),u=a(t);return(h(i)||c(i))&&(u.size=u.size+2*r,u.width=u.width+2*r,u.height=u.height+2*r),s({},n.omit(i,["match","offset"]),e,u,{size:i.size||u.size,datum:t})})))}),[])},f=function(t,n,i,o){var a=Math.atan2(o-n,i-t);return e.absoluteAngleDegrees(e.radiansToDegrees(a))},m=function(t){var i,o,a=t.x,s=t.y,u=t.noteX,l=t.noteY,d=t.noteWidth,x=void 0===d?r.noteWidth:d,m=t.noteTextOffset,y=void 0===m?r.noteTextOffset:m;if(n.isNumber(u))i=a+u;else{if(void 0===u.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");i=u.abs}if(n.isNumber(l))o=s+l;else{if(void 0===l.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");o=l.abs}var g=a,p=s,k=f(a,s,i,o);if(h(t)){var W=e.positionFromAngle(e.degreesToRadians(k),t.size/2);g+=W.x,p+=W.y}if(c(t)){var v=Math.round((k+90)/45)%8;0===v&&(p-=t.height/2),1===v&&(g+=t.width/2,p-=t.height/2),2===v&&(g+=t.width/2),3===v&&(g+=t.width/2,p+=t.height/2),4===v&&(p+=t.height/2),5===v&&(g-=t.width/2,p+=t.height/2),6===v&&(g-=t.width/2),7===v&&(g-=t.width/2,p-=t.height/2)}var b=i,w=i;return(k+90)%360>180?(b-=x,w-=x):w+=x,{points:[[g,p],[i,o],[w,o]],text:[b,o-y],angle:k+90}},y=function(n){return t.useMemo((function(){return m(n)}),[n])},g=function(n){var r=n.datum,u=n.x,l=n.y,h=n.note,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:u,y:l,config:f,immediate:!x});return"function"==typeof h?t.createElement(h,{x:u,y:l,datum:r}):a.jsxs(a.Fragment,{children:[d.annotations.text.outlineWidth>0&&a.jsx(o.animated.text,{x:m.x,y:m.y,style:s({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:h}),a.jsx(o.animated.text,{x:m.x,y:m.y,style:i(d.annotations.text,["outlineWidth","outlineColor"]),children:h})]})},p=function(n){var i=n.points,r=n.isOutline,u=void 0!==r&&r,l=e.useTheme(),h=t.useMemo((function(){var t=i[0];return i.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[i]),d=e.useAnimatedPath(h);if(u&&l.annotations.link.outlineWidth<=0)return null;var c=s({},l.annotations.link);return u&&(c.strokeLinecap="square",c.strokeWidth=l.annotations.link.strokeWidth+2*l.annotations.link.outlineWidth,c.stroke=l.annotations.link.outlineColor,c.opacity=l.annotations.link.outlineOpacity),a.jsx(o.animated.path,{fill:"none",d:d,style:c})},k=function(t){var n=t.x,i=t.y,r=t.size,u=e.useTheme(),l=e.useMotionConfig(),h=l.animate,d=l.config,c=o.useSpring({x:n,y:i,radius:r/2,config:d,immediate:!h});return a.jsxs(a.Fragment,{children:[u.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:s({},u.annotations.outline,{fill:"none",strokeWidth:u.annotations.outline.strokeWidth+2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:u.annotations.outline})]})},W=function(t){var n=t.x,i=t.y,u=t.size,l=void 0===u?r.dotSize:u,h=e.useTheme(),d=e.useMotionConfig(),c=d.animate,x=d.config,f=o.useSpring({x:n,y:i,radius:l/2,config:x,immediate:!c});return a.jsxs(a.Fragment,{children:[h.annotations.outline.outlineWidth>0&&a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:s({},h.annotations.outline,{fill:"none",strokeWidth:2*h.annotations.outline.outlineWidth,stroke:h.annotations.outline.outlineColor,opacity:h.annotations.outline.outlineOpacity})}),a.jsx(o.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:h.annotations.symbol})]})},v=function(t){var n=t.x,i=t.y,r=t.width,u=t.height,l=t.borderRadius,h=void 0===l?6:l,d=e.useTheme(),c=e.useMotionConfig(),x=c.animate,f=c.config,m=o.useSpring({x:n-r/2,y:i-u/2,width:r,height:u,config:f,immediate:!x});return a.jsxs(a.Fragment,{children:[d.annotations.outline.outlineWidth>0&&a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:s({},d.annotations.outline,{fill:"none",strokeWidth:d.annotations.outline.strokeWidth+2*d.annotations.outline.outlineWidth,stroke:d.annotations.outline.outlineColor,opacity:d.annotations.outline.outlineOpacity})}),a.jsx(o.animated.rect,{x:m.x,y:m.y,rx:h,ry:h,width:m.width,height:m.height,style:d.annotations.outline})]})},b=function(t,n){n.forEach((function(n,e){var i=n[0],o=n[1];0===e?t.moveTo(i,o):t.lineTo(i,o)}))};exports.Annotation=function(t){var n=t.datum,e=t.x,i=t.y,o=t.note,s=y(t);if(!u(o))throw new Error("note should be a valid react element");return a.jsxs(a.Fragment,{children:[a.jsx(p,{points:s.points,isOutline:!0}),h(t)&&a.jsx(k,{x:e,y:i,size:t.size}),d(t)&&a.jsx(W,{x:e,y:i,size:t.size}),c(t)&&a.jsx(v,{x:e,y:i,width:t.width,height:t.height,borderRadius:t.borderRadius}),a.jsx(p,{points:s.points}),a.jsx(g,{datum:n,x:s.text[0],y:s.text[1],note:o})]})},exports.bindAnnotations=x,exports.computeAnnotation=m,exports.defaultProps=r,exports.getLinkAngle=f,exports.isCanvasNote=l,exports.isCircleAnnotation=h,exports.isDotAnnotation=d,exports.isRectAnnotation=c,exports.isSvgNote=u,exports.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,i=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!l(n.note))throw new Error("note is invalid for canvas implementation");i.annotations.link.outlineWidth>0&&(t.lineCap="square",t.strokeStyle=i.annotations.link.outlineColor,t.lineWidth=i.annotations.link.strokeWidth+2*i.annotations.link.outlineWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),t.lineCap="butt"),h(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&i.annotations.symbol.outlineWidth>0&&(t.strokeStyle=i.annotations.symbol.outlineColor,t.lineWidth=2*i.annotations.symbol.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),c(n)&&i.annotations.outline.outlineWidth>0&&(t.strokeStyle=i.annotations.outline.outlineColor,t.lineWidth=i.annotations.outline.strokeWidth+2*i.annotations.outline.outlineWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),t.strokeStyle=i.annotations.link.stroke,t.lineWidth=i.annotations.link.strokeWidth,t.beginPath(),b(t,n.computed.points),t.stroke(),h(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),d(n)&&(t.fillStyle=i.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),c(n)&&(t.strokeStyle=i.annotations.outline.stroke,t.lineWidth=i.annotations.outline.strokeWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),"function"==typeof n.note?n.note(t,{datum:n.datum,x:n.computed.text[0],y:n.computed.text[1],theme:i}):(t.font=i.annotations.text.fontSize+"px "+i.annotations.text.fontFamily,t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle=i.annotations.text.fill,t.strokeStyle=i.annotations.text.outlineColor,t.lineWidth=2*i.annotations.text.outlineWidth,i.annotations.text.outlineWidth>0&&(t.lineJoin="round",t.strokeText(n.note,n.computed.text[0],n.computed.text[1]),t.lineJoin="miter"),t.fillText(n.note,n.computed.text[0],n.computed.text[1]))})),t.restore())},exports.useAnnotations=function(n){var e=n.data,i=n.annotations,o=n.getPosition,a=n.getDimensions;return t.useMemo((function(){return x({data:e,annotations:i,getPosition:o,getDimensions:a})}),[e,i,o,a])},exports.useComputedAnnotation=y,exports.useComputedAnnotations=function(n){var e=n.annotations;return t.useMemo((function(){return e.map((function(t){return s({},t,{computed:m(s({},t))})}))}),[e])}; | ||
//# sourceMappingURL=nivo-annotations.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
import{isValidElement as t,useMemo as n,createElement as i}from"react";import{filter as o,omit as e,isNumber as a}from"lodash";import{absoluteAngleDegrees as r,radiansToDegrees as s,positionFromAngle as l,degreesToRadians as u,useTheme as h,useMotionConfig as d,useAnimatedPath as c}from"@nivo/core";import f from"lodash/omit";import{useSpring as y,animated as x}from"@react-spring/web";import{jsxs as m,Fragment as p,jsx as g}from"react/jsx-runtime";function k(){return k=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},k.apply(this,arguments)}var W={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},v=function(n){var i=typeof n;return t(n)||"string"===i||"function"===i||"object"===i},b=function(t){var n=typeof t;return"string"===n||"function"===n},w=function(t){return"circle"===t.type},z=function(t){return"dot"===t.type},P=function(t){return"rect"===t.type},S=function(t){var n=t.data,i=t.annotations,a=t.getPosition,r=t.getDimensions;return i.reduce((function(t,i){var s=i.offset||0;return[].concat(t,o(n,i.match).map((function(t){var n=a(t),o=r(t);return(w(i)||P(i))&&(o.size=o.size+2*s,o.width=o.width+2*s,o.height=o.height+2*s),k({},e(i,["match","offset"]),n,o,{size:i.size||o.size,datum:t})})))}),[])},C=function(t,n,i,o){var e=Math.atan2(o-n,i-t);return r(s(e))},O=function(t){var n,i,o=t.x,e=t.y,r=t.noteX,s=t.noteY,h=t.noteWidth,d=void 0===h?W.noteWidth:h,c=t.noteTextOffset,f=void 0===c?W.noteTextOffset:c;if(a(r))n=o+r;else{if(void 0===r.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");n=r.abs}if(a(s))i=e+s;else{if(void 0===s.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");i=s.abs}var y=o,x=e,m=C(o,e,n,i);if(w(t)){var p=l(u(m),t.size/2);y+=p.x,x+=p.y}if(P(t)){var g=Math.round((m+90)/45)%8;0===g&&(x-=t.height/2),1===g&&(y+=t.width/2,x-=t.height/2),2===g&&(y+=t.width/2),3===g&&(y+=t.width/2,x+=t.height/2),4===g&&(x+=t.height/2),5===g&&(y-=t.width/2,x+=t.height/2),6===g&&(y-=t.width/2),7===g&&(y-=t.width/2,x-=t.height/2)}var k=n,v=n;return(m+90)%360>180?(k-=d,v-=d):v+=d,{points:[[y,x],[n,i],[v,i]],text:[k,i-f],angle:m+90}},j=function(t){var i=t.data,o=t.annotations,e=t.getPosition,a=t.getDimensions;return n((function(){return S({data:i,annotations:o,getPosition:e,getDimensions:a})}),[i,o,e,a])},M=function(t){var i=t.annotations;return n((function(){return i.map((function(t){return k({},t,{computed:O(k({},t))})}))}),[i])},T=function(t){return n((function(){return O(t)}),[t])},E=function(t){var n=t.datum,o=t.x,e=t.y,a=t.note,r=h(),s=d(),l=s.animate,u=s.config,c=y({x:o,y:e,config:u,immediate:!l});return"function"==typeof a?i(a,{x:o,y:e,datum:n}):m(p,{children:[r.annotations.text.outlineWidth>0&&g(x.text,{x:c.x,y:c.y,style:k({},r.annotations.text,{strokeLinejoin:"round",strokeWidth:2*r.annotations.text.outlineWidth,stroke:r.annotations.text.outlineColor}),children:a}),g(x.text,{x:c.x,y:c.y,style:f(r.annotations.text,["outlineWidth","outlineColor"]),children:a})]})},D=function(t){var i=t.points,o=t.isOutline,e=void 0!==o&&o,a=h(),r=n((function(){var t=i[0];return i.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[i]),s=c(r);if(e&&a.annotations.link.outlineWidth<=0)return null;var l=k({},a.annotations.link);return e&&(l.strokeLinecap="square",l.strokeWidth=a.annotations.link.strokeWidth+2*a.annotations.link.outlineWidth,l.stroke=a.annotations.link.outlineColor,l.opacity=a.annotations.link.outlineOpacity),g(x.path,{fill:"none",d:s,style:l})},I=function(t){var n=t.x,i=t.y,o=t.size,e=h(),a=d(),r=a.animate,s=a.config,l=y({x:n,y:i,radius:o/2,config:s,immediate:!r});return m(p,{children:[e.annotations.outline.outlineWidth>0&&g(x.circle,{cx:l.x,cy:l.y,r:l.radius,style:k({},e.annotations.outline,{fill:"none",strokeWidth:e.annotations.outline.strokeWidth+2*e.annotations.outline.outlineWidth,stroke:e.annotations.outline.outlineColor,opacity:e.annotations.outline.outlineOpacity})}),g(x.circle,{cx:l.x,cy:l.y,r:l.radius,style:e.annotations.outline})]})},L=function(t){var n=t.x,i=t.y,o=t.size,e=void 0===o?W.dotSize:o,a=h(),r=d(),s=r.animate,l=r.config,u=y({x:n,y:i,radius:e/2,config:l,immediate:!s});return m(p,{children:[a.annotations.outline.outlineWidth>0&&g(x.circle,{cx:u.x,cy:u.y,r:u.radius,style:k({},a.annotations.outline,{fill:"none",strokeWidth:2*a.annotations.outline.outlineWidth,stroke:a.annotations.outline.outlineColor,opacity:a.annotations.outline.outlineOpacity})}),g(x.circle,{cx:u.x,cy:u.y,r:u.radius,style:a.annotations.symbol})]})},R=function(t){var n=t.x,i=t.y,o=t.width,e=t.height,a=t.borderRadius,r=void 0===a?6:a,s=h(),l=d(),u=l.animate,c=l.config,f=y({x:n-o/2,y:i-e/2,width:o,height:e,config:c,immediate:!u});return m(p,{children:[s.annotations.outline.outlineWidth>0&&g(x.rect,{x:f.x,y:f.y,rx:r,ry:r,width:f.width,height:f.height,style:k({},s.annotations.outline,{fill:"none",strokeWidth:s.annotations.outline.strokeWidth+2*s.annotations.outline.outlineWidth,stroke:s.annotations.outline.outlineColor,opacity:s.annotations.outline.outlineOpacity})}),g(x.rect,{x:f.x,y:f.y,rx:r,ry:r,width:f.width,height:f.height,style:s.annotations.outline})]})},q=function(t){var n=t.datum,i=t.x,o=t.y,e=t.note,a=T(t);if(!v(e))throw new Error("note should be a valid react element");return m(p,{children:[g(D,{points:a.points,isOutline:!0}),w(t)&&g(I,{x:i,y:o,size:t.size}),z(t)&&g(L,{x:i,y:o,size:t.size}),P(t)&&g(R,{x:i,y:o,width:t.width,height:t.height,borderRadius:t.borderRadius}),g(D,{points:a.points}),g(E,{datum:n,x:a.text[0],y:a.text[1],note:e})]})},J=function(t,n){n.forEach((function(n,i){var o=n[0],e=n[1];0===i?t.moveTo(o,e):t.lineTo(o,e)}))},X=function(t,n){var i=n.annotations,o=n.theme;0!==i.length&&(t.save(),i.forEach((function(n){if(!b(n.note))throw new Error("note is invalid for canvas implementation");o.annotations.link.outlineWidth>0&&(t.lineCap="square",t.strokeStyle=o.annotations.link.outlineColor,t.lineWidth=o.annotations.link.strokeWidth+2*o.annotations.link.outlineWidth,t.beginPath(),J(t,n.computed.points),t.stroke(),t.lineCap="butt"),w(n)&&o.annotations.outline.outlineWidth>0&&(t.strokeStyle=o.annotations.outline.outlineColor,t.lineWidth=o.annotations.outline.strokeWidth+2*o.annotations.outline.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),z(n)&&o.annotations.symbol.outlineWidth>0&&(t.strokeStyle=o.annotations.symbol.outlineColor,t.lineWidth=2*o.annotations.symbol.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),P(n)&&o.annotations.outline.outlineWidth>0&&(t.strokeStyle=o.annotations.outline.outlineColor,t.lineWidth=o.annotations.outline.strokeWidth+2*o.annotations.outline.outlineWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),t.strokeStyle=o.annotations.link.stroke,t.lineWidth=o.annotations.link.strokeWidth,t.beginPath(),J(t,n.computed.points),t.stroke(),w(n)&&(t.strokeStyle=o.annotations.outline.stroke,t.lineWidth=o.annotations.outline.strokeWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),z(n)&&(t.fillStyle=o.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),P(n)&&(t.strokeStyle=o.annotations.outline.stroke,t.lineWidth=o.annotations.outline.strokeWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),"function"==typeof n.note?n.note(t,{datum:n.datum,x:n.computed.text[0],y:n.computed.text[1],theme:o}):(t.font=o.annotations.text.fontSize+"px "+o.annotations.text.fontFamily,t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle=o.annotations.text.fill,t.strokeStyle=o.annotations.text.outlineColor,t.lineWidth=2*o.annotations.text.outlineWidth,o.annotations.text.outlineWidth>0&&(t.lineJoin="round",t.strokeText(n.note,n.computed.text[0],n.computed.text[1]),t.lineJoin="miter"),t.fillText(n.note,n.computed.text[0],n.computed.text[1]))})),t.restore())};export{q as Annotation,S as bindAnnotations,O as computeAnnotation,W as defaultProps,C as getLinkAngle,b as isCanvasNote,w as isCircleAnnotation,z as isDotAnnotation,P as isRectAnnotation,v as isSvgNote,X as renderAnnotationsToCanvas,j as useAnnotations,T as useComputedAnnotation,M as useComputedAnnotations}; | ||
import{isValidElement as t,useMemo as n,createElement as i}from"react";import{filter as o,omit as e,isNumber as a}from"lodash";import{absoluteAngleDegrees as r,radiansToDegrees as s,positionFromAngle as l,degreesToRadians as u,useTheme as h,useMotionConfig as d,useAnimatedPath as c}from"@nivo/core";import f from"lodash/omit";import{useSpring as y,animated as x}from"@react-spring/web";import{jsxs as m,Fragment as p,jsx as g}from"react/jsx-runtime";function k(){return k=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},k.apply(this,arguments)}var W={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0},v=function(n){var i=typeof n;return t(n)||"string"===i||"function"===i||"object"===i},b=function(t){var n=typeof t;return"string"===n||"function"===n},w=function(t){return"circle"===t.type},z=function(t){return"dot"===t.type},P=function(t){return"rect"===t.type},C=function(t){var n=t.data,i=t.annotations,a=t.getPosition,r=t.getDimensions;return i.reduce((function(t,i){var s=i.offset||0;return[].concat(t,o(n,i.match).map((function(t){var n=a(t),o=r(t);return(w(i)||P(i))&&(o.size=o.size+2*s,o.width=o.width+2*s,o.height=o.height+2*s),k({},e(i,["match","offset"]),n,o,{size:i.size||o.size,datum:t})})))}),[])},O=function(t,n,i,o){var e=Math.atan2(o-n,i-t);return r(s(e))},S=function(t){var n,i,o=t.x,e=t.y,r=t.noteX,s=t.noteY,h=t.noteWidth,d=void 0===h?W.noteWidth:h,c=t.noteTextOffset,f=void 0===c?W.noteTextOffset:c;if(a(r))n=o+r;else{if(void 0===r.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");n=r.abs}if(a(s))i=e+s;else{if(void 0===s.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");i=s.abs}var y=o,x=e,m=O(o,e,n,i);if(w(t)){var p=l(u(m),t.size/2);y+=p.x,x+=p.y}if(P(t)){var g=Math.round((m+90)/45)%8;0===g&&(x-=t.height/2),1===g&&(y+=t.width/2,x-=t.height/2),2===g&&(y+=t.width/2),3===g&&(y+=t.width/2,x+=t.height/2),4===g&&(x+=t.height/2),5===g&&(y-=t.width/2,x+=t.height/2),6===g&&(y-=t.width/2),7===g&&(y-=t.width/2,x-=t.height/2)}var k=n,v=n;return(m+90)%360>180?(k-=d,v-=d):v+=d,{points:[[y,x],[n,i],[v,i]],text:[k,i-f],angle:m+90}},j=function(t){var i=t.data,o=t.annotations,e=t.getPosition,a=t.getDimensions;return n((function(){return C({data:i,annotations:o,getPosition:e,getDimensions:a})}),[i,o,e,a])},M=function(t){var i=t.annotations;return n((function(){return i.map((function(t){return k({},t,{computed:S(k({},t))})}))}),[i])},T=function(t){return n((function(){return S(t)}),[t])},E=function(t){var n=t.datum,o=t.x,e=t.y,a=t.note,r=h(),s=d(),l=s.animate,u=s.config,c=y({x:o,y:e,config:u,immediate:!l});return"function"==typeof a?i(a,{x:o,y:e,datum:n}):m(p,{children:[r.annotations.text.outlineWidth>0&&g(x.text,{x:c.x,y:c.y,style:k({},r.annotations.text,{strokeLinejoin:"round",strokeWidth:2*r.annotations.text.outlineWidth,stroke:r.annotations.text.outlineColor}),children:a}),g(x.text,{x:c.x,y:c.y,style:f(r.annotations.text,["outlineWidth","outlineColor"]),children:a})]})},I=function(t){var i=t.points,o=t.isOutline,e=void 0!==o&&o,a=h(),r=n((function(){var t=i[0];return i.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[i]),s=c(r);if(e&&a.annotations.link.outlineWidth<=0)return null;var l=k({},a.annotations.link);return e&&(l.strokeLinecap="square",l.strokeWidth=a.annotations.link.strokeWidth+2*a.annotations.link.outlineWidth,l.stroke=a.annotations.link.outlineColor,l.opacity=a.annotations.link.outlineOpacity),g(x.path,{fill:"none",d:s,style:l})},D=function(t){var n=t.x,i=t.y,o=t.size,e=h(),a=d(),r=a.animate,s=a.config,l=y({x:n,y:i,radius:o/2,config:s,immediate:!r});return m(p,{children:[e.annotations.outline.outlineWidth>0&&g(x.circle,{cx:l.x,cy:l.y,r:l.radius,style:k({},e.annotations.outline,{fill:"none",strokeWidth:e.annotations.outline.strokeWidth+2*e.annotations.outline.outlineWidth,stroke:e.annotations.outline.outlineColor,opacity:e.annotations.outline.outlineOpacity})}),g(x.circle,{cx:l.x,cy:l.y,r:l.radius,style:e.annotations.outline})]})},L=function(t){var n=t.x,i=t.y,o=t.size,e=void 0===o?W.dotSize:o,a=h(),r=d(),s=r.animate,l=r.config,u=y({x:n,y:i,radius:e/2,config:l,immediate:!s});return m(p,{children:[a.annotations.outline.outlineWidth>0&&g(x.circle,{cx:u.x,cy:u.y,r:u.radius,style:k({},a.annotations.outline,{fill:"none",strokeWidth:2*a.annotations.outline.outlineWidth,stroke:a.annotations.outline.outlineColor,opacity:a.annotations.outline.outlineOpacity})}),g(x.circle,{cx:u.x,cy:u.y,r:u.radius,style:a.annotations.symbol})]})},R=function(t){var n=t.x,i=t.y,o=t.width,e=t.height,a=t.borderRadius,r=void 0===a?6:a,s=h(),l=d(),u=l.animate,c=l.config,f=y({x:n-o/2,y:i-e/2,width:o,height:e,config:c,immediate:!u});return m(p,{children:[s.annotations.outline.outlineWidth>0&&g(x.rect,{x:f.x,y:f.y,rx:r,ry:r,width:f.width,height:f.height,style:k({},s.annotations.outline,{fill:"none",strokeWidth:s.annotations.outline.strokeWidth+2*s.annotations.outline.outlineWidth,stroke:s.annotations.outline.outlineColor,opacity:s.annotations.outline.outlineOpacity})}),g(x.rect,{x:f.x,y:f.y,rx:r,ry:r,width:f.width,height:f.height,style:s.annotations.outline})]})},q=function(t){var n=t.datum,i=t.x,o=t.y,e=t.note,a=T(t);if(!v(e))throw new Error("note should be a valid react element");return m(p,{children:[g(I,{points:a.points,isOutline:!0}),w(t)&&g(D,{x:i,y:o,size:t.size}),z(t)&&g(L,{x:i,y:o,size:t.size}),P(t)&&g(R,{x:i,y:o,width:t.width,height:t.height,borderRadius:t.borderRadius}),g(I,{points:a.points}),g(E,{datum:n,x:a.text[0],y:a.text[1],note:e})]})},J=function(t,n){n.forEach((function(n,i){var o=n[0],e=n[1];0===i?t.moveTo(o,e):t.lineTo(o,e)}))},X=function(t,n){var i=n.annotations,o=n.theme;0!==i.length&&(t.save(),i.forEach((function(n){if(!b(n.note))throw new Error("note is invalid for canvas implementation");o.annotations.link.outlineWidth>0&&(t.lineCap="square",t.strokeStyle=o.annotations.link.outlineColor,t.lineWidth=o.annotations.link.strokeWidth+2*o.annotations.link.outlineWidth,t.beginPath(),J(t,n.computed.points),t.stroke(),t.lineCap="butt"),w(n)&&o.annotations.outline.outlineWidth>0&&(t.strokeStyle=o.annotations.outline.outlineColor,t.lineWidth=o.annotations.outline.strokeWidth+2*o.annotations.outline.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),z(n)&&o.annotations.symbol.outlineWidth>0&&(t.strokeStyle=o.annotations.symbol.outlineColor,t.lineWidth=2*o.annotations.symbol.outlineWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),P(n)&&o.annotations.outline.outlineWidth>0&&(t.strokeStyle=o.annotations.outline.outlineColor,t.lineWidth=o.annotations.outline.strokeWidth+2*o.annotations.outline.outlineWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),t.strokeStyle=o.annotations.link.stroke,t.lineWidth=o.annotations.link.strokeWidth,t.beginPath(),J(t,n.computed.points),t.stroke(),w(n)&&(t.strokeStyle=o.annotations.outline.stroke,t.lineWidth=o.annotations.outline.strokeWidth,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),z(n)&&(t.fillStyle=o.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),P(n)&&(t.strokeStyle=o.annotations.outline.stroke,t.lineWidth=o.annotations.outline.strokeWidth,t.beginPath(),t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height),t.stroke()),"function"==typeof n.note?n.note(t,{datum:n.datum,x:n.computed.text[0],y:n.computed.text[1],theme:o}):(t.font=o.annotations.text.fontSize+"px "+o.annotations.text.fontFamily,t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle=o.annotations.text.fill,t.strokeStyle=o.annotations.text.outlineColor,t.lineWidth=2*o.annotations.text.outlineWidth,o.annotations.text.outlineWidth>0&&(t.lineJoin="round",t.strokeText(n.note,n.computed.text[0],n.computed.text[1]),t.lineJoin="miter"),t.fillText(n.note,n.computed.text[0],n.computed.text[1]))})),t.restore())};export{q as Annotation,C as bindAnnotations,S as computeAnnotation,W as defaultProps,O as getLinkAngle,b as isCanvasNote,w as isCircleAnnotation,z as isDotAnnotation,P as isRectAnnotation,v as isSvgNote,X as renderAnnotationsToCanvas,j as useAnnotations,T as useComputedAnnotation,M as useComputedAnnotations}; | ||
//# sourceMappingURL=nivo-annotations.es.js.map |
@@ -6,5 +6,3 @@ export declare const defaultProps: { | ||
animate: boolean; | ||
motionStiffness: number; | ||
motionDamping: number; | ||
}; | ||
//# sourceMappingURL=props.d.ts.map |
{ | ||
"name": "@nivo/annotations", | ||
"version": "0.82.1", | ||
"version": "0.83.0", | ||
"license": "MIT", | ||
@@ -31,3 +31,4 @@ "author": { | ||
"dependencies": { | ||
"@nivo/colors": "0.82.1", | ||
"@nivo/colors": "0.83.0", | ||
"@nivo/core": "0.83.0", | ||
"@react-spring/web": "9.4.5 || ^9.7.2", | ||
@@ -38,7 +39,3 @@ "@types/prop-types": "^15.7.2", | ||
}, | ||
"devDependencies": { | ||
"@nivo/core": "0.82.1" | ||
}, | ||
"peerDependencies": { | ||
"@nivo/core": "workspace:*", | ||
"react": ">= 16.14.0 < 19.0.0" | ||
@@ -49,3 +46,3 @@ }, | ||
}, | ||
"gitHead": "5aa364bb0a29e0bc41aba3f80394b1cf7e582297" | ||
"gitHead": "5ee7cba46ac12deb04095d6555c3d12bc358a211" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
113667
322
+ Added@nivo/core@0.83.0
+ Added@nivo/colors@0.83.0(transitive)
+ Added@nivo/core@0.83.0(transitive)
+ Added@nivo/recompose@0.83.0(transitive)
+ Added@nivo/tooltip@0.83.0(transitive)
+ Added@types/d3-path@2.0.4(transitive)
+ Added@types/d3-shape@2.1.7(transitive)
+ Added@types/react@18.3.12(transitive)
+ Added@types/react-lifecycles-compat@3.0.4(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedd3-format@1.4.5(transitive)
+ Addedd3-path@1.0.9(transitive)
+ Addedd3-shape@1.3.7(transitive)
+ Addedreact-lifecycles-compat@3.0.4(transitive)
- Removed@nivo/colors@0.82.1(transitive)
- Removedd3-format@2.0.0(transitive)
Updated@nivo/colors@0.83.0