Mercurial > hg > ugly-duckling
comparison src/app/visualisations/instants/instants.component.ts @ 383:1241ca979fd9
Refactor based on pattern which emerged when implementing multiple components. Still some very obvious dupe regarding the ElementRef stuff, I don't think ViewChild decorated props are inherited.. but I haven't actually verified that.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Wed, 31 May 2017 19:14:46 +0100 |
parents | b220ed78a250 |
children | 7119d62121f0 |
comparison
equal
deleted
inserted
replaced
382:c1cedba9557b | 383:1241ca979fd9 |
---|---|
17 selector: 'ugly-instants', | 17 selector: 'ugly-instants', |
18 templateUrl: '../waves-template.html', | 18 templateUrl: '../waves-template.html', |
19 styleUrls: ['../waves-template.css'], | 19 styleUrls: ['../waves-template.css'], |
20 changeDetection: ChangeDetectionStrategy.OnPush | 20 changeDetection: ChangeDetectionStrategy.OnPush |
21 }) | 21 }) |
22 export class InstantsComponent extends WavesComponent implements AfterViewInit { | 22 export class InstantsComponent extends WavesComponent<Instant[]> { |
23 | |
23 @ViewChild('track') trackDiv: ElementRef; | 24 @ViewChild('track') trackDiv: ElementRef; |
24 | 25 |
25 private mFeature: Instant[]; | |
26 private height: number; // As it stands, height is fixed. Store once onInit. | |
27 | |
28 @Input() set instants(instants: Instant[]) { | 26 @Input() set instants(instants: Instant[]) { |
29 this.mFeature = instants; | 27 this.feature = instants; |
30 this.update(); | |
31 } | 28 } |
32 | 29 |
33 get instants(): Instant[] { | 30 protected get containerHeight(): number { |
34 return this.mFeature; | 31 return this.trackDiv.nativeElement.getBoundingClientRect().height; |
35 } | 32 } |
36 | 33 |
37 ngAfterViewInit(): void { | 34 protected get trackContainer(): ElementRef { |
38 this.height = this.trackDiv.nativeElement.getBoundingClientRect().height; | 35 return this.trackDiv; |
39 this.renderTimeline(this.trackDiv); | |
40 this.update(); | |
41 } | 36 } |
42 | 37 |
43 update(): void { | 38 protected get featureLayers(): Layer[] { |
44 if (!this.waveTrack || !this.instants) { return; } | 39 return [ |
45 this.clearTimeline(this.trackDiv); | |
46 | |
47 this.addLayer( | |
48 new Waves.helpers.TickLayer( | 40 new Waves.helpers.TickLayer( |
49 this.instants, | 41 this.feature, |
50 { | 42 { |
51 height: this.height, | 43 height: this.height, |
52 color: this.colour, | 44 color: this.colour, |
53 labelPosition: 'bottom', | 45 labelPosition: 'bottom', |
54 shadeSegments: true | 46 shadeSegments: true |
55 } | 47 } |
56 ), | 48 ) |
57 this.waveTrack, | 49 ]; |
58 this.timeline.timeContext | |
59 ); | |
60 } | 50 } |
61 } | 51 } |