2
0

feat(appComponent): added more adjustable parameters

This commit is contained in:
2018-05-21 02:13:56 +02:00
parent 8bb9029779
commit 06764e3e7f
4 changed files with 45 additions and 26 deletions

View File

@@ -15,7 +15,7 @@
<li> <li>
<label> <label>
<div>Amount of points</div> <div>Points</div>
<input type="number" name="points" [(ngModel)]="canvasParam.points" max="10" min="0" step="1"> <input type="number" name="points" [(ngModel)]="canvasParam.points" max="10" min="0" step="1">
</label> </label>
</li> </li>
@@ -37,5 +37,17 @@
<input type="number" name="strokeWidth" [(ngModel)]="canvasParam.stroke.width" max="10" min="0" step="0.1"> <input type="number" name="strokeWidth" [(ngModel)]="canvasParam.stroke.width" max="10" min="0" step="0.1">
</label> </label>
</li> </li>
<li>
<label>
<div>Spread lines</div>
<input type="number" name="spread" [(ngModel)]="canvasParam.spread" max="20" min="5" step="1">
</label>
</li>
<li>
<label>
<div>Show Grid?</div>
<input type="checkbox" name="showGrid" [(ngModel)]="canvasParam.showGrid">
</label>
</li>
</ul> </ul>

View File

@@ -1,4 +1,4 @@
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Param } from './models/param.model'; import { Param } from './models/param.model';
import { Config } from './models/config.model'; import { Config } from './models/config.model';
@@ -24,10 +24,10 @@ export class AppComponent {
y: 0.4 y: 0.4
}, },
stroke: { stroke: {
width: 0.2 width: 2
}, },
spread: 80, spread: 20,
showGrid: true showGrid: false
}; };
} }

View File

@@ -184,20 +184,23 @@ export class CanvasDirective implements OnChanges {
private spreadLines(points: Point[]) { private spreadLines(points: Point[]) {
const indexMiddle = Math.floor(points.length * 0.5); const indexMiddle = Math.floor(points.length * 0.5);
const pointMiddle = points[indexMiddle]; const pointMiddle = points[indexMiddle];
const closestCenter = this.getClosestCenter(pointMiddle); const closestCenter = this.getFarestCenter(pointMiddle);
const radius = this.Δ(pointMiddle, closestCenter); const radius = this.Δ(pointMiddle, closestCenter);
const spreadPoints = []; const spreadPoints = [];
const group = this.svg.append('g').attr('id', 'spread-points'); const group = this.svg.append('g').attr('id', 'spread-points');
const pies = 80;
for (let i = 0; i < this.param.spread; i++) { for (let i = 0; i < pies; i++) {
spreadPoints.push({ spreadPoints.push({
x: radius * Math.cos(2 * i * Math.PI / this.param.spread) + closestCenter.x, x: radius * Math.cos(2 * i * Math.PI / pies) + closestCenter.x,
y: radius * Math.sin(2 * i * Math.PI / this.param.spread) + closestCenter.y, y: radius * Math.sin(2 * i * Math.PI / pies) + closestCenter.y,
}); });
} }
spreadPoints.sort((a, b) => { spreadPoints.sort((a, b) => {
return this.Δ(a, pointMiddle) - this.Δ(b, pointMiddle); return this.Δ(a, pointMiddle) - this.Δ(b, pointMiddle);
// Good possibility to align orientation points outsite
// return this.Δ(b, pointMiddle) - this.Δ(a, pointMiddle);
}); });
spreadPoints.some((point, index) => { spreadPoints.some((point, index) => {
@@ -213,7 +216,7 @@ export class CanvasDirective implements OnChanges {
this.drawLine(points); this.drawLine(points);
return index === 20; return index === this.param.spread - 1;
}); });
group.lower(); group.lower();
@@ -227,6 +230,14 @@ export class CanvasDirective implements OnChanges {
} }
} }
private getFarestCenter(point: Point) {
if (this.Δ(point, this.config.start) > this.Δ(point, this.config.end)) {
return this.config.start;
} else {
return this.config.end;
}
}
/** /**
* Draw a curve with a given set of orientation points. * Draw a curve with a given set of orientation points.
* @param points Point * @param points Point
@@ -287,12 +298,8 @@ export class CanvasDirective implements OnChanges {
} }
private resetGrid() { private resetGrid() {
const group = Selection.select('g#grid');
if (group.size() && this.param.showGrid) {
Selection.selectAll('g#grid').remove(); Selection.selectAll('g#grid').remove();
} }
}
/** /**
* Update Config Parameters and emit to parent component. * Update Config Parameters and emit to parent component.
@@ -314,7 +321,6 @@ export class CanvasDirective implements OnChanges {
color: this.param.colors.end color: this.param.colors.end
} }
}; };
// Emit Canvas Config to parent Component. // Emit Canvas Config to parent Component.
this.emitConfig.next(this.config); this.emitConfig.next(this.config);
} }

View File

@@ -6,5 +6,6 @@ html, body {
padding: 0; padding: 0;
margin: 0; margin: 0;
background: #fbfcfd;
font-family: monospace; font-family: monospace;
} }