chartjs-plugin-watermark
Advanced tools
Comparing version
@@ -190,3 +190,3 @@ /* chartjs-plugin-watermark | AlbinoDrought | MIT License | https://github.com/AlbinoDrought/chartjs-plugin-watermark/blob/master/LICENSE */ | ||
// If used in browser, register globally | ||
if (window !== undefined) { | ||
if (typeof window !== 'undefined') { | ||
if (window.Chart) { | ||
@@ -193,0 +193,0 @@ window.Chart.register(watermarkPlugin); |
/* 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 g=new Error("Cannot find module '"+o+"'");throw g.code="MODULE_NOT_FOUND",g}var f=r[o]={exports:{}};e[o][0].call(f.exports,function(t){return i(e[o][1][t]||t)},f,f.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,g=0;if(r.alignToChartArea){var f=t.chartArea;a=f.bottom-f.top,i=f.right-f.left,s=f.left,g=f.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,g+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,void 0!==window&&window.Chart&&window.Chart.register(a)},{}]},{},[1]); | ||
!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]); |
{ | ||
"name": "chartjs-plugin-watermark", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A simple watermark plugin for Chart.js", | ||
@@ -5,0 +5,0 @@ "main": "src/chart.plugin.watermark.js", |
@@ -188,3 +188,3 @@ /** | ||
// If used in browser, register globally | ||
if (window !== undefined) { | ||
if (typeof window !== 'undefined') { | ||
if (window.Chart) { | ||
@@ -191,0 +191,0 @@ window.Chart.register(watermarkPlugin); |
39433
0.07%