feat(graphsComponent): modularized graph parametrization
This commit is contained in:
@@ -57,29 +57,44 @@ export class GraphsComponent implements AfterViewInit, OnChanges {
|
||||
private updateGraphs(): void {
|
||||
const matrix = this.matrix;
|
||||
|
||||
this.graphs = [...[{
|
||||
this.graphs = [...[this.adjustGraph('start'), this.adjustGraph('end')]];
|
||||
}
|
||||
|
||||
private adjustGraph(from: string) {
|
||||
const matrix = this.matrix;
|
||||
const to = this.flipflop(from);
|
||||
|
||||
return {
|
||||
start: {
|
||||
coords: { x: matrix.start.x, y: matrix.start.y },
|
||||
coords: { x: matrix[from].x, y: matrix[from].y },
|
||||
direction: this.config.directionStart,
|
||||
color: env.guilloche.colors.start
|
||||
color: env.guilloche.colors[from]
|
||||
}, end: {
|
||||
coords: { x: matrix.end.x, y: matrix.end.y },
|
||||
coords: { x: matrix[to].x, y: matrix[to].y },
|
||||
direction: this.config.directionEnd,
|
||||
color: env.guilloche.colors.end
|
||||
color: env.guilloche.colors[to]
|
||||
},
|
||||
stroke: this.config.stroke
|
||||
}, {
|
||||
start: {
|
||||
coords: { x: matrix.end.x, y: matrix.end.y },
|
||||
direction: this.config.directionEnd,
|
||||
color: env.guilloche.colors.start
|
||||
}, end: {
|
||||
coords: { x: matrix.start.x, y: matrix.start.y },
|
||||
direction: this.config.directionStart,
|
||||
color: env.guilloche.colors.end
|
||||
},
|
||||
stroke: this.config.stroke
|
||||
}]];
|
||||
stroke: this.config.stroke,
|
||||
nodes: []
|
||||
};
|
||||
|
||||
// {
|
||||
// start: {
|
||||
// coords: { x: matrix.end.x, y: matrix.end.y },
|
||||
// direction: this.config.directionEnd,
|
||||
// color: env.guilloche.colors.start
|
||||
// }, end: {
|
||||
// coords: { x: matrix.start.x, y: matrix.start.y },
|
||||
// direction: this.config.directionStart,
|
||||
// color: env.guilloche.colors.end
|
||||
// },
|
||||
// stroke: this.config.stroke,
|
||||
// nodes: []
|
||||
// }
|
||||
}
|
||||
|
||||
private flipflop(direction: string) {
|
||||
return (direction === 'start') ? 'end' : 'start';
|
||||
}
|
||||
|
||||
private updateCanvas(): void {
|
||||
@@ -87,6 +102,13 @@ export class GraphsComponent implements AfterViewInit, OnChanges {
|
||||
this.canvasService.set(this.canvas);
|
||||
}
|
||||
|
||||
private centerPoint(width, height): Point {
|
||||
return {
|
||||
x: width * 0.5,
|
||||
y: height * 0.5
|
||||
};
|
||||
}
|
||||
|
||||
private get matrix() {
|
||||
const totalArea = Math.abs(this.canvas.clientWidth * this.canvas.clientHeight);
|
||||
const totalCenter = this.centerPoint(this.canvas.clientWidth, this.canvas.clientHeight);
|
||||
@@ -106,11 +128,4 @@ export class GraphsComponent implements AfterViewInit, OnChanges {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private centerPoint(width, height): Point {
|
||||
return {
|
||||
x: width * 0.5,
|
||||
y: height * 0.5
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user