UNPKG

bouncing-ball-d3

Version:

Bouncing Ball Graph Using d3 js

2 lines 2.12 kB
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("d3"),require("@angular/core")):"function"==typeof define&&define.amd?define("bouncing-ball",["exports","d3","@angular/core"],i):i(t["bouncing-ball"]={},t.d3,t.ng.core)}(this,function(t,i,s){"use strict";var e=(r.decorators=[{type:s.Injectable,args:[{providedIn:"root"}]}],r.ctorParameters=function(){return[]},r.ngInjectableDef=s.defineInjectable({factory:function(){return new r},token:r,providedIn:"root"}),r);function r(){}var n=(h.prototype.ngAfterContentInit=function(){this.rect=i.select("svg").insert("rect").attr("x",0).attr("y",0).attr("width",this.width).attr("height",this.height).attr("fill","black"),this.ball=i.select("svg").insert("circle").attr("cx",this.cx).attr("cy",this.cy).attr("r",this.radius).attr("fill","blue")},h.prototype.onStartClick=function(){var t=this;setInterval(function(){t.drawBall()},60)},h.prototype.drawBall=function(){this.ball.attr("cx",this.moveX()).attr("cy",this.moveY())},h.prototype.moveX=function(){return this.cx+this.radius>=this.width?(this.vx=-this.vx*this.damping,this.cx=this.width-this.radius):this.cx-this.radius<=0&&(this.vx=-this.vx*this.damping,this.cx=this.radius),this.cx+=this.vx,this.cx},h.prototype.moveY=function(){return this.cy+this.radius>=this.height?(this.vy=-this.vy*this.damping,this.cy=this.height-this.radius,this.vx*=this.traction):this.cy-this.radius<=0&&(this.vy=-this.vy*this.damping,this.cy=this.radius),this.vy+=this.gravity,this.cy+=this.vy,this.cy},h.decorators=[{type:s.Component,args:[{selector:"d3-BouncingBall",template:"<p>\r\n <svg width='100%' height='1200' class='mySvg'></svg>\r\n</p>\r\n"}]}],h);function h(){this.cx=2,this.cy=2,this.vx=2,this.vy=5,this.radius=6,this.gravity=.2,this.damping=.85,this.traction=.8,this.paused=!1,this.width=400,this.height=300}var o=(a.decorators=[{type:s.NgModule,args:[{declarations:[n],imports:[],exports:[n]}]}],a);function a(){}t.BouncingBallService=e,t.BouncingBallComponent=n,t.BouncingBallModule=o,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=bouncing-ball.umd.min.js.map