Skip to content

Commit 32b0086

Browse files
committed
Resolved notice from haslinghuis
1 parent 2cde4dd commit 32b0086

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/graph_spectrum_calc.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
110110
const flightSamples = this._getFlightSamplesFreq(false);
111111

112112
let pointsPerSegment = 512;
113-
const multipler = Math.floor(1 / analyserZoomY); // 0. ... 10
114-
if (multipler == 0) {
113+
const multiplier = Math.floor(1 / analyserZoomY); // 0. ... 10
114+
if (multiplier == 0) {
115115
pointsPerSegment = 256;
116-
} else if(multipler > 1) {
117-
pointsPerSegment *= 2 ** Math.floor(multipler / 2);
116+
} else if(multiplier > 1) {
117+
pointsPerSegment *= 2 ** Math.floor(multiplier / 2);
118118
}
119119
pointsPerSegment = Math.min(pointsPerSegment, flightSamples.samples.length);
120120
const overlapCount = Math.floor(pointsPerSegment / 2);
@@ -321,7 +321,7 @@ GraphSpectrumCalc._getFlightSamplesFreq = function(scaled = true) {
321321
for (const chunk of allChunks) {
322322
for (const frame of chunk.frames) {
323323
if (scaled) {
324-
samples[samplesCount] = (this._dataBuffer.curve.lookupRaw(frame[this._dataBuffer.fieldIndex]));
324+
samples[samplesCount] = this._dataBuffer.curve.lookupRaw(frame[this._dataBuffer.fieldIndex]);
325325
} else {
326326
samples[samplesCount] = frame[this._dataBuffer.fieldIndex];
327327
}
@@ -555,6 +555,15 @@ GraphSpectrumCalc._psd = function(samples, pointsPerSegment, overlapCount, scal
555555
// Compute average for scaled power
556556
let min = 1e6,
557557
max = -1e6;
558+
// Early exit if no segments were processed
559+
if (segmentsCount === 0) {
560+
return {
561+
psdOutput: new Float64Array(0),
562+
min: 0,
563+
max: 0,
564+
maxNoiseIdx: 0
565+
};
566+
}
558567
const maxFrequency = (this._blackBoxRate / 2.0);
559568
const noise50HzIdx = 50 / maxFrequency * dataCount;
560569
const noise3HzIdx = 3 / maxFrequency * dataCount;

src/graph_spectrum_plot.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -381,16 +381,16 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
381381
);
382382
const offset = 1;
383383
this._drawInterestFrequency(
384-
canvasCtx,
385-
this._fftData.maxNoiseIdx,
386-
PLOTTED_BLACKBOX_RATE,
387-
"Max noise",
388-
WIDTH,
389-
HEIGHT,
390-
15 * offset + MARGIN,
391-
"rgba(255,0,0,0.50)",
392-
3,
393-
);
384+
canvasCtx,
385+
this._fftData.maxNoiseIdx,
386+
PLOTTED_BLACKBOX_RATE,
387+
"Max noise",
388+
WIDTH,
389+
HEIGHT,
390+
15 * offset + MARGIN,
391+
"rgba(255,0,0,0.50)",
392+
3,
393+
);
394394

395395
canvasCtx.restore();
396396
};
@@ -1081,29 +1081,29 @@ GraphSpectrumPlot._drawVerticalGridLines = function (
10811081
minValue,
10821082
maxValue,
10831083
label,
1084-
Ticks = 5,
1084+
ticks = 5,
10851085
) {
10861086

1087-
for (let i = 0; i <= Ticks; i++) {
1087+
for (let i = 0; i <= ticks; i++) {
10881088
canvasCtx.beginPath();
10891089
canvasCtx.lineWidth = 1;
10901090
canvasCtx.strokeStyle = "rgba(255,255,255,0.25)";
10911091

1092-
const verticalPosition = i * (HEIGHT / Ticks);
1092+
const verticalPosition = i * (HEIGHT / ticks);
10931093
canvasCtx.moveTo(0, verticalPosition);
10941094
canvasCtx.lineTo(WIDTH, verticalPosition);
10951095

10961096
canvasCtx.stroke();
10971097
const verticalAxisValue = (
1098-
(maxValue - minValue) * ((Ticks - i) / Ticks) +
1098+
(maxValue - minValue) * ((ticks - i) / ticks) +
10991099
minValue
11001100
).toFixed(0);
11011101
let textBaseline;
11021102
switch (i) {
11031103
case 0:
11041104
textBaseline = "top";
11051105
break;
1106-
case Ticks:
1106+
case ticks:
11071107
textBaseline = "bottom";
11081108
break;
11091109
default:

0 commit comments

Comments
 (0)