Skip to content

Commit c031c4b

Browse files
committed
Bug fix: The spectrum graph is sometimes not displayed after change spectrums type
1 parent 8f619f7 commit c031c4b

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/graph_spectrum.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
1717
let that = this,
1818
analyserZoomX = 1.0 /* 100% */,
1919
analyserZoomY = 1.0 /* 100% */,
20+
dataReload = false,
21+
fftData = null,
22+
prefs = new PrefStorage(),
2023
dataBuffer = {
2124
fieldIndex: 0,
22-
curve: 0,
25+
curve: null,
2326
fieldName: null,
24-
},
25-
dataReload = false,
26-
fftData = null,
27-
prefs = new PrefStorage();
27+
};
2828

2929
try {
3030
let isFullscreen = false;
@@ -128,11 +128,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
128128
analyser on screen*/
129129
this.plotSpectrum = function (fieldIndex, curve, fieldName) {
130130
// Store the data pointers
131-
dataBuffer = {
132-
fieldIndex: fieldIndex,
133-
curve: curve,
134-
fieldName: fieldName,
135-
};
131+
dataBuffer.fieldIndex = fieldIndex;
132+
dataBuffer.curve = curve;
133+
dataBuffer.fieldName = fieldName;
136134

137135
// Detect change of selected field.... reload and redraw required.
138136
if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) {
@@ -208,6 +206,13 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
208206
userSettings.spectrumType = optionSelected;
209207
saveOneUserSetting("spectrumType", userSettings.spectrumType);
210208

209+
// Restore dataBuffer if it was corrupted
210+
if (!dataBuffer.curve) {
211+
dataBuffer.curve = GraphSpectrumCalc._dataBuffer.curve;
212+
dataBuffer.fieldName = GraphSpectrumCalc._dataBuffer.fieldName;
213+
dataBuffer.fieldIndex = GraphSpectrumCalc._dataBuffer.fieldIndex;
214+
console.warn("The dataBuffer was corrupted (set to default zeroes) in FlightLogAnalyser.spectrumTypeElem.change event");
215+
}
211216
// Recalculate the data, for the same curve than now, and draw it
212217
dataReload = true;
213218
that.plotSpectrum(

src/graph_spectrum_calc.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const GraphSpectrumCalc = {
2929
_blackBoxRate : 0,
3030
_dataBuffer : {
3131
fieldIndex: 0,
32-
curve: 0,
32+
curve: null,
3333
fieldName: null,
3434
},
3535
_flightLog : null,
@@ -85,7 +85,9 @@ GraphSpectrumCalc.setOutTime = function(time) {
8585
};
8686

8787
GraphSpectrumCalc.setDataBuffer = function(dataBuffer) {
88-
this._dataBuffer = dataBuffer;
88+
this._dataBuffer.curve = dataBuffer.curve;
89+
this._dataBuffer.fieldName = dataBuffer.fieldName;
90+
this._dataBuffer.fieldIndex = dataBuffer.fieldIndex;
8991
return undefined;
9092
};
9193

0 commit comments

Comments
 (0)