bouncing-ball-d3
Version:
Bouncing Ball Graph Using d3 js
162 lines (155 loc) • 5.2 kB
JavaScript
import { select } from 'd3';
import { Injectable, Component, NgModule, defineInjectable } from '@angular/core';
/**
* @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: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
BouncingBallService.ctorParameters = function () { return []; };
/** @nocollapse */ BouncingBallService.ngInjectableDef = 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 = select('svg').insert("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", this.width)
.attr("height", this.height)
.attr("fill", "black");
this.ball = 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: 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: 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
*/
export { BouncingBallService, BouncingBallComponent, BouncingBallModule };
//# sourceMappingURL=bouncing-ball.js.map