changeset 396:3eab26a629e1

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.
author Lucas Thompson <dev@lucas.im>
date Thu, 01 Jun 2017 23:04:39 +0100
parents de9864aeacf0
children 308ea1c2612e
files src/app/analysis-item/analysis-item.component.html src/app/analysis-item/analysis-item.component.ts src/app/app.component.ts src/app/services/feature-extraction/feature-extraction.service.ts src/app/visualisations/FeatureUtilities.ts src/app/visualisations/cross-hair-inspector.component.ts src/app/visualisations/curve/curve.component.ts src/app/visualisations/waves-base.component.ts
diffstat 8 files changed, 61 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- 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"
               ></ugly-curve>
-              <ugly-cross-hair-inspector *ngSwitchCase="'tracks'">
+              <ugly-cross-hair-inspector
+                *ngSwitchCase="'tracks'"
+                [unit]="item.unit"
+              >
                 <ugly-tracks
                   [colour]="getNextColour()"
                   [timeline]="timeline"
@@ -49,7 +53,10 @@
                   [tracks]="item.collected"
                 ></ugly-tracks>
               </ugly-cross-hair-inspector>
-              <ugly-cross-hair-inspector *ngSwitchCase="'notes'">
+              <ugly-cross-hair-inspector
+                *ngSwitchCase="'notes'"
+                [unit]="item.unit"
+              >
                 <ugly-notes
                   [colour]="getNextColour()"
                   [timeline]="timeline"
--- a/src/app/analysis-item/analysis-item.component.ts	Thu Jun 01 18:56:06 2017 +0100
+++ b/src/app/analysis-item/analysis-item.component.ts	Thu Jun 01 23:04:39 2017 +0100
@@ -35,7 +35,9 @@
   extractorKey: string;
 }
 
-export type AnalysisItem = PendingAnalysisItem & KnownShapedFeature;
+export type AnalysisItem = PendingAnalysisItem & KnownShapedFeature & {
+  unit?: string
+};
 
 export function isItem(item: Item): item is Item {
   return item.id != null && item.hasSharedTimeline != null;
--- a/src/app/app.component.ts	Thu Jun 01 18:56:06 2017 +0100
+++ b/src/app/app.component.ts	Thu Jun 01 23:04:39 2017 +0100
@@ -207,7 +207,12 @@
       if (i !== -1) {
         this.analyses.set(
           i,
-          Object.assign({}, this.analyses.get(i), result.result)
+          Object.assign(
+            {},
+            this.analyses.get(i),
+            result.result,
+            result.unit ? {unit: result.unit} : {}
+          )
         );
       }  // TODO else remove the item?
     }).catch(err => {
--- 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
       };
--- 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<Shape extends HigherLevelFeatureShape,
-  Data extends ShapedFeatureData & {unit?: string}> {
+  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 {
--- 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<VerticalValueInspectorRenderer>;
+  @Input() unit: string;
 
   ngAfterViewInit(): void {
     super.ngAfterViewInit();
     this.inspectorRenderers.forEach(renderer => {
-      renderer.renderInspector(this.cachedRanged);
+      renderer.renderInspector(this.cachedRanged, this.unit);
     });
   }
 }
--- 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: `<ugly-cross-hair-inspector>
+  template: `<ugly-cross-hair-inspector [unit]="unit">
     <ugly-tracks
       [timeline]="timeline"
       [width]="width"
       [onSeek]="onSeek"
       [colour]="colour"
-      [tracks]="tracks"
+      [tracks]="[curve]"
     ></ugly-tracks>
   </ugly-cross-hair-inspector>`,
   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;
 }
--- 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);