annotate src/app/visualisations/curve/curve.component.ts @ 368:a8a6e8a4ec70

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