diff src/app/waveform/waveform.component.ts @ 301:fff3a4fba992

Change guard at top of renderFeatures for change in response shape + a bunch of formatting changes.
author Lucas Thompson <dev@lucas.im>
date Wed, 10 May 2017 17:45:06 +0100
parents cda9307d9eb7
children dc415a620b15
line wrap: on
line diff
--- a/src/app/waveform/waveform.component.ts	Wed May 10 14:47:26 2017 +0100
+++ b/src/app/waveform/waveform.component.ts	Wed May 10 17:45:06 2017 +0100
@@ -22,9 +22,7 @@
   FeatureCollection,
   SimpleResponse,
   VectorFeatures,
-  MatrixFeatures,
-  TrackFeature,
-  TrackFeatures
+  MatrixFeatures
 } from 'piper/HigherLevelUtilities';
 import {toSeconds} from 'piper';
 import {FeatureList, Feature} from 'piper/Feature';
@@ -390,7 +388,7 @@
           isZooming = false;
           zoomGestureJustEnded = true;
         }
-       });
+      });
       element.addEventListener('touchmove', zoom);
     }
     // this.timeline.createTrack(track, height/2, `wave-${this.trackIdPrefix}`);
@@ -426,17 +424,17 @@
     }
     if (sample.length === 0) {
       console.log('WARNING: No samples gathered, even though we hoped for ' +
-                  (m_per * w) + ' of them');
+        (m_per * w) + ' of them');
       return 0.0;
     }
     sample.sort((a, b) => { return a - b; });
     const ix = Math.floor((sample.length * percentile) / 100);
     console.log('Estimating ' + percentile + '-%ile of ' +
-                n + '-sample dataset (' + w + ' x ' + h + ') as value ' + ix +
-                ' of sorted ' + sample.length + '-sample subset');
+      n + '-sample dataset (' + w + ' x ' + h + ') as value ' + ix +
+      ' of sorted ' + sample.length + '-sample subset');
     const estimate = sample[ix];
     console.log('Estimate is: ' + estimate + ' (where min sampled value = ' +
-                sample[0] + ' and max = ' + sample[sample.length - 1] + ')');
+      sample[0] + ' and max = ' + sample[sample.length - 1] + ')');
     return estimate;
   }
 
@@ -444,8 +442,8 @@
     const colours = hexColours.map(n => {
       const i = parseInt(n, 16);
       return [ ((i >> 16) & 255) / 255.0,
-               ((i >> 8) & 255) / 255.0,
-               ((i) & 255) / 255.0 ];
+        ((i >> 8) & 255) / 255.0,
+        ((i) & 255) / 255.0 ];
     });
     const last = colours.length - 1;
     return (value => {
@@ -462,8 +460,8 @@
       const c0 = colours[base];
       const c1 = colours[base + 1];
       return [ c0[0] * prop0 + c1[0] * prop1,
-               c0[1] * prop0 + c1[1] * prop1,
-               c0[2] * prop0 + c1[2] * prop1 ];
+        c0[1] * prop0 + c1[1] * prop1,
+        c0[2] * prop0 + c1[2] * prop1 ];
     });
   }
 
@@ -485,12 +483,12 @@
     const t = v * (1 - (1 - f) * s);
     let r = 0, g = 0, b = 0;
     switch (i % 6) {
-        case 0: r = v; g = t; b = p; break;
-        case 1: r = q; g = v; b = p; break;
-        case 2: r = p; g = v; b = t; break;
-        case 3: r = p; g = q; b = v; break;
-        case 4: r = t; g = p; b = v; break;
-        case 5: r = v; g = p; b = q; break;
+      case 0: r = v; g = t; b = p; break;
+      case 1: r = q; g = v; b = p; break;
+      case 2: r = p; g = v; b = t; break;
+      case 3: r = p; g = q; b = v; break;
+      case 4: r = t; g = p; b = v; break;
+      case 5: r = v; g = p; b = q; break;
     }
     return [ r, g, b ];
   }
@@ -622,7 +620,7 @@
       return;
     }
     if (!extracted.features.hasOwnProperty('shape')
-      || !extracted.features.hasOwnProperty('data')) {
+      || !extracted.features.hasOwnProperty('collected')) {
       return;
     }
     const features: FeatureCollection = (extracted.features as FeatureCollection);
@@ -633,8 +631,8 @@
 
     // TODO refactor all of this
     switch (features.shape) {
-    case 'vector': {
-	const collected = features.collected as VectorFeatures;
+      case 'vector': {
+        const collected = features.collected as VectorFeatures;
         const stepDuration = collected.stepDuration;
         const featureData = collected.data;
         if (featureData.length === 0) {
@@ -652,12 +650,12 @@
           min = 0;
           max = 1;
         }
-	console.log("adding line layer: min = " + min + ", max = " + max);
-	if (min !== min || max !== max) {
-	  console.log("WARNING: min or max is NaN");
-	  min = 0;
-	  max = 1;
-	}
+        console.log('adding line layer: min = ' + min + ', max = ' + max);
+        if (min !== min || max !== max) {
+          console.log('WARNING: min or max is NaN');
+          min = 0;
+          max = 1;
+        }
         const lineLayer = new wavesUI.helpers.LineLayer(plotData, {
           color: colour,
           height: height,
@@ -694,7 +692,7 @@
         break;
       }
       case 'list': {
-	const featureData = features.collected as FeatureList;
+        const featureData = features.collected as FeatureList;
         if (featureData.length === 0) {
           return;
         }
@@ -706,8 +704,8 @@
         const isRegion = hasDuration
           && featureData[0].timestamp != null;
         console.log('Have list features: length ' + featureData.length +
-                    ', isMarker ' + isMarker + ', isRegion ' + isRegion +
-                    ', hasDuration ' + hasDuration);
+          ', isMarker ' + isMarker + ', isRegion ' + isRegion +
+          ', hasDuration ' + hasDuration);
         // TODO refactor, this is incomprehensible
         if (isMarker) {
           const plotData = featureData.map(feature => ({
@@ -796,7 +794,7 @@
         break;
       }
       case 'matrix': {
-	const collected = features.collected as MatrixFeatures;
+        const collected = features.collected as MatrixFeatures;
         const stepDuration = collected.stepDuration;
         // !!! + start time
         const matrixData = collected.data;
@@ -810,10 +808,11 @@
         const targetValue = this.estimatePercentile(matrixData, 95);
         const gain = (targetValue > 0.0 ? (1.0 / targetValue) : 1.0);
         console.log('setting gain to ' + gain);
-        const matrixEntity =
-          new wavesUI.utils.PrefilledMatrixEntity(matrixData,
-                                                  0, // startTime
-                                                  stepDuration);
+        const matrixEntity = new wavesUI.utils.PrefilledMatrixEntity(
+            matrixData,
+            0, // startTime
+            stepDuration
+          );
         const matrixLayer = new wavesUI.helpers.MatrixLayer(matrixEntity, {
           gain,
           top: 0,
@@ -867,19 +866,21 @@
         const mustPageBackward = currentTime < -currentOffset;
 
         if (mustPageForward) {
-          const hasSkippedMultiplePages = offsetTimestamp - visibleDuration > visibleDuration;
+          const hasSkippedMultiplePages = offsetTimestamp -
+            visibleDuration > visibleDuration;
 
-            this.timeline.timeContext.offset = hasSkippedMultiplePages ?
-                -currentTime +  0.5 * visibleDuration :
-                currentOffset - visibleDuration;
+          this.timeline.timeContext.offset = hasSkippedMultiplePages ?
+            -currentTime +  0.5 * visibleDuration :
+            currentOffset - visibleDuration;
           this.timeline.tracks.update();
         }
 
         if (mustPageBackward) {
-          const hasSkippedMultiplePages = currentTime + visibleDuration < -currentOffset;
-            this.timeline.timeContext.offset = hasSkippedMultiplePages ?
-                -currentTime + 0.5 * visibleDuration :
-                currentOffset + visibleDuration;
+          const hasSkippedMultiplePages = currentTime +
+            visibleDuration < -currentOffset;
+          this.timeline.timeContext.offset = hasSkippedMultiplePages ?
+            -currentTime + 0.5 * visibleDuration :
+            currentOffset + visibleDuration;
           this.timeline.tracks.update();
         }