Skip to content

Commit e56e9eb

Browse files
author
Travis West
committed
amp ticks for frequency plots
also fixed bug in analytic freq plots so that amp zoom is reflected properly in these plots.
1 parent f35f368 commit e56e9eb

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

panel.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,26 @@ function drawVerticalTick(panel, text, x, tick_length = 5) {
174174
panel.buffer.line(x, panel.plotBottom, x, panel.plotBottom + tick_length);
175175
}
176176

177+
const freq_amp_ticks_doc='Amplitude is plotted on the y-axis. Ticks on the left label the linear amplitude where 1.0 is equal to the maximum amplitude. ';
178+
function drawFreqAmplitudeTicks(panel, pixel_max, num_ticks) {
179+
for (let i = 0; i <= num_ticks; ++i) {
180+
let tick_amp_pixels = i * pixel_max / num_ticks / panel.settings.ampZoom;
181+
drawHorizontalTick(panel, (tick_amp_pixels/pixel_max).toFixed(2), panel.plotBottom - tick_amp_pixels*panel.settings.ampZoom, 5, "right");
182+
}
183+
}
184+
177185
const amp_ticks_doc='Amplitude is plotted on the y-axis. Ticks on the left label the linear amplitude where +/- 1.0 is equal to the maximum amplitude. ';
178186
function drawSignalAmplitudeTicks(panel, pixel_max, num_ticks) {
179187
for (let i = 1; i <= num_ticks; ++i) {
180-
let tick_amp_pixels = i * pixel_max / num_ticks/panel.settings.ampZoom;
188+
let tick_amp_pixels = i * pixel_max / num_ticks / panel.settings.ampZoom;
181189
// let tick_amp_db = linToDB(tick_amp_pixels, pixel_max);
182190
drawHorizontalTick(panel, (tick_amp_pixels/pixel_max).toFixed(2), panel.halfh - tick_amp_pixels*panel.settings.ampZoom,5,"right");
183191
drawHorizontalTick(panel, (-tick_amp_pixels/pixel_max).toFixed(2), panel.halfh + tick_amp_pixels*panel.settings.ampZoom,5,"right");
184-
// drawHorizontalTick(panel, tick_amp_db.toFixed(1) + ' dB', panel.halfh - tick_amp_pixels*panel.settings.ampZoom);
185-
// drawHorizontalTick(panel, tick_amp_db.toFixed(1) + ' dB', panel.halfh + tick_amp_pixels*panel.settings.ampZoom);
192+
// drawHorizontalTick(panel, tick_amp_db.toFixed(1) + 'dBFS', panel.halfh - tick_amp_pixels*panel.settings.ampZoom,5, "right");
193+
// drawHorizontalTick(panel, tick_amp_db.toFixed(1) + 'dBFS', panel.halfh + tick_amp_pixels*panel.settings.ampZoom,5, "right");
186194
}
187-
// drawHorizontalTick(panel, '-inf dB', panel.halfh);
188-
drawHorizontalTick(panel, '0', panel.halfh, 5, "right");
189-
195+
// drawHorizontalTick(panel, '-inf dBFS', panel.halfh, 5, "right");
196+
drawHorizontalTick(panel, '0.00', panel.halfh, 5, "right");
190197
}
191198

192199
const bin_amp_ticks_doc='Ticks on the right side of this plot label the numerical value assigned to a given amplitude by the simulated analog-to-digital conversion. The labels are written in hexadecimal unless the bit depth is 7 bits or lower, in which case the labels are in binary. ';
@@ -330,7 +337,7 @@ class inputSigFreqPanel extends freqPanel {
330337
if (xpos > this.plotRight|| xpos< this.plotLeft) break;
331338
// if (this.settings.harmSlope == "lin") {ampScale = 1 - (harm-1)/(this.settings.numHarm)};
332339
// if (this.settings.harmSlope == "1/x") {ampScale = 1/harmPeak};
333-
let height = this.settings.amplitude * this.plotHeight *this.settings.harmonicAmps[harm-1];
340+
let height = this.settings.ampZoom * this.settings.amplitude * this.plotHeight *this.settings.harmonicAmps[harm-1];
334341
this.drawPeak(xpos, height, this.plotBottom)
335342
harm+=1;
336343
// (harmPeak ==1 && this.settings.harmType != "Odd")? harmPeak++ : harmPeak +=harmInc;
@@ -339,6 +346,7 @@ class inputSigFreqPanel extends freqPanel {
339346

340347
this.drawBorder();
341348
drawFreqTicks(this, this.numFreqTicks, pixels_per_hz);
349+
drawFreqAmplitudeTicks(this, this.plotHeight, 9);
342350
drawName(this);
343351
}
344352

@@ -380,6 +388,7 @@ function drawFFT(panel, fft, tick='freq') {
380388
drawDiracDashes(panel);
381389
else
382390
drawFreqTicks(panel, panel.numFreqTicks, pixels_per_hz);
391+
drawFreqAmplitudeTicks(panel, panel.plotHeight, 9);
383392
}
384393

385394
class inputSigFFTPanel extends freqPanel {
@@ -469,6 +478,7 @@ class impulseFreqPanel extends freqPanel {
469478
drawVerticalTick(this, text, xpos);
470479
}
471480

481+
drawFreqAmplitudeTicks(this, this.plotHeight, 9);
472482
this.drawBorder();
473483
drawName(this);
474484
}
@@ -574,8 +584,8 @@ class sampledInputFreqPanel extends freqPanel{
574584
if (hzNegative < 0) hzNegative = 0 + (0 - hzNegative); //Reflect at 0. TODO should technically use a new color.
575585
// don't reflect at sampleRate because we are already drawing the negative frequency images
576586

577-
let positiveHeight = this.settings.amplitude*this.plotHeight*this.settings.harmonicAmps[harm-1];
578-
let negativeHeight = this.settings.amplitude*this.plotHeight*this.settings.harmonicAmps[harm-1];
587+
let positiveHeight = this.settings.ampZoom * this.settings.amplitude*this.plotHeight*this.settings.harmonicAmps[harm-1];
588+
let negativeHeight = this.settings.ampZoom * this.settings.amplitude*this.plotHeight*this.settings.harmonicAmps[harm-1];
579589
let xNegative = hzNegative * pixels_per_hz + this.plotLeft;
580590
let xPositive = hzPositive * pixels_per_hz + this.plotLeft;
581591
if (xNegative < this.plotRight) this.drawPeak(xNegative, negativeHeight, base, color);
@@ -584,6 +594,7 @@ class sampledInputFreqPanel extends freqPanel{
584594
}
585595

586596
this.drawBorder();
597+
drawFreqAmplitudeTicks(this, this.plotHeight, 9);
587598
drawName(this);
588599
}
589600
}

0 commit comments

Comments
 (0)