comparison src/app/visualisations/vertical-scale.component.ts @ 488:64ed45a0bad3

Introduce PlayheadRenderer, implement in the waves base. Make VerticallyBounded and VerticalScaleRenderer generic and remove bin equivalents. Forward calls for a PlayheadRenderer from VerticalScaleComponent on to its children. Also update other components accordingly.
author Lucas Thompson <dev@lucas.im>
date Wed, 05 Jul 2017 18:42:12 +0100
parents 40ea40ebc2b3
children ab43880f1cd5
comparison
equal deleted inserted replaced
487:f2bb5ddae867 488:64ed45a0bad3
1 /** 1 /**
2 * Created by lucas on 01/06/2017. 2 * Created by lucas on 01/06/2017.
3 */ 3 */
4 import {VerticalScaleRenderer} from './waves-base.component'; 4 import {
5 PlayheadManager,
6 PlayheadRenderer,
7 VerticalScaleRenderer
8 } from './waves-base.component';
5 import { 9 import {
6 ChangeDetectionStrategy, 10 ChangeDetectionStrategy,
7 Component, 11 Component,
8 ContentChildren, 12 ContentChildren,
9 QueryList, 13 QueryList,
11 } from '@angular/core'; 15 } from '@angular/core';
12 16
13 @Component({ 17 @Component({
14 selector: 'ugly-vertical-scale', 18 selector: 'ugly-vertical-scale',
15 template: '<ng-content></ng-content>', 19 template: '<ng-content></ng-content>',
16 changeDetection: ChangeDetectionStrategy.OnPush 20 changeDetection: ChangeDetectionStrategy.OnPush,
21 providers: [
22 {provide: PlayheadRenderer, useExisting: VerticalScaleComponent }
23 ]
17 }) 24 })
18 export class VerticalScaleComponent implements AfterViewInit { 25 export class VerticalScaleComponent implements AfterViewInit, PlayheadRenderer {
19 26
20 @ContentChildren( 27 @ContentChildren(
21 VerticalScaleRenderer 28 VerticalScaleRenderer
22 ) bounded: QueryList<VerticalScaleRenderer>; 29 ) bounded: QueryList<VerticalScaleRenderer<any>>;
23 protected cachedRange: [number, number]; 30 @ContentChildren(
31 PlayheadRenderer
32 ) seekable: QueryList<PlayheadRenderer>;
33 protected cachedRange: any;
24 34
25 ngAfterViewInit(): void { 35 ngAfterViewInit(): void {
26 this.bounded.forEach(component => { 36 this.bounded.forEach(component => {
27 this.cachedRange = component.range; 37 this.cachedRange = component.range;
28 if (this.cachedRange) { 38 if (this.cachedRange) {
29 component.renderScale(this.cachedRange); 39 component.renderScale(this.cachedRange);
30 } 40 }
31 }); 41 });
32 } 42 }
43
44 renderPlayhead(initialTime: number, colour: string): PlayheadManager {
45 const rendered = this.seekable
46 .filter(x => x !== this) // why does QueryList consider itself as a child?
47 .map(component => component.renderPlayhead(initialTime, colour));
48 return {
49 update: (time: number) => {
50 rendered.forEach(component => component.update(time));
51 },
52 remove: () => rendered.map(component => component.remove)
53 };
54 }
33 } 55 }