2
0

feat(graphsComponent): modularized graph parametrization

This commit is contained in:
2018-05-23 18:39:26 +02:00
parent d42b6160e6
commit b1e6faab99
2 changed files with 53 additions and 26 deletions

View File

@@ -17,6 +17,7 @@ export class GuillocheDirective implements OnChanges {
private canvas: any;
private group: any;
private gradientId: any;
@Input() graph: Graph;
@@ -26,6 +27,7 @@ export class GuillocheDirective implements OnChanges {
) {
this.group = Selection.select(el.nativeElement);
this.canvas = Selection.select(this.canvasService.get);
this.gradientId = 'linear';
}
ngOnChanges(changes: SimpleChanges) {
@@ -36,6 +38,16 @@ export class GuillocheDirective implements OnChanges {
private drawGraph(): void {
console.log('guilloche directive(drawGraph)', this.graph);
const defs = this.group.append('defs');
const grad = defs.append('linearGradient')
.attr('id', this.gradientId);
grad.append('stop')
.attr('stop-color', this.graph.start.color)
.attr('offset', '0%');
grad.append('stop')
.attr('stop-color', this.graph.end.color)
.attr('offset', '100%');
this.group.append('path')
.attr('d', Shape.line()
.x(p => p.x)
@@ -44,7 +56,7 @@ export class GuillocheDirective implements OnChanges {
this.graph.start.coords,
this.graph.end.coords
]))
.attr('stroke', 'url(#gradient)')
.attr('stroke', `url(#${this.gradientId})`)
.attr('stroke-width', this.graph.stroke)
.attr('fill', 'none');