changeset 404:6672496ff32e

Alter Plot types slightly, moving yDomain to top level.
author Lucas Thompson <dev@lucas.im>
date Sat, 03 Jun 2017 09:59:56 +0100
parents 40ea40ebc2b3
children 3ace7672638b
files src/app/visualisations/FeatureUtilities.ts src/app/visualisations/tracks/tracks.components.ts
diffstat 2 files changed, 38 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/visualisations/FeatureUtilities.ts	Fri Jun 02 19:12:38 2017 +0100
+++ b/src/app/visualisations/FeatureUtilities.ts	Sat Jun 03 09:59:56 2017 +0100
@@ -172,19 +172,23 @@
   throwShapeError();
 }
 
-export interface PlotData {
+export interface PlotDataPoint {
   cx: number;
   cy: number;
 }
 
+export interface PlotData {
+  points: PlotDataPoint[];
+  startTime: number;
+  duration;
+}
+
 export interface PlotLayerData {
   data: PlotData[];
   yDomain: [number, number];
-  startTime: number;
-  duration: number;
 }
 
-export function generatePlotData(features: VectorFeature[]): PlotLayerData[] {
+export function generatePlotData(features: VectorFeature[]): PlotLayerData {
 
   const winnowed = features.filter(feature => feature.data.length > 0);
 
@@ -207,28 +211,30 @@
     max = 1;
   }
 
-  return winnowed.map(feature => {
-    let duration = 0;
+  return {
+    data: winnowed.map(feature => {
+      let duration = 0;
 
-    // Give the plot items positions relative to the start of the
-    // line, rather than relative to absolute time 0. This is
-    // because we'll be setting the layer timeline start property
-    // later on and these will be positioned relative to that
+      // Give the plot items positions relative to the start of the
+      // line, rather than relative to absolute time 0. This is
+      // because we'll be setting the layer timeline start property
+      // later on and these will be positioned relative to that
 
-    const plotData = [...feature.data].map((val, i) => {
-      const t = i * feature.stepDuration;
-      duration = t + feature.stepDuration;
+      const plotData = [...feature.data].map((val, i) => {
+        const t = i * feature.stepDuration;
+        duration = t + feature.stepDuration;
+        return {
+          cx: t,
+          cy: val
+        };
+      });
+
       return {
-        cx: t,
-        cy: val
+        points: plotData,
+        startTime: feature.startTime,
+        duration: duration
       };
-    });
-
-    return {
-      data: plotData,
-      yDomain: [min, max] as [number, number],
-      startTime: feature.startTime,
-      duration: duration
-    };
-  });
+    }),
+    yDomain: [min, max]
+  };
 }
--- a/src/app/visualisations/tracks/tracks.components.ts	Fri Jun 02 19:12:38 2017 +0100
+++ b/src/app/visualisations/tracks/tracks.components.ts	Sat Jun 03 09:59:56 2017 +0100
@@ -30,32 +30,32 @@
 export class TracksComponent
   extends InspectableVerticallyBoundedComponent<TracksFeature> {
 
-  private currentState: PlotLayerData[];
+  private currentState: PlotLayerData;
 
   @Input() set tracks(input: TracksFeature) {
     this.feature = input;
   }
 
   get range(): [number, number] {
-    return this.currentState && this.currentState.length > 0 ?
-      this.currentState[0].yDomain : null;
+    return this.currentState && this.currentState.data.length > 0 ?
+      this.currentState.yDomain : null;
   }
 
   protected get featureLayers(): Layer[] {
     this.currentState = generatePlotData(this.feature);
-    return this.currentState.map(feature => new Waves.helpers.LineLayer(
-      feature.data, {
+    return this.currentState.data.map(feature => new Waves.helpers.LineLayer(
+      feature.points, {
         color: this.colour,
         height: this.height,
-        yDomain: feature.yDomain
+        yDomain: this.currentState.yDomain
       })
     );
   }
 
   protected get postAddMap() {
     return (layer, index) => {
-      layer.start = this.currentState[index].startTime;
-      layer.duration = this.currentState[index].duration;
+      layer.start = this.currentState.data[index].startTime;
+      layer.duration = this.currentState.data[index].duration;
       layer.update();
     };
   }