annotate src/app/visualisations/grid/grid.component.ts @ 382:c1cedba9557b

Basic grid, bringing in old code from waveform.component.ts. Issues with display when rendered when zoom level / offset is non zero. Same for some other components too, probably needs to be solved upstream in waves-ui-piper.
author Lucas Thompson <dev@lucas.im>
date Wed, 31 May 2017 17:33:23 +0100
parents
children 1241ca979fd9
rev   line source
dev@382 1 /**
dev@382 2 * Created by lucast on 31/05/2017.
dev@382 3 */
dev@382 4 import {WavesComponent} from '../waves-base.component';
dev@382 5 import {
dev@382 6 AfterViewInit,
dev@382 7 ChangeDetectionStrategy,
dev@382 8 Component,
dev@382 9 ElementRef,
dev@382 10 Input,
dev@382 11 ViewChild
dev@382 12 } from '@angular/core';
dev@382 13 import Waves from 'waves-ui-piper';
dev@382 14 import {MatrixFeature} from 'piper/HigherLevelUtilities';
dev@382 15 import {iceMapper} from '../../spectrogram/ColourMap';
dev@382 16 import {estimatePercentile} from '../../spectrogram/MatrixUtils';
dev@382 17
dev@382 18 @Component({
dev@382 19 selector: 'ugly-grid',
dev@382 20 templateUrl: '../waves-template.html',
dev@382 21 styleUrls: ['../waves-template.css'],
dev@382 22 changeDetection: ChangeDetectionStrategy.OnPush
dev@382 23 })
dev@382 24 export class GridComponent extends WavesComponent implements AfterViewInit {
dev@382 25 @ViewChild('track') trackDiv: ElementRef;
dev@382 26
dev@382 27 private mFeature: MatrixFeature;
dev@382 28 private height: number; // As it stands, height is fixed. Store once onInit.
dev@382 29
dev@382 30 @Input() set grid(grid: MatrixFeature) {
dev@382 31 this.mFeature = grid;
dev@382 32 this.update();
dev@382 33 }
dev@382 34
dev@382 35 get grid(): MatrixFeature {
dev@382 36 return this.mFeature;
dev@382 37 }
dev@382 38
dev@382 39 ngAfterViewInit(): void {
dev@382 40 this.height = this.trackDiv.nativeElement.getBoundingClientRect().height;
dev@382 41 this.renderTimeline(this.trackDiv);
dev@382 42 this.update();
dev@382 43 }
dev@382 44
dev@382 45 update(): void {
dev@382 46 if (!this.waveTrack || !this.grid) { return; }
dev@382 47 this.clearTimeline(this.trackDiv);
dev@382 48
dev@382 49 const startTime = this.grid.startTime; // !!! + make use of
dev@382 50 const stepDuration = this.grid.stepDuration;
dev@382 51 const matrixData = this.grid.data;
dev@382 52
dev@382 53 if (matrixData.length === 0) {
dev@382 54 return;
dev@382 55 }
dev@382 56
dev@382 57 const targetValue = estimatePercentile(matrixData, 95);
dev@382 58 const gain = (targetValue > 0.0 ? (1.0 / targetValue) : 1.0);
dev@382 59 const matrixEntity = new Waves.utils.PrefilledMatrixEntity(
dev@382 60 matrixData,
dev@382 61 0, // startTime
dev@382 62 stepDuration
dev@382 63 );
dev@382 64
dev@382 65 this.addLayer(
dev@382 66 new Waves.helpers.MatrixLayer(
dev@382 67 matrixEntity,
dev@382 68 {
dev@382 69 gain: gain,
dev@382 70 height: this.height,
dev@382 71 normalise: 'none',
dev@382 72 mapper: iceMapper()
dev@382 73 }
dev@382 74 ),
dev@382 75 this.waveTrack,
dev@382 76 this.timeline.timeContext
dev@382 77 );
dev@382 78 }
dev@382 79 }