# HG changeset patch # User Lucas Thompson # Date 1496354679 -3600 # Node ID 3eab26a629e184a3955ab109b25ef72610bb86fc # Parent de9864aeacf0a725b8bda13c48d01e134b8e968e Revert changes relating to bodging unit onto the shaped features. Now return from the extraction service and add to the analysis item, and send into the cross-hair component with a prop. diff -r de9864aeacf0 -r 3eab26a629e1 src/app/analysis-item/analysis-item.component.html --- a/src/app/analysis-item/analysis-item.component.html Thu Jun 01 18:56:06 2017 +0100 +++ b/src/app/analysis-item/analysis-item.component.html Thu Jun 01 23:04:39 2017 +0100 @@ -39,8 +39,12 @@ [width]="contentWidth" [onSeek]="onSeek" [curve]="item.collected" + [unit]="item.unit" > - + - + { diff -r de9864aeacf0 -r 3eab26a629e1 src/app/services/feature-extraction/feature-extraction.service.ts --- a/src/app/services/feature-extraction/feature-extraction.service.ts Thu Jun 01 18:56:06 2017 +0100 +++ b/src/app/services/feature-extraction/feature-extraction.service.ts Thu Jun 01 23:04:39 2017 +0100 @@ -32,6 +32,7 @@ export interface ExtractionResult { id: RequestId; result: KnownShapedFeature; + unit?: string; } @Injectable() @@ -93,7 +94,12 @@ features: features, outputDescriptor: config.outputDescriptor }); - const result = { + const result = config.outputDescriptor.configured.unit ? { + id: analysisItemId, + result: shaped, + unit: shaped.shape === 'notes' ? + 'MIDI note' : config.outputDescriptor.configured.unit + } : { id: analysisItemId, result: shaped }; diff -r de9864aeacf0 -r 3eab26a629e1 src/app/visualisations/FeatureUtilities.ts --- a/src/app/visualisations/FeatureUtilities.ts Thu Jun 01 18:56:06 2017 +0100 +++ b/src/app/visualisations/FeatureUtilities.ts Thu Jun 01 23:04:39 2017 +0100 @@ -74,19 +74,18 @@ type ShapeDeducedFromList = 'instants' | 'notes'; export type HigherLevelFeatureShape = CollectedShape | ShapeDeducedFromList; -export type ShapedFeatureData = {unit?: string} & ( +export type ShapedFeatureData = VectorFeature | MatrixFeature | TracksFeature | Note[] - | Instant[] - ); + | Instant[]; // These needn't be classes (could just be interfaces), just experimenting export abstract class ShapedFeature { + Data extends ShapedFeatureData> { shape: Shape; - collected: Data & {unit?: string}; + collected: Data; } export class Vector extends ShapedFeature<'vector', VectorFeature> {} @@ -145,46 +144,32 @@ export function toKnownShape(response: SimpleResponse): KnownShapedFeature { const deducedShape = deduceHigherLevelFeatureShape(response); - const shaped: KnownShapedFeature | null = (() => { - switch (deducedShape) { - case 'vector': - return response.features as Vector; - case 'matrix': - return response.features as Matrix; - case 'tracks': - return response.features as Tracks; - case 'notes': - // TODO refactor - const notes: Note[] & {unit?: string} = mapFeaturesToNotes( + switch (deducedShape) { + case 'vector': + return response.features as Vector; + case 'matrix': + return response.features as Matrix; + case 'tracks': + return response.features as Tracks; + case 'notes': + return { + shape: deducedShape, + collected: mapFeaturesToNotes( response.features.collected as FeatureList, response.outputDescriptor - ); - notes.unit = 'MIDI'; - return { - shape: deducedShape, - collected: notes, - }; - case 'instants': - const featureData = response.features.collected as FeatureList; - return { - shape: deducedShape, - collected: featureData.map(feature => ({ - time: toSeconds(feature.timestamp), - label: feature.label - })) - }; - } - })(); - const unit = response.outputDescriptor.configured.unit; - if (shaped) { - const bodgeUnit = (shaped: KnownShapedFeature) => { - (shaped.collected as any).unit = unit; - return shaped; - }; - return unit && !shaped.collected.unit ? bodgeUnit(shaped) : shaped; - } else { - throwShapeError(); + ) + }; + case 'instants': + const featureData = response.features.collected as FeatureList; + return { + shape: deducedShape, + collected: featureData.map(feature => ({ + time: toSeconds(feature.timestamp), + label: feature.label + })) + }; } + throwShapeError(); } export interface PlotData { diff -r de9864aeacf0 -r 3eab26a629e1 src/app/visualisations/cross-hair-inspector.component.ts --- a/src/app/visualisations/cross-hair-inspector.component.ts Thu Jun 01 18:56:06 2017 +0100 +++ b/src/app/visualisations/cross-hair-inspector.component.ts Thu Jun 01 23:04:39 2017 +0100 @@ -6,6 +6,7 @@ ChangeDetectionStrategy, Component, ContentChildren, + Input, QueryList } from '@angular/core'; import { @@ -23,11 +24,12 @@ @ContentChildren( VerticalValueInspectorRenderer ) inspectorRenderers: QueryList; + @Input() unit: string; ngAfterViewInit(): void { super.ngAfterViewInit(); this.inspectorRenderers.forEach(renderer => { - renderer.renderInspector(this.cachedRanged); + renderer.renderInspector(this.cachedRanged, this.unit); }); } } diff -r de9864aeacf0 -r 3eab26a629e1 src/app/visualisations/curve/curve.component.ts --- a/src/app/visualisations/curve/curve.component.ts Thu Jun 01 18:56:06 2017 +0100 +++ b/src/app/visualisations/curve/curve.component.ts Thu Jun 01 23:04:39 2017 +0100 @@ -7,17 +7,17 @@ Input } from '@angular/core'; import {OnSeekHandler} from '../../playhead/PlayHeadHelpers'; -import {TracksFeature, VectorFeature} from 'piper/HigherLevelUtilities'; +import {VectorFeature} from 'piper/HigherLevelUtilities'; @Component({ selector: 'ugly-curve', - template: ` + template: ` `, changeDetection: ChangeDetectionStrategy.OnPush @@ -26,13 +26,7 @@ @Input() timeline: Timeline; // TODO refactor WaveComponents to have own Timeline, sharing a TimeContext @Input() onSeek: OnSeekHandler; @Input() width: number; - @Input() set curve(curve: VectorFeature & {unit?: string}) { - const tempTracks: TracksFeature & {unit?: string} = [curve]; - tempTracks.unit = curve.unit; - this.tracks = tempTracks; - } - - private tracks: TracksFeature & {unit?: string}; - + @Input() curve: VectorFeature; @Input() colour: string; + @Input() unit: string; } diff -r de9864aeacf0 -r 3eab26a629e1 src/app/visualisations/waves-base.component.ts --- a/src/app/visualisations/waves-base.component.ts Thu Jun 01 18:56:06 2017 +0100 +++ b/src/app/visualisations/waves-base.component.ts Thu Jun 01 23:04:39 2017 +0100 @@ -231,7 +231,7 @@ color: '#c33c54', // TODO pass in? labelOffset: 38, yDomain: range, - unit: unit || this.feature.unit || '' + unit: unit || '' } ); this.addLayer(this.highlight);