From d1f22e09733b6c5f2b3235bd6cab0b7a95bbd48a Mon Sep 17 00:00:00 2001 From: Erik Kimsey Date: Fri, 18 May 2018 20:58:33 -0400 Subject: [PATCH] Bindings are made and param changes are communicating to canvas.directive. --- src/app/app.component.html | 8 ++++---- src/app/app.component.ts | 19 ++++++++++++++++++- src/app/canvas/canvas.directive.ts | 19 ++++++++++++------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 2b3b433..6ae5267 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -9,25 +9,25 @@
  • diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7f81ce9..10582b9 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -31,7 +31,24 @@ export class AppComponent { spread: 80, showGrid: true }; - } + + /** + * A test of canvasParam.margin change and binding to canvas.directive + */ + let x = 1; + let intrvlId = setInterval(() => { + if (x < 5) { + this.canvasParam.margin.x += 0.2; + x += 1; + console.log("canvas param ", this.canvasParam.margin.x); + } else { + clearInterval(intrvlId); + } + }, 1000); + /** + * + */ + }; public updateCanvasConfig(config): void { this.canvasConfig = config; diff --git a/src/app/canvas/canvas.directive.ts b/src/app/canvas/canvas.directive.ts index 8b3e494..d8eb927 100644 --- a/src/app/canvas/canvas.directive.ts +++ b/src/app/canvas/canvas.directive.ts @@ -22,7 +22,8 @@ export class CanvasDirective implements OnInit, OnChanges { public config: Config; @Input() - private param: Param; + public param: Param; + public marginX: Param['margin']['x']; @Output() @@ -43,13 +44,17 @@ export class CanvasDirective implements OnInit, OnChanges { } ngOnChanges(changes: SimpleChanges) { - console.log(changes.param); + console.log("ch ch ch chaaaangesss ",changes.param); } ngDoCheck(){ + this.paramAdjustment(); + } + + paramAdjustment(){ this.resetLines(); this.resetPoints(); - this.init(); + this.init(); } ngOnInit() { @@ -121,7 +126,6 @@ export class CanvasDirective implements OnInit, OnChanges { private expandPoints(points: Point[]) { const newPoints: Point[] = []; - const matrix = { min: { x: points.reduce((a, b) => a.x < b.x ? a : b).x, @@ -131,7 +135,7 @@ export class CanvasDirective implements OnInit, OnChanges { x: points.reduce((a, b) => a.x > b.x ? a : b).x, y: points.reduce((a, b) => a.y > b.y ? a : b).y, } - }; + } points.splice(1, 0, { x: this.config.end.x, @@ -143,7 +147,7 @@ export class CanvasDirective implements OnInit, OnChanges { }); for (let i = 0; i < this.param.points; i++) { - points.splice(2, 0, this.generateRandomPoint(matrix)); + points.splice(2, 0, this.generateRandomPoint(matrix)); } return points; @@ -176,7 +180,8 @@ export class CanvasDirective implements OnInit, OnChanges { return points; } - private generateRandomPoint(matrix) { + private generateRandomPoint(matrix) { + return { x: Random.randomUniform(matrix.min.x, matrix.max.x)(), y: Random.randomUniform(matrix.min.y, matrix.max.y)()