New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@energiency/chartjs-plugin-piechart-outlabels

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@energiency/chartjs-plugin-piechart-outlabels - npm Package Compare versions

Comparing version 1.3.0-beta.1 to 1.3.0-beta.2

38

dist/chartjs-plugin-piechart-outlabels.esm.js
/*!
* @energiency/chartjs-plugin-piechart-outlabels v1.2.1-beta.1
* @energiency/chartjs-plugin-piechart-outlabels v1.3.0-beta.1
* http://www.chartjs.org

@@ -138,3 +138,3 @@ * (c) 2017-2022 @energiency/chartjs-plugin-piechart-outlabels contributors

*/
stretch: 10,
stretch: 12,

@@ -156,7 +156,7 @@ /**

/**
* The level of zoom (out) for pie/doughnut chart in percent.
* The max level of zoom (out) for pie/doughnut chart in percent.
* @member {Number}
* @default 10 (%)
* @default 50 (%)
*/
zoomOutPercentage: 30,
maxZoomOutPercentage: 50,

@@ -379,4 +379,4 @@ /**

this.computeLabelRect = function() {
var width = this.textRect.width + 2 * this.style.borderWidth + this.style.padding.left * 2;
var height = this.textRect.height + 2 * this.style.borderWidth;
var width = this.textRect.width + 2 * this.style.borderWidth + this.style.padding.left + this.style.padding.right;
var height = this.textRect.height + 2 * this.style.borderWidth + this.style.padding.top + this.style.padding.bottom;

@@ -609,3 +609,3 @@ var x = this.textRect.x - this.style.borderWidth;

const x = outlabelPlugin.labelRect.x + (!outlabelPlugin.labelRect.isLeft ? 0 : outlabelPlugin.labelRect.width);
const y = outlabelPlugin.labelRect.y + (outlabelPlugin.labelRect.isTop ? -outlabelPlugin.labelRect.height : 0);
const y = outlabelPlugin.labelRect.y + (outlabelPlugin.labelRect.isTop ? 0 : outlabelPlugin.labelRect.height);
if (x < rect.x1) {

@@ -624,17 +624,13 @@ rect.x1 = x;

});
const maxXDiff = Math.max(...[
var max = chart.options.maxZoomOutPercentage || customDefaults.maxZoomOutPercentage;
const t = [
chart.chartArea.left - rect.x1,
rect.x2 - (chart.chartArea.width - chart.chartArea.left),
]);
const diffX = maxXDiff > 0 ? maxXDiff : 0;
const maxYDiff = Math.max(...[
chart.chartArea.top - rect.y1,
rect.y2 - (chart.chartArea.height - chart.chartArea.top),
]);
const diffY = maxYDiff > 0 ? maxYDiff : 0;
const diff = Math.max(diffX, diffY) * 2;
var max = chart.options.zoomOutPercentage || customDefaults.zoomOutPercentage;
ctrl.outerRadius -= Math.min(diff, max);
rect.x2 - chart.chartArea.right,
rect.y2 - chart.chartArea.bottom
];
const diff = Math.max(...t.filter(x => x > 0));
const percent = diff * 100 / ctrl.outerRadius;
ctrl.outerRadius -= percent < max ? diff : max * 100 / ctrl.outerRadius;
ctrl.innerRadius = ctrl.outerRadius / 2;

@@ -641,0 +637,0 @@

/*!
* @energiency/chartjs-plugin-piechart-outlabels v1.2.1-beta.1
* @energiency/chartjs-plugin-piechart-outlabels v1.3.0-beta.1
* http://www.chartjs.org

@@ -141,3 +141,3 @@ * (c) 2017-2022 @energiency/chartjs-plugin-piechart-outlabels contributors

*/
stretch: 10,
stretch: 12,

@@ -159,7 +159,7 @@ /**

/**
* The level of zoom (out) for pie/doughnut chart in percent.
* The max level of zoom (out) for pie/doughnut chart in percent.
* @member {Number}
* @default 10 (%)
* @default 50 (%)
*/
zoomOutPercentage: 30,
maxZoomOutPercentage: 50,

@@ -382,4 +382,4 @@ /**

this.computeLabelRect = function() {
var width = this.textRect.width + 2 * this.style.borderWidth + this.style.padding.left * 2;
var height = this.textRect.height + 2 * this.style.borderWidth;
var width = this.textRect.width + 2 * this.style.borderWidth + this.style.padding.left + this.style.padding.right;
var height = this.textRect.height + 2 * this.style.borderWidth + this.style.padding.top + this.style.padding.bottom;

@@ -612,3 +612,3 @@ var x = this.textRect.x - this.style.borderWidth;

const x = outlabelPlugin.labelRect.x + (!outlabelPlugin.labelRect.isLeft ? 0 : outlabelPlugin.labelRect.width);
const y = outlabelPlugin.labelRect.y + (outlabelPlugin.labelRect.isTop ? -outlabelPlugin.labelRect.height : 0);
const y = outlabelPlugin.labelRect.y + (outlabelPlugin.labelRect.isTop ? 0 : outlabelPlugin.labelRect.height);
if (x < rect.x1) {

@@ -627,17 +627,13 @@ rect.x1 = x;

});
const maxXDiff = Math.max(...[
var max = chart.options.maxZoomOutPercentage || customDefaults.maxZoomOutPercentage;
const t = [
chart.chartArea.left - rect.x1,
rect.x2 - (chart.chartArea.width - chart.chartArea.left),
]);
const diffX = maxXDiff > 0 ? maxXDiff : 0;
const maxYDiff = Math.max(...[
chart.chartArea.top - rect.y1,
rect.y2 - (chart.chartArea.height - chart.chartArea.top),
]);
const diffY = maxYDiff > 0 ? maxYDiff : 0;
const diff = Math.max(diffX, diffY) * 2;
var max = chart.options.zoomOutPercentage || customDefaults.zoomOutPercentage;
ctrl.outerRadius -= Math.min(diff, max);
rect.x2 - chart.chartArea.right,
rect.y2 - chart.chartArea.bottom
];
const diff = Math.max(...t.filter(x => x > 0));
const percent = diff * 100 / ctrl.outerRadius;
ctrl.outerRadius -= percent < max ? diff : max * 100 / ctrl.outerRadius;
ctrl.innerRadius = ctrl.outerRadius / 2;

@@ -644,0 +640,0 @@

/*!
* @energiency/chartjs-plugin-piechart-outlabels v1.2.1-beta.1
* @energiency/chartjs-plugin-piechart-outlabels v1.3.0-beta.1
* http://www.chartjs.org

@@ -7,2 +7,2 @@ * (c) 2017-2022 @energiency/chartjs-plugin-piechart-outlabels contributors

*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ChartPieChartOutlabels=e(t.Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";var i={PLUGIN_KEY:"$outlabels",backgroundColor:function(t){return t.dataset.backgroundColor},borderColor:function(t){return t.dataset.backgroundColor},lineColor:function(t){return t.dataset.backgroundColor},borderRadius:0,borderWidth:0,lineWidth:2,color:"white",display:!0,font:{family:void 0,size:void 0,style:void 0,weight:null,maxSize:null,minSize:null,resizable:!0},lineHeight:1.2,padding:{top:2,right:2,bottom:2,left:2},textAlign:"center",stretch:10,horizontalStrechPad:12,text:"%l %p",zoomOutPercentage:30,percentPrecision:1,valuePrecision:3},s=function(t,e){var i=(t.startAngle+t.endAngle)/2,s=Math.cos(i),r=Math.sin(i),h=t.outerRadius,a=h+e;return{x:t.x+s*a,y:t.y+r*a,d:a,arc:t,anchor:{x:t.x+s*h,y:t.y+r*h},copy:{x:t.x+s*a,y:t.y+r*a}}},r=function(t,e){var i=t.arc,s=t.d,r=(i.startAngle+i.endAngle)/2,h=Math.cos(r),a=Math.sin(r);return s+=e,{x:i.x+h*s,y:i.y+a*s,d:s,arc:i,anchor:t.anchor,copy:{x:i.x+h*s,y:i.y+a*s}}};function h(i,s){var r=e.valueOrDefault(i.size,t.Chart.defaults.defaultFontSize);i.resizable&&(r=function(t,e,i){var s=t/100*2.5;return e&&s<e?e:i&&s>i?i:s}(s,i.minSize,i.maxSize));var h={family:e.valueOrDefault(i.family,t.Chart.defaults.defaultFontFamily),lineHeight:e.toLineHeight(i.lineHeight,r),size:r,style:e.valueOrDefault(i.style,t.Chart.defaults.defaultFontStyle),weight:e.valueOrDefault(i.weight,null),string:""};return h.string=function(t){return!t||e.isNullOrUndef(t.size)||e.isNullOrUndef(t.family)?null:(t.style?t.style+" ":"")+(t.weight?t.weight+" ":"")+t.size+"px "+t.family}(h),h}var a=i.PLUGIN_KEY,n=function(t,n,l,o,c){if(!e.resolve([o.display,!0],c,n))throw new Error("Label display property is set to false.");var d=c.dataset.data[n],x=c.labels[n],u=e.resolve([o.text,i.text],c,n);((u=u.replace(/%l/gi,x)).match(/%v\.?(\d*)/gi)||[]).map((function(t){var e=t.replace(/%v\./gi,"");return e.length?+e:o.valuePrecision||i.valuePrecision})).forEach((function(t){u=u.replace(/%v\.?(\d*)/i,d.toFixed(t))})),(u.match(/%p\.?(\d*)/gi)||[]).map((function(t){var e=t.replace(/%p\./gi,"");return e.length?+e:o.percentPrecision||i.percentPrecision})).forEach((function(t){u=u.replace(/%p\.?(\d*)/i,(100*c.percent).toFixed(t)+"%")}));var f=u.match(/[^\r\n]+/g);if(!f||!f.length)throw new Error("No text to show.");for(var y=0;y<f.length;++y)f[y]=f[y].trim();this.init=function(t,s){this.encodedText=o.text,this.text=t,this.lines=s,this.label=x,this.value=d,this.ctx=l,this.style={backgroundColor:e.resolve([o.backgroundColor,i.backgroundColor,"black"],c,n),borderColor:e.resolve([o.borderColor,i.borderColor,"black"],c,n),borderRadius:e.resolve([o.borderRadius,0],c,n),borderWidth:e.resolve([o.borderWidth,0],c,n),lineWidth:e.resolve([o.lineWidth,2],c,n),lineColor:e.resolve([o.lineColor,i.lineColor,"black"],c,n),color:e.resolve([o.color,"white"],c,n),font:h(e.resolve([o.font,{resizable:!0}]),l.canvas.style.height.slice(0,-2)),padding:e.toPadding(e.resolve([o.padding,0],c,n)),textAlign:e.resolve([o.textAlign,"left"],c,n)},this.stretch=e.resolve([o.stretch,i.stretch],c,n),this.horizontalStrechPad=e.resolve([o.horizontalStrechPad,i.horizontalStrechPad],c,n),this.size=function(t,e,i){var s,r=[].concat(e),h=r.length,a=t.font,n=0;for(t.font=i.string,s=0;s<h;++s)n=Math.max(t.measureText(r[s]).width,n);return t.font=a,{height:h*i.lineHeight,width:n}}(l,this.lines,this.style.font),this.offsetStep=this.size.width/20,this.offset={x:0,y:0}},this.init(u,f),this.computeLabelRect=function(){var t=this.textRect.width+2*this.style.borderWidth+2*this.style.padding.left,e=this.textRect.height+2*this.style.borderWidth;return{x:this.textRect.x-this.style.borderWidth,y:this.textRect.y-this.style.borderWidth,width:t,height:e,isLeft:this.textRect.isLeft,isTop:this.textRect.isTop}},this.computeTextRect=function(){const t=this.center.x-this.center.anchor.x<0,e=this.center.y-this.center.anchor.y<0,i=t?-(this.horizontalStrechPad+this.size.width):this.horizontalStrechPad;return{x:this.center.x-this.style.padding.left+i,y:this.center.y-this.size.height/2,width:this.size.width,height:this.size.height,isLeft:t,isTop:e}},this.getPoints=function(){return[{x:this.labelRect.x,y:this.labelRect.y},{x:this.labelRect.x+this.labelRect.width,y:this.labelRect.y},{x:this.labelRect.x+this.labelRect.width,y:this.labelRect.y+this.labelRect.height},{x:this.labelRect.x,y:this.labelRect.y+this.labelRect.height}]},this.containsPoint=function(t){return this.labelRect.x-5<=t.x&&t.x<=this.labelRect.x+this.labelRect.width+5&&this.labelRect.y-5<=t.y&&t.y<=this.labelRect.y+this.labelRect.height+5},this.drawText=function(){var t,e,i,s=this.style.textAlign,r=this.style.font.lineHeight,h=this.style.color,a=this.lines.length;if(a&&h)for(t=this.textRect.x,e=this.textRect.y+r/2,"center"===s?t+=this.textRect.width/2:"end"!==s&&"right"!==s||(t+=this.textRect.width),this.ctx.font=this.style.font.string,this.ctx.fillStyle=h,this.ctx.textAlign=s,this.ctx.textBaseline="middle",i=0;i<a;++i)this.ctx.fillText(this.lines[i],Math.round(t)+this.style.padding.left,Math.round(e),Math.round(this.textRect.width)),e+=r},this.ccw=function(t,e,i){return(i.y-t.y)*(e.x-t.x)>(e.y-t.y)*(i.x-t.x)},this.intersects=function(t,e,i,s){return this.ccw(t,i,s)!==this.ccw(e,i,s)&&this.ccw(t,e,i)!==this.ccw(t,e,s)},this.drawLine=function(){this.ctx.save(),this.ctx.strokeStyle=this.style.lineColor,this.ctx.lineWidth=this.style.lineWidth,this.ctx.lineJoin="miter",this.ctx.beginPath(),this.ctx.moveTo(this.center.anchor.x,this.center.anchor.y),this.ctx.lineTo(this.center.copy.x,this.center.copy.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.moveTo(this.center.copy.x,this.center.copy.y);const t=this.textRect.width+this.style.padding.width,e=this.intersects(this.textRect,{x:this.textRect.x+this.textRect.width,y:this.textRect.y+this.textRect.height},this.center.copy,{x:this.textRect.x,y:this.textRect.y+this.textRect.height/2});this.ctx.lineTo(this.textRect.x+(e?t:0),this.textRect.y+this.textRect.height/2),this.ctx.stroke(),this.ctx.restore()},this.draw=function(){t.getDataVisibility(n)&&(this.drawText(),this.drawLine())},this.update=function(e,i,h){this.center=s(e,this.stretch);for(var l=!1;!l;){this.textRect=this.computeTextRect(),this.labelRect=this.computeLabelRect();var o=this.getPoints();l=!0;for(var c=0;c<h;++c){var d=i[c][a];if(d&&t.getDataVisibility(n))for(var x=d.getPoints(),u=0;u<o.length;++u){if(d.containsPoint(o[u])){l=!1;break}if(this.containsPoint(x[u])){l=!1;break}}}l||(this.center=r(this.center,1))}}};t.defaults.plugins.outlabels=i;var l=i.PLUGIN_KEY;return{id:"outlabels",resize:function(t){t.sizeChanged=!0},afterUpdate:t=>{const e=t._metasets[0].controller;var s=e.getMeta(),r=s.data||[];const h={x1:1/0,x2:0,y1:1/0,y2:0};r.forEach(((t,e)=>{const i=t[l];if(!i)return;i.update(t,r,e);const s=i.labelRect.x+(i.labelRect.isLeft?i.labelRect.width:0),a=i.labelRect.y+(i.labelRect.isTop?-i.labelRect.height:0);s<h.x1&&(h.x1=s),s>h.x2&&(h.x2=s),a<h.y1&&(h.y1=a),a>h.y2&&(h.y2=a)}));const a=Math.max(t.chartArea.left-h.x1,h.x2-(t.chartArea.width-t.chartArea.left)),n=a>0?a:0,o=Math.max(t.chartArea.top-h.y1,h.y2-(t.chartArea.height-t.chartArea.top)),c=o>0?o:0,d=2*Math.max(n,c);var x=t.options.zoomOutPercentage||i.zoomOutPercentage;e.outerRadius-=Math.min(d,x),e.innerRadius=e.outerRadius/2,e.updateElements(s.data,0,s.data.length,"resize")},afterDatasetUpdate:function(t,e,i){var s,r,h,a,o,c,d=t.config.data.labels,x=t.data.datasets[e.index],u=function(t,e){var i=t.outlabels;return!1===i?null:(!0===i&&(i={}),Object.assign({},{},e,i))}(x,i),f=u&&u.display,y=e.meta.data||[],g=t.ctx;for(g.save(),c=0;c<y.length;++c){if(r=(s=y[c])[l],h=x.data[c]/e.meta.total,a=null,f&&s&&!s.hidden)try{o={chart:t,dataIndex:c,dataset:x,labels:d,datasetIndex:e.index,percent:h},a=new n(t,c,g,u,o)}catch(t){a=null}r&&a&&!t.sizeChanged&&r.label===a.label&&r.encodedText===a.encodedText&&(a.offset=r.offset),s[l]=a}g.restore(),t.sizeChanged=!1},afterDatasetDraw:function(t,e){var i=e.meta.data||[],s=t.ctx;i.forEach(((t,e)=>{const r=t[l];r&&(r.update(t,i,e),r.draw(s))}))}}}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ChartPieChartOutlabels=e(t.Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";var i={PLUGIN_KEY:"$outlabels",backgroundColor:function(t){return t.dataset.backgroundColor},borderColor:function(t){return t.dataset.backgroundColor},lineColor:function(t){return t.dataset.backgroundColor},borderRadius:0,borderWidth:0,lineWidth:2,color:"white",display:!0,font:{family:void 0,size:void 0,style:void 0,weight:null,maxSize:null,minSize:null,resizable:!0},lineHeight:1.2,padding:{top:2,right:2,bottom:2,left:2},textAlign:"center",stretch:12,horizontalStrechPad:12,text:"%l %p",maxZoomOutPercentage:50,percentPrecision:1,valuePrecision:3},s=function(t,e){var i=(t.startAngle+t.endAngle)/2,s=Math.cos(i),r=Math.sin(i),h=t.outerRadius,a=h+e;return{x:t.x+s*a,y:t.y+r*a,d:a,arc:t,anchor:{x:t.x+s*h,y:t.y+r*h},copy:{x:t.x+s*a,y:t.y+r*a}}},r=function(t,e){var i=t.arc,s=t.d,r=(i.startAngle+i.endAngle)/2,h=Math.cos(r),a=Math.sin(r);return s+=e,{x:i.x+h*s,y:i.y+a*s,d:s,arc:i,anchor:t.anchor,copy:{x:i.x+h*s,y:i.y+a*s}}};function h(i,s){var r=e.valueOrDefault(i.size,t.Chart.defaults.defaultFontSize);i.resizable&&(r=function(t,e,i){var s=t/100*2.5;return e&&s<e?e:i&&s>i?i:s}(s,i.minSize,i.maxSize));var h={family:e.valueOrDefault(i.family,t.Chart.defaults.defaultFontFamily),lineHeight:e.toLineHeight(i.lineHeight,r),size:r,style:e.valueOrDefault(i.style,t.Chart.defaults.defaultFontStyle),weight:e.valueOrDefault(i.weight,null),string:""};return h.string=function(t){return!t||e.isNullOrUndef(t.size)||e.isNullOrUndef(t.family)?null:(t.style?t.style+" ":"")+(t.weight?t.weight+" ":"")+t.size+"px "+t.family}(h),h}var a=i.PLUGIN_KEY,n=function(t,n,l,o,c){if(!e.resolve([o.display,!0],c,n))throw new Error("Label display property is set to false.");var d=c.dataset.data[n],x=c.labels[n],u=e.resolve([o.text,i.text],c,n);((u=u.replace(/%l/gi,x)).match(/%v\.?(\d*)/gi)||[]).map((function(t){var e=t.replace(/%v\./gi,"");return e.length?+e:o.valuePrecision||i.valuePrecision})).forEach((function(t){u=u.replace(/%v\.?(\d*)/i,d.toFixed(t))})),(u.match(/%p\.?(\d*)/gi)||[]).map((function(t){var e=t.replace(/%p\./gi,"");return e.length?+e:o.percentPrecision||i.percentPrecision})).forEach((function(t){u=u.replace(/%p\.?(\d*)/i,(100*c.percent).toFixed(t)+"%")}));var f=u.match(/[^\r\n]+/g);if(!f||!f.length)throw new Error("No text to show.");for(var y=0;y<f.length;++y)f[y]=f[y].trim();this.init=function(t,s){this.encodedText=o.text,this.text=t,this.lines=s,this.label=x,this.value=d,this.ctx=l,this.style={backgroundColor:e.resolve([o.backgroundColor,i.backgroundColor,"black"],c,n),borderColor:e.resolve([o.borderColor,i.borderColor,"black"],c,n),borderRadius:e.resolve([o.borderRadius,0],c,n),borderWidth:e.resolve([o.borderWidth,0],c,n),lineWidth:e.resolve([o.lineWidth,2],c,n),lineColor:e.resolve([o.lineColor,i.lineColor,"black"],c,n),color:e.resolve([o.color,"white"],c,n),font:h(e.resolve([o.font,{resizable:!0}]),l.canvas.style.height.slice(0,-2)),padding:e.toPadding(e.resolve([o.padding,0],c,n)),textAlign:e.resolve([o.textAlign,"left"],c,n)},this.stretch=e.resolve([o.stretch,i.stretch],c,n),this.horizontalStrechPad=e.resolve([o.horizontalStrechPad,i.horizontalStrechPad],c,n),this.size=function(t,e,i){var s,r=[].concat(e),h=r.length,a=t.font,n=0;for(t.font=i.string,s=0;s<h;++s)n=Math.max(t.measureText(r[s]).width,n);return t.font=a,{height:h*i.lineHeight,width:n}}(l,this.lines,this.style.font),this.offsetStep=this.size.width/20,this.offset={x:0,y:0}},this.init(u,f),this.computeLabelRect=function(){var t=this.textRect.width+2*this.style.borderWidth+this.style.padding.left+this.style.padding.right,e=this.textRect.height+2*this.style.borderWidth+this.style.padding.top+this.style.padding.bottom;return{x:this.textRect.x-this.style.borderWidth,y:this.textRect.y-this.style.borderWidth,width:t,height:e,isLeft:this.textRect.isLeft,isTop:this.textRect.isTop}},this.computeTextRect=function(){const t=this.center.x-this.center.anchor.x<0,e=this.center.y-this.center.anchor.y<0,i=t?-(this.horizontalStrechPad+this.size.width):this.horizontalStrechPad;return{x:this.center.x-this.style.padding.left+i,y:this.center.y-this.size.height/2,width:this.size.width,height:this.size.height,isLeft:t,isTop:e}},this.getPoints=function(){return[{x:this.labelRect.x,y:this.labelRect.y},{x:this.labelRect.x+this.labelRect.width,y:this.labelRect.y},{x:this.labelRect.x+this.labelRect.width,y:this.labelRect.y+this.labelRect.height},{x:this.labelRect.x,y:this.labelRect.y+this.labelRect.height}]},this.containsPoint=function(t){return this.labelRect.x-5<=t.x&&t.x<=this.labelRect.x+this.labelRect.width+5&&this.labelRect.y-5<=t.y&&t.y<=this.labelRect.y+this.labelRect.height+5},this.drawText=function(){var t,e,i,s=this.style.textAlign,r=this.style.font.lineHeight,h=this.style.color,a=this.lines.length;if(a&&h)for(t=this.textRect.x,e=this.textRect.y+r/2,"center"===s?t+=this.textRect.width/2:"end"!==s&&"right"!==s||(t+=this.textRect.width),this.ctx.font=this.style.font.string,this.ctx.fillStyle=h,this.ctx.textAlign=s,this.ctx.textBaseline="middle",i=0;i<a;++i)this.ctx.fillText(this.lines[i],Math.round(t)+this.style.padding.left,Math.round(e),Math.round(this.textRect.width)),e+=r},this.ccw=function(t,e,i){return(i.y-t.y)*(e.x-t.x)>(e.y-t.y)*(i.x-t.x)},this.intersects=function(t,e,i,s){return this.ccw(t,i,s)!==this.ccw(e,i,s)&&this.ccw(t,e,i)!==this.ccw(t,e,s)},this.drawLine=function(){this.ctx.save(),this.ctx.strokeStyle=this.style.lineColor,this.ctx.lineWidth=this.style.lineWidth,this.ctx.lineJoin="miter",this.ctx.beginPath(),this.ctx.moveTo(this.center.anchor.x,this.center.anchor.y),this.ctx.lineTo(this.center.copy.x,this.center.copy.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.moveTo(this.center.copy.x,this.center.copy.y);const t=this.textRect.width+this.style.padding.width,e=this.intersects(this.textRect,{x:this.textRect.x+this.textRect.width,y:this.textRect.y+this.textRect.height},this.center.copy,{x:this.textRect.x,y:this.textRect.y+this.textRect.height/2});this.ctx.lineTo(this.textRect.x+(e?t:0),this.textRect.y+this.textRect.height/2),this.ctx.stroke(),this.ctx.restore()},this.draw=function(){t.getDataVisibility(n)&&(this.drawText(),this.drawLine())},this.update=function(e,i,h){this.center=s(e,this.stretch);for(var l=!1;!l;){this.textRect=this.computeTextRect(),this.labelRect=this.computeLabelRect();var o=this.getPoints();l=!0;for(var c=0;c<h;++c){var d=i[c][a];if(d&&t.getDataVisibility(n))for(var x=d.getPoints(),u=0;u<o.length;++u){if(d.containsPoint(o[u])){l=!1;break}if(this.containsPoint(x[u])){l=!1;break}}}l||(this.center=r(this.center,1))}}};t.defaults.plugins.outlabels=i;var l=i.PLUGIN_KEY;return{id:"outlabels",resize:function(t){t.sizeChanged=!0},afterUpdate:t=>{const e=t._metasets[0].controller;var s=e.getMeta(),r=s.data||[];const h={x1:1/0,x2:0,y1:1/0,y2:0};r.forEach(((t,e)=>{const i=t[l];if(!i)return;i.update(t,r,e);const s=i.labelRect.x+(i.labelRect.isLeft?i.labelRect.width:0),a=i.labelRect.y+(i.labelRect.isTop?0:i.labelRect.height);s<h.x1&&(h.x1=s),s>h.x2&&(h.x2=s),a<h.y1&&(h.y1=a),a>h.y2&&(h.y2=a)}));var a=t.options.maxZoomOutPercentage||i.maxZoomOutPercentage;const n=[t.chartArea.left-h.x1,t.chartArea.top-h.y1,h.x2-t.chartArea.right,h.y2-t.chartArea.bottom],o=Math.max(...n.filter((t=>t>0))),c=100*o/e.outerRadius;e.outerRadius-=c<a?o:100*a/e.outerRadius,e.innerRadius=e.outerRadius/2,e.updateElements(s.data,0,s.data.length,"resize")},afterDatasetUpdate:function(t,e,i){var s,r,h,a,o,c,d=t.config.data.labels,x=t.data.datasets[e.index],u=function(t,e){var i=t.outlabels;return!1===i?null:(!0===i&&(i={}),Object.assign({},{},e,i))}(x,i),f=u&&u.display,y=e.meta.data||[],g=t.ctx;for(g.save(),c=0;c<y.length;++c){if(r=(s=y[c])[l],h=x.data[c]/e.meta.total,a=null,f&&s&&!s.hidden)try{o={chart:t,dataIndex:c,dataset:x,labels:d,datasetIndex:e.index,percent:h},a=new n(t,c,g,u,o)}catch(t){a=null}r&&a&&!t.sizeChanged&&r.label===a.label&&r.encodedText===a.encodedText&&(a.offset=r.offset),s[l]=a}g.restore(),t.sizeChanged=!1},afterDatasetDraw:function(t,e){var i=e.meta.data||[],s=t.ctx;i.forEach(((t,e)=>{const r=t[l];r&&(r.update(t,i,e),r.draw(s))}))}}}));

@@ -5,3 +5,3 @@ {

"description": "Chart.js plugin to display float data labels on pie/doughnut chart outside the border.",
"version": "1.3.0-beta.1",
"version": "1.3.0-beta.2",
"license": "MIT",

@@ -8,0 +8,0 @@ "main": "dist/chartjs-plugin-piechart-outlabels.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc