2
0

added full automatisation

This commit is contained in:
2018-05-16 13:13:53 +02:00
parent 86051a7118
commit ebf65dfbc5
2 changed files with 41 additions and 22 deletions

View File

@@ -28,7 +28,7 @@ export class AppComponent {
stroke: { stroke: {
width: 2 width: 2
}, },
spread: 40, spread: 80,
showGrid: true showGrid: true
}; };
} }

View File

@@ -95,19 +95,20 @@ export class CanvasDirective implements OnInit, OnChanges {
.attr('r', point.color ? 20 : 10) .attr('r', point.color ? 20 : 10)
.attr('cx', point.x) .attr('cx', point.x)
.attr('cy', point.y) .attr('cy', point.y)
.attr('fill', point.color ? point.color : 'lightgray') .attr('fill', () => {
.attr('stroke-width', !point.color ? 2 : 0) if (!this.param.showGrid) {
.attr('stroke', !point.color ? 'gray' : '') return 'none';
.style('cursor', 'pointer') }
.call(Drag.drag() return point.color ? point.color : 'lightgray';
.on('drag', function() { })
Selection.select(this) .attr('stroke-width', () => {
.attr('cx', Selection.event.x) if (!this.param.showGrid) {
.attr('cy', Selection.event.y); return 0;
}) }
.on('end', () => { return !point.color ? 2 : 0;
this.drawLine(this.getExpandedPoints); })
})); .attr('stroke', !point.color && !this.param.showGrid ? 'gray' : 'none')
.style('cursor', 'pointer');
}); });
} }
@@ -184,23 +185,41 @@ export class CanvasDirective implements OnInit, OnChanges {
for (let i = 0; i < this.param.spread; i++) { for (let i = 0; i < this.param.spread; 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 / this.param.spread) + closestCenter.x,
y: radius * Math.sin(2 * i * Math.PI / this.param.spread) + closestCenter.y y: radius * Math.sin(2 * i * Math.PI / this.param.spread) + closestCenter.y,
}); });
} }
spreadPoints.forEach(point => { console.warn(spreadPoints);
group.append('circle')
.attr('cx', point.x) spreadPoints.sort((a, b) => {
.attr('cy', point.y) return this.Δ(a, pointMiddle) - this.Δ(b, pointMiddle);
.attr('r', 10)
.attr('fill', 'gainsboro');
}); });
console.log(spreadPoints);
spreadPoints.some((point, index) => {
if (this.param.showGrid) {
group.append('circle')
.attr('cx', point.x)
.attr('cy', point.y)
.attr('r', 4)
.attr('fill', 'gray');
}
points[indexMiddle] = point;
this.drawLine(points);
return index === 20;
});
// console.log();
group.lower(); group.lower();
} }
private getClosestCenter(point: Point) { private getClosestCenter(point: Point) {
if (this.Δ(point, this.config.start) > this.Δ(point, this.config.end)) { if (this.Δ(point, this.config.start) < this.Δ(point, this.config.end)) {
return this.config.start; return this.config.start;
} else { } else {
return this.config.end; return this.config.end;