!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["exports","chart.js","chart.js/helpers"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).ChartErrorBars={},r.Chart,r.Chart.helpers)}(this,(function(r,e,t){"use strict";const a=["xMin","xMax","yMin","yMax"];function n(r){return r?a.slice(0,2):a.slice(2)}function o(r,e,t,a,n){const o=[a.axis+"Min",a.axis+"Max"],s=a.getBasePixel();for(const l of o){const o=e[l];Array.isArray(o)?r[l]=o.map(r=>n?s:a.getPixelForValue(r,t)):"number"==typeof o&&(r[l]=n?s:a.getPixelForValue(o,t))}}const s={errorBarLineWidth:{v:[1,3]},errorBarColor:{v:["#2c2c2c","#1f1f1f"]},errorBarWhiskerLineWidth:{v:[1,3]},errorBarWhiskerRatio:{v:[.2,.25]},errorBarWhiskerSize:{v:[20,24]},errorBarWhiskerColor:{v:["#2c2c2c","#1f1f1f"]}},l=Object.keys(s);function i(r,e){const t=Array.isArray(r)?r:[r],a=Array.isArray(e)?e:[e];if(t.length===a.length)return t.map((r,e)=>[r,a[e]]);const n=Math.max(t.length,a.length);return Array(n).map((r,e)=>[t[e%t.length],a[e%a.length]])}function c(r,e){if("string"==typeof r||"number"==typeof r)return r;const t=Array.isArray(r)?r:r.v;return t[e%t.length]}function u(r,e,t){const a=c(e.errorBarWhiskerRatio,t);if(null!=r&&a>0)return r*a*.5;return.5*c(e.errorBarWhiskerSize,t)}function d(r,e){const t=r.getProps(["x","y","width","height","xMin","xMax","yMin","yMax"]);null==t.xMin&&null==t.xMax||function(r,e,t,a,n){n.save(),n.translate(0,r.y);const o=i(null==e?r.x:e,null==t?r.x:t);o.reverse().forEach(([e,t],s)=>{const l=o.length-s-1,i=u(r.height,a,l);n.lineWidth=c(a.errorBarLineWidth,l),n.strokeStyle=c(a.errorBarColor,l),n.beginPath(),n.moveTo(e,0),n.lineTo(t,0),n.stroke(),n.lineWidth=c(a.errorBarWhiskerLineWidth,l),n.strokeStyle=c(a.errorBarWhiskerColor,l),n.beginPath(),n.moveTo(e,-i),n.lineTo(e,i),n.moveTo(t,-i),n.lineTo(t,i),n.stroke()}),n.restore()}(t,t.xMin??null,t.xMax??null,r.options,e),null==t.yMin&&null==t.yMax||function(r,e,t,a,n){n.save(),n.translate(r.x,0);const o=i(null==e?r.y:e,null==t?r.y:t);o.reverse().forEach(([e,t],s)=>{const l=o.length-s-1,i=u(r.width,a,l);n.lineWidth=c(a.errorBarLineWidth,l),n.strokeStyle=c(a.errorBarColor,l),n.beginPath(),n.moveTo(0,e),n.lineTo(0,t),n.stroke(),n.lineWidth=c(a.errorBarWhiskerLineWidth,l),n.strokeStyle=c(a.errorBarWhiskerColor,l),n.beginPath(),n.moveTo(-i,e),n.lineTo(i,e),n.moveTo(-i,t),n.lineTo(i,t),n.stroke()}),n.restore()}(t,t.yMin??null,t.yMax??null,r.options,e)}function h(r,e){const t=r.getProps(["x","y","startAngle","endAngle","rMin","rMax","outerRadius"]);null==t.rMin&&null==t.rMax||function(r,e,t,a,n){n.save(),n.translate(r.x,r.y);const o=(r.startAngle+r.endAngle)/2,s=Math.cos(o),l=Math.sin(o),d={x:-l,y:s},h=Math.sqrt(d.x*d.x+d.y*d.y);d.x/=h,d.y/=h;const f=i(e??r.outerRadius,t??r.outerRadius);f.reverse().forEach(([r,e],t)=>{const o=f.length-t-1,i=r*s,h=r*l,p=e*s,y=e*l,x=u(null,a,o),m=d.x*x,g=d.y*x;n.lineWidth=c(a.errorBarLineWidth,o),n.strokeStyle=c(a.errorBarColor,o),n.beginPath(),n.moveTo(i,h),n.lineTo(p,y),n.stroke(),n.lineWidth=c(a.errorBarWhiskerLineWidth,o),n.strokeStyle=c(a.errorBarWhiskerColor,o),n.beginPath(),n.moveTo(i+m,h+g),n.lineTo(i-m,h-g),n.moveTo(p+m,y+g),n.lineTo(p-m,y-g),n.stroke()}),n.restore()}(t,t.rMin,t.rMax,r.options,e)}class f extends e.BarElement{draw(r){super.draw(r),d(this,r)}}f.id="rectangleWithErrorBar",f.defaults={...e.BarElement.defaults,...s},f.defaultRoutes=e.BarElement.defaultRoutes;class p extends e.PointElement{draw(r){super.draw(r),d(this,r)}}p.id="pointWithErrorBar",p.defaults={...e.PointElement.defaults,...s},p.defaultRoutes=e.PointElement.defaultRoutes;class y extends e.ArcElement{draw(r){super.draw(r),h(this,r)}}function x(r){return Array.isArray(r)?r.slice().reverse():r}function m(r){const t=n(r.element.horizontal),a=e.Tooltip.defaults.callbacks.label.call(this,r),o=r.chart.data.datasets[r.datasetIndex].data[r.dataIndex];return null==o||t.every(r=>null==o[r])?a:`${a} (${x(o[t[0]])} .. ${o[t[1]]})`}y.id="arcWithErrorBar",y.defaults={...e.ArcElement.defaults,...s},y.defaultRoutes=e.ArcElement.defaultRoutes;const g={color(r,e,a){const n=r||"transparent",o=e||"transparent";if(n===o)return e;const s=t.color(n),l=s.valid&&t.color(o);return l&&l.valid?l.mix(s,a).hexString():e},number:(r,e,t)=>r===e?e:r+(e-r)*t};function M(r,e,t,a,n){if(typeof r===a&&typeof e===a)return n(r,e,t);if(Array.isArray(r)&&Array.isArray(e))return r.map((r,a)=>n(r,e[a],t));const o=r=>r&&Array.isArray(r.v);return o(r)&&Array.isArray(r.v)&&o(e)?r.v.map((r,a)=>n(r,e.v[a],t)):e}const B={animations:{numberArray:{fn:function(r,e,t){return M(r,e,t,"number",g.number)},properties:a.concat(l.filter(r=>!r.endsWith("Color")),["rMin","rMax"])},colorArray:{fn:function(r,e,t){return M(r,e,t,"string",g.color)},properties:a.concat(l.filter(r=>r.endsWith("Color")))}}};function E(r,e){const{axis:t}=r;r.axis=t+"MinMin";const{min:a}=e(r);r.axis=t+"MaxMax";const{max:n}=e(r);return r.axis=t,{min:a,max:n}}function b(r,e,t){return Array.isArray(e)?t(...e):"number"==typeof e?e:r}function C(r,e,t,a,n){const o="string"==typeof e?e:e.axis,s=o+"Min",l=o+"Max",i=o+"MinMin",c=o+"MaxMax";for(let e=0;esuper.getMinMax(r,e))}parseObjectData(r,e,t,a){const n=super.parseObjectData(r,e,t,a);return C(n,r.vScale,e,t,a),W(n,r.iScale,t,a),n}updateElement(r,e,t,a){"number"==typeof e&&o(t,this.getParsed(e),e,this._cachedMeta.vScale,"reset"===a),super.updateElement(r,e,t,a)}}v.id="barWithErrorBars",v.defaults=t.merge({},[e.BarController.defaults,B,{dataElementType:f.id}]),v.overrides=t.merge({},[e.BarController.overrides,{plugins:{tooltip:{callbacks:{label:m}}}}]),v.defaultRoutes=e.BarController.defaultRoutes;class S extends e.Chart{constructor(r,t){super(r,A("barWithErrorBars",t,v,f,[e.LinearScale,e.CategoryScale]))}}S.id=v.id;class k extends e.LineController{getMinMax(r,e){return E(r,r=>super.getMinMax(r,e))}parseObjectData(r,e,t,a){const n=super.parseObjectData(r,e,t,a);return C(n,r.vScale,e,t,a),W(n,r.iScale,t,a),n}updateElement(r,e,t,a){r instanceof p&&"number"==typeof e&&o(t,this.getParsed(e),e,this._cachedMeta.vScale,"reset"===a),super.updateElement(r,e,t,a)}}k.id="lineWithErrorBars",k.defaults=t.merge({},[e.LineController.defaults,B,{dataElementType:p.id}]),k.overrides=t.merge({},[e.LineController.overrides,{plugins:{tooltip:{callbacks:{label:m}}}}]),k.defaultRoutes=e.LineController.defaultRoutes;class P extends e.Chart{constructor(r,t){super(r,A("lineWithErrorBars",t,k,p,[e.LinearScale,e.CategoryScale]))}}P.id=k.id;class T extends e.ScatterController{getMinMax(r,e){return E(r,r=>super.getMinMax(r,e))}parseObjectData(r,e,t,a){const n=super.parseObjectData(r,e,t,a);return C(n,r.xScale,e,t,a),C(n,r.yScale,e,t,a),n}updateElement(r,e,t,a){r instanceof p&&"number"==typeof e&&(o(t,this.getParsed(e),e,this._cachedMeta.xScale,"reset"===a),o(t,this.getParsed(e),e,this._cachedMeta.yScale,"reset"===a)),super.updateElement(r,e,t,a)}}T.id="scatterWithErrorBars",T.defaults=t.merge({},[e.ScatterController.defaults,B,{dataElementType:p.id}]),T.overrides=t.merge({},[e.ScatterController.overrides,{plugins:{tooltip:{callbacks:{label:function(r){const e=r.chart.data.datasets[r.datasetIndex].data[r.dataIndex],t=(r,t)=>{const a=n(t);return null==e||a.every(r=>null==e[r])?r:`${r} [${x(e[a[0]])} .. ${e[a[1]]}]`};return`(${t(r.label,!0)}, ${t(r.parsed.y,!1)})`}}}}}]),T.defaultRoutes=e.LineController.defaultRoutes;class L extends e.Chart{constructor(r,t){super(r,A("scatterWithErrorBars",t,T,p,[e.LinearScale]))}}L.id=T.id;class R extends e.PolarAreaController{getMinMax(r,e){return E(r,r=>super.getMinMax(r,e))}countVisibleElements(){const r=this._cachedMeta;return r.data.reduce((e,t,a)=>!Number.isNaN(r._parsed[a].r)&&this.chart.getDataVisibility(a)?e+1:e,0)}parseObjectData(r,e,t,a){const n=new Array(a),o=r.rScale;for(let r=0;r{const e=t.getDistanceFromCenterForValue(r),n=o.animateScale?0:e;return a?n:e};for(const t of s){const a=e[t];Array.isArray(a)?r[t]=a.map(l):"number"==typeof a&&(r[t]=l(a))}}(t,this.getParsed(e),this._cachedMeta.rScale,"reset"===a,this.chart.options),super.updateElement(r,e,t,a)}updateElements(r,e,t,a){const n=this.chart.scales.r,o=n.getDistanceFromCenterForValue;n.getDistanceFromCenterForValue=function(r){return"number"==typeof r?o.call(this,r):o.call(this,r.r)},super.updateElements(r,e,t,a),n.getDistanceFromCenterForValue=o}}R.id="polarAreaWithErrorBars",R.defaults=t.merge({},[e.PolarAreaController.defaults,B,{dataElementType:y.id}]),R.overrides=t.merge({},[e.PolarAreaController.overrides,{plugins:{tooltip:{callbacks:{label:function(r){const t=e.PolarAreaController.overrides.plugins.tooltip.callbacks.label.call(this,r),a=r.chart.data.datasets[r.datasetIndex].data[r.dataIndex],n=["rMin","rMax"];return null==a||n.every(r=>null==a[r])?t:`${t} [${x(a[n[0]])} .. ${a[n[1]]}]`}}}}}]),R.defaultRoutes=e.PolarAreaController.defaultRoutes;class j extends e.Chart{constructor(r,t){super(r,A("polarAreaWithErrorBars",t,R,y,[e.RadialLinearScale]))}}j.id=R.id,e.registry.addControllers(v,k,R,T),e.registry.addElements(f,y,k,p),r.ArcWithErrorBar=y,r.BarWithErrorBar=f,r.BarWithErrorBarsChart=S,r.BarWithErrorBarsController=v,r.LineWithErrorBarsChart=P,r.LineWithErrorBarsController=k,r.PointWithErrorBar=p,r.PolarAreaWithErrorBarsChart=j,r.PolarAreaWithErrorBarsController=R,r.ScatterWithErrorBarsChart=L,r.ScatterWithErrorBarsController=T,Object.defineProperty(r,"__esModule",{value:!0})})); //# sourceMappingURL=index.umd.min.js.map