annotate src/app/visualisations/tracks/tracks.components.ts @ 379:a3b45218c311

Move colour prop to base class
author Lucas Thompson <dev@lucas.im>
date Wed, 31 May 2017 14:49:46 +0100
parents 9fe6e00e0700
children 1241ca979fd9
rev   line source
dev@372 1 /**
dev@372 2 * Created by lucas on 30/05/2017.
dev@372 3 */
dev@378 4 import {WavesComponent} from '../waves-base.component';
dev@372 5 import {
dev@372 6 AfterViewInit,
dev@372 7 ChangeDetectionStrategy,
dev@372 8 Component,
dev@372 9 ElementRef,
dev@372 10 Input,
dev@372 11 ViewChild
dev@378 12 } from '@angular/core';
dev@378 13 import {TracksFeature} from 'piper/HigherLevelUtilities';
dev@372 14 import Waves from 'waves-ui-piper';
dev@378 15 import {generatePlotData, PlotLayerData} from '../FeatureUtilities';
dev@372 16
dev@372 17 @Component({
dev@372 18 selector: 'ugly-tracks',
dev@372 19 templateUrl: '../waves-template.html',
dev@372 20 styleUrls: ['../waves-template.css'],
dev@372 21 changeDetection: ChangeDetectionStrategy.OnPush
dev@372 22 })
dev@372 23 export class TracksComponent extends WavesComponent implements AfterViewInit {
dev@372 24
dev@372 25 @ViewChild('track') trackDiv: ElementRef;
dev@372 26
dev@372 27 private mFeature: TracksFeature;
dev@372 28 private currentState: PlotLayerData[];
dev@372 29 private height: number; // As it stands, height is fixed. Store once onInit.
dev@372 30
dev@372 31 @Input() set tracks(input: TracksFeature) {
dev@372 32 this.mFeature = input;
dev@372 33 this.currentState = generatePlotData(input);
dev@372 34 this.update();
dev@372 35 }
dev@372 36
dev@372 37 get tracks(): TracksFeature {
dev@372 38 return this.mFeature;
dev@372 39 }
dev@372 40
dev@372 41 ngAfterViewInit(): void {
dev@372 42 this.height = this.trackDiv.nativeElement.getBoundingClientRect().height;
dev@372 43 this.renderTimeline(this.trackDiv);
dev@372 44 this.update();
dev@372 45 }
dev@372 46
dev@372 47 update(): void {
dev@372 48 if (this.waveTrack) {
dev@372 49 this.clearTimeline(this.trackDiv);
dev@372 50 for (const feature of this.currentState) {
dev@372 51 const lineLayer = new Waves.helpers.LineLayer(feature.data, {
dev@372 52 color: this.colour,
dev@372 53 height: this.height,
dev@372 54 yDomain: feature.yDomain
dev@372 55 });
dev@372 56 this.addLayer(
dev@372 57 lineLayer,
dev@372 58 this.waveTrack,
dev@372 59 this.timeline.timeContext
dev@372 60 );
dev@372 61
dev@372 62 // Set start and duration so that the highlight layer can use
dev@372 63 // them to determine which line to draw values from
dev@372 64 lineLayer.start = feature.startTime;
dev@372 65 lineLayer.duration = feature.duration;
dev@372 66 lineLayer.update(); // TODO probably better to update after all added
dev@372 67 }
dev@372 68 }
dev@372 69 }
dev@372 70 }