@nivo/annotations
Advanced tools
Comparing version 0.78.0 to 0.79.0
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=require("lodash/omit"),e=require("lodash/isNumber"),o=require("lodash/filter"),i=require("@nivo/core"),a=require("@react-spring/web"),r=require("react/jsx-runtime");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var u=s(n),l=s(e),d=s(o);function h(){return h=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},h.apply(this,arguments)}var c={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},x=function(n){var e=typeof n;return t.isValidElement(n)||"string"===e||"function"===e||"object"===e},f=function(t){var n=typeof t;return"string"===n||"function"===n},y=function(t){return"circle"===t.type},m=function(t){return"dot"===t.type},p=function(t){return"rect"===t.type},g=function(t){var n=t.data,e=t.annotations,o=t.getPosition,i=t.getDimensions;return e.reduce((function(t,e){var a=e.offset||0;return[].concat(t,d.default(n,e.match).map((function(t){var n=o(t),r=i(t);return(y(e)||p(e))&&(r.size=r.size+2*a,r.width=r.width+2*a,r.height=r.height+2*a),h({},u.default(e,["match","offset"]),n,r,{size:e.size||r.size,datum:t})})))}),[])},k=function(t,n,e,o){var a=Math.atan2(o-n,e-t);return i.absoluteAngleDegrees(i.radiansToDegrees(a))},v=function(t){var n,e,o=t.x,a=t.y,r=t.noteX,s=t.noteY,u=t.noteWidth,d=void 0===u?c.noteWidth:u,h=t.noteTextOffset,x=void 0===h?c.noteTextOffset:h;if(l.default(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(l.default(s))e=a+s;else{if(void 0===s.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");e=s.abs}var f=o,m=a,g=k(o,a,n,e);if(y(t)){var v=i.positionFromAngle(i.degreesToRadians(g),t.size/2);f+=v.x,m+=v.y}if(p(t)){var W=Math.round((g+90)/45)%8;0===W&&(m-=t.height/2),1===W&&(f+=t.width/2,m-=t.height/2),2===W&&(f+=t.width/2),3===W&&(f+=t.width/2,m+=t.height/2),4===W&&(m+=t.height/2),5===W&&(f-=t.width/2,m+=t.height/2),6===W&&(f-=t.width/2),7===W&&(f-=t.width/2,m-=t.height/2)}var b=n,w=n;return(g+90)%360>180?(b-=d,w-=d):w+=d,{points:[[f,m],[n,e],[w,e]],text:[b,e-x],angle:g+90}},W=function(n){return t.useMemo((function(){return v(n)}),[n])},b=function(n){var e=n.datum,o=n.x,s=n.y,l=n.note,d=i.useTheme(),c=i.useMotionConfig(),x=c.animate,f=c.config,y=a.useSpring({x:o,y:s,config:f,immediate:!x});return"function"==typeof l?t.createElement(l,{x:o,y:s,datum:e}):r.jsxs(r.Fragment,{children:[d.annotations.text.outlineWidth>0&&r.jsx(a.animated.text,{x:y.x,y:y.y,style:h({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:l}),r.jsx(a.animated.text,{x:y.x,y:y.y,style:u.default(d.annotations.text,["outlineWidth","outlineColor"]),children:l})]})},w=function(n){var e=n.points,o=n.isOutline,s=void 0!==o&&o,u=i.useTheme(),l=t.useMemo((function(){var t=e[0];return e.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[e]),d=i.useAnimatedPath(l);if(s&&u.annotations.link.outlineWidth<=0)return null;var c=h({},u.annotations.link);return s&&(c.strokeLinecap="square",c.strokeWidth=u.annotations.link.strokeWidth+2*u.annotations.link.outlineWidth,c.stroke=u.annotations.link.outlineColor,c.opacity=u.annotations.link.outlineOpacity),r.jsx(a.animated.path,{fill:"none",d:d,style:c})},j=function(t){var n=t.x,e=t.y,o=t.size,s=i.useTheme(),u=i.useMotionConfig(),l=u.animate,d=u.config,c=a.useSpring({x:n,y:e,radius:o/2,config:d,immediate:!l});return r.jsxs(r.Fragment,{children:[s.annotations.outline.outlineWidth>0&&r.jsx(a.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:h({},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})}),r.jsx(a.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:s.annotations.outline})]})},C=function(t){var n=t.x,e=t.y,o=t.size,s=void 0===o?c.dotSize:o,u=i.useTheme(),l=i.useMotionConfig(),d=l.animate,x=l.config,f=a.useSpring({x:n,y:e,radius:s/2,config:x,immediate:!d});return r.jsxs(r.Fragment,{children:[u.annotations.outline.outlineWidth>0&&r.jsx(a.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:h({},u.annotations.outline,{fill:"none",strokeWidth:2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),r.jsx(a.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:u.annotations.symbol})]})},z=function(t){var n=t.x,e=t.y,o=t.width,s=t.height,u=t.borderRadius,l=void 0===u?6:u,d=i.useTheme(),c=i.useMotionConfig(),x=c.animate,f=c.config,y=a.useSpring({x:n-o/2,y:e-s/2,width:o,height:s,config:f,immediate:!x});return r.jsxs(r.Fragment,{children:[d.annotations.outline.outlineWidth>0&&r.jsx(a.animated.rect,{x:y.x,y:y.y,rx:l,ry:l,width:y.width,height:y.height,style:h({},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})}),r.jsx(a.animated.rect,{x:y.x,y:y.y,rx:l,ry:l,width:y.width,height:y.height,style:d.annotations.outline})]})},P=function(t,n){n.forEach((function(n,e){var o=n[0],i=n[1];0===e?t.moveTo(o,i):t.lineTo(o,i)}))};exports.Annotation=function(t){var n=t.datum,e=t.x,o=t.y,i=t.note,a=W(t);if(!x(i))throw new Error("note should be a valid react element");return r.jsxs(r.Fragment,{children:[r.jsx(w,{points:a.points,isOutline:!0}),y(t)&&r.jsx(j,{x:e,y:o,size:t.size}),m(t)&&r.jsx(C,{x:e,y:o,size:t.size}),p(t)&&r.jsx(z,{x:e,y:o,width:t.width,height:t.height,borderRadius:t.borderRadius}),r.jsx(w,{points:a.points}),r.jsx(b,{datum:n,x:a.text[0],y:a.text[1],note:i})]})},exports.bindAnnotations=g,exports.computeAnnotation=v,exports.defaultProps=c,exports.getLinkAngle=k,exports.isCanvasNote=f,exports.isCircleAnnotation=y,exports.isDotAnnotation=m,exports.isRectAnnotation=p,exports.isSvgNote=x,exports.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,o=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!f(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(),P(t,n.computed.points),t.stroke(),t.lineCap="butt"),y(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()),m(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(),P(t,n.computed.points),t.stroke(),y(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()),m(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.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())},exports.useAnnotations=function(n){var e=n.data,o=n.annotations,i=n.getPosition,a=n.getDimensions;return t.useMemo((function(){return g({data:e,annotations:o,getPosition:i,getDimensions:a})}),[e,o,i,a])},exports.useComputedAnnotation=W,exports.useComputedAnnotations=function(n){var e=n.annotations;return t.useMemo((function(){return e.map((function(t){return h({},t,{computed:v(h({},t))})}))}),[e])}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=require("lodash/omit"),e=require("lodash/isNumber"),o=require("lodash/filter"),i=require("@nivo/core"),a=require("@react-spring/web"),r=require("react/jsx-runtime");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var u=s(n),l=s(e),d=s(o);function h(){return h=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},h.apply(this,arguments)}var c={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},x=function(n){var e=typeof n;return t.isValidElement(n)||"string"===e||"function"===e||"object"===e},f=function(t){var n=typeof t;return"string"===n||"function"===n},y=function(t){return"circle"===t.type},m=function(t){return"dot"===t.type},p=function(t){return"rect"===t.type},g=function(t){var n=t.data,e=t.annotations,o=t.getPosition,i=t.getDimensions;return e.reduce((function(t,e){var a=e.offset||0;return[].concat(t,d.default(n,e.match).map((function(t){var n=o(t),r=i(t);return(y(e)||p(e))&&(r.size=r.size+2*a,r.width=r.width+2*a,r.height=r.height+2*a),h({},u.default(e,["match","offset"]),n,r,{size:e.size||r.size,datum:t})})))}),[])},k=function(t,n,e,o){var a=Math.atan2(o-n,e-t);return i.absoluteAngleDegrees(i.radiansToDegrees(a))},v=function(t){var n,e,o=t.x,a=t.y,r=t.noteX,s=t.noteY,u=t.noteWidth,d=void 0===u?c.noteWidth:u,h=t.noteTextOffset,x=void 0===h?c.noteTextOffset:h;if(l.default(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(l.default(s))e=a+s;else{if(void 0===s.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");e=s.abs}var f=o,m=a,g=k(o,a,n,e);if(y(t)){var v=i.positionFromAngle(i.degreesToRadians(g),t.size/2);f+=v.x,m+=v.y}if(p(t)){var W=Math.round((g+90)/45)%8;0===W&&(m-=t.height/2),1===W&&(f+=t.width/2,m-=t.height/2),2===W&&(f+=t.width/2),3===W&&(f+=t.width/2,m+=t.height/2),4===W&&(m+=t.height/2),5===W&&(f-=t.width/2,m+=t.height/2),6===W&&(f-=t.width/2),7===W&&(f-=t.width/2,m-=t.height/2)}var b=n,w=n;return(g+90)%360>180?(b-=d,w-=d):w+=d,{points:[[f,m],[n,e],[w,e]],text:[b,e-x],angle:g+90}},W=function(n){return t.useMemo((function(){return v(n)}),[n])},b=function(n){var e=n.datum,o=n.x,s=n.y,l=n.note,d=i.useTheme(),c=i.useMotionConfig(),x=c.animate,f=c.config,y=a.useSpring({x:o,y:s,config:f,immediate:!x});return"function"==typeof l?t.createElement(l,{x:o,y:s,datum:e}):r.jsxs(r.Fragment,{children:[d.annotations.text.outlineWidth>0&&r.jsx(a.animated.text,{x:y.x,y:y.y,style:h({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:l}),r.jsx(a.animated.text,{x:y.x,y:y.y,style:u.default(d.annotations.text,["outlineWidth","outlineColor"]),children:l})]})},w=function(n){var e=n.points,o=n.isOutline,s=void 0!==o&&o,u=i.useTheme(),l=t.useMemo((function(){var t=e[0];return e.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[e]),d=i.useAnimatedPath(l);if(s&&u.annotations.link.outlineWidth<=0)return null;var c=h({},u.annotations.link);return s&&(c.strokeLinecap="square",c.strokeWidth=u.annotations.link.strokeWidth+2*u.annotations.link.outlineWidth,c.stroke=u.annotations.link.outlineColor,c.opacity=u.annotations.link.outlineOpacity),r.jsx(a.animated.path,{fill:"none",d:d,style:c})},j=function(t){var n=t.x,e=t.y,o=t.size,s=i.useTheme(),u=i.useMotionConfig(),l=u.animate,d=u.config,c=a.useSpring({x:n,y:e,radius:o/2,config:d,immediate:!l});return r.jsxs(r.Fragment,{children:[s.annotations.outline.outlineWidth>0&&r.jsx(a.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:h({},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})}),r.jsx(a.animated.circle,{cx:c.x,cy:c.y,r:c.radius,style:s.annotations.outline})]})},C=function(t){var n=t.x,e=t.y,o=t.size,s=void 0===o?c.dotSize:o,u=i.useTheme(),l=i.useMotionConfig(),d=l.animate,x=l.config,f=a.useSpring({x:n,y:e,radius:s/2,config:x,immediate:!d});return r.jsxs(r.Fragment,{children:[u.annotations.outline.outlineWidth>0&&r.jsx(a.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:h({},u.annotations.outline,{fill:"none",strokeWidth:2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),r.jsx(a.animated.circle,{cx:f.x,cy:f.y,r:f.radius,style:u.annotations.symbol})]})},z=function(t){var n=t.x,e=t.y,o=t.width,s=t.height,u=t.borderRadius,l=void 0===u?6:u,d=i.useTheme(),c=i.useMotionConfig(),x=c.animate,f=c.config,y=a.useSpring({x:n-o/2,y:e-s/2,width:o,height:s,config:f,immediate:!x});return r.jsxs(r.Fragment,{children:[d.annotations.outline.outlineWidth>0&&r.jsx(a.animated.rect,{x:y.x,y:y.y,rx:l,ry:l,width:y.width,height:y.height,style:h({},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})}),r.jsx(a.animated.rect,{x:y.x,y:y.y,rx:l,ry:l,width:y.width,height:y.height,style:d.annotations.outline})]})},P=function(t,n){n.forEach((function(n,e){var o=n[0],i=n[1];0===e?t.moveTo(o,i):t.lineTo(o,i)}))};exports.Annotation=function(t){var n=t.datum,e=t.x,o=t.y,i=t.note,a=W(t);if(!x(i))throw new Error("note should be a valid react element");return r.jsxs(r.Fragment,{children:[r.jsx(w,{points:a.points,isOutline:!0}),y(t)&&r.jsx(j,{x:e,y:o,size:t.size}),m(t)&&r.jsx(C,{x:e,y:o,size:t.size}),p(t)&&r.jsx(z,{x:e,y:o,width:t.width,height:t.height,borderRadius:t.borderRadius}),r.jsx(w,{points:a.points}),r.jsx(b,{datum:n,x:a.text[0],y:a.text[1],note:i})]})},exports.bindAnnotations=g,exports.computeAnnotation=v,exports.defaultProps=c,exports.getLinkAngle=k,exports.isCanvasNote=f,exports.isCircleAnnotation=y,exports.isDotAnnotation=m,exports.isRectAnnotation=p,exports.isSvgNote=x,exports.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,o=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!f(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(),P(t,n.computed.points),t.stroke(),t.lineCap="butt"),y(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()),m(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(),P(t,n.computed.points),t.stroke(),y(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()),m(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())},exports.useAnnotations=function(n){var e=n.data,o=n.annotations,i=n.getPosition,a=n.getDimensions;return t.useMemo((function(){return g({data:e,annotations:o,getPosition:i,getDimensions:a})}),[e,o,i,a])},exports.useComputedAnnotation=W,exports.useComputedAnnotations=function(n){var e=n.annotations;return t.useMemo((function(){return e.map((function(t){return h({},t,{computed:v(h({},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 o from"lodash/omit";import e from"lodash/isNumber";import a from"lodash/filter";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{useSpring as f,animated as y}from"@react-spring/web";import{jsxs as m,Fragment as x,jsx as p}from"react/jsx-runtime";function g(){return g=Object.assign||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},g.apply(this,arguments)}var k={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},W=function(n){var i=typeof n;return t(n)||"string"===i||"function"===i||"object"===i},v=function(t){var n=typeof t;return"string"===n||"function"===n},b=function(t){return"circle"===t.type},w=function(t){return"dot"===t.type},z=function(t){return"rect"===t.type},P=function(t){var n=t.data,i=t.annotations,e=t.getPosition,r=t.getDimensions;return i.reduce((function(t,i){var s=i.offset||0;return[].concat(t,a(n,i.match).map((function(t){var n=e(t),a=r(t);return(b(i)||z(i))&&(a.size=a.size+2*s,a.width=a.width+2*s,a.height=a.height+2*s),g({},o(i,["match","offset"]),n,a,{size:i.size||a.size,datum:t})})))}),[])},S=function(t,n,i,o){var e=Math.atan2(o-n,i-t);return r(s(e))},C=function(t){var n,i,o=t.x,a=t.y,r=t.noteX,s=t.noteY,h=t.noteWidth,d=void 0===h?k.noteWidth:h,c=t.noteTextOffset,f=void 0===c?k.noteTextOffset:c;if(e(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(e(s))i=a+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,m=a,x=S(o,a,n,i);if(b(t)){var p=l(u(x),t.size/2);y+=p.x,m+=p.y}if(z(t)){var g=Math.round((x+90)/45)%8;0===g&&(m-=t.height/2),1===g&&(y+=t.width/2,m-=t.height/2),2===g&&(y+=t.width/2),3===g&&(y+=t.width/2,m+=t.height/2),4===g&&(m+=t.height/2),5===g&&(y-=t.width/2,m+=t.height/2),6===g&&(y-=t.width/2),7===g&&(y-=t.width/2,m-=t.height/2)}var W=n,v=n;return(x+90)%360>180?(W-=d,v-=d):v+=d,{points:[[y,m],[n,i],[v,i]],text:[W,i-f],angle:x+90}},O=function(t){var i=t.data,o=t.annotations,e=t.getPosition,a=t.getDimensions;return n((function(){return P({data:i,annotations:o,getPosition:e,getDimensions:a})}),[i,o,e,a])},j=function(t){var i=t.annotations;return n((function(){return i.map((function(t){return g({},t,{computed:C(g({},t))})}))}),[i])},M=function(t){return n((function(){return C(t)}),[t])},T=function(t){var n=t.datum,e=t.x,a=t.y,r=t.note,s=h(),l=d(),u=l.animate,c=l.config,k=f({x:e,y:a,config:c,immediate:!u});return"function"==typeof r?i(r,{x:e,y:a,datum:n}):m(x,{children:[s.annotations.text.outlineWidth>0&&p(y.text,{x:k.x,y:k.y,style:g({},s.annotations.text,{strokeLinejoin:"round",strokeWidth:2*s.annotations.text.outlineWidth,stroke:s.annotations.text.outlineColor}),children:r}),p(y.text,{x:k.x,y:k.y,style:o(s.annotations.text,["outlineWidth","outlineColor"]),children:r})]})},E=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=g({},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),p(y.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=f({x:n,y:i,radius:o/2,config:s,immediate:!r});return m(x,{children:[e.annotations.outline.outlineWidth>0&&p(y.circle,{cx:l.x,cy:l.y,r:l.radius,style:g({},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})}),p(y.circle,{cx:l.x,cy:l.y,r:l.radius,style:e.annotations.outline})]})},I=function(t){var n=t.x,i=t.y,o=t.size,e=void 0===o?k.dotSize:o,a=h(),r=d(),s=r.animate,l=r.config,u=f({x:n,y:i,radius:e/2,config:l,immediate:!s});return m(x,{children:[a.annotations.outline.outlineWidth>0&&p(y.circle,{cx:u.x,cy:u.y,r:u.radius,style:g({},a.annotations.outline,{fill:"none",strokeWidth:2*a.annotations.outline.outlineWidth,stroke:a.annotations.outline.outlineColor,opacity:a.annotations.outline.outlineOpacity})}),p(y.circle,{cx:u.x,cy:u.y,r:u.radius,style:a.annotations.symbol})]})},L=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,k=f({x:n-o/2,y:i-e/2,width:o,height:e,config:c,immediate:!u});return m(x,{children:[s.annotations.outline.outlineWidth>0&&p(y.rect,{x:k.x,y:k.y,rx:r,ry:r,width:k.width,height:k.height,style:g({},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})}),p(y.rect,{x:k.x,y:k.y,rx:r,ry:r,width:k.width,height:k.height,style:s.annotations.outline})]})},R=function(t){var n=t.datum,i=t.x,o=t.y,e=t.note,a=M(t);if(!W(e))throw new Error("note should be a valid react element");return m(x,{children:[p(E,{points:a.points,isOutline:!0}),b(t)&&p(D,{x:i,y:o,size:t.size}),w(t)&&p(I,{x:i,y:o,size:t.size}),z(t)&&p(L,{x:i,y:o,width:t.width,height:t.height,borderRadius:t.borderRadius}),p(E,{points:a.points}),p(T,{datum:n,x:a.text[0],y:a.text[1],note:e})]})},q=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)}))},J=function(t,n){var i=n.annotations,o=n.theme;0!==i.length&&(t.save(),i.forEach((function(n){if(!v(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(),q(t,n.computed.points),t.stroke(),t.lineCap="butt"),b(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()),w(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()),z(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(),q(t,n.computed.points),t.stroke(),b(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()),w(n)&&(t.fillStyle=o.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),z(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.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{R as Annotation,P as bindAnnotations,C as computeAnnotation,k as defaultProps,S as getLinkAngle,v as isCanvasNote,b as isCircleAnnotation,w as isDotAnnotation,z as isRectAnnotation,W as isSvgNote,J as renderAnnotationsToCanvas,O as useAnnotations,M as useComputedAnnotation,j as useComputedAnnotations}; | ||
import{isValidElement as t,useMemo as n,createElement as i}from"react";import o from"lodash/omit";import e from"lodash/isNumber";import a from"lodash/filter";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{useSpring as f,animated as y}from"@react-spring/web";import{jsxs as x,Fragment as m,jsx as p}from"react/jsx-runtime";function g(){return g=Object.assign||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},g.apply(this,arguments)}var k={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},W=function(n){var i=typeof n;return t(n)||"string"===i||"function"===i||"object"===i},v=function(t){var n=typeof t;return"string"===n||"function"===n},b=function(t){return"circle"===t.type},w=function(t){return"dot"===t.type},z=function(t){return"rect"===t.type},P=function(t){var n=t.data,i=t.annotations,e=t.getPosition,r=t.getDimensions;return i.reduce((function(t,i){var s=i.offset||0;return[].concat(t,a(n,i.match).map((function(t){var n=e(t),a=r(t);return(b(i)||z(i))&&(a.size=a.size+2*s,a.width=a.width+2*s,a.height=a.height+2*s),g({},o(i,["match","offset"]),n,a,{size:i.size||a.size,datum:t})})))}),[])},S=function(t,n,i,o){var e=Math.atan2(o-n,i-t);return r(s(e))},C=function(t){var n,i,o=t.x,a=t.y,r=t.noteX,s=t.noteY,h=t.noteWidth,d=void 0===h?k.noteWidth:h,c=t.noteTextOffset,f=void 0===c?k.noteTextOffset:c;if(e(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(e(s))i=a+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=a,m=S(o,a,n,i);if(b(t)){var p=l(u(m),t.size/2);y+=p.x,x+=p.y}if(z(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 W=n,v=n;return(m+90)%360>180?(W-=d,v-=d):v+=d,{points:[[y,x],[n,i],[v,i]],text:[W,i-f],angle:m+90}},O=function(t){var i=t.data,o=t.annotations,e=t.getPosition,a=t.getDimensions;return n((function(){return P({data:i,annotations:o,getPosition:e,getDimensions:a})}),[i,o,e,a])},j=function(t){var i=t.annotations;return n((function(){return i.map((function(t){return g({},t,{computed:C(g({},t))})}))}),[i])},M=function(t){return n((function(){return C(t)}),[t])},T=function(t){var n=t.datum,e=t.x,a=t.y,r=t.note,s=h(),l=d(),u=l.animate,c=l.config,k=f({x:e,y:a,config:c,immediate:!u});return"function"==typeof r?i(r,{x:e,y:a,datum:n}):x(m,{children:[s.annotations.text.outlineWidth>0&&p(y.text,{x:k.x,y:k.y,style:g({},s.annotations.text,{strokeLinejoin:"round",strokeWidth:2*s.annotations.text.outlineWidth,stroke:s.annotations.text.outlineColor}),children:r}),p(y.text,{x:k.x,y:k.y,style:o(s.annotations.text,["outlineWidth","outlineColor"]),children:r})]})},E=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=g({},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),p(y.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=f({x:n,y:i,radius:o/2,config:s,immediate:!r});return x(m,{children:[e.annotations.outline.outlineWidth>0&&p(y.circle,{cx:l.x,cy:l.y,r:l.radius,style:g({},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})}),p(y.circle,{cx:l.x,cy:l.y,r:l.radius,style:e.annotations.outline})]})},I=function(t){var n=t.x,i=t.y,o=t.size,e=void 0===o?k.dotSize:o,a=h(),r=d(),s=r.animate,l=r.config,u=f({x:n,y:i,radius:e/2,config:l,immediate:!s});return x(m,{children:[a.annotations.outline.outlineWidth>0&&p(y.circle,{cx:u.x,cy:u.y,r:u.radius,style:g({},a.annotations.outline,{fill:"none",strokeWidth:2*a.annotations.outline.outlineWidth,stroke:a.annotations.outline.outlineColor,opacity:a.annotations.outline.outlineOpacity})}),p(y.circle,{cx:u.x,cy:u.y,r:u.radius,style:a.annotations.symbol})]})},L=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,k=f({x:n-o/2,y:i-e/2,width:o,height:e,config:c,immediate:!u});return x(m,{children:[s.annotations.outline.outlineWidth>0&&p(y.rect,{x:k.x,y:k.y,rx:r,ry:r,width:k.width,height:k.height,style:g({},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})}),p(y.rect,{x:k.x,y:k.y,rx:r,ry:r,width:k.width,height:k.height,style:s.annotations.outline})]})},R=function(t){var n=t.datum,i=t.x,o=t.y,e=t.note,a=M(t);if(!W(e))throw new Error("note should be a valid react element");return x(m,{children:[p(E,{points:a.points,isOutline:!0}),b(t)&&p(D,{x:i,y:o,size:t.size}),w(t)&&p(I,{x:i,y:o,size:t.size}),z(t)&&p(L,{x:i,y:o,width:t.width,height:t.height,borderRadius:t.borderRadius}),p(E,{points:a.points}),p(T,{datum:n,x:a.text[0],y:a.text[1],note:e})]})},q=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)}))},J=function(t,n){var i=n.annotations,o=n.theme;0!==i.length&&(t.save(),i.forEach((function(n){if(!v(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(),q(t,n.computed.points),t.stroke(),t.lineCap="butt"),b(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()),w(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()),z(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(),q(t,n.computed.points),t.stroke(),b(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()),w(n)&&(t.fillStyle=o.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),z(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{R as Annotation,P as bindAnnotations,C as computeAnnotation,k as defaultProps,S as getLinkAngle,v as isCanvasNote,b as isCircleAnnotation,w as isDotAnnotation,z as isRectAnnotation,W as isSvgNote,J as renderAnnotationsToCanvas,O as useAnnotations,M as useComputedAnnotation,j as useComputedAnnotations}; | ||
//# sourceMappingURL=nivo-annotations.es.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react"),require("lodash/omit"),require("lodash/isNumber"),require("lodash/filter"),require("@nivo/core"),require("@react-spring/web"),require("react/jsx-runtime")):"function"==typeof define&&define.amd?define(["exports","react","lodash/omit","lodash/isNumber","lodash/filter","@nivo/core","@react-spring/web","react/jsx-runtime"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).nivo=t.nivo||{},t.React,t["lodash/omit"],t["lodash/isNumber"],t["lodash/filter"],t.nivo,t["@react-spring/web"],t["react/jsx-runtime"])}(this,(function(t,n,e,i,o,a,s,r){"use strict";function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var l=u(e),d=u(i),h=u(o);function c(){return c=Object.assign||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},c.apply(this,arguments)}var f={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},m=function(t){var e=typeof t;return n.isValidElement(t)||"string"===e||"function"===e||"object"===e},x=function(t){var n=typeof t;return"string"===n||"function"===n},y=function(t){return"circle"===t.type},g=function(t){return"dot"===t.type},p=function(t){return"rect"===t.type},k=function(t){var n=t.data,e=t.annotations,i=t.getPosition,o=t.getDimensions;return e.reduce((function(t,e){var a=e.offset||0;return[].concat(t,h.default(n,e.match).map((function(t){var n=i(t),s=o(t);return(y(e)||p(e))&&(s.size=s.size+2*a,s.width=s.width+2*a,s.height=s.height+2*a),c({},l.default(e,["match","offset"]),n,s,{size:e.size||s.size,datum:t})})))}),[])},v=function(t,n,e,i){var o=Math.atan2(i-n,e-t);return a.absoluteAngleDegrees(a.radiansToDegrees(o))},b=function(t){var n,e,i=t.x,o=t.y,s=t.noteX,r=t.noteY,u=t.noteWidth,l=void 0===u?f.noteWidth:u,h=t.noteTextOffset,c=void 0===h?f.noteTextOffset:h;if(d.default(s))n=i+s;else{if(void 0===s.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");n=s.abs}if(d.default(r))e=o+r;else{if(void 0===r.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");e=r.abs}var m=i,x=o,g=v(i,o,n,e);if(y(t)){var k=a.positionFromAngle(a.degreesToRadians(g),t.size/2);m+=k.x,x+=k.y}if(p(t)){var b=Math.round((g+90)/45)%8;0===b&&(x-=t.height/2),1===b&&(m+=t.width/2,x-=t.height/2),2===b&&(m+=t.width/2),3===b&&(m+=t.width/2,x+=t.height/2),4===b&&(x+=t.height/2),5===b&&(m-=t.width/2,x+=t.height/2),6===b&&(m-=t.width/2),7===b&&(m-=t.width/2,x-=t.height/2)}var W=n,j=n;return(g+90)%360>180?(W-=l,j-=l):j+=l,{points:[[m,x],[n,e],[j,e]],text:[W,e-c],angle:g+90}},W=function(t){return n.useMemo((function(){return b(t)}),[t])},j=function(t){var e=t.datum,i=t.x,o=t.y,u=t.note,d=a.useTheme(),h=a.useMotionConfig(),f=h.animate,m=h.config,x=s.useSpring({x:i,y:o,config:m,immediate:!f});return"function"==typeof u?n.createElement(u,{x:i,y:o,datum:e}):r.jsxs(r.Fragment,{children:[d.annotations.text.outlineWidth>0&&r.jsx(s.animated.text,{x:x.x,y:x.y,style:c({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:u}),r.jsx(s.animated.text,{x:x.x,y:x.y,style:l.default(d.annotations.text,["outlineWidth","outlineColor"]),children:u})]})},w=function(t){var e=t.points,i=t.isOutline,o=void 0!==i&&i,u=a.useTheme(),l=n.useMemo((function(){var t=e[0];return e.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[e]),d=a.useAnimatedPath(l);if(o&&u.annotations.link.outlineWidth<=0)return null;var h=c({},u.annotations.link);return o&&(h.strokeLinecap="square",h.strokeWidth=u.annotations.link.strokeWidth+2*u.annotations.link.outlineWidth,h.stroke=u.annotations.link.outlineColor,h.opacity=u.annotations.link.outlineOpacity),r.jsx(s.animated.path,{fill:"none",d:d,style:h})},C=function(t){var n=t.x,e=t.y,i=t.size,o=a.useTheme(),u=a.useMotionConfig(),l=u.animate,d=u.config,h=s.useSpring({x:n,y:e,radius:i/2,config:d,immediate:!l});return r.jsxs(r.Fragment,{children:[o.annotations.outline.outlineWidth>0&&r.jsx(s.animated.circle,{cx:h.x,cy:h.y,r:h.radius,style:c({},o.annotations.outline,{fill:"none",strokeWidth:o.annotations.outline.strokeWidth+2*o.annotations.outline.outlineWidth,stroke:o.annotations.outline.outlineColor,opacity:o.annotations.outline.outlineOpacity})}),r.jsx(s.animated.circle,{cx:h.x,cy:h.y,r:h.radius,style:o.annotations.outline})]})},z=function(t){var n=t.x,e=t.y,i=t.size,o=void 0===i?f.dotSize:i,u=a.useTheme(),l=a.useMotionConfig(),d=l.animate,h=l.config,m=s.useSpring({x:n,y:e,radius:o/2,config:h,immediate:!d});return r.jsxs(r.Fragment,{children:[u.annotations.outline.outlineWidth>0&&r.jsx(s.animated.circle,{cx:m.x,cy:m.y,r:m.radius,style:c({},u.annotations.outline,{fill:"none",strokeWidth:2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),r.jsx(s.animated.circle,{cx:m.x,cy:m.y,r:m.radius,style:u.annotations.symbol})]})},P=function(t){var n=t.x,e=t.y,i=t.width,o=t.height,u=t.borderRadius,l=void 0===u?6:u,d=a.useTheme(),h=a.useMotionConfig(),f=h.animate,m=h.config,x=s.useSpring({x:n-i/2,y:e-o/2,width:i,height:o,config:m,immediate:!f});return r.jsxs(r.Fragment,{children:[d.annotations.outline.outlineWidth>0&&r.jsx(s.animated.rect,{x:x.x,y:x.y,rx:l,ry:l,width:x.width,height:x.height,style:c({},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})}),r.jsx(s.animated.rect,{x:x.x,y:x.y,rx:l,ry:l,width:x.width,height:x.height,style:d.annotations.outline})]})},S=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)}))};t.Annotation=function(t){var n=t.datum,e=t.x,i=t.y,o=t.note,a=W(t);if(!m(o))throw new Error("note should be a valid react element");return r.jsxs(r.Fragment,{children:[r.jsx(w,{points:a.points,isOutline:!0}),y(t)&&r.jsx(C,{x:e,y:i,size:t.size}),g(t)&&r.jsx(z,{x:e,y:i,size:t.size}),p(t)&&r.jsx(P,{x:e,y:i,width:t.width,height:t.height,borderRadius:t.borderRadius}),r.jsx(w,{points:a.points}),r.jsx(j,{datum:n,x:a.text[0],y:a.text[1],note:o})]})},t.bindAnnotations=k,t.computeAnnotation=b,t.defaultProps=f,t.getLinkAngle=v,t.isCanvasNote=x,t.isCircleAnnotation=y,t.isDotAnnotation=g,t.isRectAnnotation=p,t.isSvgNote=m,t.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,i=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!x(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(),S(t,n.computed.points),t.stroke(),t.lineCap="butt"),y(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()),g(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()),p(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(),S(t,n.computed.points),t.stroke(),y(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()),g(n)&&(t.fillStyle=i.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),p(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.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())},t.useAnnotations=function(t){var e=t.data,i=t.annotations,o=t.getPosition,a=t.getDimensions;return n.useMemo((function(){return k({data:e,annotations:i,getPosition:o,getDimensions:a})}),[e,i,o,a])},t.useComputedAnnotation=W,t.useComputedAnnotations=function(t){var e=t.annotations;return n.useMemo((function(){return e.map((function(t){return c({},t,{computed:b(c({},t))})}))}),[e])},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react"),require("lodash/omit"),require("lodash/isNumber"),require("lodash/filter"),require("@nivo/core"),require("@react-spring/web"),require("react/jsx-runtime")):"function"==typeof define&&define.amd?define(["exports","react","lodash/omit","lodash/isNumber","lodash/filter","@nivo/core","@react-spring/web","react/jsx-runtime"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).nivo=t.nivo||{},t.React,t["lodash/omit"],t["lodash/isNumber"],t["lodash/filter"],t.nivo,t["@react-spring/web"],t["react/jsx-runtime"])}(this,(function(t,n,e,i,o,a,s,r){"use strict";function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var l=u(e),d=u(i),h=u(o);function c(){return c=Object.assign||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},c.apply(this,arguments)}var f={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0,motionStiffness:90,motionDamping:13},x=function(t){var e=typeof t;return n.isValidElement(t)||"string"===e||"function"===e||"object"===e},m=function(t){var n=typeof t;return"string"===n||"function"===n},y=function(t){return"circle"===t.type},g=function(t){return"dot"===t.type},p=function(t){return"rect"===t.type},k=function(t){var n=t.data,e=t.annotations,i=t.getPosition,o=t.getDimensions;return e.reduce((function(t,e){var a=e.offset||0;return[].concat(t,h.default(n,e.match).map((function(t){var n=i(t),s=o(t);return(y(e)||p(e))&&(s.size=s.size+2*a,s.width=s.width+2*a,s.height=s.height+2*a),c({},l.default(e,["match","offset"]),n,s,{size:e.size||s.size,datum:t})})))}),[])},v=function(t,n,e,i){var o=Math.atan2(i-n,e-t);return a.absoluteAngleDegrees(a.radiansToDegrees(o))},b=function(t){var n,e,i=t.x,o=t.y,s=t.noteX,r=t.noteY,u=t.noteWidth,l=void 0===u?f.noteWidth:u,h=t.noteTextOffset,c=void 0===h?f.noteTextOffset:h;if(d.default(s))n=i+s;else{if(void 0===s.abs)throw new Error("noteX should be either a number or an object containing an 'abs' property");n=s.abs}if(d.default(r))e=o+r;else{if(void 0===r.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");e=r.abs}var x=i,m=o,g=v(i,o,n,e);if(y(t)){var k=a.positionFromAngle(a.degreesToRadians(g),t.size/2);x+=k.x,m+=k.y}if(p(t)){var b=Math.round((g+90)/45)%8;0===b&&(m-=t.height/2),1===b&&(x+=t.width/2,m-=t.height/2),2===b&&(x+=t.width/2),3===b&&(x+=t.width/2,m+=t.height/2),4===b&&(m+=t.height/2),5===b&&(x-=t.width/2,m+=t.height/2),6===b&&(x-=t.width/2),7===b&&(x-=t.width/2,m-=t.height/2)}var W=n,j=n;return(g+90)%360>180?(W-=l,j-=l):j+=l,{points:[[x,m],[n,e],[j,e]],text:[W,e-c],angle:g+90}},W=function(t){return n.useMemo((function(){return b(t)}),[t])},j=function(t){var e=t.datum,i=t.x,o=t.y,u=t.note,d=a.useTheme(),h=a.useMotionConfig(),f=h.animate,x=h.config,m=s.useSpring({x:i,y:o,config:x,immediate:!f});return"function"==typeof u?n.createElement(u,{x:i,y:o,datum:e}):r.jsxs(r.Fragment,{children:[d.annotations.text.outlineWidth>0&&r.jsx(s.animated.text,{x:m.x,y:m.y,style:c({},d.annotations.text,{strokeLinejoin:"round",strokeWidth:2*d.annotations.text.outlineWidth,stroke:d.annotations.text.outlineColor}),children:u}),r.jsx(s.animated.text,{x:m.x,y:m.y,style:l.default(d.annotations.text,["outlineWidth","outlineColor"]),children:u})]})},w=function(t){var e=t.points,i=t.isOutline,o=void 0!==i&&i,u=a.useTheme(),l=n.useMemo((function(){var t=e[0];return e.slice(1).reduce((function(t,n){return t+" L"+n[0]+","+n[1]}),"M"+t[0]+","+t[1])}),[e]),d=a.useAnimatedPath(l);if(o&&u.annotations.link.outlineWidth<=0)return null;var h=c({},u.annotations.link);return o&&(h.strokeLinecap="square",h.strokeWidth=u.annotations.link.strokeWidth+2*u.annotations.link.outlineWidth,h.stroke=u.annotations.link.outlineColor,h.opacity=u.annotations.link.outlineOpacity),r.jsx(s.animated.path,{fill:"none",d:d,style:h})},C=function(t){var n=t.x,e=t.y,i=t.size,o=a.useTheme(),u=a.useMotionConfig(),l=u.animate,d=u.config,h=s.useSpring({x:n,y:e,radius:i/2,config:d,immediate:!l});return r.jsxs(r.Fragment,{children:[o.annotations.outline.outlineWidth>0&&r.jsx(s.animated.circle,{cx:h.x,cy:h.y,r:h.radius,style:c({},o.annotations.outline,{fill:"none",strokeWidth:o.annotations.outline.strokeWidth+2*o.annotations.outline.outlineWidth,stroke:o.annotations.outline.outlineColor,opacity:o.annotations.outline.outlineOpacity})}),r.jsx(s.animated.circle,{cx:h.x,cy:h.y,r:h.radius,style:o.annotations.outline})]})},z=function(t){var n=t.x,e=t.y,i=t.size,o=void 0===i?f.dotSize:i,u=a.useTheme(),l=a.useMotionConfig(),d=l.animate,h=l.config,x=s.useSpring({x:n,y:e,radius:o/2,config:h,immediate:!d});return r.jsxs(r.Fragment,{children:[u.annotations.outline.outlineWidth>0&&r.jsx(s.animated.circle,{cx:x.x,cy:x.y,r:x.radius,style:c({},u.annotations.outline,{fill:"none",strokeWidth:2*u.annotations.outline.outlineWidth,stroke:u.annotations.outline.outlineColor,opacity:u.annotations.outline.outlineOpacity})}),r.jsx(s.animated.circle,{cx:x.x,cy:x.y,r:x.radius,style:u.annotations.symbol})]})},P=function(t){var n=t.x,e=t.y,i=t.width,o=t.height,u=t.borderRadius,l=void 0===u?6:u,d=a.useTheme(),h=a.useMotionConfig(),f=h.animate,x=h.config,m=s.useSpring({x:n-i/2,y:e-o/2,width:i,height:o,config:x,immediate:!f});return r.jsxs(r.Fragment,{children:[d.annotations.outline.outlineWidth>0&&r.jsx(s.animated.rect,{x:m.x,y:m.y,rx:l,ry:l,width:m.width,height:m.height,style:c({},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})}),r.jsx(s.animated.rect,{x:m.x,y:m.y,rx:l,ry:l,width:m.width,height:m.height,style:d.annotations.outline})]})},S=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)}))};t.Annotation=function(t){var n=t.datum,e=t.x,i=t.y,o=t.note,a=W(t);if(!x(o))throw new Error("note should be a valid react element");return r.jsxs(r.Fragment,{children:[r.jsx(w,{points:a.points,isOutline:!0}),y(t)&&r.jsx(C,{x:e,y:i,size:t.size}),g(t)&&r.jsx(z,{x:e,y:i,size:t.size}),p(t)&&r.jsx(P,{x:e,y:i,width:t.width,height:t.height,borderRadius:t.borderRadius}),r.jsx(w,{points:a.points}),r.jsx(j,{datum:n,x:a.text[0],y:a.text[1],note:o})]})},t.bindAnnotations=k,t.computeAnnotation=b,t.defaultProps=f,t.getLinkAngle=v,t.isCanvasNote=m,t.isCircleAnnotation=y,t.isDotAnnotation=g,t.isRectAnnotation=p,t.isSvgNote=x,t.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,i=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!m(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(),S(t,n.computed.points),t.stroke(),t.lineCap="butt"),y(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()),g(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()),p(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(),S(t,n.computed.points),t.stroke(),y(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()),g(n)&&(t.fillStyle=i.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),p(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())},t.useAnnotations=function(t){var e=t.data,i=t.annotations,o=t.getPosition,a=t.getDimensions;return n.useMemo((function(){return k({data:e,annotations:i,getPosition:o,getDimensions:a})}),[e,i,o,a])},t.useComputedAnnotation=W,t.useComputedAnnotations=function(t){var e=t.annotations;return n.useMemo((function(){return e.map((function(t){return c({},t,{computed:b(c({},t))})}))}),[e])},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=nivo-annotations.umd.js.map |
{ | ||
"name": "@nivo/annotations", | ||
"version": "0.78.0", | ||
"version": "0.79.0", | ||
"license": "MIT", | ||
@@ -31,3 +31,3 @@ "author": { | ||
"dependencies": { | ||
"@nivo/colors": "0.78.0", | ||
"@nivo/colors": "0.79.0", | ||
"@react-spring/web": "9.3.1", | ||
@@ -37,6 +37,6 @@ "lodash": "^4.17.21" | ||
"devDependencies": { | ||
"@nivo/core": "0.78.0" | ||
"@nivo/core": "0.79.0" | ||
}, | ||
"peerDependencies": { | ||
"@nivo/core": "0.78.0", | ||
"@nivo/core": "0.79.0", | ||
"react": ">= 16.14.0 < 18.0.0" | ||
@@ -47,3 +47,3 @@ }, | ||
}, | ||
"gitHead": "166935501f9a971540ceccc1ec562a65341e5fb3" | ||
"gitHead": "c9d8f198962d242872a0267e304f950eb57e2ec4" | ||
} |
@@ -0,1 +1,6 @@ | ||
<a href="https://nivo.rocks"><img alt="nivo" src="https://raw.githubusercontent.com/plouc/nivo/master/nivo.png" width="216" height="68"/></a> | ||
# `@nivo/annotations` | ||
[![version](https://img.shields.io/npm/v/@nivo/annotations?style=for-the-badge)](https://www.npmjs.com/package/@nivo/annotations) | ||
[![downloads](https://img.shields.io/npm/dm/@nivo/annotations?style=for-the-badge)](https://www.npmjs.com/package/@nivo/annotations) |
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
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
144741
327
7
+ Added@nivo/colors@0.79.0(transitive)
+ Added@nivo/core@0.79.0(transitive)
+ Added@nivo/recompose@0.79.0(transitive)
+ Added@nivo/tooltip@0.79.0(transitive)
- Removed@nivo/colors@0.78.0(transitive)
- Removed@nivo/core@0.78.0(transitive)
- Removed@nivo/recompose@0.78.0(transitive)
- Removed@nivo/tooltip@0.78.0(transitive)
- Removedresize-observer-polyfill@1.5.1(transitive)
Updated@nivo/colors@0.79.0