comparison src/app/visualisations/curve/curve.component.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 3fa0c8cab919
children 2df7b3722eb9
comparison
equal deleted inserted replaced
371:44ed7a3916c8 372:bc2680f0736b
1 /** 1 /**
2 * Created by lucas on 30/05/2017. 2 * Created by lucas on 30/05/2017.
3 */ 3 */
4 import {WavesComponent} from "../waves-base.component";
5 import { 4 import {
6 AfterViewInit,
7 ChangeDetectionStrategy, 5 ChangeDetectionStrategy,
8 Component, 6 Component,
9 ElementRef, 7 Input
10 Input,
11 ViewChild
12 } from "@angular/core"; 8 } from "@angular/core";
9 import {OnSeekHandler} from "../../playhead/PlayHeadHelpers";
13 import {VectorFeature} from "piper/HigherLevelUtilities"; 10 import {VectorFeature} from "piper/HigherLevelUtilities";
14 import Waves from 'waves-ui-piper';
15 import {generatePlotData, PlotLayerData} from "../FeatureUtilities";
16 11
17 @Component({ 12 @Component({
18 selector: 'ugly-curve', 13 selector: 'ugly-curve',
19 templateUrl: '../waves-template.html', 14 template: `<ugly-tracks
15 [timeline]="timeline"
16 [trackIdPrefix]="id"
17 [width]="width"
18 [onSeek]="onSeek"
19 [colour]="colour"
20 [tracks]="[curve]"
21 ></ugly-tracks>`,
20 styleUrls: ['../waves-template.css'], 22 styleUrls: ['../waves-template.css'],
21 changeDetection: ChangeDetectionStrategy.OnPush 23 changeDetection: ChangeDetectionStrategy.OnPush
22 }) 24 })
23 export class CurveComponent extends WavesComponent implements AfterViewInit { 25 export class CurveComponent {
24 26 @Input() id: string; // TODO refactor WaveComponents to have own Timeline, sharing a TimeContext
25 @ViewChild('track') trackDiv: ElementRef; 27 @Input() timeline: Timeline; // TODO as above
26 28 @Input() onSeek: OnSeekHandler;
27 private mFeature: VectorFeature[]; 29 @Input() width: number;
28 private currentState: PlotLayerData[]; 30 @Input() curve: VectorFeature;
29 private height: number; // As it stands, height is fixed. Store once onInit.
30
31 @Input() set feature(input: VectorFeature[]) {
32 this.mFeature = input;
33 this.currentState = generatePlotData(input);
34 this.update();
35 }
36 @Input() colour: string; 31 @Input() colour: string;
37
38 get feature(): VectorFeature[] {
39 return this.mFeature;
40 }
41
42 ngAfterViewInit(): void {
43 this.height = this.trackDiv.nativeElement.getBoundingClientRect().height;
44 this.renderTimeline(this.trackDiv);
45 this.update();
46 }
47
48 update(): void {
49 if (this.waveTrack) {
50 this.clearTimeline(this.trackDiv);
51 for (const feature of this.currentState) {
52 const lineLayer = new Waves.helpers.LineLayer(feature.data, {
53 color: this.colour,
54 height: this.height,
55 yDomain: feature.yDomain
56 });
57 this.addLayer(
58 lineLayer,
59 this.waveTrack,
60 this.timeline.timeContext
61 );
62
63 // Set start and duration so that the highlight layer can use
64 // them to determine which line to draw values from
65 lineLayer.start = feature.startTime;
66 lineLayer.duration = feature.duration;
67 lineLayer.update(); // TODO probably better to update after all added
68 }
69 }
70 }
71 } 32 }