7 lines
34 KiB
JavaScript
7 lines
34 KiB
JavaScript
|
|
/*!
|
||
|
|
* chartjs-plugin-annotation v3.0.1
|
||
|
|
* https://www.chartjs.org/chartjs-plugin-annotation/index
|
||
|
|
* (c) 2023 chartjs-plugin-annotation Contributors
|
||
|
|
* Released under the MIT License
|
||
|
|
*/
|
||
|
|
!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 o={modes:{point:(t,e)=>r(t,e,{intersect:!0}),nearest:(t,o,n)=>function(t,o,n){let i=Number.POSITIVE_INFINITY;return r(t,o,n).reduce(((t,r)=>{const s=r.getCenterPoint(),a=function(t,e,o){if("x"===o)return{x:t.x,y:e.y};if("y"===o)return{x:e.x,y:t.y};return e}(o,s,n.axis),d=e.distanceBetweenPoints(o,a);return d<i?(t=[r],i=d):d===i&&t.push(r),t}),[]).sort(((t,e)=>t._index-e._index)).slice(0,1)}(t,o,n),x:(t,e,o)=>r(t,e,{intersect:o.intersect,axis:"x"}),y:(t,e,o)=>r(t,e,{intersect:o.intersect,axis:"y"})}};function n(t,e,n){return(o.modes[n.mode]||o.modes.nearest)(t,e,n)}function r(t,e,o){return t.visibleElements.filter((t=>o.intersect?t.inRange(e.x,e.y):function(t,e,o){return"x"!==o&&"y"!==o?t.inRange(e.x,e.y,"x",!0)||t.inRange(e.x,e.y,"y",!0):t.inRange(e.x,e.y,o,!0)}(t,e,o.axis)))}const i=(t,e)=>e>t||t.length>e.length&&t.slice(0,e.length)===e,s=.001,a=(t,e,o)=>Math.min(o,Math.max(e,t));function d(t,e,o){for(const n of Object.keys(t))t[n]=a(t[n],e,o);return t}function c(t,{x:e,y:o,x2:n,y2:r},i,a){const d=a/2,c=t.x>=e-d-s&&t.x<=n+d+s,l=t.y>=o-d-s&&t.y<=r+d+s;return"x"===i?c:("y"===i||c)&&l}function l(t,e){const{centerX:o,centerY:n}=t.getProps(["centerX","centerY"],e);return{x:o,y:n}}const h=t=>"string"==typeof t&&t.endsWith("%"),u=t=>parseFloat(t)/100,f=t=>a(u(t),0,1),x=(t,e)=>({x:t,y:e,x2:t,y2:e,width:0,height:0}),y={box:t=>x(t.centerX,t.centerY),ellipse:t=>({centerX:t.centerX,centerY:t.centerX,radius:0,width:0,height:0}),label:t=>x(t.centerX,t.centerY),line:t=>x(t.x,t.y),point:t=>({centerX:t.centerX,centerY:t.centerY,radius:0,width:0,height:0}),polygon:t=>x(t.centerX,t.centerY)};function p(t,e){return"start"===e?0:"end"===e?t:h(e)?f(e)*t:t/2}function b(t,e,o=!0){return"number"==typeof e?e:h(e)?(o?f(e):u(e))*t:t}function g(t,o="center"){return e.isObject(t)?{x:e.valueOrDefault(t.x,o),y:e.valueOrDefault(t.y,o)}:{x:t=e.valueOrDefault(t,o),y:t}}function m(t){return t&&(e.defined(t.xValue)||e.defined(t.yValue))}function v(t,o,n){const r=n.init;if(r)return!0===r?M(o,n):function(t,o,n){const r=e.callback(n.init,[{chart:t,properties:o,options:n}]);if(!0===r)return M(o,n);if(e.isObject(r))return r}(t,o,n)}function w(t,o,n){let r=!1;return o.forEach((o=>{e.isFunction(t[o])?(r=!0,n[o]=t[o]):e.defined(n[o])&&delete n[o]})),r}function M(t,e){const o=e.type||"line";return y[o](t)}const P=new Map,S=t=>isNaN(t)||t<=0,C=t=>t.reduce((function(t,e){return t+=e.string}),"");function k(t){if(t&&"object"==typeof t){const e=t.toString();return"[object HTMLImageElement]"===e||"[object HTMLCanvasElement]"===e}}function D(t,{x:o,y:n},r){r&&(t.translate(o,n),t.rotate(e.toRadians(r)),t.translate(-o,-n))}function A(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 j(t,e){t.shadowColor=e.backgroundShadowColor,t.shadowBlur=e.shadowBlur,t.shadowOffsetX=e.shadowOffsetX,t.shadowOffsetY=e.shadowOffsetY}function I(t,o){const n=o.content;if(k(n))return{width:b(n.width,o.width),height:b(n.height,o.height)};const r=o.font,i=e.isArray(r)?r.map((t=>e.toFont(t))):[e.toFont(r)],s=o.textStrokeWidth,a=e.isArray(n)?n:[n],d=a.join()+C(i)+s+(t._measureText?"-spriting":"");return P.has(d)||P.set(d,function(t,e,o,n){t.save();const r=e.length;let i=0,s=n;for(let a=0;a<r;a++){const r=o[Math.min(a,o.length-1)];t.font=r.string;const d=e[a];i=Math.max(i,t.measureText(d).width+n),s+=r.lineHeight}return t.restore(),{width:i,height:s}}(t,a,i,s)),P.get(d)}function O(t,o,n){const{x:r,y:i,width:s,height:a}=o;t.save(),j(t,n);const c=A(t,n);t.fillStyle=n.backgroundColor,t.beginPath(),e.addRoundedRectPath(t,{x:r,y:i,w:s,h:a,radius:d(e.toTRBLCorners(n.borderRadius),0
|