Skip to content

Commit 79b5c83

Browse files
committed
Added export/import PSD curves data
1 parent ddf5d63 commit 79b5c83

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/graph_spectrum.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,3 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
442442
console.error(`Failed to create analyser... error: ${e}`);
443443
}
444444
}
445-

src/graph_spectrum_calc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
130130
const psdData = {
131131
fieldIndex : this._dataBuffer.fieldIndex,
132132
fieldName : this._dataBuffer.fieldName,
133-
psdLength : psd.psdOutput.length,
134-
psdOutput : psd.psdOutput,
133+
fftLength : psd.psdOutput.length,
134+
fftOutput : psd.psdOutput,
135135
blackBoxRate : this._blackBoxRate,
136136
minimum: psd.min,
137137
maximum: psd.max,

src/graph_spectrum_plot.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ GraphSpectrumPlot.redraw = function () {
143143
GraphSpectrumPlot.draw();
144144
};
145145

146-
GraphSpectrumPlot.clearImportedSpectrums = function (curvesData) {
147-
this._importedSpectrumsData.length = 0;
148-
this._invalidateCache();
149-
this._invalidateDataCache();
150-
GraphSpectrumPlot.draw();
151-
};
152-
153146
GraphSpectrumPlot.setOverdraw = function (overdrawType) {
154147
this._overdrawType = overdrawType;
155148
this._invalidateCache();
@@ -344,7 +337,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
344337
canvasCtx.translate(LEFT, TOP);
345338
this._drawGradientBackground(canvasCtx, WIDTH, HEIGHT);
346339

347-
const pointsCount = this._fftData.psdLength;
340+
const pointsCount = this._fftData.fftLength;
348341
const scaleX = 2 * WIDTH / PLOTTED_BLACKBOX_RATE * this._zoomX;
349342
canvasCtx.beginPath();
350343
canvasCtx.lineWidth = 1;
@@ -367,7 +360,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
367360
canvasCtx.moveTo(0, 0);
368361
for (let pointNum = 0; pointNum < pointsCount; pointNum++) {
369362
const freq = PLOTTED_BLACKBOX_RATE / 2 * pointNum / pointsCount;
370-
const y = HEIGHT - (this._fftData.psdOutput[pointNum] - minY) * scaleY;
363+
const y = HEIGHT - (this._fftData.fftOutput[pointNum] - minY) * scaleY;
371364
canvasCtx.lineTo(freq * scaleX, y);
372365
}
373366
canvasCtx.stroke();
@@ -440,10 +433,10 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv
440433
}
441434
}
442435
GraphSpectrumPlot.getPSDbyFreq = function(frequency) {
443-
let freqIndex = Math.round(2 * frequency / this._fftData.blackBoxRate * (this._fftData.psdOutput.length - 1) );
444-
freqIndex = Math.min(freqIndex, this._fftData.psdOutput.length - 1);
436+
let freqIndex = Math.round(2 * frequency / this._fftData.blackBoxRate * (this._fftData.fftOutput.length - 1) );
437+
freqIndex = Math.min(freqIndex, this._fftData.fftOutput.length - 1);
445438
freqIndex = Math.max(freqIndex, 0);
446-
return this._fftData.psdOutput.length ? this._fftData.psdOutput[freqIndex] : 0;
439+
return this._fftData.fftOutput.length ? this._fftData.fftOutput[freqIndex] : 0;
447440
};
448441

449442
GraphSpectrumPlot._drawFrequencyVsXGraph = function (canvasCtx, drawPSD = false) {

src/main.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,17 @@ function BlackboxLogViewer() {
11491149
CsvExporter(flightLog, options).dump(onSuccess);
11501150
}
11511151

1152-
function exportSpectrumToCsv(file, options = {}) {
1152+
function exportSpectrumToCsv(options = {}) {
1153+
const fileName = graph.getAnalyser().getExportedFileName();
1154+
if (fileName == null) {
1155+
console.warn("The export is not supported for this spectrum type");
1156+
return;
1157+
}
1158+
11531159
const onSuccess = createExportCallback(
11541160
"csv",
11551161
"text/csv",
1156-
file,
1162+
fileName,
11571163
performance.now(),
11581164
);
11591165
graph.getAnalyser().exportSpectrumToCSV(onSuccess, options);
@@ -1732,7 +1738,7 @@ function BlackboxLogViewer() {
17321738
});
17331739

17341740
$("#btn-spectrum-export").click(function (e) {
1735-
exportSpectrumToCsv("bf_spectrum");
1741+
exportSpectrumToCsv();
17361742
e.preventDefault();
17371743
});
17381744

@@ -1741,12 +1747,12 @@ function BlackboxLogViewer() {
17411747
e.preventDefault();
17421748
e.target.value = "";
17431749
});
1744-
1750+
17451751
$("#btn-spectrum-clear").click(function (e) {
1746-
graph.getAnalyser().clearImportedSpectrums();
1752+
graph.getAnalyser().removeImportedSpectrums();
17471753
e.preventDefault();
17481754
});
1749-
1755+
17501756
$(".btn-gpx-export").click(function (e) {
17511757
setGraphState(GRAPH_STATE_PAUSED);
17521758
exportGpx();

0 commit comments

Comments
 (0)