/*!
 * @license
 * chartjs-plugin-datalabels
 * http://chartjs.org/
 * Version: 0.3.0
 *
 * Copyright 2018 Chart.js Contributors
 * Released under the MIT license
 * https://github.com/chartjs/chartjs-plugin-datalabels/blob/master/LICENSE.md
 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js")):"function"==typeof define&&define.amd?define(["chart.js"],e):e(t.Chart)}(this,function(t){"use strict";var e=(t=t&&t.hasOwnProperty("default")?t.default:t).helpers,n=function(){this._rect=null,this._rotation=0};e.extend(n.prototype,{update:function(t,e,n){var a=t.x,r=t.y,i=a+e.x,o=r+e.y;this._rotation=n,this._rect={x0:i-1,y0:o-1,x1:i+e.w+2,y1:o+e.h+2,cx:a,cy:r}},contains:function(t,e){var n,a,r,i,o,l=this._rect;return!!l&&(n=l.cx,a=l.cy,r=this._rotation,i=n+(t-n)*Math.cos(r)+(e-a)*Math.sin(r),o=a-(t-n)*Math.sin(r)+(e-a)*Math.cos(r),!(i<l.x0||o<l.y0||i>l.x1||o>l.y1))}});var a=t.helpers,r={toTextLines:function(t){var e,n=[];for(t=[].concat(t);t.length;)"string"==typeof(e=t.pop())?n.unshift.apply(n,e.split("\n")):Array.isArray(e)?t.push.apply(t,e):a.isNullOrUndef(t)||n.unshift(""+e);return n},toFontString:function(t){return!t||a.isNullOrUndef(t.size)||a.isNullOrUndef(t.family)?null:(t.style?t.style+" ":"")+(t.weight?t.weight+" ":"")+t.size+"px "+t.family},textSize:function(t,e,n){var a,r=[].concat(e),i=r.length,o=t.font,l=0;for(t.font=n.string,a=0;a<i;++a)l=Math.max(t.measureText(r[a]).width,l);return t.font=o,{height:i*n.lineHeight,width:l}},parseFont:function(e){var n=t.defaults.global,i=a.valueOrDefault(e.size,n.defaultFontSize),o={family:a.valueOrDefault(e.family,n.defaultFontFamily),lineHeight:a.options.toLineHeight(e.lineHeight,i),size:i,style:a.valueOrDefault(e.style,n.defaultFontStyle),weight:a.valueOrDefault(e.weight,null),string:""};return o.string=r.toFontString(o),o},bound:function(t,e,n){return Math.max(t,Math.min(e,n))},arrayDiff:function(t,e){var n,a,r,i,o=t.slice(),l=[];for(n=0,r=e.length;n<r;++n)i=e[n],-1===(a=o.indexOf(i))?l.push([i,1]):o.splice(a,1);for(n=0,r=o.length;n<r;++n)l.push([o[n],-1]);return l}};function i(t,e){var n=e.x,a=e.y;if(null===n)return{x:0,y:-1};if(null===a)return{x:1,y:0};var r=t.x-n,i=t.y-a,o=Math.sqrt(r*r+i*i);return{x:o?r/o:0,y:o?i/o:-1}}function o(t,e,n,a,r){switch(r){case"center":n=a=0;break;case"bottom":n=0,a=1;break;case"right":n=1,a=0;break;case"left":n=-1,a=0;break;case"top":n=0,a=-1;break;case"start":n=-n,a=-a;break;case"end":break;default:r*=Math.PI/180,n=Math.cos(r),a=Math.sin(r)}return{x:t,y:e,vx:n,vy:a}}var l={arc:function(t,e,n){var a,r=(t.startAngle+t.endAngle)/2,i=Math.cos(r),l=Math.sin(r),s=t.innerRadius,u=t.outerRadius;return a="start"===e?s:"end"===e?u:(s+u)/2,o(t.x+i*a,t.y+l*a,i,l,n)},point:function(t,e,n,a){var r=i(t,a),l=t.radius,s=0;return"start"===e?s=-l:"end"===e&&(s=l),o(t.x+r.x*s,t.y+r.y*s,r.x,r.y,n)},rect:function(t,e,n,a){var r=t.horizontal,l=Math.abs(t.base-(r?t.x:t.y)),s=r?Math.min(t.x,t.base):t.x,u=r?t.y:Math.min(t.y,t.base),f=i(t,a);return"center"===e?r?s+=l/2:u+=l/2:"start"!==e||r?"end"===e&&r&&(s+=l):u+=l,o(s,u,f.x,f.y,n)},fallback:function(t,e,n,a){var r=i(t,a);return o(t.x,t.y,r.x,r.y,n)}},s=t.helpers;var u=function(t,e,a,r){var i=this;i._hitbox=new n,i._config=t,i._index=r,i._model=null,i._ctx=e,i._el=a};s.extend(u.prototype,{_modelize:function(e,n,a){var i,o=this._index,u=s.options.resolve,f=r.parseFont(u([n.font,{}],a,o));return{align:u([n.align,"center"],a,o),anchor:u([n.anchor,"center"],a,o),backgroundColor:u([n.backgroundColor,null],a,o),borderColor:u([n.borderColor,null],a,o),borderRadius:u([n.borderRadius,0],a,o),borderWidth:u([n.borderWidth,0],a,o),color:u([n.color,t.defaults.global.defaultFontColor],a,o),font:f,lines:e,offset:u([n.offset,0],a,o),opacity:u([n.opacity,1],a,o),origin:function(t){var e=t._model.horizontal,n=t._scale||e&&t._xScale||t._yScale;if(!n)return null;if(void 0!==n.xCenter&&void 0!==n.yCenter)return{x:n.xCenter,y:n.yCenter};var a=n.getBasePixel();return e?{x:a,y:null}:{x:null,y:a}}(this._el),padding:s.options.toPadding(u([n.padding,0],a,o)),positioner:(i=this._el,i instanceof t.elements.Arc?l.arc:i instanceof t.elements.Point?l.point:i instanceof t.elements.Rectangle?l.rect:l.fallback),rotation:u([n.rotation,0],a,o)*(Math.PI/180),size:r.textSize(this._ctx,e,f),textAlign:u([n.textAlign,"start"],a,o)}},update:function(t){var e,n,a,i=null,o=this._index,l=this._config;s.options.resolve([l.display,!0],t,o)&&(e=t.dataset.data[o],n=s.valueOrDefault(s.callback(l.formatter,[e,t]),e),i=(a=s.isNullOrUndef(n)?[]:r.toTextLines(n)).length?this._modelize(a,l,t):null),this._model=i},draw:function(t){var e,n,a,i,o,l,u,f,d=this._model;d&&d.opacity&&(a=d.size,i=d.padding,o=a.height,l=a.width,f=-o/2,e={frame:{x:(u=-l/2)-i.left,y:f-i.top,w:l+i.width,h:o+i.height},text:{x:u,y:f,w:l,h:o}},n=function(t,e,n){var a=e.positioner(t._view,e.anchor,e.align,e.origin),r=a.vx,i=a.vy;if(!r&&!i)return{x:a.x,y:a.y};var o=e.borderWidth||0,l=n.w+2*o,s=n.h+2*o,u=e.rotation,f=Math.abs(l/2*Math.cos(u))+Math.abs(s/2*Math.sin(u)),d=Math.abs(l/2*Math.sin(u))+Math.abs(s/2*Math.cos(u)),c=1/Math.max(Math.abs(r),Math.abs(i));return f*=r*c,d*=i*c,f+=e.offset*r,d+=e.offset*i,{x:a.x+f,y:a.y+d}}(this._el,d,e.frame),this._hitbox.update(n,e.frame,d.rotation),t.save(),t.globalAlpha=r.bound(0,d.opacity,1),t.translate(Math.round(n.x),Math.round(n.y)),t.rotate(d.rotation),function(t,e,n){var a=n.backgroundColor,r=n.borderColor,i=n.borderWidth;(a||r&&i)&&(t.beginPath(),s.canvas.roundedRect(t,Math.round(e.x)-i/2,Math.round(e.y)-i/2,Math.round(e.w)+i,Math.round(e.h)+i,n.borderRadius),t.closePath(),a&&(t.fillStyle=a,t.fill()),r&&i&&(t.strokeStyle=r,t.lineWidth=i,t.lineJoin="miter",t.stroke()))}(t,e.frame,d),function(t,e,n,a){var r,i,o,l=a.textAlign,s=a.font.lineHeight,u=a.color,f=e.length;if(f&&u)for(r=n.x,i=n.y+s/2,"center"===l?r+=n.w/2:"end"!==l&&"right"!==l||(r+=n.w),t.font=a.font.string,t.fillStyle=u,t.textAlign=l,t.textBaseline="middle",o=0;o<f;++o)t.fillText(e[o],Math.round(r),Math.round(i),Math.round(n.w)),i+=s}(t,d.lines,e.text,d),t.restore())},contains:function(t,e){return this._hitbox.contains(t,e)}});var f=t.helpers,d={align:"center",anchor:"center",backgroundColor:null,borderColor:null,borderRadius:0,borderWidth:0,color:void 0,display:!0,font:{family:void 0,lineHeight:1.2,size:void 0,style:void 0,weight:null},offset:4,opacity:1,padding:{top:4,right:4,bottom:4,left:4},rotation:0,textAlign:"start",formatter:function(t){if(f.isNullOrUndef(t))return null;var e,n,a,r=t;if(f.isObject(t))if(f.isNullOrUndef(t.label))if(f.isNullOrUndef(t.r))for(r="",a=0,n=(e=Object.keys(t)).length;a<n;++a)r+=(0!==a?", ":"")+e[a]+": "+t[e[a]];else r=t.r;else r=t.label;return""+r},listeners:{}},c=t.helpers,h="$datalabels";function x(t,e){var n,a,r=t.getDatasetMeta(e).data||[],i=r.length;for(n=0;n<i;++n)(a=r[n][h])&&a.draw(t.ctx)}function y(t,e,n){var a,r,i,o,l=t[h].labels;for(a=l.length-1;a>=0;--a)for(r=(i=l[a]||[]).length-1;r>=0;--r)if((o=i[r]).contains(e,n))return{dataset:a,label:o};return null}function g(t,e,n){var a=e&&e[n.dataset];if(a){var r=n.label,i=r.$context;!0===c.callback(a,[i])&&(t[h].dirty=!0,r.update(i))}}function v(t,e){var n,a,r=t[h],i=r.listeners;if(i.enter||i.leave){if("mousemove"===e.type)a=y(t,e.x,e.y);else if("mouseout"!==e.type)return;n=r.hovered,r.hovered=a,function(t,e,n,a){var r,i;(n||a)&&(n?a?n.label!==a.label&&(i=r=!0):i=!0:r=!0,i&&g(t,e.leave,n),r&&g(t,e.enter,a))}(t,i,n,a)}}t.defaults.global.plugins.datalabels=d,t.defaults.global.plugins.datalabels=d,t.plugins.register({id:"datalabels",beforeInit:function(t){t[h]={actives:[]}},beforeUpdate:function(t){var e=t[h];e.listened=!1,e.listeners={},e.labels=[]},afterDatasetUpdate:function(t,e,n){var a,r,i,o=e.index,l=t[h],s=l.labels[o]=[],f=t.data.datasets[o],d=function(t,e){var n=t.datalabels;return!1===n?null:(!0===n&&(n={}),c.merge({},[e,n]))}(f,n),x=e.meta.data||[],y=x.length,g=t.ctx;for(g.save(),a=0;a<y;++a)!(r=x[a])||r.hidden||r._model.skip?i=null:(s.push(i=new u(d,g,r,a)),i.update(i.$context={active:!1,chart:t,dataIndex:a,dataset:f,datasetIndex:o})),r[h]=i;g.restore(),c.merge(l.listeners,d.listeners||{},{merger:function(t,n,a){n[t]=n[t]||{},n[t][e.index]=a[t],l.listened=!0}})},afterDatasetsDraw:function(t){for(var e=0,n=t.data.datasets.length;e<n;++e)x(t,e)},beforeEvent:function(t,e){if(t[h].listened)switch(e.type){case"mousemove":case"mouseout":v(t,e);break;case"click":!function(t,e){var n=t[h].listeners.click,a=n&&y(t,e.x,e.y);a&&g(t,n,a)}(t,e)}},afterEvent:function(t){var e,n,a,i,o=t[h],l=o.actives,s=o.actives=t.lastActive||[],u=r.arrayDiff(l,s);for(e=0,n=u.length;e<n;++e)(a=u[e])[1]&&(i=a[0][h])&&i.$context&&(i.$context.active=1===a[1],i.update(i.$context));!o.dirty&&!u.length||t.animating||t.render(),delete o.dirty}})});