chartjs-chart-error-bars
Advanced tools
Comparing version 3.7.2 to 3.8.0
@@ -431,6 +431,24 @@ /** | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.vScale, mode === 'reset'); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
super.updateElement(element, index, properties, mode); | ||
} | ||
updateElementScale(index, properties, mode) { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.vScale, mode === 'reset'); | ||
} | ||
updateElements(points, start, count, mode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point, mode); | ||
} | ||
} | ||
} | ||
} | ||
@@ -480,7 +498,25 @@ LineWithErrorBarsController.id = 'lineWithErrorBars'; | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.xScale, mode === 'reset'); | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.yScale, mode === 'reset'); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
super.updateElement(element, index, properties, mode); | ||
} | ||
updateElementScale(index, properties, mode) { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.xScale, mode === 'reset'); | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.yScale, mode === 'reset'); | ||
} | ||
updateElements(points, start, count, mode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point, mode); | ||
} | ||
} | ||
} | ||
} | ||
@@ -516,5 +552,25 @@ ScatterWithErrorBarsController.id = 'scatterWithErrorBars'; | ||
class PolarAreaWithErrorBarsController extends chart_js.PolarAreaController { | ||
getMinMax(scale, canStack) { | ||
return getMinMax(scale, (patchedScale) => super.getMinMax(patchedScale, canStack)); | ||
getMinMaxImpl(scale) { | ||
const t = this._cachedMeta; | ||
const e = { | ||
min: Number.POSITIVE_INFINITY, | ||
max: Number.NEGATIVE_INFINITY, | ||
}; | ||
t.data.forEach((_, i) => { | ||
const s = this.getParsed(i)[scale.axis]; | ||
if (Number.isNaN(s) || !this.chart.getDataVisibility(i)) { | ||
return; | ||
} | ||
if (s < e.min) { | ||
e.min = s; | ||
} | ||
if (s > e.max) { | ||
e.max = s; | ||
} | ||
}); | ||
return e; | ||
} | ||
getMinMax(scale) { | ||
return getMinMax(scale, (patchedScale) => this.getMinMaxImpl(patchedScale)); | ||
} | ||
countVisibleElements() { | ||
@@ -521,0 +577,0 @@ const meta = this._cachedMeta; |
@@ -143,2 +143,4 @@ /** | ||
updateElement(element: Element, index: number | undefined, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
protected updateElementScale(index: number, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
updateElements(points: Element[], start: number, count: number, mode: UpdateMode): void; | ||
static readonly id = "lineWithErrorBars"; | ||
@@ -177,2 +179,4 @@ static readonly defaults: any; | ||
updateElement(element: Element, index: number | undefined, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
protected updateElementScale(index: number, properties: Record<string, unknown>, mode: UpdateMode): void; | ||
updateElements(points: Element[], start: number, count: number, mode: UpdateMode): void; | ||
static readonly id = "scatterWithErrorBars"; | ||
@@ -205,6 +209,10 @@ static readonly defaults: any; | ||
declare class PolarAreaWithErrorBarsController extends PolarAreaController { | ||
getMinMax(scale: Scale, canStack: boolean): { | ||
getMinMaxImpl(scale: Scale): { | ||
min: number; | ||
max: number; | ||
}; | ||
getMinMax(scale: Scale): { | ||
min: number; | ||
max: number; | ||
}; | ||
countVisibleElements(): number; | ||
@@ -211,0 +219,0 @@ parseObjectData(meta: ChartMeta, data: any[], start: number, count: number): Record<string, unknown>[]; |
@@ -427,6 +427,24 @@ /** | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.vScale, mode === 'reset'); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
super.updateElement(element, index, properties, mode); | ||
} | ||
updateElementScale(index, properties, mode) { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.vScale, mode === 'reset'); | ||
} | ||
updateElements(points, start, count, mode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point, mode); | ||
} | ||
} | ||
} | ||
} | ||
@@ -476,7 +494,25 @@ LineWithErrorBarsController.id = 'lineWithErrorBars'; | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.xScale, mode === 'reset'); | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.yScale, mode === 'reset'); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
super.updateElement(element, index, properties, mode); | ||
} | ||
updateElementScale(index, properties, mode) { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.xScale, mode === 'reset'); | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.yScale, mode === 'reset'); | ||
} | ||
updateElements(points, start, count, mode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point, mode); | ||
} | ||
} | ||
} | ||
} | ||
@@ -512,5 +548,25 @@ ScatterWithErrorBarsController.id = 'scatterWithErrorBars'; | ||
class PolarAreaWithErrorBarsController extends PolarAreaController { | ||
getMinMax(scale, canStack) { | ||
return getMinMax(scale, (patchedScale) => super.getMinMax(patchedScale, canStack)); | ||
getMinMaxImpl(scale) { | ||
const t = this._cachedMeta; | ||
const e = { | ||
min: Number.POSITIVE_INFINITY, | ||
max: Number.NEGATIVE_INFINITY, | ||
}; | ||
t.data.forEach((_, i) => { | ||
const s = this.getParsed(i)[scale.axis]; | ||
if (Number.isNaN(s) || !this.chart.getDataVisibility(i)) { | ||
return; | ||
} | ||
if (s < e.min) { | ||
e.min = s; | ||
} | ||
if (s > e.max) { | ||
e.max = s; | ||
} | ||
}); | ||
return e; | ||
} | ||
getMinMax(scale) { | ||
return getMinMax(scale, (patchedScale) => this.getMinMaxImpl(patchedScale)); | ||
} | ||
countVisibleElements() { | ||
@@ -517,0 +573,0 @@ const meta = this._cachedMeta; |
@@ -430,6 +430,24 @@ /** | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.vScale, mode === 'reset'); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
super.updateElement(element, index, properties, mode); | ||
} | ||
updateElementScale(index, properties, mode) { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.vScale, mode === 'reset'); | ||
} | ||
updateElements(points, start, count, mode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point, mode); | ||
} | ||
} | ||
} | ||
} | ||
@@ -479,7 +497,25 @@ LineWithErrorBarsController.id = 'lineWithErrorBars'; | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.xScale, mode === 'reset'); | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.yScale, mode === 'reset'); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
super.updateElement(element, index, properties, mode); | ||
} | ||
updateElementScale(index, properties, mode) { | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.xScale, mode === 'reset'); | ||
calculateScale(properties, this.getParsed(index), index, this._cachedMeta.yScale, mode === 'reset'); | ||
} | ||
updateElements(points, start, count, mode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point, mode); | ||
} | ||
} | ||
} | ||
} | ||
@@ -515,5 +551,25 @@ ScatterWithErrorBarsController.id = 'scatterWithErrorBars'; | ||
class PolarAreaWithErrorBarsController extends chart_js.PolarAreaController { | ||
getMinMax(scale, canStack) { | ||
return getMinMax(scale, (patchedScale) => super.getMinMax(patchedScale, canStack)); | ||
getMinMaxImpl(scale) { | ||
const t = this._cachedMeta; | ||
const e = { | ||
min: Number.POSITIVE_INFINITY, | ||
max: Number.NEGATIVE_INFINITY, | ||
}; | ||
t.data.forEach((_, i) => { | ||
const s = this.getParsed(i)[scale.axis]; | ||
if (Number.isNaN(s) || !this.chart.getDataVisibility(i)) { | ||
return; | ||
} | ||
if (s < e.min) { | ||
e.min = s; | ||
} | ||
if (s > e.max) { | ||
e.max = s; | ||
} | ||
}); | ||
return e; | ||
} | ||
getMinMax(scale) { | ||
return getMinMax(scale, (patchedScale) => this.getMinMaxImpl(patchedScale)); | ||
} | ||
countVisibleElements() { | ||
@@ -520,0 +576,0 @@ const meta = this._cachedMeta; |
@@ -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="barWithErrorBar",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 b={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 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 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 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){"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,b,{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 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 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,b,{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 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 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,b,{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 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<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,b,{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,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(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 n(e){return e?a.slice(0,2):a.slice(2)}function s(e,r,t,a,n){const s=[`${a.axis}Min`,`${a.axis}Max`],o=a.getBasePixel();for(const l of s){const s=r[l];Array.isArray(s)?e[l]=s.map((e=>n?o:a.getPixelForValue(e,t))):"number"==typeof s&&(e[l]=n?o:a.getPixelForValue(s,t))}}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"]}},l={_scriptable:!0,_indexable:e=>"v"!==e},i=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 n=Math.max(t.length,a.length);return Array(n).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,n,s;const o=e.getProps(["x","y","width","height","xMin","xMax","yMin","yMax"]);null==o.xMin&&null==o.xMax||function(e,r,t,a,n){n.save(),n.translate(0,e.y);const s=c(null==r?e.x:r,null==t?e.x:t);s.reverse().forEach((([r,t],o)=>{const l=s.length-o-1,i=d(e.height,a,l);n.lineWidth=u(a.errorBarLineWidth,l),n.strokeStyle=u(a.errorBarColor,l),n.beginPath(),n.moveTo(r,0),n.lineTo(t,0),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,l),n.strokeStyle=u(a.errorBarWhiskerColor,l),n.beginPath(),n.moveTo(r,-i),n.lineTo(r,i),n.moveTo(t,-i),n.lineTo(t,i),n.stroke()})),n.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,n){n.save(),n.translate(e.x,0);const s=c(null==r?e.y:r,null==t?e.y:t);s.reverse().forEach((([r,t],o)=>{const l=s.length-o-1,i=d(e.width,a,l);n.lineWidth=u(a.errorBarLineWidth,l),n.strokeStyle=u(a.errorBarColor,l),n.beginPath(),n.moveTo(0,r),n.lineTo(0,t),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,l),n.strokeStyle=u(a.errorBarWhiskerColor,l),n.beginPath(),n.moveTo(-i,r),n.lineTo(i,r),n.moveTo(-i,t),n.lineTo(i,t),n.stroke()})),n.restore()}(o,null!==(n=o.yMin)&&void 0!==n?n:null,null!==(s=o.yMax)&&void 0!==s?s: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,n){n.save(),n.translate(e.x,e.y);const s=(e.startAngle+e.endAngle)/2,o=Math.cos(s),l=Math.sin(s),i={x:-l,y:o},h=Math.sqrt(i.x*i.x+i.y*i.y);i.x/=h,i.y/=h;const p=c(null!=r?r:e.outerRadius,null!=t?t:e.outerRadius);p.reverse().forEach((([e,r],t)=>{const s=p.length-t-1,c=e*o,h=e*l,f=r*o,m=r*l,x=d(null,a,s),y=i.x*x,g=i.y*x;n.lineWidth=u(a.errorBarLineWidth,s),n.strokeStyle=u(a.errorBarColor,s),n.beginPath(),n.moveTo(c,h),n.lineTo(f,m),n.stroke(),n.lineWidth=u(a.errorBarWhiskerLineWidth,s),n.strokeStyle=u(a.errorBarWhiskerColor,s),n.beginPath(),n.moveTo(c+y,h+g),n.lineTo(c-y,h-g),n.moveTo(f+y,m+g),n.lineTo(f-y,m-g),n.stroke()})),n.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=l;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=l;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=n(e.element.horizontal),a=r.Tooltip.defaults.callbacks.label.call(this,e),s=e.chart.data.datasets[e.datasetIndex].data[e.dataIndex];return null==s||t.every((e=>null==s[e]))?a:`${a} (${y(s[t[0]])} .. ${s[t[1]]})`}x.id="arcWithErrorBar",x.defaults={...r.ArcElement.defaults,...o},x.defaultRoutes=r.ArcElement.defaultRoutes,x.descriptors=l;const M={color(e,r,a){const n=e||"transparent",s=r||"transparent";if(n===s)return r;const o=t.color(n),l=o.valid&&t.color(s);return l&&l.valid?l.mix(o,a).hexString():r},number:(e,r,t)=>e===r?r:e+(r-e)*t};function E(e,r,t,a,n){if(typeof e===a&&typeof r===a)return n(e,r,t);if(Array.isArray(e)&&Array.isArray(r))return e.map(((e,a)=>n(e,r[a],t)));const s=e=>e&&Array.isArray(e.v);return s(e)&&s(r)?{v:e.v.map(((e,a)=>n(e,r.v[a],t)))}:r}const b={animations:{numberArray:{fn:function(e,r,t){return E(e,r,t,"number",M.number)},properties:a.concat(i.filter((e=>!e.endsWith("Color"))),["rMin","rMax"])},colorArray:{fn:function(e,r,t){return E(e,r,t,"string",M.color)},properties:i.filter((e=>e.endsWith("Color")))}}};function B(e,r){const{axis:t}=e;e.axis=`${t}MinMin`;const{min:a}=r(e);e.axis=`${t}MaxMax`;const{max:n}=r(e);return e.axis=t,{min:a,max:n}}function v(e,r,t){return Array.isArray(r)?t(...r):"number"==typeof r?r:e}function C(e,r,t,a,n){const s="string"==typeof r?r:r.axis,o=`${s}Min`,l=`${s}Max`,i=`${s}MinMin`,c=`${s}MaxMax`;for(let r=0;r<n;r+=1){const n=r+a,u=e[r];u[o]=t[n][o],u[l]=t[n][l],u[i]=v(u[s],u[o],Math.min),u[c]=v(u[s],u[l],Math.max)}}function W(e,r,t,a){const{axis:n}=r,s=r.getLabels();for(let o=0;o<a;o+=1){const a=o+t;e[o][n]=r.parse(s[a],a)}}function A(e,t,a,n=[],s=[]){r.registry.addControllers(a),Array.isArray(n)?r.registry.addElements(...n):r.registry.addElements(n),Array.isArray(s)?r.registry.addScales(...s):r.registry.addScales(s);const o=t;return o.type=e,o}class S extends r.BarController{getMinMax(e,r){return B(e,(e=>super.getMinMax(e,r)))}parseObjectData(e,r,t,a){const n=super.parseObjectData(e,r,t,a);return C(n,e.vScale,r,t,a),W(n,e.iScale,t,a),n}updateElement(e,r,t,a){"number"==typeof r&&s(t,this.getParsed(r),r,this._cachedMeta.vScale,"reset"===a),super.updateElement(e,r,t,a)}}S.id="barWithErrorBars",S.defaults=t.merge({},[r.BarController.defaults,b,{dataElementType:f.id}]),S.overrides=t.merge({},[r.BarController.overrides,{plugins:{tooltip:{callbacks:{label:g}}}}]),S.defaultRoutes=r.BarController.defaultRoutes;class k extends r.Chart{constructor(e,t){super(e,A("barWithErrorBars",t,S,f,[r.LinearScale,r.CategoryScale]))}}k.id=S.id;class P extends r.LineController{getMinMax(e,r){return B(e,(e=>super.getMinMax(e,r)))}parseObjectData(e,r,t,a){const n=super.parseObjectData(e,r,t,a);return C(n,e.vScale,r,t,a),W(n,e.iScale,t,a),n}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){s(r,this.getParsed(e),e,this._cachedMeta.vScale,"reset"===t)}updateElements(e,r,t,a){const n="reset"===a,s=this.chart._animationsDisabled||n||"none"===a;if(super.updateElements(e,r,t,a),s)for(let n=r;n<r+t;++n){const r=e[n];r instanceof m&&this.updateElementScale(n,r,a)}}}P.id="lineWithErrorBars",P.defaults=t.merge({},[r.LineController.defaults,b,{dataElementType:m.id}]),P.overrides=t.merge({},[r.LineController.overrides,{plugins:{tooltip:{callbacks:{label:g}}}}]),P.defaultRoutes=r.LineController.defaultRoutes;class T extends r.Chart{constructor(e,t){super(e,A("lineWithErrorBars",t,P,m,[r.LinearScale,r.CategoryScale]))}}T.id=P.id;class $ extends r.ScatterController{getMinMax(e,r){return B(e,(e=>super.getMinMax(e,r)))}parseObjectData(e,r,t,a){const n=super.parseObjectData(e,r,t,a);return C(n,e.xScale,r,t,a),C(n,e.yScale,r,t,a),n}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){s(r,this.getParsed(e),e,this._cachedMeta.xScale,"reset"===t),s(r,this.getParsed(e),e,this._cachedMeta.yScale,"reset"===t)}updateElements(e,r,t,a){const n="reset"===a,s=this.chart._animationsDisabled||n||"none"===a;if(super.updateElements(e,r,t,a),s)for(let n=r;n<r+t;++n){const r=e[n];r instanceof m&&this.updateElementScale(n,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=n(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,A("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 n=this.getParsed(a)[e.axis];!Number.isNaN(n)&&this.chart.getDataVisibility(a)&&(n<t.min&&(t.min=n),n>t.max&&(t.max=n))})),t}getMinMax(e){return B(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)}parseObjectData(e,r,t,a){const n=new Array(a),s=e.rScale;for(let e=0;e<a;e+=1){const a=e+t,o=r[a],l=s.parse(o[s.axis],a);n[e]={[s.axis]:l}}return C(n,s,r,t,a),n}updateElement(e,r,t,a){"number"==typeof r&&function(e,r,t,a,n){const s=n.animation,o=[`${t.axis}Min`,`${t.axis}Max`],l=e=>{const r=t.getDistanceFromCenterForValue(e),n=s.animateScale?0:r;return a?n:r};for(const t of o){const a=r[t];Array.isArray(a)?e[t]=a.map(l):"number"==typeof a&&(e[t]=l(a))}}(t,this.getParsed(r),this._cachedMeta.rScale,"reset"===a,this.chart.options),super.updateElement(e,r,t,a)}updateElements(e,r,t,a){const n=this.chart.scales.r,s=n.getDistanceFromCenterForValue;n.getDistanceFromCenterForValue=function(e){return"number"==typeof e?s.call(this,e):s.call(this,e.r)},super.updateElements(e,r,t,a),n.getDistanceFromCenterForValue=s}}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],n=["rMin","rMax"];return null==a||n.every((e=>null==a[e]))?t:`${t} [${y(a[n[0]])} .. ${a[n[1]]}]`}}}}}]),R.defaultRoutes=r.PolarAreaController.defaultRoutes;class I extends r.Chart{constructor(e,t){super(e,A("polarAreaWithErrorBars",t,R,x,[r.RadialLinearScale]))}}I.id=R.id,r.registry.addControllers(S,P,R,$),r.registry.addElements(f,x,m),e.ArcWithErrorBar=x,e.BarWithErrorBar=f,e.BarWithErrorBarsChart=k,e.BarWithErrorBarsController=S,e.LineWithErrorBarsChart=T,e.LineWithErrorBarsController=P,e.PointWithErrorBar=m,e.PolarAreaWithErrorBarsChart=I,e.PolarAreaWithErrorBarsController=R,e.ScatterWithErrorBarsChart=L,e.ScatterWithErrorBarsController=$,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
{ | ||
"name": "chartjs-chart-error-bars", | ||
"description": "Chart.js module for charting error bars", | ||
"version": "3.7.2", | ||
"version": "3.8.0", | ||
"author": { | ||
@@ -36,3 +36,3 @@ "name": "Samuel Gratzl", | ||
"peerDependencies": { | ||
"chart.js": "^3.7.1" | ||
"chart.js": "^3.8.0" | ||
}, | ||
@@ -47,15 +47,15 @@ "browserslist": [ | ||
"@rollup/plugin-commonjs": "^22.0.0", | ||
"@rollup/plugin-node-resolve": "^13.2.1", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"@rollup/plugin-replace": "^4.0.0", | ||
"@rollup/plugin-typescript": "^8.3.2", | ||
"@types/jest": "^27.4.1", | ||
"@rollup/plugin-typescript": "^8.3.3", | ||
"@types/jest": "^28.1.1", | ||
"@types/jest-image-snapshot": "^4.3.1", | ||
"@types/node": "^17.0.31", | ||
"@typescript-eslint/eslint-plugin": "^5.21.0", | ||
"@typescript-eslint/parser": "^5.21.0", | ||
"@yarnpkg/sdks": "^2.6.0", | ||
"@types/node": "^17.0.42", | ||
"@typescript-eslint/eslint-plugin": "^5.27.1", | ||
"@typescript-eslint/parser": "^5.27.1", | ||
"@yarnpkg/sdks": "^2.6.2", | ||
"canvas": "^2.9.1", | ||
"canvas-5-polyfill": "^0.1.5", | ||
"chart.js": "^3.7.1", | ||
"eslint": "^8.14.0", | ||
"chart.js": "^3.8.0", | ||
"eslint": "^8.17.0", | ||
"eslint-config-airbnb-typescript": "^17.0.0", | ||
@@ -68,16 +68,16 @@ "eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-react": "^7.29.4", | ||
"eslint-plugin-react": "^7.30.0", | ||
"eslint-plugin-react-hooks": "^4.5.0", | ||
"jest": "^27.5.1", | ||
"jest-environment-jsdom": "^27.5.1", | ||
"jest-image-snapshot": "^4.5.1", | ||
"jest": "^28.1.1", | ||
"jest-environment-jsdom": "^28.1.1", | ||
"jest-image-snapshot": "^5.1.0", | ||
"prettier": "^2.6.2", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.71.1", | ||
"rollup": "~2.75.6", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-dts": "^4.2.1", | ||
"ts-jest": "^27.1.4", | ||
"rollup-plugin-dts": "^4.2.2", | ||
"ts-jest": "^28.0.4", | ||
"tslib": "^2.4.0", | ||
"typedoc": "^0.22.15", | ||
"typescript": "^4.6.4" | ||
"typedoc": "^0.22.17", | ||
"typescript": "^4.7.3" | ||
}, | ||
@@ -104,3 +104,3 @@ "scripts": { | ||
}, | ||
"packageManager": "yarn@3.2.0" | ||
"packageManager": "yarn@3.2.1" | ||
} |
@@ -53,10 +53,3 @@ import { | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
// inject the other error bar related properties | ||
calculateScale( | ||
properties, | ||
this.getParsed(index) as Partial<IErrorBarXYDataPoint>, | ||
index, | ||
this._cachedMeta.vScale as LinearScale, | ||
mode === 'reset' | ||
); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
@@ -66,2 +59,33 @@ super.updateElement(element, index, properties, mode); | ||
protected updateElementScale(index: number, properties: Record<string, unknown>, mode: UpdateMode): void { | ||
// inject the other error bar related properties | ||
calculateScale( | ||
properties, | ||
this.getParsed(index) as Partial<IErrorBarXYDataPoint>, | ||
index, | ||
this._cachedMeta.vScale as LinearScale, | ||
mode === 'reset' | ||
); | ||
} | ||
updateElements(points: Element[], start: number, count: number, mode: UpdateMode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart as unknown as { _animationsDisabled: boolean }; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
// directUpdate not supported hack it | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
// manually update since with optimizations updateElement is not called | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
// inject the other error bar related properties | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point as unknown as Record<string, unknown>, mode); | ||
} | ||
} | ||
} | ||
static readonly id = 'lineWithErrorBars'; | ||
@@ -68,0 +92,0 @@ |
@@ -25,6 +25,28 @@ import { | ||
export class PolarAreaWithErrorBarsController extends PolarAreaController { | ||
getMinMax(scale: Scale, canStack: boolean): { min: number; max: number } { | ||
return getMinMax(scale, (patchedScale) => super.getMinMax(patchedScale, canStack)); | ||
getMinMaxImpl(scale: Scale) { | ||
// new version doesn't use scale.axis wrongly | ||
const t = this._cachedMeta; | ||
const e = { | ||
min: Number.POSITIVE_INFINITY, | ||
max: Number.NEGATIVE_INFINITY, | ||
}; | ||
t.data.forEach((_, i) => { | ||
const s = (this.getParsed(i) as any)[scale.axis] as number; | ||
if (Number.isNaN(s) || !this.chart.getDataVisibility(i)) { | ||
return; | ||
} | ||
if (s < e.min) { | ||
e.min = s; | ||
} | ||
if (s > e.max) { | ||
e.max = s; | ||
} | ||
}); | ||
return e; | ||
} | ||
getMinMax(scale: Scale): { min: number; max: number } { | ||
return getMinMax(scale, (patchedScale) => this.getMinMaxImpl(patchedScale)); | ||
} | ||
countVisibleElements(): number { | ||
@@ -31,0 +53,0 @@ const meta = this._cachedMeta; |
@@ -47,17 +47,3 @@ import { | ||
if (element instanceof PointWithErrorBar && typeof index === 'number') { | ||
// inject the other error bar related properties | ||
calculateScale( | ||
properties, | ||
this.getParsed(index) as Partial<IErrorBarXYDataPoint>, | ||
index, | ||
this._cachedMeta.xScale as LinearScale, | ||
mode === 'reset' | ||
); | ||
calculateScale( | ||
properties, | ||
this.getParsed(index) as Partial<IErrorBarXYDataPoint>, | ||
index, | ||
this._cachedMeta.yScale as LinearScale, | ||
mode === 'reset' | ||
); | ||
this.updateElementScale(index, properties, mode); | ||
} | ||
@@ -67,2 +53,40 @@ super.updateElement(element, index, properties, mode); | ||
protected updateElementScale(index: number, properties: Record<string, unknown>, mode: UpdateMode): void { | ||
// inject the other error bar related properties | ||
calculateScale( | ||
properties, | ||
this.getParsed(index) as Partial<IErrorBarXYDataPoint>, | ||
index, | ||
this._cachedMeta.xScale as LinearScale, | ||
mode === 'reset' | ||
); | ||
calculateScale( | ||
properties, | ||
this.getParsed(index) as Partial<IErrorBarXYDataPoint>, | ||
index, | ||
this._cachedMeta.yScale as LinearScale, | ||
mode === 'reset' | ||
); | ||
} | ||
updateElements(points: Element[], start: number, count: number, mode: UpdateMode) { | ||
const reset = mode === 'reset'; | ||
const c = this.chart as unknown as { _animationsDisabled: boolean }; | ||
const directUpdate = c._animationsDisabled || reset || mode === 'none'; | ||
// directUpdate not supported hack it | ||
super.updateElements(points, start, count, mode); | ||
if (!directUpdate) { | ||
return; | ||
} | ||
// manually update since with optimizations updateElement is not called | ||
for (let i = start; i < start + count; ++i) { | ||
const point = points[i]; | ||
// inject the other error bar related properties | ||
if (point instanceof PointWithErrorBar) { | ||
this.updateElementScale(i, point as unknown as Record<string, unknown>, mode); | ||
} | ||
} | ||
} | ||
static readonly id = 'scatterWithErrorBars'; | ||
@@ -69,0 +93,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
257330
3577