2
0

fix(graphsComponent): polishment

This commit is contained in:
2018-05-23 16:51:42 +02:00
parent 161bf7d02c
commit d7672535d0
4 changed files with 27 additions and 21 deletions

View File

@@ -85,6 +85,12 @@
<option value="270">Links</option>
</select>
</div>
<div class="form-group">
<label class="form-control-label">
Skalierung
</label>
<input type="number" class="form-control" formControlName="scale" min="0" max="1" step="0.1">
</div>
<div class="form-group">
<label class="form-control-label">
Knotenpunkte

View File

@@ -9,6 +9,7 @@ import { GuillocheDirective } from './../directives/guilloche.directive';
import { CanvasService } from './../services/canvas.service';
import { Graph } from '../models/graph.model';
import { Config } from './../models/config.model';
import { Point } from '../models/point.model';
@Component({
selector: 'app-graphs',
@@ -86,24 +87,12 @@ export class GraphsComponent implements AfterViewInit, OnChanges {
}
private get matrix() {
const totalWidth = this.canvas.clientWidth;
const totalHeight = this.canvas.clientHeight;
const totalArea = Math.abs(totalWidth * totalHeight);
const totalCenter = {
x: totalWidth * 0.5,
y: totalHeight * 0.5
};
const totalArea = Math.abs(this.canvas.clientWidth * this.canvas.clientHeight);
const totalCenter = this.centerPoint(this.canvas.clientWidth, this.canvas.clientHeight);
const baseWidth = this.config.width;
const baseHeight = this.config.height;
const baseArea = Math.abs(this.config.width * this.config.height);
const baseScale = Math.pow(totalArea / baseArea * env.guilloche.scale, 0.5);
const baseScaledWidth = baseScale * baseWidth;
const baseScaledHeight = baseScale * baseHeight;
const baseCenter = {
x: baseScaledWidth * 0.5,
y: baseScaledHeight * 0.5
};
const baseScale = Math.pow(totalArea / baseArea * this.config.scale, 0.5);
const baseCenter = this.centerPoint( baseScale * this.config.width, baseScale * this.config.height);
return {
start: {
@@ -116,4 +105,11 @@ export class GraphsComponent implements AfterViewInit, OnChanges {
}
};
}
private centerPoint(width, height): Point {
return {
x: width * 0.5,
y: height * 0.5
};
}
}

View File

@@ -16,5 +16,9 @@ export let ConfigForm: FormGroup = fb.group({
nodes: fb.control('', Validators.compose([
Validators.min(1),
Validators.max(10)
]))
])),
scale: fb.control('', Validators.compose([
Validators.min(0),
Validators.max(1)
])),
});

View File

@@ -8,15 +8,15 @@ export const environment = {
colors: {
start: '#cc0045',
end: '#0067cc'
},
scale: 0.3
}
},
formDefaults: {
width: 10,
height: -20,
height: 10,
directionStart: 180,
directionEnd: 270,
nodes: 1
nodes: 1,
scale: 0.3
}
};