-
Notifications
You must be signed in to change notification settings - Fork 7
/
chartjs-plugin-watermark.min.js
2 lines (2 loc) · 2.22 KB
/
chartjs-plugin-watermark.min.js
1
2
/* chartjs-plugin-watermark | AlbinoDrought | MIT License | https://github.com/AlbinoDrought/chartjs-plugin-watermark/blob/master/LICENSE */
!function(){function t(e,r,a){function i(o,c){if(!r[o]){if(!e[o]){var s="function"==typeof require&&require;if(!c&&s)return s(o,!0);if(n)return n(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var g=r[o]={exports:{}};e[o][0].call(g.exports,function(t){return i(e[o][1][t]||t)},g,g.exports,t,e,r,a)}return r[o].exports}for(var n="function"==typeof require&&require,o=0;o<a.length;o++)i(a[o]);return i}return t}()({1:[function(t,e,r){var a={id:"watermark",defaultOptions:{x:0,y:0,height:!1,width:!1,alignX:"top",alignY:"left",alignToChartArea:!1,position:"front",opacity:1,image:!1},isPercentage:function(t){return"string"==typeof t&&"%"==t.charAt(t.length-1)},calcPercentage:function(t,e){var r=t.substr(0,t.length-1);return r=parseFloat(r),e*(r/100)},autoPercentage:function(t,e){return this.isPercentage(t)&&(t=this.calcPercentage(t,e)),t},imageFromString:function(t){var e=new Image;return e.src=t,e},drawWatermark:function(t,e){var r=t.watermark;if(r.position==e&&r.image){var a,i,n=r.image,o=t.ctx,c=o.canvas,s=0,f=0;if(r.alignToChartArea){var g=t.chartArea;a=g.bottom-g.top,i=g.right-g.left,s=g.left,f=g.top}else a=c.clientHeight||c.height,i=c.clientWidth||c.width;var u=r.height||n.height;u=this.autoPercentage(u,a);var h=r.width||n.width;h=this.autoPercentage(h,i);var w=this.autoPercentage(r.x,i),l=this.autoPercentage(r.y,a);switch(r.alignX){case"right":w=i-w-h;break;case"middle":w=i/2-h/2-w}switch(r.alignY){case"bottom":l=a-l-u;break;case"middle":l=a/2-u/2-l}o.save(),o.globalAlpha=r.opacity,o.drawImage(n,s+w,f+l,h,u),o.restore()}},beforeInit:function(t){t.watermark={};var e=t.options;if(e.watermark){var r=Object.assign({},this.defaultOptions),a=Object.assign(r,e.watermark);if(a.image){var i=a.image;"string"==typeof i&&(i=this.imageFromString(i)),i.onload=function(){t.ctx&&t.update()},a.image=i}t.watermark=a}},beforeDraw:function(t){this.drawWatermark(t,"back")},afterDraw:function(t){this.drawWatermark(t,"front")},afterDatasetsDraw:function(t){this.drawWatermark(t,"between")}};e.exports=a,"undefined"!=typeof window&&window.Chart&&window.Chart.register(a)},{}]},{},[1]);