Browse Source

Updating patterns for two-point data

Noah 7 years ago
parent
commit
b74747856e
4 changed files with 12 additions and 14 deletions
  1. 0 3
      audiogram/index.js
  2. 1 1
      audiogram/waveform.js
  3. 10 9
      renderer/patterns.js
  4. 1 1
      renderer/sample-wave.js

+ 0 - 3
audiogram/index.js View File

@@ -132,9 +132,6 @@ Audiogram.prototype.render = function(cb) {
132 132
     q.defer(this.trimAudio.bind(this), this.settings.start || 0, this.settings.end);
133 133
   }
134 134
 
135
-  // Get the audio's duration for computing number of frames
136
-  q.defer(this.probe.bind(this));
137
-
138 135
   // Get the audio waveform data
139 136
   q.defer(this.getWaveform.bind(this));
140 137
 

+ 1 - 1
audiogram/waveform.js View File

@@ -77,7 +77,7 @@ function processSamples(samples, numFrames, samplesPerFrame) {
77 77
 
78 78
   });
79 79
 
80
-  // Scale up to -1 or 1
80
+  // Scale up to -1 / 1
81 81
   var adjustment = 1 / Math.max(Math.abs(min), Math.abs(max));
82 82
 
83 83
   var adjusted = unadjusted.map(function(frame){

+ 10 - 9
renderer/patterns.js View File

@@ -36,13 +36,13 @@ function curve(interpolator) {
36 36
 
37 37
     var top = data.map(function(d,i){
38 38
 
39
-      return [x(i), baseline - height(d)];
39
+      return [x(i), baseline - height(d[1])];
40 40
 
41 41
     });
42 42
 
43 43
     var bottom = data.map(function(d,i){
44 44
 
45
-      return [x(i), baseline + height(d)];
45
+      return [x(i), baseline + height(-d[0])];
46 46
 
47 47
     }).reverse();
48 48
 
@@ -90,16 +90,17 @@ function bars(round) {
90 90
 
91 91
     data.forEach(function(val, i){
92 92
 
93
-      var h = height(val),
94
-          x = barX(i);
93
+      var h = height(-val[0]) + height(val[1]),
94
+          x = barX(i),
95
+          y = baseline - height(val[1]);
95 96
 
96
-      context.fillRect(x, baseline - h, barWidth, h * 2);
97
+      context.fillRect(x, y, barWidth, h);
97 98
 
98 99
       if (round) {
99 100
         context.beginPath();
100
-        context.arc(x + barWidth / 2, baseline - h, barWidth / 2, 0, 2 * Math.PI);
101
-        context.moveTo(x + barWidth / 2, baseline + h);
102
-        context.arc(x + barWidth / 2, baseline + h, barWidth / 2, 0, 2 * Math.PI);
101
+        context.arc(x + barWidth / 2, y, barWidth / 2, 0, 2 * Math.PI);
102
+        context.moveTo(x + barWidth / 2, y + h);
103
+        context.arc(x + barWidth / 2, y + h, barWidth / 2, 0, 2 * Math.PI);
103 104
         context.fill();
104 105
       }
105 106
 
@@ -132,7 +133,7 @@ function bricks(rainbow) {
132 133
 
133 134
     data.forEach(function(val, i){
134 135
 
135
-      var bricks = Math.max(1, Math.floor(height(val) / (brickHeight + brickGap))),
136
+      var bricks = Math.max(1, Math.floor(height(val[1]) / (brickHeight + brickGap))),
136 137
           x = barX(i);
137 138
 
138 139
       d3.range(bricks).forEach(function(b){

File diff suppressed because it is too large
+ 1 - 1
renderer/sample-wave.js