Skip to content

Commit 318cc75

Browse files
authored
Removed superfluous dataBuffer in graph_spectrum to prevent the random spectrum type change bug (#841)
* Removed superfluous dataBuffer in graph_spectrum to prevent the random spectrum type change bug * Removed useless dataBuffer variable
1 parent 900c0df commit 318cc75

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

src/graph_spectrum.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
1919
analyserZoomY = 1.0 /* 100% */,
2020
dataReload = false,
2121
fftData = null,
22-
prefs = new PrefStorage(),
23-
dataBuffer = {
24-
fieldIndex: 0,
25-
curve: null,
26-
fieldName: null,
27-
};
22+
prefs = new PrefStorage();
2823

2924
try {
3025
let isFullscreen = false;
@@ -100,8 +95,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
10095
});
10196
};
10297

103-
let dataLoad = function () {
104-
GraphSpectrumCalc.setDataBuffer(dataBuffer);
98+
const dataLoad = function (fieldIndex, curve, fieldName) {
99+
if (fieldIndex > 0 && curve != null && fieldName != null) {
100+
GraphSpectrumCalc.setDataBuffer(fieldIndex, curve, fieldName);
101+
}
105102

106103
switch (userSettings.spectrumType) {
107104
case SPECTRUM_TYPE.FREQ_VS_THROTTLE:
@@ -127,15 +124,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
127124
It is only used to record the current curve positions, collect the data and draw the
128125
analyser on screen*/
129126
this.plotSpectrum = function (fieldIndex, curve, fieldName) {
130-
// Store the data pointers
131-
dataBuffer.fieldIndex = fieldIndex;
132-
dataBuffer.curve = curve;
133-
dataBuffer.fieldName = fieldName;
134-
135127
// Detect change of selected field.... reload and redraw required.
136128
if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) {
137129
dataReload = false;
138-
dataLoad();
130+
dataLoad(fieldIndex, curve, fieldName);
139131
GraphSpectrumPlot.setData(fftData, userSettings.spectrumType);
140132
}
141133

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

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-
}
216201
// Recalculate the data, for the same curve than now, and draw it
217202
dataReload = true;
218-
that.plotSpectrum(
219-
dataBuffer.fieldIndex,
220-
dataBuffer.curve,
221-
dataBuffer.fieldName,
222-
);
203+
that.plotSpectrum(-1, null, null); // Update fft data only
223204
}
224205

225206
// Hide overdraw and zoomY if needed

src/graph_spectrum_calc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ GraphSpectrumCalc.setOutTime = function(time) {
8484
return this._analyserTimeRange.out;
8585
};
8686

87-
GraphSpectrumCalc.setDataBuffer = function(dataBuffer) {
88-
this._dataBuffer.curve = dataBuffer.curve;
89-
this._dataBuffer.fieldName = dataBuffer.fieldName;
90-
this._dataBuffer.fieldIndex = dataBuffer.fieldIndex;
87+
GraphSpectrumCalc.setDataBuffer = function(fieldIndex, curve, fieldName) {
88+
this._dataBuffer.curve = curve;
89+
this._dataBuffer.fieldName = fieldName;
90+
this._dataBuffer.fieldIndex = fieldIndex;
9191
return undefined;
9292
};
9393

0 commit comments

Comments
 (0)