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