Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 7 additions & 26 deletions src/graph_spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
analyserZoomY = 1.0 /* 100% */,
dataReload = false,
fftData = null,
prefs = new PrefStorage(),
dataBuffer = {
fieldIndex: 0,
curve: null,
fieldName: null,
};
prefs = new PrefStorage();

try {
let isFullscreen = false;
Expand Down Expand Up @@ -100,8 +95,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
});
};

let dataLoad = function () {
GraphSpectrumCalc.setDataBuffer(dataBuffer);
const dataLoad = function (fieldIndex, curve, fieldName) {
if (fieldIndex > 0 && curve != null && fieldName != null) {
GraphSpectrumCalc.setDataBuffer(fieldIndex, curve, fieldName);
}

switch (userSettings.spectrumType) {
case SPECTRUM_TYPE.FREQ_VS_THROTTLE:
Expand All @@ -127,15 +124,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
It is only used to record the current curve positions, collect the data and draw the
analyser on screen*/
this.plotSpectrum = function (fieldIndex, curve, fieldName) {
// Store the data pointers
dataBuffer.fieldIndex = fieldIndex;
dataBuffer.curve = curve;
dataBuffer.fieldName = fieldName;

// Detect change of selected field.... reload and redraw required.
if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) {
dataReload = false;
dataLoad();
dataLoad(fieldIndex, curve, fieldName);
GraphSpectrumPlot.setData(fftData, userSettings.spectrumType);
}

Expand Down Expand Up @@ -206,20 +198,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
userSettings.spectrumType = optionSelected;
saveOneUserSetting("spectrumType", userSettings.spectrumType);

// Restore dataBuffer if it was corrupted
if (!dataBuffer.curve) {
dataBuffer.curve = GraphSpectrumCalc._dataBuffer.curve;
dataBuffer.fieldName = GraphSpectrumCalc._dataBuffer.fieldName;
dataBuffer.fieldIndex = GraphSpectrumCalc._dataBuffer.fieldIndex;
console.warn("The dataBuffer was corrupted (set to default zeroes) in FlightLogAnalyser.spectrumTypeElem.change event");
}
// Recalculate the data, for the same curve than now, and draw it
dataReload = true;
that.plotSpectrum(
dataBuffer.fieldIndex,
dataBuffer.curve,
dataBuffer.fieldName,
);
that.plotSpectrum(-1, null, null); // Update fft data only
}

// Hide overdraw and zoomY if needed
Expand Down
8 changes: 4 additions & 4 deletions src/graph_spectrum_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ GraphSpectrumCalc.setOutTime = function(time) {
return this._analyserTimeRange.out;
};

GraphSpectrumCalc.setDataBuffer = function(dataBuffer) {
this._dataBuffer.curve = dataBuffer.curve;
this._dataBuffer.fieldName = dataBuffer.fieldName;
this._dataBuffer.fieldIndex = dataBuffer.fieldIndex;
GraphSpectrumCalc.setDataBuffer = function(fieldIndex, curve, fieldName) {
this._dataBuffer.curve = curve;
this._dataBuffer.fieldName = fieldName;
this._dataBuffer.fieldIndex = fieldIndex;
return undefined;
};

Expand Down