added service to provide canvas all over
This commit is contained in:
@@ -85,6 +85,12 @@
|
|||||||
<option value="270">Links</option>
|
<option value="270">Links</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-control-label">
|
||||||
|
Knotenpunkte
|
||||||
|
</label>
|
||||||
|
<input type="number" class="form-control" formControlName="nodes" min="1" max="10">
|
||||||
|
</div>
|
||||||
<button type="submit" class="btn btn-primary" [disabled]="configForm.invalid">Aktualisieren</button>
|
<button type="submit" class="btn btn-primary" [disabled]="configForm.invalid">Aktualisieren</button>
|
||||||
</form>
|
</form>
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ export class AppComponent implements OnInit {
|
|||||||
width: 10,
|
width: 10,
|
||||||
height: -20,
|
height: -20,
|
||||||
directionStart: 180,
|
directionStart: 180,
|
||||||
directionEnd: 270
|
directionEnd: 270,
|
||||||
|
nodes: 1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +49,8 @@ export class AppComponent implements OnInit {
|
|||||||
width: 10,
|
width: 10,
|
||||||
height: -20,
|
height: -20,
|
||||||
directionStart: 180,
|
directionStart: 180,
|
||||||
directionEnd: 270
|
directionEnd: 270,
|
||||||
|
nodes: 1
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { CanvasDirective } from './directives/canvas.directive';
|
|||||||
import { GraphsComponent } from './components/graphs.component';
|
import { GraphsComponent } from './components/graphs.component';
|
||||||
// import { GuillocheComponent } from './components/guilloche.component';
|
// import { GuillocheComponent } from './components/guilloche.component';
|
||||||
import { GuillocheDirective } from './directives/guilloche.directive';
|
import { GuillocheDirective } from './directives/guilloche.directive';
|
||||||
|
import { CanvasService } from './services/canvas.service';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -21,7 +22,9 @@ import { GuillocheDirective } from './directives/guilloche.directive';
|
|||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [
|
||||||
|
CanvasService
|
||||||
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
import { ViewChildren, QueryList, Component, AfterViewInit, ViewChild, Input, OnInit, SimpleChanges, OnChanges } from '@angular/core';
|
import { ViewChildren, QueryList, Component, AfterViewInit, ViewChild, Input, SimpleChanges, OnChanges } from '@angular/core';
|
||||||
import * as Selection from 'd3-selection';
|
import * as Selection from 'd3-selection';
|
||||||
import * as Shape from 'd3-shape';
|
import * as Shape from 'd3-shape';
|
||||||
import * as Random from 'd3-random';
|
import * as Random from 'd3-random';
|
||||||
import * as Drag from 'd3-drag';
|
import * as Drag from 'd3-drag';
|
||||||
|
|
||||||
import { GuillocheDirective } from './../directives/guilloche.directive';
|
import { GuillocheDirective } from './../directives/guilloche.directive';
|
||||||
|
import { CanvasService } from './../services/canvas.service';
|
||||||
import { Graph } from '../models/graph.model';
|
import { Graph } from '../models/graph.model';
|
||||||
|
import { Config } from './../models/config.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-graphs',
|
selector: 'app-graphs',
|
||||||
templateUrl: './graphs.component.html',
|
templateUrl: './graphs.component.html',
|
||||||
styleUrls: ['./graphs.component.scss']
|
styleUrls: ['./graphs.component.scss']
|
||||||
})
|
})
|
||||||
export class GraphsComponent implements AfterViewInit, OnInit, OnChanges {
|
export class GraphsComponent implements AfterViewInit, OnChanges {
|
||||||
|
|
||||||
public graphs: Graph[];
|
public graphs: Graph[];
|
||||||
public svg: any;
|
public canvas: any | null;
|
||||||
|
|
||||||
@Input() config: any;
|
@Input() config: any;
|
||||||
|
|
||||||
@@ -23,26 +25,25 @@ export class GraphsComponent implements AfterViewInit, OnInit, OnChanges {
|
|||||||
@ViewChild(GuillocheDirective) guillocheViewChild: GuillocheDirective;
|
@ViewChild(GuillocheDirective) guillocheViewChild: GuillocheDirective;
|
||||||
@ViewChildren(GuillocheDirective) guillocheViewChildren: QueryList<GuillocheDirective>;
|
@ViewChildren(GuillocheDirective) guillocheViewChildren: QueryList<GuillocheDirective>;
|
||||||
|
|
||||||
ngOnInit() {
|
constructor(
|
||||||
this.updateGraphs();
|
private canvasService: CanvasService
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
console.log('graph component (changes)', changes.config);
|
console.log('graph component (changes:config)', changes.config.currentValue);
|
||||||
|
this.updateCanvas();
|
||||||
this.updateGraphs();
|
this.updateGraphs();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
this.svg = Selection.select(this.svgElementRef.nativeElement);
|
console.log('graph component (afterView:children)', this.guillocheViewChildren.toArray());
|
||||||
|
|
||||||
console.log('graph component (after view)', this.guillocheViewChildren.toArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateGraphs(): void {
|
private updateGraphs(): void {
|
||||||
this.graphs = [...[{
|
this.graphs = [...[{
|
||||||
id: 'first',
|
id: 'first',
|
||||||
start: {coords: { x: 0, y: 0 }, direction: this.config.directionStart },
|
start: {coords: { x: 0, y: 0 }, direction: this.config.directionStart},
|
||||||
end: { coords: { x: 0, y: -10 }, direction: this.config.directionEnd}
|
end: { coords: { x: 0, y: -10 }, direction: this.config.directionEnd}
|
||||||
}, {
|
}, {
|
||||||
id: 'second',
|
id: 'second',
|
||||||
@@ -50,4 +51,8 @@ export class GraphsComponent implements AfterViewInit, OnInit, OnChanges {
|
|||||||
end: { coords: { x: 0, y: -10 }, direction: this.config.directionStart}
|
end: { coords: { x: 0, y: -10 }, direction: this.config.directionStart}
|
||||||
}]];
|
}]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateCanvas(): void {
|
||||||
|
this.canvasService.set(this.svgElementRef.nativeElement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,33 @@ import * as Drag from 'd3-drag';
|
|||||||
import { Config } from './../models/config.model';
|
import { Config } from './../models/config.model';
|
||||||
import { Point } from './../models/point.model';
|
import { Point } from './../models/point.model';
|
||||||
import { Param } from './../models/param.model';
|
import { Param } from './../models/param.model';
|
||||||
|
import { CanvasService } from './../services/canvas.service';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[guilloche]'
|
selector: '[guilloche]'
|
||||||
})
|
})
|
||||||
export class GuillocheDirective implements OnChanges {
|
export class GuillocheDirective implements OnChanges {
|
||||||
|
|
||||||
|
private canvas: any;
|
||||||
|
|
||||||
@Input() graph: Graph;
|
@Input() graph: Graph;
|
||||||
|
|
||||||
constructor() {
|
constructor(
|
||||||
|
private canvasService: CanvasService
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
console.log('guilloche directive (changes)', changes.graph);
|
console.log('guilloche directive (changes)', changes.graph.currentValue);
|
||||||
|
this.selectCanvas();
|
||||||
|
this.drawGraph();
|
||||||
|
}
|
||||||
|
|
||||||
|
private drawGraph(): void {
|
||||||
|
console.log('guilloche directive(drawGraph)', this.graph, this.canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
private selectCanvas(): void {
|
||||||
|
this.canvas = Selection.select(this.canvasService.get);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,8 @@ export let ConfigForm: FormGroup = fb.group({
|
|||||||
Validators.min(0),
|
Validators.min(0),
|
||||||
Validators.max(360)
|
Validators.max(360)
|
||||||
])),
|
])),
|
||||||
nodes: fb.control('', Validators.min(1))
|
nodes: fb.control('', Validators.compose([
|
||||||
|
Validators.min(1),
|
||||||
|
Validators.max(10)
|
||||||
|
]))
|
||||||
});
|
});
|
||||||
|
|||||||
19
src/app/services/canvas.service.ts
Normal file
19
src/app/services/canvas.service.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Inject, Injectable, Optional, ViewChild } from '@angular/core';
|
||||||
|
import * as Selection from 'd3-selection';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CanvasService {
|
||||||
|
|
||||||
|
public canvas: any;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public get get() {
|
||||||
|
return this.canvas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set(el) {
|
||||||
|
this.canvas = el;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user