annotate src/app/visualisations/tracks/tracks.components.ts @ 372:bc2680f0736b

Move curve logic to a tracks component, and use that component to create a curve component.
author Lucas Thompson <dev@lucas.im>
date Wed, 31 May 2017 02:42:45 +0100
parents
children 9fe6e00e0700
rev   line source
dev@372 1 /**
dev@372 2 * Created by lucas on 30/05/2017.
dev@372 3 */
dev@372 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@372 12 } from "@angular/core";
dev@372 13 import {TracksFeature} from "piper/HigherLevelUtilities";
dev@372 14 import Waves from 'waves-ui-piper';
dev@372 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 @Input() colour: string;
dev@372 37
dev@372 38 get tracks(): TracksFeature {
dev@372 39 return this.mFeature;
dev@372 40 }
dev@372 41
dev@372 42 ngAfterViewInit(): void {
dev@372 43 this.height = this.trackDiv.nativeElement.getBoundingClientRect().height;
dev@372 44 this.renderTimeline(this.trackDiv);
dev@372 45 this.update();
dev@372 46 }
dev@372 47
dev@372 48 update(): void {
dev@372 49 if (this.waveTrack) {
dev@372 50 this.clearTimeline(this.trackDiv);
dev@372 51 for (const feature of this.currentState) {
dev@372 52 const lineLayer = new Waves.helpers.LineLayer(feature.data, {
dev@372 53 color: this.colour,
dev@372 54 height: this.height,
dev@372 55 yDomain: feature.yDomain
dev@372 56 });
dev@372 57 this.addLayer(
dev@372 58 lineLayer,
dev@372 59 this.waveTrack,
dev@372 60 this.timeline.timeContext
dev@372 61 );
dev@372 62
dev@372 63 // Set start and duration so that the highlight layer can use
dev@372 64 // them to determine which line to draw values from
dev@372 65 lineLayer.start = feature.startTime;
dev@372 66 lineLayer.duration = feature.duration;
dev@372 67 lineLayer.update(); // TODO probably better to update after all added
dev@372 68 }
dev@372 69 }
dev@372 70 }
dev@372 71 }