chartjs-chart-error-bars
Advanced tools
Comparing version 3.1.0 to 3.5.0
@@ -169,4 +169,4 @@ /** | ||
class PointWithErrorBar extends chart_js.PointElement { | ||
draw(ctx) { | ||
super.draw(ctx); | ||
draw(ctx, area) { | ||
super.draw.call(this, ctx, area); | ||
renderErrorBar(this, ctx); | ||
@@ -173,0 +173,0 @@ } |
@@ -8,3 +8,3 @@ /** | ||
import { BarElement, PointElement, ArcElement, BarController, Scale, ChartMeta, UpdateMode, BarControllerDatasetOptions, ScriptableAndArrayOptions, ScriptableContext, Chart, ChartItem, ChartConfiguration, LineController, LineControllerDatasetOptions, ScatterController, ScatterControllerDatasetOptions, PolarAreaController, Element, PolarAreaControllerDatasetOptions } from 'chart.js'; | ||
import { BarElement, PointElement, ArcElement, BarController, Scale, ChartMeta, Element, UpdateMode, BarControllerDatasetOptions, ScriptableAndArrayOptions, ScriptableContext, Chart, ChartItem, ChartConfiguration, LineController, LineControllerDatasetOptions, ScatterController, ScatterControllerDatasetOptions, PolarAreaController, PolarAreaControllerDatasetOptions } from 'chart.js'; | ||
@@ -25,3 +25,3 @@ declare class BarWithErrorBar extends BarElement { | ||
declare class PointWithErrorBar extends PointElement { | ||
draw(ctx: CanvasRenderingContext2D): void; | ||
draw(ctx: CanvasRenderingContext2D, area?: any): void; | ||
static readonly id = "pointWithErrorBar"; | ||
@@ -96,3 +96,3 @@ static readonly defaults: any; | ||
parseObjectData(meta: ChartMeta, data: any[], start: number, count: number): Record<string, unknown>[]; | ||
updateElement(element: BarElement, index: number | undefined, properties: any, mode: UpdateMode): void; | ||
updateElement(element: Element, index: number | undefined, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
static readonly id = "barWithErrorBars"; | ||
@@ -114,2 +114,3 @@ static readonly defaults: any; | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarXDataPoint & ChartTypeRegistry['bar']['parsedDataType']; | ||
@@ -130,3 +131,3 @@ }; | ||
parseObjectData(meta: ChartMeta, data: any[], start: number, count: number): Record<string, unknown>[]; | ||
updateElement(element: PointElement, index: number | undefined, properties: any, mode: UpdateMode): void; | ||
updateElement(element: Element, index: number | undefined, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
static readonly id = "lineWithErrorBars"; | ||
@@ -148,2 +149,3 @@ static readonly defaults: any; | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarXDataPoint & ChartTypeRegistry['line']['parsedDataType']; | ||
@@ -164,3 +166,3 @@ }; | ||
parseObjectData(meta: ChartMeta, data: any[], start: number, count: number): Record<string, unknown>[]; | ||
updateElement(element: PointElement, index: number | undefined, properties: any, mode: UpdateMode): void; | ||
updateElement(element: Element, index: number | undefined, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
static readonly id = "scatterWithErrorBars"; | ||
@@ -182,2 +184,3 @@ static readonly defaults: any; | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarXYDataPoint & ChartTypeRegistry['scatter']['parsedDataType']; | ||
@@ -199,3 +202,3 @@ }; | ||
parseObjectData(meta: ChartMeta, data: any[], start: number, count: number): Record<string, unknown>[]; | ||
updateElement(element: Element, index: number | undefined, properties: any, mode: UpdateMode): void; | ||
updateElement(element: Element, index: number | undefined, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
updateElements(arcs: Element[], start: number, count: number, mode: UpdateMode): void; | ||
@@ -218,2 +221,3 @@ static readonly id = "polarAreaWithErrorBars"; | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarRDataPoint & ChartTypeRegistry['polarArea']['parsedDataType']; | ||
@@ -220,0 +224,0 @@ }; |
@@ -165,4 +165,4 @@ /** | ||
class PointWithErrorBar extends PointElement { | ||
draw(ctx) { | ||
super.draw(ctx); | ||
draw(ctx, area) { | ||
super.draw.call(this, ctx, area); | ||
renderErrorBar(this, ctx); | ||
@@ -169,0 +169,0 @@ } |
@@ -204,4 +204,4 @@ /** | ||
class PointWithErrorBar extends chart_js.PointElement { | ||
draw(ctx) { | ||
super.draw(ctx); | ||
draw(ctx, area) { | ||
super.draw.call(this, ctx, area); | ||
renderErrorBar(this, ctx); | ||
@@ -208,0 +208,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!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={_scriptable:!0,_indexable:r=>"v"!==r},i=Object.keys(s);function c(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 u(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 d(r,e,t){const a=u(e.errorBarWhiskerRatio,t);if(null!=r&&a>0)return r*a*.5;return.5*u(e.errorBarWhiskerSize,t)}function h(r,e){var t,a,n,o;const s=r.getProps(["x","y","width","height","xMin","xMax","yMin","yMax"]);null==s.xMin&&null==s.xMax||function(r,e,t,a,n){n.save(),n.translate(0,r.y);const o=c(null==e?r.x:e,null==t?r.x:t);o.reverse().forEach((([e,t],s)=>{const l=o.length-s-1,i=d(r.height,a,l);n.lineWidth=u(a.errorBarLineWidth,l),n.strokeStyle=u(a.errorBarColor,l),n.beginPath(),n.moveTo(e,0),n.lineTo(t,0),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,l),n.strokeStyle=u(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()}(s,null!==(t=s.xMin)&&void 0!==t?t:null,null!==(a=s.xMax)&&void 0!==a?a:null,r.options,e),null==s.yMin&&null==s.yMax||function(r,e,t,a,n){n.save(),n.translate(r.x,0);const o=c(null==e?r.y:e,null==t?r.y:t);o.reverse().forEach((([e,t],s)=>{const l=o.length-s-1,i=d(r.width,a,l);n.lineWidth=u(a.errorBarLineWidth,l),n.strokeStyle=u(a.errorBarColor,l),n.beginPath(),n.moveTo(0,e),n.lineTo(0,t),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,l),n.strokeStyle=u(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()}(s,null!==(n=s.yMin)&&void 0!==n?n:null,null!==(o=s.yMax)&&void 0!==o?o:null,r.options,e)}function f(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),i={x:-l,y:s},h=Math.sqrt(i.x*i.x+i.y*i.y);i.x/=h,i.y/=h;const f=c(null!=e?e:r.outerRadius,null!=t?t:r.outerRadius);f.reverse().forEach((([r,e],t)=>{const o=f.length-t-1,c=r*s,h=r*l,p=e*s,y=e*l,x=d(null,a,o),m=i.x*x,g=i.y*x;n.lineWidth=u(a.errorBarLineWidth,o),n.strokeStyle=u(a.errorBarColor,o),n.beginPath(),n.moveTo(c,h),n.lineTo(p,y),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,o),n.strokeStyle=u(a.errorBarWhiskerColor,o),n.beginPath(),n.moveTo(c+m,h+g),n.lineTo(c-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 p extends e.BarElement{draw(r){super.draw(r),h(this,r)}}p.id="rectangleWithErrorBar",p.defaults={...e.BarElement.defaults,...s},p.defaultRoutes=e.BarElement.defaultRoutes,p.descriptors=l;class y extends e.PointElement{draw(r){super.draw(r),h(this,r)}}y.id="pointWithErrorBar",y.defaults={...e.PointElement.defaults,...s},y.defaultRoutes=e.PointElement.defaultRoutes,y.descriptors=l;class x extends e.ArcElement{draw(r){super.draw(r),f(this,r)}}function m(r){return Array.isArray(r)?r.slice().reverse():r}function g(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} (${m(o[t[0]])} .. ${o[t[1]]})`}x.id="arcWithErrorBar",x.defaults={...e.ArcElement.defaults,...s},x.defaultRoutes=e.ArcElement.defaultRoutes,x.descriptors=l;const M={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 B(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)&&o(e)?{v:r.v.map(((r,a)=>n(r,e.v[a],t)))}:e}const E={animations:{numberArray:{fn:function(r,e,t){return B(r,e,t,"number",M.number)},properties:a.concat(i.filter((r=>!r.endsWith("Color"))),["rMin","rMax"])},colorArray:{fn:function(r,e,t){return B(r,e,t,"string",M.color)},properties:i.filter((r=>r.endsWith("Color")))}}};function b(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 v(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;e<n;e+=1){const n=e+a,u=r[e];u[s]=t[n][s],u[l]=t[n][l],u[i]=v(u[o],u[s],Math.min),u[c]=v(u[o],u[l],Math.max)}}function W(r,e,t,a){const{axis:n}=e,o=e.getLabels();for(let s=0;s<a;s+=1){const a=s+t;r[s][n]=e.parse(o[a],a)}}function A(r,t,a,n=[],o=[]){e.registry.addControllers(a),Array.isArray(n)?e.registry.addElements(...n):e.registry.addElements(n),Array.isArray(o)?e.registry.addScales(...o):e.registry.addScales(o);const s=t;return s.type=r,s}class S extends e.BarController{getMinMax(r,e){return b(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){"number"==typeof e&&o(t,this.getParsed(e),e,this._cachedMeta.vScale,"reset"===a),super.updateElement(r,e,t,a)}}S.id="barWithErrorBars",S.defaults=t.merge({},[e.BarController.defaults,E,{dataElementType:p.id}]),S.overrides=t.merge({},[e.BarController.overrides,{plugins:{tooltip:{callbacks:{label:g}}}}]),S.defaultRoutes=e.BarController.defaultRoutes;class k extends e.Chart{constructor(r,t){super(r,A("barWithErrorBars",t,S,p,[e.LinearScale,e.CategoryScale]))}}k.id=S.id;class P extends e.LineController{getMinMax(r,e){return b(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 y&&"number"==typeof e&&o(t,this.getParsed(e),e,this._cachedMeta.vScale,"reset"===a),super.updateElement(r,e,t,a)}}P.id="lineWithErrorBars",P.defaults=t.merge({},[e.LineController.defaults,E,{dataElementType:y.id}]),P.overrides=t.merge({},[e.LineController.overrides,{plugins:{tooltip:{callbacks:{label:g}}}}]),P.defaultRoutes=e.LineController.defaultRoutes;class T extends e.Chart{constructor(r,t){super(r,A("lineWithErrorBars",t,P,y,[e.LinearScale,e.CategoryScale]))}}T.id=P.id;class $ extends e.ScatterController{getMinMax(r,e){return b(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 y&&"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)}}$.id="scatterWithErrorBars",$.defaults=t.merge({},[e.ScatterController.defaults,E,{dataElementType:y.id}]),$.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} [${m(e[a[0]])} .. ${e[a[1]]}]`};return`(${t(r.label,!0)}, ${t(r.parsed.y,!1)})`}}}}}]),$.defaultRoutes=e.LineController.defaultRoutes;class L extends e.Chart{constructor(r,t){super(r,A("scatterWithErrorBars",t,$,y,[e.LinearScale]))}}L.id=$.id;class R extends e.PolarAreaController{getMinMax(r,e){return b(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<a;r+=1){const a=r+t,s=e[a],l=o.parse(s[o.axis],a);n[r]={[o.axis]:l}}return C(n,o,e,t,a),n}updateElement(r,e,t,a){"number"==typeof e&&function(r,e,t,a,n){const o=n.animation,s=[`${t.axis}Min`,`${t.axis}Max`],l=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,E,{dataElementType:x.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} [${m(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,x,[e.RadialLinearScale]))}}j.id=R.id,e.registry.addControllers(S,P,R,$),e.registry.addElements(p,x,P,y),r.ArcWithErrorBar=x,r.BarWithErrorBar=p,r.BarWithErrorBarsChart=k,r.BarWithErrorBarsController=S,r.LineWithErrorBarsChart=T,r.LineWithErrorBarsController=P,r.PointWithErrorBar=y,r.PolarAreaWithErrorBarsChart=j,r.PolarAreaWithErrorBarsController=R,r.ScatterWithErrorBarsChart=L,r.ScatterWithErrorBarsController=$,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
!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={_scriptable:!0,_indexable:r=>"v"!==r},i=Object.keys(s);function c(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 u(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 d(r,e,t){const a=u(e.errorBarWhiskerRatio,t);if(null!=r&&a>0)return r*a*.5;return.5*u(e.errorBarWhiskerSize,t)}function h(r,e){var t,a,n,o;const s=r.getProps(["x","y","width","height","xMin","xMax","yMin","yMax"]);null==s.xMin&&null==s.xMax||function(r,e,t,a,n){n.save(),n.translate(0,r.y);const o=c(null==e?r.x:e,null==t?r.x:t);o.reverse().forEach((([e,t],s)=>{const l=o.length-s-1,i=d(r.height,a,l);n.lineWidth=u(a.errorBarLineWidth,l),n.strokeStyle=u(a.errorBarColor,l),n.beginPath(),n.moveTo(e,0),n.lineTo(t,0),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,l),n.strokeStyle=u(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()}(s,null!==(t=s.xMin)&&void 0!==t?t:null,null!==(a=s.xMax)&&void 0!==a?a:null,r.options,e),null==s.yMin&&null==s.yMax||function(r,e,t,a,n){n.save(),n.translate(r.x,0);const o=c(null==e?r.y:e,null==t?r.y:t);o.reverse().forEach((([e,t],s)=>{const l=o.length-s-1,i=d(r.width,a,l);n.lineWidth=u(a.errorBarLineWidth,l),n.strokeStyle=u(a.errorBarColor,l),n.beginPath(),n.moveTo(0,e),n.lineTo(0,t),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,l),n.strokeStyle=u(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()}(s,null!==(n=s.yMin)&&void 0!==n?n:null,null!==(o=s.yMax)&&void 0!==o?o:null,r.options,e)}function f(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),i={x:-l,y:s},h=Math.sqrt(i.x*i.x+i.y*i.y);i.x/=h,i.y/=h;const f=c(null!=e?e:r.outerRadius,null!=t?t:r.outerRadius);f.reverse().forEach((([r,e],t)=>{const o=f.length-t-1,c=r*s,h=r*l,p=e*s,y=e*l,x=d(null,a,o),m=i.x*x,g=i.y*x;n.lineWidth=u(a.errorBarLineWidth,o),n.strokeStyle=u(a.errorBarColor,o),n.beginPath(),n.moveTo(c,h),n.lineTo(p,y),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,o),n.strokeStyle=u(a.errorBarWhiskerColor,o),n.beginPath(),n.moveTo(c+m,h+g),n.lineTo(c-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 p extends e.BarElement{draw(r){super.draw(r),h(this,r)}}p.id="rectangleWithErrorBar",p.defaults={...e.BarElement.defaults,...s},p.defaultRoutes=e.BarElement.defaultRoutes,p.descriptors=l;class y extends e.PointElement{draw(r,e){super.draw.call(this,r,e),h(this,r)}}y.id="pointWithErrorBar",y.defaults={...e.PointElement.defaults,...s},y.defaultRoutes=e.PointElement.defaultRoutes,y.descriptors=l;class x extends e.ArcElement{draw(r){super.draw(r),f(this,r)}}function m(r){return Array.isArray(r)?r.slice().reverse():r}function g(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} (${m(o[t[0]])} .. ${o[t[1]]})`}x.id="arcWithErrorBar",x.defaults={...e.ArcElement.defaults,...s},x.defaultRoutes=e.ArcElement.defaultRoutes,x.descriptors=l;const M={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 B(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)&&o(e)?{v:r.v.map(((r,a)=>n(r,e.v[a],t)))}:e}const E={animations:{numberArray:{fn:function(r,e,t){return B(r,e,t,"number",M.number)},properties:a.concat(i.filter((r=>!r.endsWith("Color"))),["rMin","rMax"])},colorArray:{fn:function(r,e,t){return B(r,e,t,"string",M.color)},properties:i.filter((r=>r.endsWith("Color")))}}};function b(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 v(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;e<n;e+=1){const n=e+a,u=r[e];u[s]=t[n][s],u[l]=t[n][l],u[i]=v(u[o],u[s],Math.min),u[c]=v(u[o],u[l],Math.max)}}function W(r,e,t,a){const{axis:n}=e,o=e.getLabels();for(let s=0;s<a;s+=1){const a=s+t;r[s][n]=e.parse(o[a],a)}}function A(r,t,a,n=[],o=[]){e.registry.addControllers(a),Array.isArray(n)?e.registry.addElements(...n):e.registry.addElements(n),Array.isArray(o)?e.registry.addScales(...o):e.registry.addScales(o);const s=t;return s.type=r,s}class S extends e.BarController{getMinMax(r,e){return b(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){"number"==typeof e&&o(t,this.getParsed(e),e,this._cachedMeta.vScale,"reset"===a),super.updateElement(r,e,t,a)}}S.id="barWithErrorBars",S.defaults=t.merge({},[e.BarController.defaults,E,{dataElementType:p.id}]),S.overrides=t.merge({},[e.BarController.overrides,{plugins:{tooltip:{callbacks:{label:g}}}}]),S.defaultRoutes=e.BarController.defaultRoutes;class k extends e.Chart{constructor(r,t){super(r,A("barWithErrorBars",t,S,p,[e.LinearScale,e.CategoryScale]))}}k.id=S.id;class P extends e.LineController{getMinMax(r,e){return b(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 y&&"number"==typeof e&&o(t,this.getParsed(e),e,this._cachedMeta.vScale,"reset"===a),super.updateElement(r,e,t,a)}}P.id="lineWithErrorBars",P.defaults=t.merge({},[e.LineController.defaults,E,{dataElementType:y.id}]),P.overrides=t.merge({},[e.LineController.overrides,{plugins:{tooltip:{callbacks:{label:g}}}}]),P.defaultRoutes=e.LineController.defaultRoutes;class T extends e.Chart{constructor(r,t){super(r,A("lineWithErrorBars",t,P,y,[e.LinearScale,e.CategoryScale]))}}T.id=P.id;class $ extends e.ScatterController{getMinMax(r,e){return b(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 y&&"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)}}$.id="scatterWithErrorBars",$.defaults=t.merge({},[e.ScatterController.defaults,E,{dataElementType:y.id}]),$.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} [${m(e[a[0]])} .. ${e[a[1]]}]`};return`(${t(r.label,!0)}, ${t(r.parsed.y,!1)})`}}}}}]),$.defaultRoutes=e.LineController.defaultRoutes;class L extends e.Chart{constructor(r,t){super(r,A("scatterWithErrorBars",t,$,y,[e.LinearScale]))}}L.id=$.id;class R extends e.PolarAreaController{getMinMax(r,e){return b(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<a;r+=1){const a=r+t,s=e[a],l=o.parse(s[o.axis],a);n[r]={[o.axis]:l}}return C(n,o,e,t,a),n}updateElement(r,e,t,a){"number"==typeof e&&function(r,e,t,a,n){const o=n.animation,s=[`${t.axis}Min`,`${t.axis}Max`],l=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,E,{dataElementType:x.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} [${m(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,x,[e.RadialLinearScale]))}}j.id=R.id,e.registry.addControllers(S,P,R,$),e.registry.addElements(p,x,P,y),r.ArcWithErrorBar=x,r.BarWithErrorBar=p,r.BarWithErrorBarsChart=k,r.BarWithErrorBarsController=S,r.LineWithErrorBarsChart=T,r.LineWithErrorBarsController=P,r.PointWithErrorBar=y,r.PolarAreaWithErrorBarsChart=j,r.PolarAreaWithErrorBarsController=R,r.ScatterWithErrorBarsChart=L,r.ScatterWithErrorBarsController=$,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
{ | ||
"name": "chartjs-chart-error-bars", | ||
"description": "Chart.js module for charting error bars", | ||
"version": "3.1.0", | ||
"version": "3.5.0", | ||
"author": { | ||
@@ -36,3 +36,3 @@ "name": "Samuel Gratzl", | ||
"peerDependencies": { | ||
"chart.js": "^3.3.2" | ||
"chart.js": "^3.5.0" | ||
}, | ||
@@ -45,20 +45,20 @@ "browserslist": [ | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^19.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@rollup/plugin-replace": "^2.4.2", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@types/jest": "^26.0.23", | ||
"@types/jest-image-snapshot": "^4.3.0", | ||
"@types/node": "^15.12.1", | ||
"@typescript-eslint/eslint-plugin": "^4.26.0", | ||
"@typescript-eslint/parser": "^4.26.0", | ||
"@rollup/plugin-commonjs": "^20.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.4", | ||
"@rollup/plugin-replace": "^3.0.0", | ||
"@rollup/plugin-typescript": "^8.2.5", | ||
"@types/jest": "^26.0.24", | ||
"@types/jest-image-snapshot": "^4.3.1", | ||
"@types/node": "^16.4.13", | ||
"@typescript-eslint/eslint-plugin": "^4.29.0", | ||
"@typescript-eslint/parser": "^4.29.0", | ||
"@yarnpkg/pnpify": "^2.4.0", | ||
"canvas": "^2.8.0", | ||
"canvas-5-polyfill": "^0.1.5", | ||
"chart.js": "^3.3.2", | ||
"eslint": "^7.28.0", | ||
"chart.js": "^3.5.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb-typescript": "^12.3.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-config-react-app": "^6.0.0", | ||
"eslint-plugin-flowtype": "^5.7.2", | ||
"eslint-plugin-flowtype": "^5.9.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
@@ -69,15 +69,14 @@ "eslint-plugin-jsx-a11y": "^6.4.1", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"jest": "^27.0.4", | ||
"jest-image-snapshot": "^4.5.0", | ||
"prettier": "^2.3.1", | ||
"release-it": "^14.7.0", | ||
"jest": "^27.0.6", | ||
"jest-image-snapshot": "^4.5.1", | ||
"prettier": "^2.3.2", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.50.6", | ||
"rollup": "^2.56.0", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-dts": "^3.0.2", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"ts-jest": "^27.0.2", | ||
"tslib": "^2.2.0", | ||
"typedoc": "^0.20.36", | ||
"typescript": "^4.3.2" | ||
"ts-jest": "^27.0.4", | ||
"tslib": "^2.3.0", | ||
"typedoc": "^0.21.5", | ||
"typescript": "^4.3.5" | ||
}, | ||
@@ -101,6 +100,5 @@ "scripts": { | ||
"docs": "typedoc src/index.ts", | ||
"prepare": "yarn run build", | ||
"release": "release-it --disable-metrics --npm.skipChecks", | ||
"release:pre": "release-it --disable-metrics --npm.skipChecks --preRelease=alpha --npm.tag=next" | ||
} | ||
"prepare": "yarn run build" | ||
}, | ||
"packageManager": "yarn@3.0.0" | ||
} |
@@ -58,12 +58,28 @@ # Chart.js Error Bars | ||
The data structure depends on the chart type. It uses the fact that chart.js is supporting scatterplot. Thus, it is already prepared for object values. | ||
The data structure depends on the chart type. It uses the fact that chart.js is supporting scatterplots. Thus, it is already prepared for object values. | ||
### Chart types: `bar` and `line` | ||
see TypeScript Interface: | ||
[IErrorBarXDataPoint](https://github.com/sgratzl/chartjs-chart-error-bars/blob/main/src/controllers/base.ts#L3-L16) | ||
### Chart type: `bar` with `indexAxis: 'y'` | ||
[IErrorBarYDataPoint](https://github.com/sgratzl/chartjs-chart-error-bars/blob/main/src/controllers/base.ts#L18-L31) | ||
### Chart type: `scatter` | ||
a combination of the previous two ones | ||
[IErrorBarXDataPoint](https://github.com/sgratzl/chartjs-chart-error-bars/blob/main/src/controllers/base.ts#L3-L16) | ||
and | ||
[IErrorBarYDataPoint](https://github.com/sgratzl/chartjs-chart-error-bars/blob/main/src/controllers/base.ts#L18-L31) | ||
### Chart type: `polarArea` | ||
[IErrorBarRDataPoint](https://github.com/sgratzl/chartjs-chart-error-bars/blob/main/src/controllers/base.ts#L33-L46) | ||
## Multiple Error Bars | ||
@@ -81,2 +97,6 @@ | ||
see TypeScript interface: | ||
[IErrorBarOptions](https://github.com/sgratzl/chartjs-chart-error-bars/blob/main/src/elements/render.ts#L17-L54) | ||
### Data structure | ||
@@ -83,0 +103,0 @@ |
@@ -8,3 +8,2 @@ import { | ||
ChartMeta, | ||
BarElement, | ||
UpdateMode, | ||
@@ -16,2 +15,3 @@ ScriptableAndArrayOptions, | ||
BarControllerDatasetOptions, | ||
Element, | ||
} from 'chart.js'; | ||
@@ -47,4 +47,8 @@ import { merge } from 'chart.js/helpers'; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
updateElement(element: BarElement, index: number | undefined, properties: any, mode: UpdateMode): void { | ||
updateElement( | ||
element: Element, | ||
index: number | undefined, | ||
properties: Record<string, unknown>, | ||
mode: UpdateMode | ||
): void { | ||
// inject the other error bar related properties | ||
@@ -100,2 +104,3 @@ if (typeof index === 'number') { | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarXDataPoint & ChartTypeRegistry['bar']['parsedDataType']; | ||
@@ -102,0 +107,0 @@ }; |
@@ -7,3 +7,2 @@ import { | ||
ChartItem, | ||
PointElement, | ||
Scale, | ||
@@ -16,2 +15,3 @@ ChartConfiguration, | ||
ScriptableContext, | ||
Element, | ||
} from 'chart.js'; | ||
@@ -47,4 +47,8 @@ import { merge } from 'chart.js/helpers'; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
updateElement(element: PointElement, index: number | undefined, properties: any, mode: UpdateMode): void { | ||
updateElement( | ||
element: Element, | ||
index: number | undefined, | ||
properties: Record<string, unknown>, | ||
mode: UpdateMode | ||
): void { | ||
// inject the other error bar related properties | ||
@@ -101,2 +105,3 @@ if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarXDataPoint & ChartTypeRegistry['line']['parsedDataType']; | ||
@@ -103,0 +108,0 @@ }; |
@@ -74,4 +74,8 @@ import { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
updateElement(element: Element, index: number | undefined, properties: any, mode: UpdateMode): void { | ||
updateElement( | ||
element: Element, | ||
index: number | undefined, | ||
properties: Record<string, unknown>, | ||
mode: UpdateMode | ||
): void { | ||
if (typeof index === 'number') { | ||
@@ -139,2 +143,3 @@ calculatePolarScale( | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarRDataPoint & ChartTypeRegistry['polarArea']['parsedDataType']; | ||
@@ -141,0 +146,0 @@ }; |
@@ -9,3 +9,2 @@ import { | ||
ScatterControllerDatasetOptions, | ||
PointElement, | ||
Scale, | ||
@@ -16,2 +15,3 @@ ScriptableAndArrayOptions, | ||
ScriptableContext, | ||
Element, | ||
} from 'chart.js'; | ||
@@ -41,4 +41,8 @@ import { merge } from 'chart.js/helpers'; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
updateElement(element: PointElement, index: number | undefined, properties: any, mode: UpdateMode): void { | ||
updateElement( | ||
element: Element, | ||
index: number | undefined, | ||
properties: Record<string, unknown>, | ||
mode: UpdateMode | ||
): void { | ||
// inject the other error bar related properties | ||
@@ -102,2 +106,3 @@ if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
scales: keyof CartesianScaleTypeRegistry; | ||
metaExtensions: Record<string, never>; | ||
parsedDataType: IErrorBarXYDataPoint & ChartTypeRegistry['scatter']['parsedDataType']; | ||
@@ -104,0 +109,0 @@ }; |
@@ -5,4 +5,5 @@ import { PointElement } from 'chart.js'; | ||
export default class PointWithErrorBar extends PointElement { | ||
draw(ctx: CanvasRenderingContext2D): void { | ||
super.draw(ctx); | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
draw(ctx: CanvasRenderingContext2D, area?: any): void { | ||
(super.draw.call as any)(this, ctx, area); | ||
@@ -9,0 +10,0 @@ renderErrorBar(this as any, ctx); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
230167
35
3295
186