2
0

prepared dragging, but will not be neccessary

This commit is contained in:
2018-05-13 02:24:43 +02:00
parent 19cb4f06d2
commit 8ee4ac9316
7 changed files with 44 additions and 20 deletions

View File

@@ -1,7 +1,9 @@
<div class="canvas" appCanvas (emitConfig)="updateCanvasConfig($event)" [param]="canvasParam"></div> <div class="canvas" appCanvas (emitConfig)="updateCanvasConfig($event)" [param]="canvasParam"></div>
<ul *ngIf="canvasConfig"> <ul *ngIf="canvasConfig">
<li><b>Static Configuration</b></li>
<li><pre>{{canvasConfig | json}}</pre></li> <li><pre>{{canvasConfig | json}}</pre></li>
<li><b>Changeable Parameters</b></li>
<li><pre>{{canvasParam | json}}</pre></li> <li><pre>{{canvasParam | json}}</pre></li>
</ul> </ul>

View File

@@ -18,10 +18,16 @@ ul {
justify-content: center; justify-content: center;
margin: 0; margin: 0;
padding: 3rem; padding: 3rem;
background: rgba(0,0,0,0.1); background: rgba(0,0,0,0.3);
opacity: 0.3;
transition: all 360ms 120ms ease-out;
cursor: pointer;
list-style-type: none; list-style-type: none;
&:hover {
opacity: 1;
}
li { li {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@@ -17,7 +17,8 @@ export class AppComponent {
colors: { colors: {
start: '#cc0045', start: '#cc0045',
end: '#0067cc' end: '#0067cc'
} },
points: 5
}; };
} }

View File

@@ -43,6 +43,10 @@ export class CanvasDirective implements OnInit {
private init() { private init() {
this.updateConfig(); this.updateConfig();
this.expandedPoints = this.expandPoints([
this.config.start,
this.config.end
]);
this.initSvg(); this.initSvg();
this.render(); this.render();
} }
@@ -54,13 +58,21 @@ export class CanvasDirective implements OnInit {
this.svg this.svg
.attr('width', this.config.width) .attr('width', this.config.width)
.attr('height', this.config.height) .attr('height', this.config.height)
.call(Drag.drag().on('drag', () => { .call(Drag.drag()
this.drag = { .on('drag', () => {
x: Selection.event.x, this.drag = {
y: Selection.event.y x: Selection.event.x,
}; y: Selection.event.y
this.updateConfig(); };
})); this.updateConfig();
this.render();
})
.on('end', () => {
delete this.drag;
this.updateConfig();
this.render();
})
);
this.defs = this.svg.append('defs'); this.defs = this.svg.append('defs');
@@ -76,13 +88,9 @@ export class CanvasDirective implements OnInit {
private render() { private render() {
this.resetPoints(); this.resetPoints();
this.expandedPoints = this.expandPoints([ this.drawPoints(this.getExpandedPoints);
this.config.start,
this.config.end
]);
this.drawPoints(this.expandedPoints);
this.resetLines(); this.resetLines();
this.drawLine(this.expandedPoints); this.drawLine(this.getExpandedPoints);
} }
private resetPoints(): void { private resetPoints(): void {
@@ -128,13 +136,16 @@ export class CanvasDirective implements OnInit {
} }
}; };
points.splice(1, 0, this.generateRandomPoint(matrix)); for (let i = 0; i <= this.param.points; i++) {
points.splice(1, 0, this.generateRandomPoint(matrix)); points.splice(1, 0, this.generateRandomPoint(matrix));
points.splice(1, 0, this.generateRandomPoint(matrix)); }
return points; return points;
} }
private get getExpandedPoints() {
return this.expandedPoints;
}
private calcDelta(a: Point, b: Point) { private calcDelta(a: Point, b: Point) {
return Math.pow(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2), 0.5); return Math.pow(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2), 0.5);
} }

View File

@@ -5,4 +5,5 @@ export interface Config {
height: number; height: number;
start: Point; start: Point;
end: Point; end: Point;
drag?: Point;
} }

View File

@@ -3,4 +3,5 @@ export interface Param {
start: string, start: string,
end: string end: string
}; };
points: number;
} }

View File

@@ -5,4 +5,6 @@ html, body {
height: 100%; height: 100%;
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: monospace;
} }