bouncing-ball-d3
Version:
Bouncing Ball Graph Using d3 js
170 lines (161 loc) • 6.46 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3'), require('@angular/core')) :
typeof define === 'function' && define.amd ? define('bouncing-ball', ['exports', 'd3', '@angular/core'], factory) :
(factory((global['bouncing-ball'] = {}),global.d3,global.ng.core));
}(this, (function (exports,d3,i0) { 'use strict';
/**
* @fileoverview added by tsickle
* Generated from: lib/bouncing-ball.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BouncingBallService = /** @class */ (function () {
function BouncingBallService() {
}
BouncingBallService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
BouncingBallService.ctorParameters = function () { return []; };
/** @nocollapse */ BouncingBallService.ngInjectableDef = i0.defineInjectable({ factory: function BouncingBallService_Factory() { return new BouncingBallService(); }, token: BouncingBallService, providedIn: "root" });
return BouncingBallService;
}());
/**
* @fileoverview added by tsickle
* Generated from: lib/bouncing-ball.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BouncingBallComponent = /** @class */ (function () {
function BouncingBallComponent() {
this.cx = 2;
this.cy = 2;
this.vx = 2;
this.vy = 5;
this.radius = 6;
this.gravity = 0.2;
this.damping = 0.85;
this.traction = 0.8;
this.paused = false;
this.width = 400;
this.height = 300;
}
/**
* @return {?}
*/
BouncingBallComponent.prototype.ngAfterContentInit = /**
* @return {?}
*/
function () {
this.rect = d3.select('svg').insert("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", this.width)
.attr("height", this.height)
.attr("fill", "black");
this.ball = d3.select('svg').insert("circle")
.attr("cx", this.cx)
.attr("cy", this.cy)
.attr("r", this.radius)
.attr("fill", "blue");
};
/**
* @return {?}
*/
BouncingBallComponent.prototype.onStartClick = /**
* @return {?}
*/
function () {
var _this = this;
setInterval(( /**
* @return {?}
*/function () { _this.drawBall(); }), 60);
};
/**
* @return {?}
*/
BouncingBallComponent.prototype.drawBall = /**
* @return {?}
*/
function () {
this.ball.attr("cx", this.moveX()).attr("cy", this.moveY());
};
/**
* @return {?}
*/
BouncingBallComponent.prototype.moveX = /**
* @return {?}
*/
function () {
if (this.cx + this.radius >= this.width) {
this.vx = -this.vx * this.damping;
this.cx = this.width - this.radius;
}
else if (this.cx - this.radius <= 0) {
this.vx = -this.vx * this.damping;
this.cx = this.radius;
}
this.cx += this.vx;
return this.cx;
};
/**
* @return {?}
*/
BouncingBallComponent.prototype.moveY = /**
* @return {?}
*/
function () {
if (this.cy + this.radius >= this.height) {
this.vy = -this.vy * this.damping;
this.cy = this.height - this.radius;
this.vx *= this.traction;
}
else if (this.cy - this.radius <= 0) {
this.vy = -this.vy * this.damping;
this.cy = this.radius;
}
this.vy += this.gravity;
this.cy += this.vy;
return this.cy;
};
BouncingBallComponent.decorators = [
{ type: i0.Component, args: [{
selector: 'd3-BouncingBall',
template: "<p>\r\n <svg width='100%' height='1200' class='mySvg'></svg>\r\n</p>\r\n"
}] }
];
return BouncingBallComponent;
}());
/**
* @fileoverview added by tsickle
* Generated from: lib/bouncing-ball.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BouncingBallModule = /** @class */ (function () {
function BouncingBallModule() {
}
BouncingBallModule.decorators = [
{ type: i0.NgModule, args: [{
declarations: [BouncingBallComponent],
imports: [],
exports: [BouncingBallComponent]
},] }
];
return BouncingBallModule;
}());
/**
* @fileoverview added by tsickle
* Generated from: public_api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: bouncing-ball.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
exports.BouncingBallService = BouncingBallService;
exports.BouncingBallComponent = BouncingBallComponent;
exports.BouncingBallModule = BouncingBallModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=bouncing-ball.umd.js.map