Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chartjs-plugin-annotation

Package Overview
Dependencies
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chartjs-plugin-annotation - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

17

dist/chartjs-plugin-annotation.esm.js
/*!
* chartjs-plugin-annotation v1.2.0
* chartjs-plugin-annotation v1.2.1
* https://www.chartjs.org/chartjs-plugin-annotation/index

@@ -1146,3 +1146,3 @@ * (c) 2021 chartjs-plugin-annotation Contributors

function calculatePosition(start, size, adjust, position) {
function calculatePosition(start, size, adjust = 0, position) {
return start - getRelativePosition(size, position) + adjust;

@@ -1422,5 +1422,6 @@ }

var version = "1.2.0";
var version = "1.2.1";
const chartStates = new Map();
const versionParts = Chart.version.split('.');

@@ -1434,2 +1435,12 @@ var annotation = {

Chart.register(annotationTypes);
// TODO: Remove this workaround when strictly requiring Chart.js v3.7 or newer
if (versionParts[0] === '3' && parseInt(versionParts[1], 10) <= 6) {
// Workaround for https://github.com/chartjs/chartjs-plugin-annotation/issues/572
Chart.defaults.set('elements.lineAnnotation', {
callout: {},
font: {},
padding: 6
});
}
},

@@ -1436,0 +1447,0 @@

/*!
* chartjs-plugin-annotation v1.2.0
* chartjs-plugin-annotation v1.2.1
* https://www.chartjs.org/chartjs-plugin-annotation/index

@@ -1149,3 +1149,3 @@ * (c) 2021 chartjs-plugin-annotation Contributors

function calculatePosition(start, size, adjust, position) {
function calculatePosition(start, size, adjust = 0, position) {
return start - getRelativePosition(size, position) + adjust;

@@ -1425,5 +1425,6 @@ }

var version = "1.2.0";
var version = "1.2.1";
const chartStates = new Map();
const versionParts = chart_js.Chart.version.split('.');

@@ -1437,2 +1438,12 @@ var Annotation = {

chart_js.Chart.register(annotationTypes);
// TODO: Remove this workaround when strictly requiring Chart.js v3.7 or newer
if (versionParts[0] === '3' && parseInt(versionParts[1], 10) <= 6) {
// Workaround for https://github.com/chartjs/chartjs-plugin-annotation/issues/572
chart_js.Chart.defaults.set('elements.lineAnnotation', {
callout: {},
font: {},
padding: 6
});
}
},

@@ -1439,0 +1450,0 @@

4

dist/chartjs-plugin-annotation.min.js
/*!
* chartjs-plugin-annotation v1.2.0
* chartjs-plugin-annotation v1.2.1
* https://www.chartjs.org/chartjs-plugin-annotation/index

@@ -7,2 +7,2 @@ * (c) 2021 chartjs-plugin-annotation Contributors

*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["chartjs-plugin-annotation"]=e(t.Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";const i=["click","dblclick"],o=["enter","leave"],n=i.concat(o);function r(t,e,i){if(t.listened)switch(e.type){case"mousemove":case"mouseout":!function(t,e){if(!t.moveListened)return;let i;"mousemove"===e.type&&(i=s(t.elements,e));const o=t.hovered;t.hovered=i,function(t,e,i){const{previous:o,element:n}=e;o&&o!==n&&a(o.options.leave||t.listeners.leave,o,i);n&&n!==o&&a(n.options.enter||t.listeners.enter,n,i)}(t,{previous:o,element:i},e)}(t,e);break;case"click":!function(t,e,i){const o=t.listeners,n=s(t.elements,e);if(n){const t=n.options,r=t.dblclick||o.dblclick,s=t.click||o.click;n.clickTimeout?(clearTimeout(n.clickTimeout),delete n.clickTimeout,a(r,n,e)):r?n.clickTimeout=setTimeout((()=>{delete n.clickTimeout,a(s,n,e)}),i.dblClickSpeed):a(s,n,e)}}(t,e,i)}}function a(t,i,o){e.callback(t,[i.$context,o])}function s(t,i){let o=Number.POSITIVE_INFINITY;return t.filter((t=>t.options.display&&t.inRange(i.x,i.y))).reduce(((t,n)=>{const r=n.getCenterPoint(),a=e.distanceBetweenPoints(i,r);return a<o?(t=[n],o=a):a===o&&t.push(n),t}),[]).sort(((t,e)=>t._index-e._index)).slice(0,1)[0]}const l=(t,e,i)=>Math.min(i,Math.max(e,t));function d(t,e,i){for(const o of Object.keys(t))t[o]=l(t[o],e,i);return t}function h(t,e,{x:i,y:o,width:n,height:r}){return t>=i&&t<=i+n&&e>=o&&e<=o+r}function c(t,e){const{x:i,y:o}=t.getProps(["x","y"],e);return{x:i,y:o}}const u=t=>t&&(t.display||t.enabled),f=t=>"string"==typeof t&&t.endsWith("%"),x=t=>l(parseFloat(t)/100,0,1);function y(t,e){return"start"===e?0:"end"===e?t:f(e)?x(e)*t:t/2}function b(t,e){return"number"==typeof e?e:f(e)?x(e)*t:t}function g(t){return u(t)&&t.content}function p(t){return function(t,i,o){const n={},r=e.isObject(i),a=r?Object.keys(i):i,s=e.isObject(t)?r?o=>e.valueOrDefault(t[o],t[i[o]]):e=>t[e]:()=>t;for(const t of a)n[t]=e.valueOrDefault(s(t),o);return n}(t,["x","y"],"center")}function m(t){return t&&(e.defined(t.xValue)||e.defined(t.yValue))}const v=new Map;function w(t){return t instanceof Image||t instanceof HTMLCanvasElement}function M(t,e){if(e&&e.borderWidth)return t.lineCap=e.borderCapStyle,t.setLineDash(e.borderDash),t.lineDashOffset=e.borderDashOffset,t.lineJoin=e.borderJoinStyle,t.lineWidth=e.borderWidth,t.strokeStyle=e.borderColor,!0}function D(t,i){const o=i.content;if(w(o))return{width:b(o.width,i.width),height:b(o.height,i.height)};const n=e.toFont(i.font),r=e.isArray(o)?o:[o],a=r.join()+n.string+(t._measureText?"-spriting":"");if(!v.has(a)){t.save(),t.font=n.string;const e=r.length;let i=0;for(let o=0;o<e;o++){const e=r[o];i=Math.max(i,t.measureText(e).width)}t.restore();const o=e*n.lineHeight;v.set(a,{width:i,height:o})}return v.get(a)}function S(t,i,o){(function(t){return u(t)&&t.radius>.1})(o)&&(t.save(),t.fillStyle=o.backgroundColor,M(t,o),e.drawPoint(t,o,i.x,i.y),t.restore())}function P(t,i,o){const{x:n,y:r,width:a,height:s}=i;t.save();const l=M(t,o);t.fillStyle=o.backgroundColor,t.beginPath(),e.addRoundedRectPath(t,{x:n,y:r,w:a,h:s,radius:d(e.toTRBLCorners(e.valueOrDefault(o.cornerRadius,o.borderRadius)),0,Math.min(a,s)/2)}),t.closePath(),t.fill(),l&&t.stroke(),t.restore()}function j(t,i,o){if(!g(o))return;const n=o.content;if(w(n))return void t.drawImage(n,i.x,i.y,i.width,i.height);const r=e.isArray(n)?n:[n],a=e.toFont(o.font),s=a.lineHeight,l=function(t,e){const{x:i,width:o}=t,n=e.textAlign;return"center"===n?i+o/2:"end"===n||"right"===n?i+o:i}(i,o),d=i.y+s/2;t.font=a.string,t.textBaseline="middle",t.textAlign=o.textAlign,t.fillStyle=o.color,r.forEach(((e,i)=>t.fillText(e,l,d+i*s)))}function k(t){const{x:e,y:i,width:o,height:n}=t;return{x:e+o/2,y:i+n/2}}function C(t,i,o){return i="number"==typeof i?i:t.parse(i),e.isFinite(i)?t.getPixelForValue(i):o}function A(t,e){if(t){const i=C(t,e.min,e.start),o=C(t,e.max,e.end);return{start:Math.min(i,o),end:Math.max(i,o)}}return{start:e.start,end:e.end}}function I(t,e){const{chartArea:i,scales:o}=t,n=o[e.xScaleID],r=o[e.yScaleID];let a=i.width/2,s=i.height/2;return n&&(a=C(n,e.xValue,a)),r&&(s=C(r,e.yValue,s)),{x:a,y:s}}function W(t,e){const i=t.scales[e.xScaleID],o=t.scales[e.yScaleID];let{top:n,left:r,bottom:a,right:s}=t.chartArea;if(!i&&!o)return{options:{}};const l=A(i,{min:e.xMin,max:e.xMax,start:r,end:s});r=l.start,s=l.end;const d=A(o,{min:e.yMin,max:e.yMax,start:n,end:a});return n=d.start,a=d.end,{x:r,y:n,x2:s,y2:a,width:s-r,height:a-n}}function R(t,e){if(!m(e)){const i=W(t,e),o=k(i);let n=e.radius;return n&&!isNaN(n)||(n=Math.min(i.width,i.height)/2,e.radius=n),{x:o.x+e.xAdjust,y:o.y+e.yAdjust,width:2*n,height:2*n}}return function(t,e){const i=I(t,e);return{x:i.x+e.xAdjust,y:i.y+e.yAdjust,width:2*e.radius,height:2*e.radius}}(t,e)}class T extends t.Element{inRange(t,e,i){return h(t,e,this.getProps(["x","y","width","height"],i))}getCenterPoint(t){return k(this.getProps(["x","y","width","height"],t))}draw(t){t.save(),P(t,this,this.options),t.restore()}drawLabel(t){const{x:i,y:o,width:n,height:r,options:a}=this,s=a.label;if(g(s)){s.borderWidth=a.borderWidth,t.save(),t.beginPath(),t.rect(i+s.borderWidth/2,o+s.borderWidth/2,n-s.borderWidth,r-s.borderWidth),t.clip();const l=p(s.position),d=e.toPadding(s.padding),h=D(t,s);j(t,{x:O(this,h,l,d),y:E(this,h,l,d),width:h.width,height:h.height},s),t.restore()}}resolveElementProperties(t,e){return W(t,e)}}function O(t,e,i,o){const{x:n,x2:r,width:a,options:s}=t,{xAdjust:l,borderWidth:d}=s.label;return V({start:n,end:r,size:a},{position:i.x,padding:{start:o.left,end:o.right},adjust:l,borderWidth:d,size:e.width})}function E(t,e,i,o){const{y:n,y2:r,height:a,options:s}=t,{yAdjust:l,borderWidth:d}=s.label;return V({start:n,end:r,size:a},{position:i.y,padding:{start:o.top,end:o.bottom},adjust:l,borderWidth:d,size:e.height})}function V(t,e){const{start:i,end:o}=t,{position:n,padding:{start:r,end:a},adjust:s,borderWidth:l}=e;return i+l/2+s+r+y(o-l-i-r-a-e.size,n)}T.id="boxAnnotation",T.defaults={adjustScaleRange:!0,borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,cornerRadius:void 0,borderWidth:1,display:!0,xMax:void 0,xMin:void 0,xScaleID:"x",yMax:void 0,yMin:void 0,yScaleID:"y",label:{color:"black",content:null,drawTime:void 0,enabled:!1,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,padding:6,position:"center",textAlign:"start",xAdjust:0,yAdjust:0,width:void 0}},T.defaultRoutes={borderColor:"color",backgroundColor:"color"};const N=Math.PI,L=(t,e,i)=>({x:t.x+i*(e.x-t.x),y:t.y+i*(e.y-t.y)}),z=(t,e,i)=>L(e,i,Math.abs((t-e.y)/(i.y-e.y))).x,H=(t,e,i)=>L(e,i,Math.abs((t-e.x)/(i.x-e.x))).y;function Y({x:t,y:e,x2:i,y2:o},{top:n,right:r,bottom:a,left:s}){return!(t<s&&i<s||t>r&&i>r||e<n&&o<n||e>a&&o>a)}function _({x:t,y:e},i,{top:o,right:n,bottom:r,left:a}){return t<a&&(e=H(a,{x:t,y:e},i),t=a),t>n&&(e=H(n,{x:t,y:e},i),t=n),e<o&&(t=z(o,{x:t,y:e},i),e=o),e>r&&(t=z(r,{x:t,y:e},i),e=r),{x:t,y:e}}class X extends t.Element{intersects(t,e,i=.001,o){const n=t=>t*t,{x:r,y:a,x2:s,y2:l}=this.getProps(["x","y","x2","y2"],o),d=s-r,h=l-a,c=n(d)+n(h),u=0===c?-1:((t-r)*d+(e-a)*h)/c;let f,x;return u<0?(f=r,x=a):u>1?(f=s,x=l):(f=r+u*d,x=a+u*h),n(t-f)+n(e-x)<i}labelIsVisible(t,e){return!!this.labelVisible&&(!e||Y(this.getProps(["x","y","x2","y2"],t),e))}isOnLabel(t,e,i){if(!this.labelIsVisible(i))return!1;const{labelX:o,labelY:n,labelWidth:r,labelHeight:a,labelRotation:s}=this.getProps(["labelX","labelY","labelWidth","labelHeight","labelRotation"],i),{x:l,y:d}=(h={x:t,y:e},c={x:o,y:n},u=-s,f=Math.cos(u),x=Math.sin(u),y=c.x,b=c.y,{x:y+f*(h.x-y)-x*(h.y-b),y:b+x*(h.x-y)+f*(h.y-b)});var h,c,u,f,x,y,b;const g=r/2,p=a/2;return l>=o-g&&l<=o+g&&d>=n-p&&d<=n+p}inRange(t,e,i){const o=this.options.borderWidth||1;return this.intersects(t,e,o,i)||this.isOnLabel(t,e,i)}getCenterPoint(){return{x:(this.x2+this.x)/2,y:(this.y2+this.y)/2}}draw(t){const{x:e,y:i,x2:o,y2:n,options:r}=this;t.save(),t.lineWidth=r.borderWidth,t.strokeStyle=r.borderColor,t.setLineDash(r.borderDash),t.lineDashOffset=r.borderDashOffset,t.beginPath(),t.moveTo(e,i),t.lineTo(o,n),t.stroke(),t.restore()}drawLabel(t,e){this.labelIsVisible(!1,e)&&(t.save(),function(t,e){const{labelX:i,labelY:o,labelWidth:n,labelHeight:r,labelRotation:a,labelPadding:s,labelTextSize:l,options:d}=e,h=d.label;t.translate(i,o),t.rotate(a);P(t,{x:-n/2,y:-r/2,width:n,height:r},h);const c={x:-n/2+s.left+h.borderWidth/2,y:-r/2+s.top+h.borderWidth/2,width:l.width,height:l.height};j(t,c,h)}(t,this),t.restore())}resolveElementProperties(t,i){const o=t.scales[i.scaleID];let n,r,{top:a,left:s,bottom:l,right:d}=t.chartArea;if(o)n=C(o,i.value,NaN),r=C(o,i.endValue,n),o.isHorizontal()?(s=n,d=r):(a=n,l=r);else{const e=t.scales[i.xScaleID],o=t.scales[i.yScaleID];e&&(s=C(e,i.xMin,s),d=C(e,i.xMax,d)),o&&(a=C(o,i.yMin,a),l=C(o,i.yMax,l))}const h=Y({x:s,y:a,x2:d,y2:l},t.chartArea)?function(t,e,i){const{x:o,y:n}=_(t,e,i),{x:r,y:a}=_(e,t,i);return{x:o,y:n,x2:r,y2:a,width:Math.abs(r-o),height:Math.abs(a-n)}}({x:s,y:a},{x:d,y:l},t.chartArea):{x:s,y:a,x2:d,y2:l,width:Math.abs(d-s),height:Math.abs(l-a)},c=i.label;return h.labelVisible=!!g(c),h.labelVisible?function(t,i,o){const{padding:n,xPadding:r,yPadding:a,borderWidth:s}=o,l=function(t,i,o){let n=t;(i||o)&&(n={x:i||6,y:o||6});return e.toPadding(n)}(n,r,a),d=D(i.ctx,o),h=d.width+l.width+s,c=d.height+l.height+s,u=function(t,i,o,n){const{width:r,height:a,padding:s}=o,{xAdjust:l,yAdjust:d}=i,h={x:t.x,y:t.y},c={x:t.x2,y:t.y2},u="auto"===i.rotation?function(t){const{x:e,y:i,x2:o,y2:n}=t,r=Math.atan2(n-i,o-e);return r>N/2?r-N:r<N/-2?r+N:r}(t):e.toRadians(i.rotation),f=function(t,e,i){const o=Math.cos(i),n=Math.sin(i);return{w:Math.abs(t*o)+Math.abs(e*n),h:Math.abs(t*n)+Math.abs(e*o)}}(r,a,u),x=function(t,e,i,o){let n;const r=function(t,e){const{x:i,x2:o,y:n,y2:r}=t,a=Math.min(n,r)-e.top,s=Math.min(i,o)-e.left,l=e.bottom-Math.max(n,r),d=e.right-Math.max(i,o);return{x:Math.min(s,d),y:Math.min(a,l),dx:s<=d?1:-1,dy:a<=l?1:-1}}(t,o);n="start"===e.position?F({w:t.x2-t.x,h:t.y2-t.y},i,e,r):"end"===e.position?1-F({w:t.x-t.x2,h:t.y-t.y2},i,e,r):y(1,e.position);return n}(t,i,{labelSize:f,padding:s},n),b=L(h,c,x),g={size:f.w,min:n.left,max:n.right,padding:s.left},p={size:f.h,min:n.top,max:n.bottom,padding:s.top};return{x:$(b.x,g)+l,y:$(b.y,p)+d,width:r,height:a,rotation:u}}(t,o,{width:h,height:c,padding:l},i.chartArea);return t.labelX=u.x,t.labelY=u.y,t.labelWidth=u.width,t.labelHeight=u.height,t.labelRotation=u.rotation,t.labelPadding=l,t.labelTextSize=d,t}(h,t,c):h}}function F(t,e,i,o){const{labelSize:n,padding:r}=e,a=t.w*o.dx,s=t.h*o.dy,d=a>0&&(n.w/2+r.left-o.x)/a,h=s>0&&(n.h/2+r.top-o.y)/s;return l(Math.max(d,h),0,.25)}function $(t,e){const{size:i,min:o,max:n,padding:r}=e,a=i/2;return i>n-o?(n+o)/2:(o>=t-r-a&&(t=o+r+a),n<=t+r+a&&(t=n-r-a),t)}X.id="lineAnnotation",X.defaults={display:!0,adjustScaleRange:!0,borderWidth:2,borderDash:[],borderDashOffset:0,label:{backgroundColor:"rgba(0,0,0,0.8)",borderCapStyle:"butt",borderColor:"black",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:6,borderWidth:0,color:"#fff",content:null,cornerRadius:void 0,drawTime:void 0,enabled:!1,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,padding:6,xPadding:void 0,yPadding:void 0,position:"center",rotation:0,textAlign:"center",width:void 0,xAdjust:0,yAdjust:0},value:void 0,endValue:void 0,scaleID:void 0,xScaleID:"x",xMin:void 0,xMax:void 0,yScaleID:"y",yMin:void 0,yMax:void 0},X.defaultRoutes={borderColor:"color"};class J extends t.Element{inRange(t,e,i){return function(t,e){const{width:i,height:o}=e,n=e.getCenterPoint(!0),r=i/2,a=o/2;if(r<=0||a<=0)return!1;return Math.pow(t.x-n.x,2)/Math.pow(r,2)+Math.pow(t.y-n.y,2)/Math.pow(a,2)<=1}({x:t,y:e},this.getProps(["x","y","width","height"],i))}getCenterPoint(t){return k(this.getProps(["x","y","width","height"],t))}draw(t){const{width:i,height:o,options:n}=this,r=this.getCenterPoint();t.save(),t.translate(r.x,r.y),n.rotation&&t.rotate(e.toRadians(n.rotation)),t.beginPath(),t.lineWidth=n.borderWidth,t.strokeStyle=n.borderColor,t.fillStyle=n.backgroundColor,t.setLineDash(n.borderDash),t.lineDashOffset=n.borderDashOffset,t.ellipse(0,0,o/2,i/2,Math.PI/2,0,2*Math.PI),t.fill(),t.stroke(),t.restore()}resolveElementProperties(t,e){return W(t,e)}}J.id="ellipseAnnotation",J.defaults={display:!0,adjustScaleRange:!0,borderDash:[],borderDashOffset:0,borderWidth:1,rotation:0,xScaleID:"x",xMin:void 0,xMax:void 0,yScaleID:"y",yMin:void 0,yMax:void 0},J.defaultRoutes={borderColor:"color",backgroundColor:"color"};class U extends t.Element{inRange(t,e,i){return this.visible&&h(t,e,this.getProps(["x","y","width","height"],i))}getCenterPoint(t){return k(this.getProps(["x","y","width","height"],t))}draw(t){if(!this.visible)return;const{labelX:e,labelY:i,labelWidth:o,labelHeight:n,options:r}=this;!function(t,e){const{pointX:i,pointY:o,calloutPosition:n,options:r}=e;if(!n)return;const a=r.callout,{separatorStart:s,separatorEnd:l}=function(t,e){const{x:i,y:o,width:n,height:r}=t,a=function(t,e){const{width:i,height:o,options:n}=t,r=n.callout.margin+n.borderWidth/2;if("right"===e)return i+r;if("bottom"===e)return o+r;return-r}(t,e);let s,l;"left"===e||"right"===e?(s={x:i+a,y:o},l={x:s.x,y:s.y+r}):"top"!==e&&"bottom"!==e||(s={x:i,y:o+a},l={x:s.x+n,y:s.y});return{separatorStart:s,separatorEnd:l}}(e,n),{sideStart:d,sideEnd:h}=function(t,e,i){const{y:o,width:n,height:r,options:a}=t,s=a.callout.start,l=function(t,e){const i=e.side;if("left"===t||"top"===t)return-i;return i}(e,a.callout);let d,h;"left"===e||"right"===e?(d={x:i.x,y:o+b(r,s)},h={x:d.x+l,y:d.y}):"top"!==e&&"bottom"!==e||(d={x:i.x+b(n,s),y:i.y},h={x:d.x,y:d.y+l});return{sideStart:d,sideEnd:h}}(e,n,s);t.save(),t.beginPath();const c=M(t,a);(a.margin>0||0===r.borderWidth)&&(t.moveTo(s.x,s.y),t.lineTo(l.x,l.y));t.moveTo(d.x,d.y),t.lineTo(h.x,h.y),t.lineTo(i,o),c&&t.stroke();t.restore()}(t,this),this.boxVisible&&P(t,this,r),j(t,{x:e,y:i,width:o,height:n},r)}resolveElementProperties(t,i){const o=!!g(i),n=m(i)?I(t,i):k(W(t,i)),r=e.toPadding(i.padding),a=D(t.ctx,i),s=function(t,e,i,o){const n=e.width+o.width+i.borderWidth,r=e.height+o.height+i.borderWidth,a=p(i.position);return{x:B(t.x,n,i.xAdjust,a.x),y:B(t.y,r,i.yAdjust,a.y),width:n,height:r}}(n,a,i,r),l=e.color(i.backgroundColor),d={visible:o,boxVisible:i.borderWidth>0||l&&l.valid&&l.rgb.a>0,pointX:n.x,pointY:n.y,...s,labelX:s.x+r.left+i.borderWidth/2,labelY:s.y+r.top+i.borderWidth/2,labelWidth:a.width,labelHeight:a.height};return d.calloutPosition=i.callout.enabled&&function(t,e){const i=e.position;if("left"===i||"right"===i||"top"===i||"bottom"===i)return i;return function(t,e){const{x:i,y:o,width:n,height:r,pointX:a,pointY:s}=t,{margin:l,side:d}=e,h=l+d;if(a<i-h)return"left";if(a>i+n+h)return"right";if(s<o+r+h)return"top";if(s>o-h)return"bottom"}(t,e)}(d,i.callout),d}}function B(t,e,i,o){return t-y(e,o)+i}U.id="labelAnnotation",U.defaults={adjustScaleRange:!0,backgroundColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,borderWidth:0,callout:{borderCapStyle:"butt",borderColor:void 0,borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:1,enabled:!1,margin:5,position:"auto",side:5,start:"50%"},color:"black",content:null,display:!0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:void 0},height:void 0,padding:6,position:"center",textAlign:"center",width:void 0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:"x",xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:"y",yValue:void 0},U.defaultRoutes={borderColor:"color",backgroundColor:"color"};class q extends t.Element{inRange(t,e,i){const{width:o}=this.getProps(["width"],i);return n={x:t,y:e},r=this.getCenterPoint(i),a=o/2+this.options.borderWidth,!(!n||!r||a<=0)&&Math.pow(n.x-r.x,2)+Math.pow(n.y-r.y,2)<=Math.pow(a,2);var n,r,a}getCenterPoint(t){return c(this,t)}draw(t){S(t,this,this.options)}resolveElementProperties(t,e){return R(t,e)}}q.id="pointAnnotation",q.defaults={display:!0,adjustScaleRange:!0,borderDash:[],borderDashOffset:0,borderWidth:1,pointStyle:"circle",radius:10,rotation:0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:"x",xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:"y",yValue:void 0},q.defaultRoutes={borderColor:"color",backgroundColor:"color"};class G extends t.Element{inRange(t,e,i){const o=K(this.getProps(["x","y"],i),this.options);return o&&o.length>0&&function(t,e,i){let o=!1,n=0,r=t.length-1;for(;n<t.length;r=n++)t[n].y>i!=t[r].y>i&&e<(t[r].x-t[n].x)*(i-t[n].y)/(t[r].y-t[n].y)+t[n].x&&(o=!o);return o}(o,t,e)}getCenterPoint(t){return c(this,t)}draw(t){const{x:e,y:i,options:o}=this,n=K({x:e,y:i},o);let r=n[0];t.save(),t.beginPath(),t.fillStyle=o.backgroundColor;const a=M(t,o);t.moveTo(r.x,r.y);for(let e=1;e<n.length;e++)r=n[e],t.lineTo(r.x,r.y);t.closePath(),t.fill(),a&&t.stroke(),t.restore()}resolveElementProperties(t,i){return e.isNumber(i.sides)&&i.sides>=1?R(t,i):{options:{}}}}function K(t,i){const{sides:o,radius:n}=i;let r=2*e.PI/o,a=i.rotation*e.RAD_PER_DEG;const s=new Array;Q(s,t,a,n);for(let e=0;e<o;e++)a+=r,Q(s,t,a,n);return s}function Q(t,e,i,o){t.push({x:e.x+Math.sin(i)*o,y:e.y-Math.cos(i)*o})}G.id="polygonAnnotation",G.defaults={display:!0,adjustScaleRange:!0,borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:1,radius:10,rotation:0,sides:3,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:"x",xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:"y",yValue:void 0},G.defaultRoutes={borderColor:"color",backgroundColor:"color"};const Z={box:T,ellipse:J,label:U,line:X,point:q,polygon:G};Object.keys(Z).forEach((e=>{t.defaults.describe(`elements.${Z[e].id}`,{_fallback:"plugins.annotation"})}));const tt=new Map;var et={id:"annotation",version:"1.2.0",afterRegister(){t.Chart.register(Z)},afterUnregister(){t.Chart.unregister(Z)},beforeInit(t){tt.set(t,{annotations:[],elements:[],listeners:{},listened:!1,moveListened:!1})},beforeUpdate(t,i,o){const n=tt.get(t).annotations=[];let r=o.annotations;e.isObject(r)?Object.keys(r).forEach((t=>{const i=r[t];e.isObject(i)&&(i.id=t,n.push(i))})):e.isArray(r)&&n.push(...r),function(t,e){for(const i of t)for(const t of["scaleID","xScaleID","yScaleID"])i[t]&&!e[i[t]]&&console.warn(`No scale found with id '${i[t]}' for annotation '${i.id}'`)}(n,t.scales)},afterDataLimits(t,i){const o=tt.get(t);!function(t,i,o){const n=function(t,i){const o=t.axis,n=t.id,r=o+"ScaleID";let a=e.valueOrDefault(t.min,Number.NEGATIVE_INFINITY),s=e.valueOrDefault(t.max,Number.POSITIVE_INFINITY);for(const e of i)if(e.scaleID===n)for(const i of["value","endValue"]){const o=e[i];if(o){const e=t.parse(o);a=Math.min(a,e),s=Math.max(s,e)}}else if(e[r]===n)for(const i of[o+"Min",o+"Max",o+"Value"]){const o=e[i];if(o){const e=t.parse(o);a=Math.min(a,e),s=Math.max(s,e)}}return{min:a,max:s}}(i,o);let r=!1;e.isFinite(n.min)&&void 0===i.options.min&&void 0===i.options.suggestedMin&&(r=i.min!==n.min,i.min=n.min);e.isFinite(n.max)&&void 0===i.options.max&&void 0===i.options.suggestedMax&&(r=i.max!==n.max,i.max=n.max);r&&"function"==typeof i.handleTickRangeOptions&&i.handleTickRangeOptions()}(0,i.scale,o.annotations.filter((t=>t.display&&t.adjustScaleRange)))},afterUpdate(e,r,a){const s=tt.get(e);!function(t,e,r){const a=e.annotations||[];e.listened=!1,e.moveListened=!1,n.forEach((t=>{"function"==typeof r[t]&&(e.listened=!0,e.listeners[t]=r[t])})),o.forEach((t=>{"function"==typeof r[t]&&(e.moveListened=!0)})),e.listened&&e.moveListened||a.forEach((t=>{e.listened||i.forEach((i=>{"function"==typeof t[i]&&(e.listened=!0)})),e.moveListened||o.forEach((i=>{"function"==typeof t[i]&&(e.listened=!0,e.moveListened=!0)}))}))}(0,s,a),function(e,i,o,n){const r=function(e,i,o){if("reset"===o||"none"===o||"resize"===o)return it;return new t.Animations(e,i)}(e,o.animations,n),a=i.annotations,s=function(t,e){const i=e.length,o=t.length;if(o<i){const e=i-o;t.splice(o,0,...new Array(e))}else o>i&&t.splice(i,o-i);return t}(i.elements,a);for(let t=0;t<a.length;t++){const i=a[t];let o=s[t];const n=Z[ot(i.type)];o&&o instanceof n||(o=s[t]=new n);const l=nt(i.setContext(at(e,o,i))),d=o.resolveElementProperties(e,l);d.skip=isNaN(d.x)||isNaN(d.y),d.options=l,r.update(o,d)}}(e,s,a,r.mode)},beforeDatasetsDraw(t,e,i){st(t,"beforeDatasetsDraw",i.clip)},afterDatasetsDraw(t,e,i){st(t,"afterDatasetsDraw",i.clip)},beforeDraw(t,e,i){st(t,"beforeDraw",i.clip)},afterDraw(t,e,i){st(t,"afterDraw",i.clip)},beforeEvent(t,e,i){r(tt.get(t),e.event,i)},destroy(t){tt.delete(t)},_getState:t=>tt.get(t),defaults:{drawTime:"afterDatasetsDraw",dblClickSpeed:350,animations:{numbers:{properties:["x","y","x2","y2","width","height","pointX","pointY","labelX","labelY","labelWidth","labelHeight","radius"],type:"number"}},clip:!0,label:{drawTime:null}},descriptors:{_indexable:!1,_scriptable:t=>!n.includes(t),annotations:{_allKeys:!1,_fallback:(t,e)=>`elements.${Z[ot(e.type)].id}`}},additionalOptionScopes:[""]};const it={update:Object.assign};function ot(t="line"){return Z[t]?t:(console.warn(`Unknown annotation type: '${t}', defaulting to 'line'`),"line")}function nt(t){const e=Z[ot(t.type)],i={};i.id=t.id,i.type=t.type,i.drawTime=t.drawTime,Object.assign(i,rt(t,e.defaults),rt(t,e.defaultRoutes));for(const e of n)i[e]=t[e];return i}function rt(t,i){const o={};for(const n of Object.keys(i)){const r=i[n],a=t[n];o[n]=e.isObject(r)?rt(a,r):a}return o}function at(t,e,i){return e.$context||(e.$context=Object.assign(Object.create(t.getContext()),{element:e,id:i.id,type:"annotation"}))}function st(t,i,o){const{ctx:n,chartArea:r}=t,a=tt.get(t).elements.filter((t=>!t.skip&&t.options.display));o&&e.clipArea(n,r),a.forEach((t=>{t.options.drawTime===i&&t.draw(n)})),o&&e.unclipArea(n),a.forEach((t=>{"drawLabel"in t&&t.options.label&&(t.options.label.drawTime||t.options.drawTime)===i&&t.drawLabel(n,r)}))}return t.Chart.register(et),et}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["chartjs-plugin-annotation"]=e(t.Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";const i=["click","dblclick"],o=["enter","leave"],n=i.concat(o);function r(t,e,i){if(t.listened)switch(e.type){case"mousemove":case"mouseout":!function(t,e){if(!t.moveListened)return;let i;"mousemove"===e.type&&(i=s(t.elements,e));const o=t.hovered;t.hovered=i,function(t,e,i){const{previous:o,element:n}=e;o&&o!==n&&a(o.options.leave||t.listeners.leave,o,i);n&&n!==o&&a(n.options.enter||t.listeners.enter,n,i)}(t,{previous:o,element:i},e)}(t,e);break;case"click":!function(t,e,i){const o=t.listeners,n=s(t.elements,e);if(n){const t=n.options,r=t.dblclick||o.dblclick,s=t.click||o.click;n.clickTimeout?(clearTimeout(n.clickTimeout),delete n.clickTimeout,a(r,n,e)):r?n.clickTimeout=setTimeout((()=>{delete n.clickTimeout,a(s,n,e)}),i.dblClickSpeed):a(s,n,e)}}(t,e,i)}}function a(t,i,o){e.callback(t,[i.$context,o])}function s(t,i){let o=Number.POSITIVE_INFINITY;return t.filter((t=>t.options.display&&t.inRange(i.x,i.y))).reduce(((t,n)=>{const r=n.getCenterPoint(),a=e.distanceBetweenPoints(i,r);return a<o?(t=[n],o=a):a===o&&t.push(n),t}),[]).sort(((t,e)=>t._index-e._index)).slice(0,1)[0]}const l=(t,e,i)=>Math.min(i,Math.max(e,t));function d(t,e,i){for(const o of Object.keys(t))t[o]=l(t[o],e,i);return t}function h(t,e,{x:i,y:o,width:n,height:r}){return t>=i&&t<=i+n&&e>=o&&e<=o+r}function c(t,e){const{x:i,y:o}=t.getProps(["x","y"],e);return{x:i,y:o}}const u=t=>t&&(t.display||t.enabled),f=t=>"string"==typeof t&&t.endsWith("%"),x=t=>l(parseFloat(t)/100,0,1);function y(t,e){return"start"===e?0:"end"===e?t:f(e)?x(e)*t:t/2}function b(t,e){return"number"==typeof e?e:f(e)?x(e)*t:t}function g(t){return u(t)&&t.content}function p(t){return function(t,i,o){const n={},r=e.isObject(i),a=r?Object.keys(i):i,s=e.isObject(t)?r?o=>e.valueOrDefault(t[o],t[i[o]]):e=>t[e]:()=>t;for(const t of a)n[t]=e.valueOrDefault(s(t),o);return n}(t,["x","y"],"center")}function m(t){return t&&(e.defined(t.xValue)||e.defined(t.yValue))}const v=new Map;function w(t){return t instanceof Image||t instanceof HTMLCanvasElement}function M(t,e){if(e&&e.borderWidth)return t.lineCap=e.borderCapStyle,t.setLineDash(e.borderDash),t.lineDashOffset=e.borderDashOffset,t.lineJoin=e.borderJoinStyle,t.lineWidth=e.borderWidth,t.strokeStyle=e.borderColor,!0}function D(t,i){const o=i.content;if(w(o))return{width:b(o.width,i.width),height:b(o.height,i.height)};const n=e.toFont(i.font),r=e.isArray(o)?o:[o],a=r.join()+n.string+(t._measureText?"-spriting":"");if(!v.has(a)){t.save(),t.font=n.string;const e=r.length;let i=0;for(let o=0;o<e;o++){const e=r[o];i=Math.max(i,t.measureText(e).width)}t.restore();const o=e*n.lineHeight;v.set(a,{width:i,height:o})}return v.get(a)}function S(t,i,o){(function(t){return u(t)&&t.radius>.1})(o)&&(t.save(),t.fillStyle=o.backgroundColor,M(t,o),e.drawPoint(t,o,i.x,i.y),t.restore())}function P(t,i,o){const{x:n,y:r,width:a,height:s}=i;t.save();const l=M(t,o);t.fillStyle=o.backgroundColor,t.beginPath(),e.addRoundedRectPath(t,{x:n,y:r,w:a,h:s,radius:d(e.toTRBLCorners(e.valueOrDefault(o.cornerRadius,o.borderRadius)),0,Math.min(a,s)/2)}),t.closePath(),t.fill(),l&&t.stroke(),t.restore()}function C(t,i,o){if(!g(o))return;const n=o.content;if(w(n))return void t.drawImage(n,i.x,i.y,i.width,i.height);const r=e.isArray(n)?n:[n],a=e.toFont(o.font),s=a.lineHeight,l=function(t,e){const{x:i,width:o}=t,n=e.textAlign;return"center"===n?i+o/2:"end"===n||"right"===n?i+o:i}(i,o),d=i.y+s/2;t.font=a.string,t.textBaseline="middle",t.textAlign=o.textAlign,t.fillStyle=o.color,r.forEach(((e,i)=>t.fillText(e,l,d+i*s)))}function j(t){const{x:e,y:i,width:o,height:n}=t;return{x:e+o/2,y:i+n/2}}function k(t,i,o){return i="number"==typeof i?i:t.parse(i),e.isFinite(i)?t.getPixelForValue(i):o}function A(t,e){if(t){const i=k(t,e.min,e.start),o=k(t,e.max,e.end);return{start:Math.min(i,o),end:Math.max(i,o)}}return{start:e.start,end:e.end}}function I(t,e){const{chartArea:i,scales:o}=t,n=o[e.xScaleID],r=o[e.yScaleID];let a=i.width/2,s=i.height/2;return n&&(a=k(n,e.xValue,a)),r&&(s=k(r,e.yValue,s)),{x:a,y:s}}function W(t,e){const i=t.scales[e.xScaleID],o=t.scales[e.yScaleID];let{top:n,left:r,bottom:a,right:s}=t.chartArea;if(!i&&!o)return{options:{}};const l=A(i,{min:e.xMin,max:e.xMax,start:r,end:s});r=l.start,s=l.end;const d=A(o,{min:e.yMin,max:e.yMax,start:n,end:a});return n=d.start,a=d.end,{x:r,y:n,x2:s,y2:a,width:s-r,height:a-n}}function R(t,e){if(!m(e)){const i=W(t,e),o=j(i);let n=e.radius;return n&&!isNaN(n)||(n=Math.min(i.width,i.height)/2,e.radius=n),{x:o.x+e.xAdjust,y:o.y+e.yAdjust,width:2*n,height:2*n}}return function(t,e){const i=I(t,e);return{x:i.x+e.xAdjust,y:i.y+e.yAdjust,width:2*e.radius,height:2*e.radius}}(t,e)}class T extends t.Element{inRange(t,e,i){return h(t,e,this.getProps(["x","y","width","height"],i))}getCenterPoint(t){return j(this.getProps(["x","y","width","height"],t))}draw(t){t.save(),P(t,this,this.options),t.restore()}drawLabel(t){const{x:i,y:o,width:n,height:r,options:a}=this,s=a.label;if(g(s)){s.borderWidth=a.borderWidth,t.save(),t.beginPath(),t.rect(i+s.borderWidth/2,o+s.borderWidth/2,n-s.borderWidth,r-s.borderWidth),t.clip();const l=p(s.position),d=e.toPadding(s.padding),h=D(t,s);C(t,{x:O(this,h,l,d),y:E(this,h,l,d),width:h.width,height:h.height},s),t.restore()}}resolveElementProperties(t,e){return W(t,e)}}function O(t,e,i,o){const{x:n,x2:r,width:a,options:s}=t,{xAdjust:l,borderWidth:d}=s.label;return V({start:n,end:r,size:a},{position:i.x,padding:{start:o.left,end:o.right},adjust:l,borderWidth:d,size:e.width})}function E(t,e,i,o){const{y:n,y2:r,height:a,options:s}=t,{yAdjust:l,borderWidth:d}=s.label;return V({start:n,end:r,size:a},{position:i.y,padding:{start:o.top,end:o.bottom},adjust:l,borderWidth:d,size:e.height})}function V(t,e){const{start:i,end:o}=t,{position:n,padding:{start:r,end:a},adjust:s,borderWidth:l}=e;return i+l/2+s+r+y(o-l-i-r-a-e.size,n)}T.id="boxAnnotation",T.defaults={adjustScaleRange:!0,borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,cornerRadius:void 0,borderWidth:1,display:!0,xMax:void 0,xMin:void 0,xScaleID:"x",yMax:void 0,yMin:void 0,yScaleID:"y",label:{color:"black",content:null,drawTime:void 0,enabled:!1,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,padding:6,position:"center",textAlign:"start",xAdjust:0,yAdjust:0,width:void 0}},T.defaultRoutes={borderColor:"color",backgroundColor:"color"};const N=Math.PI,L=(t,e,i)=>({x:t.x+i*(e.x-t.x),y:t.y+i*(e.y-t.y)}),z=(t,e,i)=>L(e,i,Math.abs((t-e.y)/(i.y-e.y))).x,H=(t,e,i)=>L(e,i,Math.abs((t-e.x)/(i.x-e.x))).y;function Y({x:t,y:e,x2:i,y2:o},{top:n,right:r,bottom:a,left:s}){return!(t<s&&i<s||t>r&&i>r||e<n&&o<n||e>a&&o>a)}function _({x:t,y:e},i,{top:o,right:n,bottom:r,left:a}){return t<a&&(e=H(a,{x:t,y:e},i),t=a),t>n&&(e=H(n,{x:t,y:e},i),t=n),e<o&&(t=z(o,{x:t,y:e},i),e=o),e>r&&(t=z(r,{x:t,y:e},i),e=r),{x:t,y:e}}class X extends t.Element{intersects(t,e,i=.001,o){const n=t=>t*t,{x:r,y:a,x2:s,y2:l}=this.getProps(["x","y","x2","y2"],o),d=s-r,h=l-a,c=n(d)+n(h),u=0===c?-1:((t-r)*d+(e-a)*h)/c;let f,x;return u<0?(f=r,x=a):u>1?(f=s,x=l):(f=r+u*d,x=a+u*h),n(t-f)+n(e-x)<i}labelIsVisible(t,e){return!!this.labelVisible&&(!e||Y(this.getProps(["x","y","x2","y2"],t),e))}isOnLabel(t,e,i){if(!this.labelIsVisible(i))return!1;const{labelX:o,labelY:n,labelWidth:r,labelHeight:a,labelRotation:s}=this.getProps(["labelX","labelY","labelWidth","labelHeight","labelRotation"],i),{x:l,y:d}=(h={x:t,y:e},c={x:o,y:n},u=-s,f=Math.cos(u),x=Math.sin(u),y=c.x,b=c.y,{x:y+f*(h.x-y)-x*(h.y-b),y:b+x*(h.x-y)+f*(h.y-b)});var h,c,u,f,x,y,b;const g=r/2,p=a/2;return l>=o-g&&l<=o+g&&d>=n-p&&d<=n+p}inRange(t,e,i){const o=this.options.borderWidth||1;return this.intersects(t,e,o,i)||this.isOnLabel(t,e,i)}getCenterPoint(){return{x:(this.x2+this.x)/2,y:(this.y2+this.y)/2}}draw(t){const{x:e,y:i,x2:o,y2:n,options:r}=this;t.save(),t.lineWidth=r.borderWidth,t.strokeStyle=r.borderColor,t.setLineDash(r.borderDash),t.lineDashOffset=r.borderDashOffset,t.beginPath(),t.moveTo(e,i),t.lineTo(o,n),t.stroke(),t.restore()}drawLabel(t,e){this.labelIsVisible(!1,e)&&(t.save(),function(t,e){const{labelX:i,labelY:o,labelWidth:n,labelHeight:r,labelRotation:a,labelPadding:s,labelTextSize:l,options:d}=e,h=d.label;t.translate(i,o),t.rotate(a);P(t,{x:-n/2,y:-r/2,width:n,height:r},h);const c={x:-n/2+s.left+h.borderWidth/2,y:-r/2+s.top+h.borderWidth/2,width:l.width,height:l.height};C(t,c,h)}(t,this),t.restore())}resolveElementProperties(t,i){const o=t.scales[i.scaleID];let n,r,{top:a,left:s,bottom:l,right:d}=t.chartArea;if(o)n=k(o,i.value,NaN),r=k(o,i.endValue,n),o.isHorizontal()?(s=n,d=r):(a=n,l=r);else{const e=t.scales[i.xScaleID],o=t.scales[i.yScaleID];e&&(s=k(e,i.xMin,s),d=k(e,i.xMax,d)),o&&(a=k(o,i.yMin,a),l=k(o,i.yMax,l))}const h=Y({x:s,y:a,x2:d,y2:l},t.chartArea)?function(t,e,i){const{x:o,y:n}=_(t,e,i),{x:r,y:a}=_(e,t,i);return{x:o,y:n,x2:r,y2:a,width:Math.abs(r-o),height:Math.abs(a-n)}}({x:s,y:a},{x:d,y:l},t.chartArea):{x:s,y:a,x2:d,y2:l,width:Math.abs(d-s),height:Math.abs(l-a)},c=i.label;return h.labelVisible=!!g(c),h.labelVisible?function(t,i,o){const{padding:n,xPadding:r,yPadding:a,borderWidth:s}=o,l=function(t,i,o){let n=t;(i||o)&&(n={x:i||6,y:o||6});return e.toPadding(n)}(n,r,a),d=D(i.ctx,o),h=d.width+l.width+s,c=d.height+l.height+s,u=function(t,i,o,n){const{width:r,height:a,padding:s}=o,{xAdjust:l,yAdjust:d}=i,h={x:t.x,y:t.y},c={x:t.x2,y:t.y2},u="auto"===i.rotation?function(t){const{x:e,y:i,x2:o,y2:n}=t,r=Math.atan2(n-i,o-e);return r>N/2?r-N:r<N/-2?r+N:r}(t):e.toRadians(i.rotation),f=function(t,e,i){const o=Math.cos(i),n=Math.sin(i);return{w:Math.abs(t*o)+Math.abs(e*n),h:Math.abs(t*n)+Math.abs(e*o)}}(r,a,u),x=function(t,e,i,o){let n;const r=function(t,e){const{x:i,x2:o,y:n,y2:r}=t,a=Math.min(n,r)-e.top,s=Math.min(i,o)-e.left,l=e.bottom-Math.max(n,r),d=e.right-Math.max(i,o);return{x:Math.min(s,d),y:Math.min(a,l),dx:s<=d?1:-1,dy:a<=l?1:-1}}(t,o);n="start"===e.position?F({w:t.x2-t.x,h:t.y2-t.y},i,e,r):"end"===e.position?1-F({w:t.x-t.x2,h:t.y-t.y2},i,e,r):y(1,e.position);return n}(t,i,{labelSize:f,padding:s},n),b=L(h,c,x),g={size:f.w,min:n.left,max:n.right,padding:s.left},p={size:f.h,min:n.top,max:n.bottom,padding:s.top};return{x:$(b.x,g)+l,y:$(b.y,p)+d,width:r,height:a,rotation:u}}(t,o,{width:h,height:c,padding:l},i.chartArea);return t.labelX=u.x,t.labelY=u.y,t.labelWidth=u.width,t.labelHeight=u.height,t.labelRotation=u.rotation,t.labelPadding=l,t.labelTextSize=d,t}(h,t,c):h}}function F(t,e,i,o){const{labelSize:n,padding:r}=e,a=t.w*o.dx,s=t.h*o.dy,d=a>0&&(n.w/2+r.left-o.x)/a,h=s>0&&(n.h/2+r.top-o.y)/s;return l(Math.max(d,h),0,.25)}function $(t,e){const{size:i,min:o,max:n,padding:r}=e,a=i/2;return i>n-o?(n+o)/2:(o>=t-r-a&&(t=o+r+a),n<=t+r+a&&(t=n-r-a),t)}X.id="lineAnnotation",X.defaults={display:!0,adjustScaleRange:!0,borderWidth:2,borderDash:[],borderDashOffset:0,label:{backgroundColor:"rgba(0,0,0,0.8)",borderCapStyle:"butt",borderColor:"black",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:6,borderWidth:0,color:"#fff",content:null,cornerRadius:void 0,drawTime:void 0,enabled:!1,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,padding:6,xPadding:void 0,yPadding:void 0,position:"center",rotation:0,textAlign:"center",width:void 0,xAdjust:0,yAdjust:0},value:void 0,endValue:void 0,scaleID:void 0,xScaleID:"x",xMin:void 0,xMax:void 0,yScaleID:"y",yMin:void 0,yMax:void 0},X.defaultRoutes={borderColor:"color"};class J extends t.Element{inRange(t,e,i){return function(t,e){const{width:i,height:o}=e,n=e.getCenterPoint(!0),r=i/2,a=o/2;if(r<=0||a<=0)return!1;return Math.pow(t.x-n.x,2)/Math.pow(r,2)+Math.pow(t.y-n.y,2)/Math.pow(a,2)<=1}({x:t,y:e},this.getProps(["x","y","width","height"],i))}getCenterPoint(t){return j(this.getProps(["x","y","width","height"],t))}draw(t){const{width:i,height:o,options:n}=this,r=this.getCenterPoint();t.save(),t.translate(r.x,r.y),n.rotation&&t.rotate(e.toRadians(n.rotation)),t.beginPath(),t.lineWidth=n.borderWidth,t.strokeStyle=n.borderColor,t.fillStyle=n.backgroundColor,t.setLineDash(n.borderDash),t.lineDashOffset=n.borderDashOffset,t.ellipse(0,0,o/2,i/2,Math.PI/2,0,2*Math.PI),t.fill(),t.stroke(),t.restore()}resolveElementProperties(t,e){return W(t,e)}}J.id="ellipseAnnotation",J.defaults={display:!0,adjustScaleRange:!0,borderDash:[],borderDashOffset:0,borderWidth:1,rotation:0,xScaleID:"x",xMin:void 0,xMax:void 0,yScaleID:"y",yMin:void 0,yMax:void 0},J.defaultRoutes={borderColor:"color",backgroundColor:"color"};class U extends t.Element{inRange(t,e,i){return this.visible&&h(t,e,this.getProps(["x","y","width","height"],i))}getCenterPoint(t){return j(this.getProps(["x","y","width","height"],t))}draw(t){if(!this.visible)return;const{labelX:e,labelY:i,labelWidth:o,labelHeight:n,options:r}=this;!function(t,e){const{pointX:i,pointY:o,calloutPosition:n,options:r}=e;if(!n)return;const a=r.callout,{separatorStart:s,separatorEnd:l}=function(t,e){const{x:i,y:o,width:n,height:r}=t,a=function(t,e){const{width:i,height:o,options:n}=t,r=n.callout.margin+n.borderWidth/2;if("right"===e)return i+r;if("bottom"===e)return o+r;return-r}(t,e);let s,l;"left"===e||"right"===e?(s={x:i+a,y:o},l={x:s.x,y:s.y+r}):"top"!==e&&"bottom"!==e||(s={x:i,y:o+a},l={x:s.x+n,y:s.y});return{separatorStart:s,separatorEnd:l}}(e,n),{sideStart:d,sideEnd:h}=function(t,e,i){const{y:o,width:n,height:r,options:a}=t,s=a.callout.start,l=function(t,e){const i=e.side;if("left"===t||"top"===t)return-i;return i}(e,a.callout);let d,h;"left"===e||"right"===e?(d={x:i.x,y:o+b(r,s)},h={x:d.x+l,y:d.y}):"top"!==e&&"bottom"!==e||(d={x:i.x+b(n,s),y:i.y},h={x:d.x,y:d.y+l});return{sideStart:d,sideEnd:h}}(e,n,s);t.save(),t.beginPath();const c=M(t,a);(a.margin>0||0===r.borderWidth)&&(t.moveTo(s.x,s.y),t.lineTo(l.x,l.y));t.moveTo(d.x,d.y),t.lineTo(h.x,h.y),t.lineTo(i,o),c&&t.stroke();t.restore()}(t,this),this.boxVisible&&P(t,this,r),C(t,{x:e,y:i,width:o,height:n},r)}resolveElementProperties(t,i){const o=!!g(i),n=m(i)?I(t,i):j(W(t,i)),r=e.toPadding(i.padding),a=D(t.ctx,i),s=function(t,e,i,o){const n=e.width+o.width+i.borderWidth,r=e.height+o.height+i.borderWidth,a=p(i.position);return{x:B(t.x,n,i.xAdjust,a.x),y:B(t.y,r,i.yAdjust,a.y),width:n,height:r}}(n,a,i,r),l=e.color(i.backgroundColor),d={visible:o,boxVisible:i.borderWidth>0||l&&l.valid&&l.rgb.a>0,pointX:n.x,pointY:n.y,...s,labelX:s.x+r.left+i.borderWidth/2,labelY:s.y+r.top+i.borderWidth/2,labelWidth:a.width,labelHeight:a.height};return d.calloutPosition=i.callout.enabled&&function(t,e){const i=e.position;if("left"===i||"right"===i||"top"===i||"bottom"===i)return i;return function(t,e){const{x:i,y:o,width:n,height:r,pointX:a,pointY:s}=t,{margin:l,side:d}=e,h=l+d;if(a<i-h)return"left";if(a>i+n+h)return"right";if(s<o+r+h)return"top";if(s>o-h)return"bottom"}(t,e)}(d,i.callout),d}}function B(t,e,i=0,o){return t-y(e,o)+i}U.id="labelAnnotation",U.defaults={adjustScaleRange:!0,backgroundColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,borderWidth:0,callout:{borderCapStyle:"butt",borderColor:void 0,borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:1,enabled:!1,margin:5,position:"auto",side:5,start:"50%"},color:"black",content:null,display:!0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:void 0},height:void 0,padding:6,position:"center",textAlign:"center",width:void 0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:"x",xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:"y",yValue:void 0},U.defaultRoutes={borderColor:"color",backgroundColor:"color"};class q extends t.Element{inRange(t,e,i){const{width:o}=this.getProps(["width"],i);return n={x:t,y:e},r=this.getCenterPoint(i),a=o/2+this.options.borderWidth,!(!n||!r||a<=0)&&Math.pow(n.x-r.x,2)+Math.pow(n.y-r.y,2)<=Math.pow(a,2);var n,r,a}getCenterPoint(t){return c(this,t)}draw(t){S(t,this,this.options)}resolveElementProperties(t,e){return R(t,e)}}q.id="pointAnnotation",q.defaults={display:!0,adjustScaleRange:!0,borderDash:[],borderDashOffset:0,borderWidth:1,pointStyle:"circle",radius:10,rotation:0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:"x",xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:"y",yValue:void 0},q.defaultRoutes={borderColor:"color",backgroundColor:"color"};class G extends t.Element{inRange(t,e,i){const o=K(this.getProps(["x","y"],i),this.options);return o&&o.length>0&&function(t,e,i){let o=!1,n=0,r=t.length-1;for(;n<t.length;r=n++)t[n].y>i!=t[r].y>i&&e<(t[r].x-t[n].x)*(i-t[n].y)/(t[r].y-t[n].y)+t[n].x&&(o=!o);return o}(o,t,e)}getCenterPoint(t){return c(this,t)}draw(t){const{x:e,y:i,options:o}=this,n=K({x:e,y:i},o);let r=n[0];t.save(),t.beginPath(),t.fillStyle=o.backgroundColor;const a=M(t,o);t.moveTo(r.x,r.y);for(let e=1;e<n.length;e++)r=n[e],t.lineTo(r.x,r.y);t.closePath(),t.fill(),a&&t.stroke(),t.restore()}resolveElementProperties(t,i){return e.isNumber(i.sides)&&i.sides>=1?R(t,i):{options:{}}}}function K(t,i){const{sides:o,radius:n}=i;let r=2*e.PI/o,a=i.rotation*e.RAD_PER_DEG;const s=new Array;Q(s,t,a,n);for(let e=0;e<o;e++)a+=r,Q(s,t,a,n);return s}function Q(t,e,i,o){t.push({x:e.x+Math.sin(i)*o,y:e.y-Math.cos(i)*o})}G.id="polygonAnnotation",G.defaults={display:!0,adjustScaleRange:!0,borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:1,radius:10,rotation:0,sides:3,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:"x",xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:"y",yValue:void 0},G.defaultRoutes={borderColor:"color",backgroundColor:"color"};const Z={box:T,ellipse:J,label:U,line:X,point:q,polygon:G};Object.keys(Z).forEach((e=>{t.defaults.describe(`elements.${Z[e].id}`,{_fallback:"plugins.annotation"})}));const tt=new Map,et=t.Chart.version.split(".");var it={id:"annotation",version:"1.2.1",afterRegister(){t.Chart.register(Z),"3"===et[0]&&parseInt(et[1],10)<=6&&t.Chart.defaults.set("elements.lineAnnotation",{callout:{},font:{},padding:6})},afterUnregister(){t.Chart.unregister(Z)},beforeInit(t){tt.set(t,{annotations:[],elements:[],listeners:{},listened:!1,moveListened:!1})},beforeUpdate(t,i,o){const n=tt.get(t).annotations=[];let r=o.annotations;e.isObject(r)?Object.keys(r).forEach((t=>{const i=r[t];e.isObject(i)&&(i.id=t,n.push(i))})):e.isArray(r)&&n.push(...r),function(t,e){for(const i of t)for(const t of["scaleID","xScaleID","yScaleID"])i[t]&&!e[i[t]]&&console.warn(`No scale found with id '${i[t]}' for annotation '${i.id}'`)}(n,t.scales)},afterDataLimits(t,i){const o=tt.get(t);!function(t,i,o){const n=function(t,i){const o=t.axis,n=t.id,r=o+"ScaleID";let a=e.valueOrDefault(t.min,Number.NEGATIVE_INFINITY),s=e.valueOrDefault(t.max,Number.POSITIVE_INFINITY);for(const e of i)if(e.scaleID===n)for(const i of["value","endValue"]){const o=e[i];if(o){const e=t.parse(o);a=Math.min(a,e),s=Math.max(s,e)}}else if(e[r]===n)for(const i of[o+"Min",o+"Max",o+"Value"]){const o=e[i];if(o){const e=t.parse(o);a=Math.min(a,e),s=Math.max(s,e)}}return{min:a,max:s}}(i,o);let r=!1;e.isFinite(n.min)&&void 0===i.options.min&&void 0===i.options.suggestedMin&&(r=i.min!==n.min,i.min=n.min);e.isFinite(n.max)&&void 0===i.options.max&&void 0===i.options.suggestedMax&&(r=i.max!==n.max,i.max=n.max);r&&"function"==typeof i.handleTickRangeOptions&&i.handleTickRangeOptions()}(0,i.scale,o.annotations.filter((t=>t.display&&t.adjustScaleRange)))},afterUpdate(e,r,a){const s=tt.get(e);!function(t,e,r){const a=e.annotations||[];e.listened=!1,e.moveListened=!1,n.forEach((t=>{"function"==typeof r[t]&&(e.listened=!0,e.listeners[t]=r[t])})),o.forEach((t=>{"function"==typeof r[t]&&(e.moveListened=!0)})),e.listened&&e.moveListened||a.forEach((t=>{e.listened||i.forEach((i=>{"function"==typeof t[i]&&(e.listened=!0)})),e.moveListened||o.forEach((i=>{"function"==typeof t[i]&&(e.listened=!0,e.moveListened=!0)}))}))}(0,s,a),function(e,i,o,n){const r=function(e,i,o){if("reset"===o||"none"===o||"resize"===o)return ot;return new t.Animations(e,i)}(e,o.animations,n),a=i.annotations,s=function(t,e){const i=e.length,o=t.length;if(o<i){const e=i-o;t.splice(o,0,...new Array(e))}else o>i&&t.splice(i,o-i);return t}(i.elements,a);for(let t=0;t<a.length;t++){const i=a[t];let o=s[t];const n=Z[nt(i.type)];o&&o instanceof n||(o=s[t]=new n);const l=rt(i.setContext(st(e,o,i))),d=o.resolveElementProperties(e,l);d.skip=isNaN(d.x)||isNaN(d.y),d.options=l,r.update(o,d)}}(e,s,a,r.mode)},beforeDatasetsDraw(t,e,i){lt(t,"beforeDatasetsDraw",i.clip)},afterDatasetsDraw(t,e,i){lt(t,"afterDatasetsDraw",i.clip)},beforeDraw(t,e,i){lt(t,"beforeDraw",i.clip)},afterDraw(t,e,i){lt(t,"afterDraw",i.clip)},beforeEvent(t,e,i){r(tt.get(t),e.event,i)},destroy(t){tt.delete(t)},_getState:t=>tt.get(t),defaults:{drawTime:"afterDatasetsDraw",dblClickSpeed:350,animations:{numbers:{properties:["x","y","x2","y2","width","height","pointX","pointY","labelX","labelY","labelWidth","labelHeight","radius"],type:"number"}},clip:!0,label:{drawTime:null}},descriptors:{_indexable:!1,_scriptable:t=>!n.includes(t),annotations:{_allKeys:!1,_fallback:(t,e)=>`elements.${Z[nt(e.type)].id}`}},additionalOptionScopes:[""]};const ot={update:Object.assign};function nt(t="line"){return Z[t]?t:(console.warn(`Unknown annotation type: '${t}', defaulting to 'line'`),"line")}function rt(t){const e=Z[nt(t.type)],i={};i.id=t.id,i.type=t.type,i.drawTime=t.drawTime,Object.assign(i,at(t,e.defaults),at(t,e.defaultRoutes));for(const e of n)i[e]=t[e];return i}function at(t,i){const o={};for(const n of Object.keys(i)){const r=i[n],a=t[n];o[n]=e.isObject(r)?at(a,r):a}return o}function st(t,e,i){return e.$context||(e.$context=Object.assign(Object.create(t.getContext()),{element:e,id:i.id,type:"annotation"}))}function lt(t,i,o){const{ctx:n,chartArea:r}=t,a=tt.get(t).elements.filter((t=>!t.skip&&t.options.display));o&&e.clipArea(n,r),a.forEach((t=>{t.options.drawTime===i&&t.draw(n)})),o&&e.unclipArea(n),a.forEach((t=>{"drawLabel"in t&&t.options.label&&(t.options.label.drawTime||t.options.drawTime)===i&&t.drawLabel(n,r)}))}return t.Chart.register(it),it}));

@@ -5,3 +5,3 @@ {

"description": "Annotations for Chart.js",
"version": "1.2.0",
"version": "1.2.1",
"author": "Evert Timberg <evert.timberg@gmail.com>",

@@ -27,9 +27,10 @@ "license": "MIT",

"lint": "concurrently \"npm:lint-*\"",
"lint-js": "eslint \"old_samples/**/*.html\" \"test/**/*.js\" \"src/**/*.js\"",
"lint-js": "eslint \"test/**/*.js\" \"src/**/*.js\"",
"lint-md": "eslint \"**/*.md\"",
"lint-types": "eslint \"types/**/*.ts\" && tsc -p types/tests/",
"test": "cross-env NODE_ENV=test concurrently \"npm:test-*\"",
"test-types": "tsc -p types/tests/",
"test-integration": "mocha --full-trace test/integration/*-test.js",
"test-karma": "karma start --auto-watch --single-run",
"test-lint": "npm run lint",
"test-karma": "karma start --auto-watch --single-run"
"test-types": "tsc -p types/tests/"
},

@@ -52,2 +53,3 @@ "devDependencies": {

"eslint-plugin-markdown": "^2.0.1",
"fs-extra": "^10.0.0",
"karma": "^6.3.2",

@@ -60,2 +62,3 @@ "karma-chrome-launcher": "^3.1.0",

"karma-rollup-preprocessor": "^7.0.7",
"mocha": "^9.1.3",
"pixelmatch": "^5.2.1",

@@ -62,0 +65,0 @@ "rollup": "^2.45.2",

@@ -124,3 +124,3 @@ import { Color, FontSpec, BorderRadius } from 'chart.js';

type percentString = `${number}%`;
type percentString = string;
export type LabelPosition = 'start' | 'center' | 'end' | percentString;

@@ -127,0 +127,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc