Bindings seem to be working now.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
<li>
|
<li>
|
||||||
<label>
|
<label>
|
||||||
<div>Amount of points</div>
|
<div>Amount of points</div>
|
||||||
<input type="number" [(ngModel)]="canvasParam.points" max="10" min="0" step="1">
|
<input type="number" name="canvasParam.points" [(ngModel)]="canvasParam.points" max="10" min="0" step="1">
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
background: rgb(55,55,55)
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
@@ -19,10 +20,11 @@ ul {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 3rem;
|
padding: 3rem;
|
||||||
background: rgba(0,0,0,0.3);
|
background: rgba(0,0,0,0.3);
|
||||||
opacity: 0.3;
|
// opacity: 0.3;
|
||||||
transition: all 360ms 120ms ease-out;
|
transition: all 360ms 120ms ease-out;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
|
color:white;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FormsModule } from '@angular/forms';
|
// import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
import { Param } from './models/param.model';
|
import { Param } from './models/param.model';
|
||||||
import { Config } from './models/config.model';
|
import { Config } from './models/config.model';
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { CanvasDirective } from './canvas/canvas.directive';
|
|||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
FormsModule
|
FormsModule,
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
private param: Param;
|
private param: Param;
|
||||||
|
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
private emitConfig: EventEmitter<Config>;
|
private emitConfig: EventEmitter<Config>;
|
||||||
@@ -31,7 +32,7 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
private onResize(event) {
|
private onResize(event) {
|
||||||
this.resetLines();
|
this.resetLines();
|
||||||
this.resetPoints();
|
this.resetPoints();
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -45,6 +46,12 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
console.log(changes.param);
|
console.log(changes.param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngDoCheck(){
|
||||||
|
this.resetLines();
|
||||||
|
this.resetPoints();
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
@@ -113,6 +120,8 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
|
|
||||||
private expandPoints(points: Point[]) {
|
private expandPoints(points: Point[]) {
|
||||||
const newPoints: Point[] = [];
|
const newPoints: Point[] = [];
|
||||||
|
|
||||||
|
|
||||||
const matrix = {
|
const matrix = {
|
||||||
min: {
|
min: {
|
||||||
x: points.reduce((a, b) => a.x < b.x ? a : b).x,
|
x: points.reduce((a, b) => a.x < b.x ? a : b).x,
|
||||||
@@ -123,7 +132,7 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
y: points.reduce((a, b) => a.y > b.y ? a : b).y,
|
y: points.reduce((a, b) => a.y > b.y ? a : b).y,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
points.splice(1, 0, {
|
points.splice(1, 0, {
|
||||||
x: this.config.end.x,
|
x: this.config.end.x,
|
||||||
y: this.config.height - this.config.height * this.param.margin.y
|
y: this.config.height - this.config.height * this.param.margin.y
|
||||||
@@ -134,7 +143,7 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < this.param.points; i++) {
|
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;
|
return points;
|
||||||
@@ -148,7 +157,7 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
|
|
||||||
let point = null;
|
let point = null;
|
||||||
|
|
||||||
if (group.size() <= 1) {
|
if (group.size()<=1) {
|
||||||
return this.expandPoints([
|
return this.expandPoints([
|
||||||
this.config.start,
|
this.config.start,
|
||||||
this.config.end
|
this.config.end
|
||||||
@@ -167,8 +176,8 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateRandomPoint(matrix) {
|
private generateRandomPoint(matrix) {
|
||||||
return {
|
return {
|
||||||
x: Random.randomUniform(matrix.min.x, matrix.max.x)(),
|
x: Random.randomUniform(matrix.min.x, matrix.max.x)(),
|
||||||
y: Random.randomUniform(matrix.min.y, matrix.max.y)()
|
y: Random.randomUniform(matrix.min.y, matrix.max.y)()
|
||||||
};
|
};
|
||||||
@@ -288,7 +297,7 @@ export class CanvasDirective implements OnInit, OnChanges {
|
|||||||
* Update Config Parameters and emit to parent component.
|
* Update Config Parameters and emit to parent component.
|
||||||
*/
|
*/
|
||||||
private updateConfig(): void {
|
private updateConfig(): void {
|
||||||
const margin = this.canvas.clientWidth * this.param.margin.x;
|
const margin = this.canvas.clientWidth * this.param.margin.x;
|
||||||
|
|
||||||
this.config = {
|
this.config = {
|
||||||
width: this.canvas.clientWidth,
|
width: this.canvas.clientWidth,
|
||||||
|
|||||||
Reference in New Issue
Block a user