Comparing version 1.0.2 to 1.0.3
@@ -96,3 +96,6 @@ ;(function(root, factory) { | ||
} else { | ||
this.opts[key] = value > 100 ? 100 : value; | ||
if (value > 100) { | ||
return; | ||
} | ||
this.opts[key] = value; | ||
} | ||
@@ -145,2 +148,3 @@ this._update(); | ||
_update: function () { | ||
this.eAngle = 0; | ||
cancelAnimationFrame(this.timer); | ||
@@ -181,6 +185,5 @@ this.reverse = this._reverse();//百分比对应的数值 | ||
// 外层的球 | ||
ctx.lineWidth = this.opts.borderWidth; | ||
ctx.save(); | ||
ctx.beginPath(); | ||
@@ -193,3 +196,3 @@ ctx.strokeStyle = this.opts.borderColor; | ||
ctx.arc(this.opts.r, this.opts.r, this.opts.r - this.opts.borderWidth - 5, 0, 2 * Math.PI); | ||
ctx.fill(); | ||
ctx.closePath() | ||
ctx.clip(); | ||
@@ -227,2 +230,3 @@ | ||
// 绘制文本 | ||
@@ -238,2 +242,3 @@ var fColor = this._HexToRGB(this.opts.color); | ||
ctx.fillText(this._ceil(this.opts.value) + this.opts.ext, this.opts.r, this.opts.r); | ||
ctx.restore(); | ||
@@ -240,0 +245,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";function WaterBall(t,e){this.elem="object"==typeof t?t:this._getElement(t),this.opts=e,this["default"]={r:100,fill:"#fff",waveStyle:["#5bf6a1","#2bdb72"],waveWidth:.02,waveHeight:8,speed:.1,borderColor:"#2bdc76",borderWidth:2,value:10,color:"#fff",fontSize:"25px microsoft yahei",textAlign:"center",ext:"%"},this.timer=null,this.oc=null,this.xOffset=0,this.eAngle=0}Date.now||(Date.now=function(){return(new Date).getTime()}),function(){for(var t=["webkit","moz"],e=0;e<t.length&&!window.requestAnimationFrame;++e){var i=t[e];window.requestAnimationFrame=window[i+"RequestAnimationFrame"],window.cancelAnimationFrame=window[i+"CancelAnimationFrame"]||window[i+"CancelRequestAnimationFrame"]}if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent)||!window.requestAnimationFrame||!window.cancelAnimationFrame){var s=0;window.requestAnimationFrame=function(t){var e=Date.now(),i=Math.max(s+16,e);return setTimeout(function(){t(s=i)},i-e)},window.cancelAnimationFrame=clearTimeout}}(),Object.assign(WaterBall.prototype,{render:function(){return this.opts=Object.assign({},this["default"],this.opts),this.opts.d=2*this.opts.r,this.maxY=this.opts.d,this.yOffset=this.opts.r,this.oc=this._createCanvas(),this._update(this._ceil(this.opts.value)),this},setOptions:function(t,e){if("object"==typeof t)for(var i in t)this.opts[i]=t[i];else this.opts[t]=e>100?100:e;this._update()},getCanvas:function(){return this.oc},destroy:function(){cancelAnimationFrame(this.timer),document.querySelector("body").removeChild(this.elem)},_inverse:function(t){var e=t.replace(/(?:rgb\()/,"");e=e.replace(/\)/,"");for(var i=e.split(","),s=0;s<i.length;s++){var o=i[s];i.splice(s,1,255-o)}return"rgb("+i.toString()+")"},_HexToRGB:function(t){if(t=t.match(/(?:#([a-f0-9]{3,8}))/i)){t=t[1],3===t.length&&(t+="fff");for(var e=[],i=0,s=t.length;i<s;i+=2)e.push(parseInt(t.substr(i,2),16)/(6===i?255:1));return"rgb("+e.toString()+")"}return t},_ceil:function(t){return Math.ceil(t)},_reverse:function(){return this.opts.d-this.opts.d*this.opts.value/100},_getElement:function(t){return document.getElementById(t)},_update:function(){cancelAnimationFrame(this.timer),this.reverse=this._reverse(),this._drawArc(this.oc,this.reverse)},_createCanvas:function(){var t=document.createElement("canvas");t.setAttribute("width",this.opts.d),t.setAttribute("height",this.opts.d);var e=this.elem.parentNode;return e.removeChild(this.elem),e.appendChild(t),this.elem=t,t},_createGradient:function(t,e){var i=t.createRadialGradient(75,50,5,90,60,100);if("string"==typeof e&&i.addColorStop(0,e),"object"==typeof e&&e instanceof Array)for(var s=e.length,o=0;o<s;o++){var r=o*(1/(s-1));i.addColorStop(r,e[o])}return i},_drawArc:function(t,e){this.eAngle++;var i=t.getContext("2d");i.clearRect(0,0,this.opts.d,this.opts.d),i.lineWidth=this.opts.borderWidth,i.beginPath(),i.strokeStyle=this.opts.borderColor,i.fillStyle=this._createGradient(i,this.opts.fill),i.arc(this.opts.r,this.opts.r,this.opts.r-this.opts.borderWidth,0,2*Math.PI),i.stroke(),i.beginPath(),i.arc(this.opts.r,this.opts.r,this.opts.r-this.opts.borderWidth-5,0,2*Math.PI),i.fill(),i.clip();var s=[];i.beginPath(),this.xOffset+=this.opts.speed;for(var o=0;o<0+this.opts.d;o+=20/this.opts.d){var r=-Math.sin((0+o)*this.opts.waveWidth+this.xOffset);s.push([o,e+r*this.opts.waveHeight]),i.lineTo(o,e+0+r*this.opts.waveHeight)}i.lineTo(this.opts.d,this.opts.d),i.lineTo(0,this.opts.d),i.lineTo(s[0][0],s[0][1]),i.fillStyle=this._createGradient(i,this.opts.waveStyle),i.fill(),i.beginPath(),i.strokeStyle=this.opts.fill,i.globalAlpha=.3;var n=-Math.sin(.1*this.eAngle);this.maxY<-50&&(this.maxY=this.opts.d),i.arc(this.yOffset+5*n,this.maxY--,8,0,2*Math.PI),i.stroke();var a=this._HexToRGB(this.opts.color);this.opts.value>55&&(a=this._inverse(a)),i.globalAlpha=1,i.font=this.opts.fontSize,i.fillStyle=a,i.textAlign=this.opts.textAlign,i.fillText(this._ceil(this.opts.value)+this.opts.ext,this.opts.r,this.opts.r);var h=this;this.timer=window.requestAnimationFrame(function(){h._drawArc(h.oc,h.reverse)})}}); | ||
"use strict";function WaterBall(t,e){this.elem="object"==typeof t?t:this._getElement(t),this.opts=e,this["default"]={r:100,fill:"#fff",waveStyle:["#5bf6a1","#2bdb72"],waveWidth:.02,waveHeight:8,speed:.1,borderColor:"#2bdc76",borderWidth:2,value:10,color:"#fff",fontSize:"25px microsoft yahei",textAlign:"center",ext:"%"},this.timer=null,this.oc=null,this.xOffset=0,this.eAngle=0}Date.now||(Date.now=function(){return(new Date).getTime()}),function(){for(var t=["webkit","moz"],e=0;e<t.length&&!window.requestAnimationFrame;++e){var i=t[e];window.requestAnimationFrame=window[i+"RequestAnimationFrame"],window.cancelAnimationFrame=window[i+"CancelAnimationFrame"]||window[i+"CancelRequestAnimationFrame"]}if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent)||!window.requestAnimationFrame||!window.cancelAnimationFrame){var s=0;window.requestAnimationFrame=function(t){var e=Date.now(),i=Math.max(s+16,e);return setTimeout(function(){t(s=i)},i-e)},window.cancelAnimationFrame=clearTimeout}}(),Object.assign(WaterBall.prototype,{render:function(){return this.opts=Object.assign({},this["default"],this.opts),this.opts.d=2*this.opts.r,this.maxY=this.opts.d,this.yOffset=this.opts.r,this.oc=this._createCanvas(),this._update(this._ceil(this.opts.value)),this},setOptions:function(t,e){if("object"==typeof t)for(var i in t)this.opts[i]=t[i];else{if(e>100)return;this.opts[t]=e}this._update()},getCanvas:function(){return this.oc},destroy:function(){cancelAnimationFrame(this.timer),document.querySelector("body").removeChild(this.elem)},_inverse:function(t){var e=t.replace(/(?:rgb\()/,"");e=e.replace(/\)/,"");for(var i=e.split(","),s=0;s<i.length;s++){var o=i[s];i.splice(s,1,255-o)}return"rgb("+i.toString()+")"},_HexToRGB:function(t){if(t=t.match(/(?:#([a-f0-9]{3,8}))/i)){t=t[1],3===t.length&&(t+="fff");for(var e=[],i=0,s=t.length;i<s;i+=2)e.push(parseInt(t.substr(i,2),16)/(6===i?255:1));return"rgb("+e.toString()+")"}return t},_ceil:function(t){return Math.ceil(t)},_reverse:function(){return this.opts.d-this.opts.d*this.opts.value/100},_getElement:function(t){return document.getElementById(t)},_update:function(){this.eAngle=0,cancelAnimationFrame(this.timer),this.reverse=this._reverse(),this._drawArc(this.oc,this.reverse)},_createCanvas:function(){var t=document.createElement("canvas");t.setAttribute("width",this.opts.d),t.setAttribute("height",this.opts.d);var e=this.elem.parentNode;return e.removeChild(this.elem),e.appendChild(t),this.elem=t,t},_createGradient:function(t,e){var i=t.createRadialGradient(75,50,5,90,60,100);if("string"==typeof e&&i.addColorStop(0,e),"object"==typeof e&&e instanceof Array)for(var s=e.length,o=0;o<s;o++){var r=o*(1/(s-1));i.addColorStop(r,e[o])}return i},_drawArc:function(t,e){this.eAngle++;var i=t.getContext("2d");i.clearRect(0,0,this.opts.d,this.opts.d),i.lineWidth=this.opts.borderWidth,i.save(),i.beginPath(),i.strokeStyle=this.opts.borderColor,i.fillStyle=this._createGradient(i,this.opts.fill),i.arc(this.opts.r,this.opts.r,this.opts.r-this.opts.borderWidth,0,2*Math.PI),i.stroke(),i.beginPath(),i.arc(this.opts.r,this.opts.r,this.opts.r-this.opts.borderWidth-5,0,2*Math.PI),i.closePath(),i.clip();var s=[];i.beginPath(),this.xOffset+=this.opts.speed;for(var o=0;o<0+this.opts.d;o+=20/this.opts.d){var r=-Math.sin((0+o)*this.opts.waveWidth+this.xOffset);s.push([o,e+r*this.opts.waveHeight]),i.lineTo(o,e+0+r*this.opts.waveHeight)}i.lineTo(this.opts.d,this.opts.d),i.lineTo(0,this.opts.d),i.lineTo(s[0][0],s[0][1]),i.fillStyle=this._createGradient(i,this.opts.waveStyle),i.fill(),i.beginPath(),i.strokeStyle=this.opts.fill,i.globalAlpha=.3;var n=-Math.sin(.1*this.eAngle);this.maxY<-50&&(this.maxY=this.opts.d),i.arc(this.yOffset+5*n,this.maxY--,8,0,2*Math.PI),i.stroke();var a=this._HexToRGB(this.opts.color);this.opts.value>55&&(a=this._inverse(a)),i.globalAlpha=1,i.font=this.opts.fontSize,i.fillStyle=a,i.textAlign=this.opts.textAlign,i.fillText(this._ceil(this.opts.value)+this.opts.ext,this.opts.r,this.opts.r),i.restore();var h=this;this.timer=window.requestAnimationFrame(function(){h._drawArc(h.oc,h.reverse)})}}); |
@@ -0,0 +0,0 @@ /** |
{ | ||
"name": "waterball", | ||
"description": "A Canvas Graph library", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"scripts": { | ||
@@ -15,5 +15,6 @@ "test": "mocha", | ||
"author": { | ||
"name": "Zed Wang", | ||
"email": "343650735@qq.com" | ||
"name": "Zed Wong", | ||
"email": "woox.wzd@gmail.com" | ||
}, | ||
"copyright": "Copyright ZedWong, Inc.", | ||
"licenses": [ | ||
@@ -26,3 +27,7 @@ { | ||
"issues": "https://github.com/zedwang/waterball/issues", | ||
"main": "src/water-ball.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/zedwang/waterball" | ||
}, | ||
"main": "dist/water-ball.js", | ||
"dependencies": {}, | ||
@@ -29,0 +34,0 @@ "devDependencies": { |
# WaterBall | ||
Light cross-platform Graph,Custom Configuration and animation supported | ||
[![NPM](https://nodei.co/npm/waterball.png?compact=true)](https://nodei.co/npm/waterball/) | ||
### Demo | ||
[https://zedwang.github.io/waterball/demo/index.html](https://zedwang.github.io/waterball/demo/index.html) | ||
![](/jdfw.gif) | ||
* The component support AMD、CMD and standalone model | ||
* The component supported AMD、CMD and standalone model | ||
@@ -8,0 +13,0 @@ #### Install with standalone |
@@ -87,3 +87,6 @@ /** | ||
} else { | ||
this.opts[key] = value > 100 ? 100 : value; | ||
if (value > 100) { | ||
return; | ||
} | ||
this.opts[key] = value; | ||
} | ||
@@ -95,2 +98,3 @@ this._update(); | ||
}, | ||
// 君要臣死,臣不得不死 | ||
destroy: function () { | ||
@@ -137,2 +141,3 @@ cancelAnimationFrame(this.timer); | ||
_update: function () { | ||
this.eAngle = 0; | ||
cancelAnimationFrame(this.timer); | ||
@@ -173,6 +178,5 @@ this.reverse = this._reverse();//百分比对应的数值 | ||
// 外层的球 | ||
ctx.lineWidth = this.opts.borderWidth; | ||
ctx.save(); | ||
ctx.beginPath(); | ||
@@ -185,3 +189,3 @@ ctx.strokeStyle = this.opts.borderColor; | ||
ctx.arc(this.opts.r, this.opts.r, this.opts.r - this.opts.borderWidth - 5, 0, 2 * Math.PI); | ||
ctx.fill(); | ||
ctx.closePath() | ||
ctx.clip(); | ||
@@ -219,2 +223,3 @@ | ||
// 绘制文本 | ||
@@ -230,2 +235,3 @@ var fColor = this._HexToRGB(this.opts.color); | ||
ctx.fillText(this._ceil(this.opts.value) + this.opts.ext, this.opts.r, this.opts.r); | ||
ctx.restore(); | ||
@@ -232,0 +238,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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
499
79
0
289502
15