2
0

added margin as parameter

This commit is contained in:
2018-05-13 03:34:25 +02:00
parent d08f9e4c7c
commit b493fa0ed7
4 changed files with 17 additions and 5 deletions

View File

@@ -7,7 +7,16 @@
<li><pre>{{canvasParam | json}}</pre></li> <li><pre>{{canvasParam | json}}</pre></li>
<li> <li>
<div><input type="number" [(ngModel)]="canvasParam.points"></div> <label>
<div>Amount of points</div>
<input type="number" [(ngModel)]="canvasParam.points">
</label>
</li>
<li>
<label>
<div>Margin</div>
<input type="number" [(ngModel)]="canvasParam.margin">
</label>
</li> </li>
</ul> </ul>

View File

@@ -20,9 +20,9 @@ export class AppComponent {
start: '#cc0045', start: '#cc0045',
end: '#0067cc' end: '#0067cc'
}, },
points: 3 points: 3,
margin: 0.1
}; };
this.test = 1;
} }
public updateCanvasConfig(config): void { public updateCanvasConfig(config): void {

View File

@@ -163,16 +163,18 @@ export class CanvasDirective implements OnInit, OnChanges {
} }
private updateConfig(): void { private updateConfig(): void {
const margin = this.canvas.clientWidth * this.param.margin;
this.config = { this.config = {
width: this.canvas.clientWidth, width: this.canvas.clientWidth,
height: this.canvas.clientHeight, height: this.canvas.clientHeight,
start: { start: {
x: this.canvas.clientWidth, x: this.canvas.clientWidth - margin,
y: 0, y: 0,
color: this.param.colors.start color: this.param.colors.start
}, },
end: { end: {
x: 0, x: 0 + margin,
y: this.canvas.clientHeight, y: this.canvas.clientHeight,
color: this.param.colors.end color: this.param.colors.end
}, },

View File

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