You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
8 lines
27 KiB
8 lines
27 KiB
2 years ago
|
/*!
|
||
|
* chartjs-plugin-annotation v1.4.0
|
||
|
* https://www.chartjs.org/chartjs-plugin-annotation/index
|
||
|
* (c) 2022 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=["click","dblclick"],n=["enter","leave"],i=o.concat(n);function r(t,e,o){if(t.listened)switch(e.type){case"mousemove":case"mouseout":!function(t,e){if(!t.moveListened)return;let o;"mousemove"===e.type&&(o=a(t.elements,e));const n=t.hovered;t.hovered=o,function(t,e,o){const{previous:n,element:i}=e;n&&n!==i&&s(n.options.leave||t.listeners.leave,n,o);i&&i!==n&&s(i.options.enter||t.listeners.enter,i,o)}(t,{previous:n,element:o},e)}(t,e);break;case"click":!function(t,e,o){const n=t.listeners,i=a(t.elements,e);if(i){const t=i.options,r=t.dblclick||n.dblclick,a=t.click||n.click;i.clickTimeout?(clearTimeout(i.clickTimeout),delete i.clickTimeout,s(r,i,e)):r?i.clickTimeout=setTimeout((()=>{delete i.clickTimeout,s(a,i,e)}),o.dblClickSpeed):s(a,i,e)}}(t,e,o)}}function s(t,o,n){e.callback(t,[o.$context,n])}function a(t,o){let n=Number.POSITIVE_INFINITY;return t.filter((t=>t.options.display&&t.inRange(o.x,o.y))).reduce(((t,i)=>{const r=i.getCenterPoint(),s=e.distanceBetweenPoints(o,r);return s<n?(t=[i],n=s):s===n&&t.push(i),t}),[]).sort(((t,e)=>t._index-e._index)).slice(0,1)[0]}function d(t,o,n){const i=function(t,o){const n=t.axis,i=t.id,r=n+"ScaleID",s={min:e.valueOrDefault(t.min,Number.NEGATIVE_INFINITY),max:e.valueOrDefault(t.max,Number.POSITIVE_INFINITY)};for(const e of o)e.scaleID===i?u(e,t,["value","endValue"],s):e[r]===i&&u(e,t,[n+"Min",n+"Max",n+"Value"],s);return s}(o,n);let r=l(o,i,"min","suggestedMin");r=l(o,i,"max","suggestedMax")||r,r&&"function"==typeof o.handleTickRangeOptions&&o.handleTickRangeOptions()}function l(t,o,n,i){if(e.isFinite(o[n])&&!function(t,o,n){return e.defined(t[o])||e.defined(t[n])}(t.options,n,i)){const e=t[n]!==o[n];return t[n]=o[n],e}}function h(t,e){for(const o of["scaleID","xScaleID","yScaleID"])t[o]&&!e[t[o]]&&c(t,o)&&console.warn(`No scale found with id '${t[o]}' for annotation '${t.id}'`)}function c(t,o){if("scaleID"===o)return!0;const n=o.charAt(0);for(const o of["Min","Max","Value"])if(e.defined(t[n+o]))return!0;return!1}function u(t,o,n,i){for(const r of n){const n=t[r];if(e.defined(n)){const t=o.parse(n);i.min=Math.min(i.min,t),i.max=Math.max(i.max,t)}}}const f=.001,b=(t,e,o)=>Math.min(o,Math.max(e,t));function x(t,e,o){for(const n of Object.keys(t))t[n]=b(t[n],e,o);return t}function y(t,e,{x:o,y:n,width:i,height:r},s){const a=s/2;return t>=o-a-f&&t<=o+i+a+f&&e>=n-a-f&&e<=n+r+a+f}function p(t,e){const{x:o,y:n}=t.getProps(["x","y"],e);return{x:o,y:n}}const g=(t,e)=>e>t||t.length>e.length&&t.substr(0,e.length)===e;const w=t=>"string"==typeof t&&t.endsWith("%"),m=t=>b(parseFloat(t)/100,0,1);function v(t,e){return"start"===e?0:"end"===e?t:w(e)?m(e)*t:t/2}function S(t,e){return"number"==typeof e?e:w(e)?m(e)*t:t}function C(t){return e.isObject(t)?{x:e.valueOrDefault(t.x,"center"),y:e.valueOrDefault(t.y,"center")}:{x:t=e.valueOrDefault(t,"center"),y:t}}function M(t){return t&&(e.defined(t.xValue)||e.defined(t.yValue))}const k=new Map;function P(t){if(t&&"object"==typeof t){const e=t.toString();return"[object HTMLImageElement]"===e||"[object HTMLCanvasElement]"===e}}function D(t,o,n){if(n){const i=o.getCenterPoint();t.translate(i.x,i.y),t.rotate(e.toRadians(n)),t.translate(-i.x,-i.y)}}function O(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 A(t,o){const n=o.content;if(P(n))return{width:S(n.width,o.width),height:S(n.height,o.height)};const i=e.toFont(o.font),r=o.textStrokeWidth,s=e.isArray(n)?n:[n],a=s.join()+i.string+r+(t._mea
|