@nivo/annotations
Advanced tools
| export declare const AnnotationLink: ({ points, isOutline, }: { | ||
| points: [number, number][]; | ||
| isOutline?: boolean | undefined; | ||
| isOutline?: boolean; | ||
| }) => import("react/jsx-runtime").JSX.Element | null; | ||
| //# sourceMappingURL=AnnotationLink.d.ts.map |
| export declare const DotAnnotationOutline: ({ x, y, size, }: { | ||
| x: number; | ||
| y: number; | ||
| size?: number | undefined; | ||
| size?: number; | ||
| }) => import("react/jsx-runtime").JSX.Element; | ||
| //# sourceMappingURL=DotAnnotationOutline.d.ts.map |
@@ -6,4 +6,4 @@ export declare const RectAnnotationOutline: ({ x, y, width, height, borderRadius, }: { | ||
| height: number; | ||
| borderRadius?: number | undefined; | ||
| borderRadius?: number; | ||
| }) => import("react/jsx-runtime").JSX.Element; | ||
| //# sourceMappingURL=RectAnnotationOutline.d.ts.map |
@@ -78,7 +78,7 @@ import { Theme } from '@nivo/theming'; | ||
| }; | ||
| export type AnnotationInstructions = { | ||
| export interface AnnotationInstructions { | ||
| points: [number, number][]; | ||
| text: [number, number]; | ||
| angle: number; | ||
| }; | ||
| } | ||
| export type ComputedAnnotation<Datum> = BoundAnnotation<Datum> & { | ||
@@ -85,0 +85,0 @@ computed: AnnotationInstructions; |
+5
-5
| { | ||
| "name": "@nivo/annotations", | ||
| "version": "0.92.2", | ||
| "version": "0.93.0", | ||
| "license": "MIT", | ||
@@ -31,5 +31,5 @@ "author": { | ||
| "dependencies": { | ||
| "@nivo/colors": "0.92.2", | ||
| "@nivo/core": "0.92.2", | ||
| "@nivo/theming": "0.92.0", | ||
| "@nivo/colors": "0.93.0", | ||
| "@nivo/core": "0.93.0", | ||
| "@nivo/theming": "0.93.0", | ||
| "@react-spring/web": "9.4.5 || ^9.7.2", | ||
@@ -51,3 +51,3 @@ "lodash": "^4.17.21" | ||
| }, | ||
| "gitHead": "204ff516ab45656e0197965d6e3458388cc8a8e3" | ||
| "gitHead": "83293c9d3d4c8fd10e92077f6d8e64057e15221d" | ||
| } |
| "use strict";var t=require("react"),n=require("lodash/filter.js"),e=require("lodash/isNumber.js"),i=require("lodash/omit.js"),o=require("@nivo/core"),a=require("@react-spring/web"),s=require("@nivo/theming"),r=require("react/jsx-runtime");function u(){return u=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var i in e)({}).hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},u.apply(null,arguments)}var l={dotSize:4,noteWidth:120,noteTextOffset:8,animate:!0},h=function(n){var e=typeof n;return t.isValidElement(n)||"string"===e||"function"===e||"object"===e},d=function(t){var n=typeof t;return"string"===n||"function"===n},c=function(t){return"circle"===t.type},x=function(t){return"dot"===t.type},f=function(t){return"rect"===t.type},m=function(t){var e=t.data,o=t.annotations,a=t.getPosition,s=t.getDimensions;return o.reduce((function(t,o){var r=o.offset||0;return[].concat(t,n(e,o.match).map((function(t){var n=a(t),e=s(t);return(c(o)||f(o))&&(e.size=e.size+2*r,e.width=e.width+2*r,e.height=e.height+2*r),u({},i(o,["match","offset"]),n,e,{size:o.size||e.size,datum:t})})))}),[])},y=function(t,n,e,i){var a=Math.atan2(i-n,e-t);return o.absoluteAngleDegrees(o.radiansToDegrees(a))},g=function(t){var n,i,a=t.x,s=t.y,r=t.noteX,u=t.noteY,h=t.noteWidth,d=void 0===h?l.noteWidth:h,x=t.noteTextOffset,m=void 0===x?l.noteTextOffset:x;if(e(r))n=a+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(u))i=s+u;else{if(void 0===u.abs)throw new Error("noteY should be either a number or an object containing an 'abs' property");i=u.abs}var g=a,p=s,k=y(a,s,n,i);if(c(t)){var W=o.positionFromAngle(o.degreesToRadians(k),t.size/2);g+=W.x,p+=W.y}if(f(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=n,j=n;return(k+90)%360>180?(b-=d,j-=d):j+=d,{points:[[g,p],[n,i],[j,i]],text:[b,i-m],angle:k+90}},p=function(n){return t.useMemo((function(){return g(n)}),[n])},k=function(n){var e=n.datum,l=n.x,h=n.y,d=n.note,c=s.useTheme(),x=o.useMotionConfig(),f=x.animate,m=x.config,y=a.useSpring({x:l,y:h,config:m,immediate:!f});return"function"==typeof d?t.createElement(d,{x:l,y:h,datum:e}):r.jsxs(r.Fragment,{children:[c.annotations.text.outlineWidth>0&&r.jsx(a.animated.text,{x:y.x,y:y.y,style:u({},c.annotations.text,{strokeLinejoin:"round",strokeWidth:2*c.annotations.text.outlineWidth,stroke:c.annotations.text.outlineColor}),children:d}),r.jsx(a.animated.text,{x:y.x,y:y.y,style:i(c.annotations.text,["outlineWidth","outlineColor"]),children:d})]})},W=function(n){var e=n.points,i=n.isOutline,l=void 0!==i&&i,h=s.useTheme(),d=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]),c=o.useAnimatedPath(d);if(l&&h.annotations.link.outlineWidth<=0)return null;var x=u({},h.annotations.link);return l&&(x.strokeLinecap="square",x.strokeWidth=h.annotations.link.strokeWidth+2*h.annotations.link.outlineWidth,x.stroke=h.annotations.link.outlineColor,x.opacity=h.annotations.link.outlineOpacity),r.jsx(a.animated.path,{fill:"none",d:c,style:x})},v=function(t){var n=t.x,e=t.y,i=t.size,l=s.useTheme(),h=o.useMotionConfig(),d=h.animate,c=h.config,x=a.useSpring({x:n,y:e,radius:i/2,config:c,immediate:!d});return r.jsxs(r.Fragment,{children:[l.annotations.outline.outlineWidth>0&&r.jsx(a.animated.circle,{cx:x.x,cy:x.y,r:x.radius,style:u({},l.annotations.outline,{fill:"none",strokeWidth:l.annotations.outline.strokeWidth+2*l.annotations.outline.outlineWidth,stroke:l.annotations.outline.outlineColor,opacity:l.annotations.outline.outlineOpacity})}),r.jsx(a.animated.circle,{cx:x.x,cy:x.y,r:x.radius,style:l.annotations.outline})]})},b=function(t){var n=t.x,e=t.y,i=t.size,h=void 0===i?l.dotSize:i,d=s.useTheme(),c=o.useMotionConfig(),x=c.animate,f=c.config,m=a.useSpring({x:n,y:e,radius:h/2,config:f,immediate:!x});return r.jsxs(r.Fragment,{children:[d.annotations.outline.outlineWidth>0&&r.jsx(a.animated.circle,{cx:m.x,cy:m.y,r:m.radius,style:u({},d.annotations.outline,{fill:"none",strokeWidth:2*d.annotations.outline.outlineWidth,stroke:d.annotations.outline.outlineColor,opacity:d.annotations.outline.outlineOpacity})}),r.jsx(a.animated.circle,{cx:m.x,cy:m.y,r:m.radius,style:d.annotations.symbol})]})},j=function(t){var n=t.x,e=t.y,i=t.width,l=t.height,h=t.borderRadius,d=void 0===h?6:h,c=s.useTheme(),x=o.useMotionConfig(),f=x.animate,m=x.config,y=a.useSpring({x:n-i/2,y:e-l/2,width:i,height:l,config:m,immediate:!f});return r.jsxs(r.Fragment,{children:[c.annotations.outline.outlineWidth>0&&r.jsx(a.animated.rect,{x:y.x,y:y.y,rx:d,ry:d,width:y.width,height:y.height,style:u({},c.annotations.outline,{fill:"none",strokeWidth:c.annotations.outline.strokeWidth+2*c.annotations.outline.outlineWidth,stroke:c.annotations.outline.outlineColor,opacity:c.annotations.outline.outlineOpacity})}),r.jsx(a.animated.rect,{x:y.x,y:y.y,rx:d,ry:d,width:y.width,height:y.height,style:c.annotations.outline})]})},w=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,a=p(t);if(!h(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}),c(t)&&r.jsx(v,{x:e,y:i,size:t.size}),x(t)&&r.jsx(b,{x:e,y:i,size:t.size}),f(t)&&r.jsx(j,{x:e,y:i,width:t.width,height:t.height,borderRadius:t.borderRadius}),r.jsx(W,{points:a.points}),r.jsx(k,{datum:n,x:a.text[0],y:a.text[1],note:o})]})},exports.bindAnnotations=m,exports.computeAnnotation=g,exports.defaultProps=l,exports.getLinkAngle=y,exports.isCanvasNote=d,exports.isCircleAnnotation=c,exports.isDotAnnotation=x,exports.isRectAnnotation=f,exports.isSvgNote=h,exports.renderAnnotationsToCanvas=function(t,n){var e=n.annotations,i=n.theme;0!==e.length&&(t.save(),e.forEach((function(n){if(!d(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(),w(t,n.computed.points),t.stroke(),t.lineCap="butt"),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.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.stroke()),x(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()),f(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(),w(t,n.computed.points),t.stroke(),c(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()),x(n)&&(t.fillStyle=i.annotations.symbol.fill,t.beginPath(),t.arc(n.x,n.y,n.size/2,0,2*Math.PI),t.fill()),f(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 m({data:e,annotations:i,getPosition:o,getDimensions:a})}),[e,i,o,a])},exports.useComputedAnnotation=p,exports.useComputedAnnotations=function(n){var e=n.annotations;return t.useMemo((function(){return e.map((function(t){return u({},t,{computed:g(u({},t))})}))}),[e])}; | ||
| //# sourceMappingURL=nivo-annotations.cjs.js.map |
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
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
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
Sorry, the diff of this file is not supported yet
4
-20%107213
-6.29%33
-2.94%281
-11.08%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated