From 34458717b375757fd392a50efc82156862200585 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 13:58:12 +0300 Subject: [PATCH 01/44] Added sceletion of code to add PSD curves into import list by press Insert key --- src/graph_spectrum.js | 4 ++++ src/graph_spectrum_plot.js | 7 +++++++ src/main.js | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 8b82f11a..5fb4355a 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -438,6 +438,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { return fileName; }; + this.addCurrentSpectrumIntoImport = function() { + GraphSpectrumPlot.addCurrentSpectrumIntoImport(); + }; + } catch (e) { console.error(`Failed to create analyser... error: ${e}`); } diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index c1402485..edc2cf58 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1799,3 +1799,10 @@ GraphSpectrumPlot.removeImportedCurves = function() { break; } }; + +GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { + if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) { + alert("The PSD curve is added into import"); + } +}; + diff --git a/src/main.js b/src/main.js index 95a15ec9..76abde7b 100644 --- a/src/main.js +++ b/src/main.js @@ -2454,6 +2454,12 @@ function BlackboxLogViewer() { logJumpEnd(); e.preventDefault(); break; + case 45: // Insert key - add current spectrum PSD curve into import list + if (hasAnalyser) { + graph.getAnalyser().addCurrentSpectrumIntoImport(); + } + e.preventDefault(); + break; } } }); From 29d6d7b7c796721f17d6c313e268d22ec2eae324 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 15:02:14 +0300 Subject: [PATCH 02/44] Added one log PSD curves into import list by press Insert key to spectrum comparison --- src/graph_imported_curves.js | 25 ++++++++++++++++++++++++- src/graph_spectrum_plot.js | 15 +++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index df507285..cf76a0e2 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -6,7 +6,7 @@ export function ImportedCurves(curvesChanged) { this.maxX = -Number.MAX_VALUE; this.minY = Number.MAX_VALUE; this.maxY = -Number.MAX_VALUE; - + this.curvesCount = function() { return this._curvesData.length; }; @@ -64,6 +64,29 @@ export function ImportedCurves(curvesChanged) { } }; + this.addCurve = function(points, name) { + this._curvesData.push({ + name: name, + points: points, + }); + for (const point of points) { + this.minX = Math.min(point.x, _that.minX); + this.maxX = Math.max(point.x, _that.maxX); + this.minY = Math.min(point.y, _that.minY); + this.maxY = Math.max(point.y, _that.maxY); + } + curvesChanged(); + } + + this.isNewCurve = function(name) { + for (const curve of this._curvesData) { + if (curve.name == name) { + return false; + } + } + return true; + } + this.removeCurves = function() { this._curvesData.length = 0; this.minX = Number.MAX_VALUE; diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index edc2cf58..56d000b6 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1801,8 +1801,19 @@ GraphSpectrumPlot.removeImportedCurves = function() { }; GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { - if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) { - alert("The PSD curve is added into import"); + if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY && + this._importedPSD.isNewCurve(this._fftData.fieldName)) { + const fftLength = this._fftData.fftLength; + const frequencyStep = 0.5 * this._fftData.blackBoxRate / fftLength; + const points = []; + for (let index = 0; index < fftLength; index++) { + const frequency = frequencyStep * index; + points.push({ + x: frequency, + y: this._fftData.fftOutput[index], + }); + } + this._importedPSD.addCurve(points, this._fftData.fieldName); } }; From 7104be82a74288431e78f18978f64e33d1322a52 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 18:33:36 +0300 Subject: [PATCH 03/44] Code issues improvement --- src/graph_imported_curves.js | 94 ++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index cf76a0e2..ff218fc8 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -12,57 +12,57 @@ export function ImportedCurves(curvesChanged) { }; this.importCurvesFromCSV = function(files) { - let importsLeft = maxImportCount - this._curvesData.length; + let importsLeft = maxImportCount - this._curvesData.length; - for (const file of files) { - if (importsLeft-- == 0) { - break; - } - const reader = new FileReader(); - reader.onload = function (e) { - try { - const stringRows = e.target.result.split("\n"); - - const header = stringRows[0].split(","); - if (header.length != 2 || header[0] != "x" || header[1] != "y") { - throw new SyntaxError("Wrong curves CSV data format"); - } + for (const file of files) { + if (importsLeft-- == 0) { + break; + } + const reader = new FileReader(); + reader.onload = function (e) { + try { + const stringRows = e.target.result.split("\n"); - stringRows.shift(); - //remove bad last row - if (stringRows.at(-1) == "") { - stringRows.pop(); - } + const header = stringRows[0].split(","); + if (header.length != 2 || header[0] != "x" || header[1] != "y") { + throw new SyntaxError("Wrong curves CSV data format"); + } - const curvesData = stringRows.map( function(row) { - const data = row.split(","), - x = parseFloat(data[0]), - y = parseFloat(data[1]); - _that.minX = Math.min(x, _that.minX); - _that.maxX = Math.max(x, _that.maxX); - _that.minY = Math.min(y, _that.minY); - _that.maxY = Math.max(y, _that.maxY); - return { - x: x, - y: y, - }; - }); + stringRows.shift(); + //remove bad last row + if (stringRows.at(-1) == "") { + stringRows.pop(); + } - const curve = { - name: file.name.split('.')[0], - points: curvesData, + const curvesData = stringRows.map( function(row) { + const data = row.split(","), + x = parseFloat(data[0]), + y = parseFloat(data[1]); + _that.minX = Math.min(x, _that.minX); + _that.maxX = Math.max(x, _that.maxX); + _that.minY = Math.min(y, _that.minY); + _that.maxY = Math.max(y, _that.maxY); + return { + x: x, + y: y, }; - _that._curvesData.push(curve); - curvesChanged(); - } catch (e) { - alert('Curves data import error: ' + e.message); - return; - } - }; + }); - reader.readAsText(file); - } - }; + const curve = { + name: file.name.split('.')[0], + points: curvesData, + }; + _that._curvesData.push(curve); + curvesChanged(); + } catch (e) { + alert('Curves data import error: ' + e.message); + return; + } + }; + + reader.readAsText(file); + } + }; this.addCurve = function(points, name) { this._curvesData.push({ @@ -76,7 +76,7 @@ export function ImportedCurves(curvesChanged) { this.maxY = Math.max(point.y, _that.maxY); } curvesChanged(); - } + }; this.isNewCurve = function(name) { for (const curve of this._curvesData) { @@ -85,7 +85,7 @@ export function ImportedCurves(curvesChanged) { } } return true; - } + }; this.removeCurves = function() { this._curvesData.length = 0; From 4606c374b8f4ada449bbcf64f63ff0b4ef2ac32b Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 18:46:00 +0300 Subject: [PATCH 04/44] Code style improvement --- src/graph_spectrum_plot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 56d000b6..464ddea2 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -431,7 +431,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { }; GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurves) { - if (!userSettings?.analyser_legend) { + if (!userSettings?.analyser_legend?.left || !userSettings?.analyser_legend?.top || !userSettings?.analyser_legend?.width) { return; } const spectrumCount = importedCurves.length, @@ -452,7 +452,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv canvasCtx.textAlign = "left"; for (let row = 0; row < spectrumCount; row++) { const curvesName = importedCurves[row].name; - const Y = legendPosY + padding + rowHeight * (row + 1); + const Y = legendPosY + padding + rowHeight * row + rowHeight/2; // Center text vertically canvasCtx.strokeStyle = this.curvesColors[row]; canvasCtx.strokeText(curvesName, legendPosX + padding, Y); } From bade57df5bf2dacdafa2935542732365133ca551 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 16 Jul 2025 19:25:50 +0300 Subject: [PATCH 05/44] Code style improvement Co-authored-by: Mark Haslinghuis --- src/graph_spectrum_plot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 464ddea2..137a6186 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -452,7 +452,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv canvasCtx.textAlign = "left"; for (let row = 0; row < spectrumCount; row++) { const curvesName = importedCurves[row].name; - const Y = legendPosY + padding + rowHeight * row + rowHeight/2; // Center text vertically + const Y = legendPosY + padding + rowHeight * row + rowHeight / 2; // Center text vertically canvasCtx.strokeStyle = this.curvesColors[row]; canvasCtx.strokeText(curvesName, legendPosX + padding, Y); } From 91f8c4cc7a3947bce3ef6e3dfb514cc9b0fe35a8 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 20:34:41 +0300 Subject: [PATCH 06/44] Added Add button to compare spectrums --- index.html | 1 + src/main.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index ab9494e3..57fe3224 100644 --- a/index.html +++ b/index.html @@ -477,6 +477,7 @@

Workspace

+ diff --git a/src/main.js b/src/main.js index 76abde7b..5c45a6c7 100644 --- a/src/main.js +++ b/src/main.js @@ -1737,6 +1737,13 @@ function BlackboxLogViewer() { e.preventDefault(); }); + $("#btn-spectrum-add").click(function (e) { + if (hasAnalyser) { + graph.getAnalyser().addCurrentSpectrumIntoImport(); + } + e.preventDefault(); + }); + $("#btn-spectrum-export").click(function (e) { exportSpectrumToCsv(); e.preventDefault(); @@ -1771,10 +1778,10 @@ function BlackboxLogViewer() { const exportDialog = new VideoExportDialog($("#dlgVideoExport"), function(newConfig) { videoConfig = newConfig; - + prefs.set('videoConfig', newConfig); }); - + exportDialog.show( flightLog, { From 6c523545fa30b9c10abe3cb7e979ae4f8324a66f Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 20:47:23 +0300 Subject: [PATCH 07/44] The Import Export Clear buttons captions are changed to short Exp,Imp,Clr --- index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 57fe3224..0958b82b 100644 --- a/index.html +++ b/index.html @@ -478,10 +478,10 @@

Workspace

- - + + - +
From 0025b949d239c2f6d2dc84cd1bffb9ff117c9372 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 20:48:16 +0300 Subject: [PATCH 08/44] The spectrums legend height is improved --- src/graph_spectrum_plot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 137a6186..c7443ef1 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -440,7 +440,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv rowHeight = 16, padding = 4, legendWidth = parseInt(userSettings.analyser_legend.width) / 100 * WIDTH, - legendHeight = spectrumCount * rowHeight + 3 * padding, + legendHeight = spectrumCount * rowHeight + padding, legendArea = new Path2D(); canvasCtx.save(); From 978f027ce2c007a90bb9d9a1737d02ec679a26fb Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 16 Jul 2025 21:09:56 +0300 Subject: [PATCH 09/44] The spectrum Add button is visible for PSD curve only --- src/graph_spectrum.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 5fb4355a..e8739e03 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -354,6 +354,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { const showSpectrumsComparisonPanel = optionSelected === SPECTRUM_TYPE.FREQUENCY || optionSelected === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY; $("#spectrumComparison").css("visibility", (showSpectrumsComparisonPanel ? "visible" : "hidden")); + + const showAddSpectrumButton = optionSelected === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY; + $("#btn-spectrum-add").css("display", (showAddSpectrumButton ? "inline" : "none")); }) .change(); From 459875794799b15aeed54b6f5bc36a3a1eb930d8 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 16 Jul 2025 21:22:05 +0300 Subject: [PATCH 10/44] Using of toggle method to change css property Co-authored-by: Mark Haslinghuis --- src/graph_spectrum.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index e8739e03..2fe8536f 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -356,7 +356,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { $("#spectrumComparison").css("visibility", (showSpectrumsComparisonPanel ? "visible" : "hidden")); const showAddSpectrumButton = optionSelected === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY; - $("#btn-spectrum-add").css("display", (showAddSpectrumButton ? "inline" : "none")); + $("#btn-spectrum-add").toggle(showAddSpectrumButton); }) .change(); From 45a620c362b7872623f5daac03ebb0bc888aa7e0 Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 18 Jul 2025 11:02:39 +0300 Subject: [PATCH 11/44] Added checking of maximal imported curves count --- src/graph_imported_curves.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index ff218fc8..e645d5f6 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -65,17 +65,19 @@ export function ImportedCurves(curvesChanged) { }; this.addCurve = function(points, name) { - this._curvesData.push({ - name: name, - points: points, - }); - for (const point of points) { - this.minX = Math.min(point.x, _that.minX); - this.maxX = Math.max(point.x, _that.maxX); - this.minY = Math.min(point.y, _that.minY); - this.maxY = Math.max(point.y, _that.maxY); + if (this.curvesCount() < maxImportCount) { + this._curvesData.push({ + name: name, + points: points, + }); + for (const point of points) { + this.minX = Math.min(point.x, _that.minX); + this.maxX = Math.max(point.x, _that.maxX); + this.minY = Math.min(point.y, _that.minY); + this.maxY = Math.max(point.y, _that.maxY); + } + curvesChanged(); } - curvesChanged(); }; this.isNewCurve = function(name) { From db9d05f8adfa0d0140f6e5aae9c554aaeca69999 Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 18 Jul 2025 09:51:28 +0300 Subject: [PATCH 12/44] Code refactoring: using of getCurve method instead of direct _curvesData field access in ImportedCurves --- src/graph_imported_curves.js | 22 +++++++++++++++------- src/graph_spectrum_plot.js | 12 ++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index e645d5f6..8c5c68aa 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -1,6 +1,6 @@ export function ImportedCurves(curvesChanged) { const maxImportCount = 5; - this._curvesData = []; + const _curvesData = []; const _that = this; this.minX = Number.MAX_VALUE; this.maxX = -Number.MAX_VALUE; @@ -8,11 +8,19 @@ export function ImportedCurves(curvesChanged) { this.maxY = -Number.MAX_VALUE; this.curvesCount = function() { - return this._curvesData.length; + return _curvesData.length; + }; + + this.getCurve = function(index) { + if (index < _curvesData.length) { + return _curvesData[index]; + } else { + throw "The imported curves index has exceeded maximal value" + } }; this.importCurvesFromCSV = function(files) { - let importsLeft = maxImportCount - this._curvesData.length; + let importsLeft = maxImportCount - _curvesData.length; for (const file of files) { if (importsLeft-- == 0) { @@ -52,7 +60,7 @@ export function ImportedCurves(curvesChanged) { name: file.name.split('.')[0], points: curvesData, }; - _that._curvesData.push(curve); + _curvesData.push(curve); curvesChanged(); } catch (e) { alert('Curves data import error: ' + e.message); @@ -66,7 +74,7 @@ export function ImportedCurves(curvesChanged) { this.addCurve = function(points, name) { if (this.curvesCount() < maxImportCount) { - this._curvesData.push({ + _curvesData.push({ name: name, points: points, }); @@ -81,7 +89,7 @@ export function ImportedCurves(curvesChanged) { }; this.isNewCurve = function(name) { - for (const curve of this._curvesData) { + for (const curve of _curvesData) { if (curve.name == name) { return false; } @@ -90,7 +98,7 @@ export function ImportedCurves(curvesChanged) { }; this.removeCurves = function() { - this._curvesData.length = 0; + _curvesData.length = 0; this.minX = Number.MAX_VALUE; this.maxX = -Number.MAX_VALUE; this.minY = Number.MAX_VALUE; diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index c7443ef1..2a4af952 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -264,7 +264,7 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) { const scaleX = WIDTH / MAXIMAL_PLOTTED_FREQUENCY; const spectrumCount = this._importedSpectrums.curvesCount(); for (let spectrumNum = 0; spectrumNum < spectrumCount; spectrumNum++) { - const curvesPonts = this._importedSpectrums._curvesData[spectrumNum].points; + const curvesPonts = this._importedSpectrums.getCurve(spectrumNum).points; const pointsCount = curvesPonts.length; canvasCtx.beginPath(); @@ -299,7 +299,7 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) { //Legend draw if (this._isFullScreen && spectrumCount > 0) { - this._drawLegend(canvasCtx, WIDTH, HEIGHT, this._importedSpectrums._curvesData); + this._drawLegend(canvasCtx, WIDTH, HEIGHT, this._importedSpectrums); } this._drawAxisLabel( @@ -368,7 +368,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { const spectrumCount = this._importedPSD.curvesCount(); for (let spectrumNum = 0; spectrumNum < spectrumCount; spectrumNum++) { - const curvesPonts = this._importedPSD._curvesData[spectrumNum].points; + const curvesPonts = this._importedPSD.getCurve(spectrumNum).points; canvasCtx.beginPath(); canvasCtx.lineWidth = 1; @@ -385,7 +385,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { //Legend draw if (this._isFullScreen && spectrumCount > 0) { - this._drawLegend(canvasCtx, WIDTH, HEIGHT, this._importedPSD._curvesData); + this._drawLegend(canvasCtx, WIDTH, HEIGHT, this._importedPSD); } this._drawAxisLabel( @@ -434,7 +434,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv if (!userSettings?.analyser_legend?.left || !userSettings?.analyser_legend?.top || !userSettings?.analyser_legend?.width) { return; } - const spectrumCount = importedCurves.length, + const spectrumCount = importedCurves.curvesCount(), legendPosX = parseInt(userSettings.analyser_legend.left) / 100 * WIDTH, legendPosY = parseInt(userSettings.analyser_legend.top) / 100 * HEIGHT, rowHeight = 16, @@ -451,7 +451,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv canvasCtx.font = `${this._drawingParams.fontSizeFrameLabelFullscreen}pt ${DEFAULT_FONT_FACE}`; canvasCtx.textAlign = "left"; for (let row = 0; row < spectrumCount; row++) { - const curvesName = importedCurves[row].name; + const curvesName = importedCurves.getCurve(row).name; const Y = legendPosY + padding + rowHeight * row + rowHeight / 2; // Center text vertically canvasCtx.strokeStyle = this.curvesColors[row]; canvasCtx.strokeText(curvesName, legendPosX + padding, Y); From ed3fbc3d920edd3e8245ddf9924cd64047b5735a Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 18 Jul 2025 10:10:17 +0300 Subject: [PATCH 13/44] Code refactoring in graph_spectrum_plot: using getCurveColor method instaed of direct access to curvesColors array --- src/graph_spectrum_plot.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 2a4af952..e39eab1f 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -217,6 +217,10 @@ GraphSpectrumPlot._drawGraph = function (canvasCtx) { } }; +GraphSpectrumPlot.getCurveColor = function (index) { + return this.curvesColors[index % this.curvesColors.length]; +}; + GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) { const HEIGHT = canvasCtx.canvas.height - MARGIN; const WIDTH = canvasCtx.canvas.width; @@ -269,7 +273,7 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) { canvasCtx.beginPath(); canvasCtx.lineWidth = 1; - canvasCtx.strokeStyle = this.curvesColors[spectrumNum]; + canvasCtx.strokeStyle = this.getCurveColor(spectrumNum); canvasCtx.moveTo(0, HEIGHT); const filterPointsCount = 200; for (let pointNum = 0; pointNum < pointsCount; pointNum++) { @@ -372,7 +376,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { canvasCtx.beginPath(); canvasCtx.lineWidth = 1; - canvasCtx.strokeStyle = this.curvesColors[spectrumNum]; + canvasCtx.strokeStyle = this.getCurveColor(spectrumNum); canvasCtx.moveTo(0, HEIGHT); for (const point of curvesPonts) { if(point.x > MAXIMAL_PLOTTED_FREQUENCY) { @@ -453,7 +457,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv for (let row = 0; row < spectrumCount; row++) { const curvesName = importedCurves.getCurve(row).name; const Y = legendPosY + padding + rowHeight * row + rowHeight / 2; // Center text vertically - canvasCtx.strokeStyle = this.curvesColors[row]; + canvasCtx.strokeStyle = this.getCurveColor(row); canvasCtx.strokeText(curvesName, legendPosX + padding, Y); } canvasCtx.restore(); From a6f97c1b978651edab40d041a983c2b6c9c0692f Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 18 Jul 2025 10:21:48 +0300 Subject: [PATCH 14/44] Code refactoring in graph_imported_curves.js: added using of trim method --- src/graph_imported_curves.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index 8c5c68aa..7aabdbe5 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -32,7 +32,7 @@ export function ImportedCurves(curvesChanged) { const stringRows = e.target.result.split("\n"); const header = stringRows[0].split(","); - if (header.length != 2 || header[0] != "x" || header[1] != "y") { + if (header.length != 2 || header[0].trim() != "x" || header[1].trim() != "y") { throw new SyntaxError("Wrong curves CSV data format"); } @@ -44,8 +44,8 @@ export function ImportedCurves(curvesChanged) { const curvesData = stringRows.map( function(row) { const data = row.split(","), - x = parseFloat(data[0]), - y = parseFloat(data[1]); + x = parseFloat(data[0].trim()), + y = parseFloat(data[1].trim()); _that.minX = Math.min(x, _that.minX); _that.maxX = Math.max(x, _that.maxX); _that.minY = Math.min(y, _that.minY); From 3cb9365a4b02d70476c7a73716930e377fae91ba Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 18 Jul 2025 17:53:21 +0300 Subject: [PATCH 15/44] Semi comma issue is resolved --- src/graph_imported_curves.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index 7aabdbe5..90877ac3 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -15,7 +15,7 @@ export function ImportedCurves(curvesChanged) { if (index < _curvesData.length) { return _curvesData[index]; } else { - throw "The imported curves index has exceeded maximal value" + throw "The imported curves index has exceeded maximal value"; } }; From f7f9861786836b595fc574b1b98f88d64a22b24f Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 18 Jul 2025 17:55:16 +0300 Subject: [PATCH 16/44] Added IndexError exeption --- src/graph_imported_curves.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index 90877ac3..0a12497c 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -15,7 +15,7 @@ export function ImportedCurves(curvesChanged) { if (index < _curvesData.length) { return _curvesData[index]; } else { - throw "The imported curves index has exceeded maximal value"; + throw IndexError("The imported curves index has exceeded maximal value"); } }; From 2639ebc68691a4827e2691731108f7f16fc88641 Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 18 Jul 2025 18:01:13 +0300 Subject: [PATCH 17/44] Resolved missing operator new issue --- src/graph_imported_curves.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index 0a12497c..f8177672 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -15,7 +15,7 @@ export function ImportedCurves(curvesChanged) { if (index < _curvesData.length) { return _curvesData[index]; } else { - throw IndexError("The imported curves index has exceeded maximal value"); + throw new IndexError("The imported curves index has exceeded maximal value"); } }; From 6835774539a8f64eadec09937098675f8181e5a3 Mon Sep 17 00:00:00 2001 From: demvlad Date: Sat, 19 Jul 2025 15:13:56 +0300 Subject: [PATCH 18/44] Added Ctrl+Mouse click at curves legend action to show and compare it --- src/graph_legend.js | 4 ++-- src/graph_spectrum.js | 18 ++++++++++++++++-- src/graph_spectrum_plot.js | 4 ++++ src/grapher.js | 10 +++++++++- src/main.js | 8 +++++--- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/graph_legend.js b/src/graph_legend.js index b1f95aea..36af61f4 100644 --- a/src/graph_legend.js +++ b/src/graph_legend.js @@ -101,10 +101,10 @@ export function GraphLegend( config.selectedGraphIndex = selectedGraphIndex; config.selectedFieldIndex = selectedFieldIndex; if (onNewSelectionChange) { - onNewSelectionChange(); + onNewSelectionChange(false, e.ctrlKey); } } else { - onNewSelectionChange(true); + onNewSelectionChange(true, e.ctrlKey); } } e.preventDefault(); diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 2fe8536f..92a2e79d 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -21,7 +21,8 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { let analyserZoomX = 1.0 /* 100% */, analyserZoomY = 1.0 /* 100% */, dataReload = false, - fftData = null; + fftData = null, + addSpectrumToImport = false; try { let isFullscreen = false; @@ -47,6 +48,12 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { that.resize(); }; + this.prepareSpectrumForImport = function () { + if (userSettings.spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) { + addSpectrumToImport = true; + } + }; + this.setInTime = function (time) { dataReload = true; return GraphSpectrumCalc.setInTime(time); @@ -166,7 +173,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { dataLoad(fieldIndex, curve, fieldName); GraphSpectrumPlot.setData(fftData, userSettings.spectrumType); } - + if (addSpectrumToImport == true) { + this.addCurrentSpectrumIntoImport(); + addSpectrumToImport = false; + } that.draw(); // draw the analyser on the canvas.... }; @@ -445,6 +455,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { GraphSpectrumPlot.addCurrentSpectrumIntoImport(); }; + this.isMultiSpectrum = function() { + return GraphSpectrumPlot.isMultiSpectrum(); + }; + } catch (e) { console.error(`Failed to create analyser... error: ${e}`); } diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index e39eab1f..80d1b27f 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1821,3 +1821,7 @@ GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { } }; +GraphSpectrumPlot.isMultiSpectrum = function() { + return this._importedPSD.curvesCount() > 0; +}; + diff --git a/src/grapher.js b/src/grapher.js index ca177a0b..a3bbbd9f 100644 --- a/src/grapher.js +++ b/src/grapher.js @@ -1240,10 +1240,18 @@ export function FlightLogGrapher( }; // Add option toggling - this.setDrawAnalyser = function (state) { + this.setDrawAnalyser = function (state, ctrlKey = false) { + if (state == true && ctrlKey == true) { + analyser.prepareSpectrumForImport(); + } options.drawAnalyser = state; }; + // Add option toggling + this.hasMultiSpectrumAnalyser = function () { + return analyser.isMultiSpectrum(); + }; + // Add analyser zoom toggling this.setAnalyser = function (state) { analyser.setFullscreen(state); diff --git a/src/main.js b/src/main.js index 5c45a6c7..18743266 100644 --- a/src/main.js +++ b/src/main.js @@ -961,9 +961,11 @@ function BlackboxLogViewer() { updateCanvasSize(); } - function onLegendSelectionChange(toggleAnalizer) { - hasAnalyser = toggleAnalizer ? !hasAnalyser : true; - graph.setDrawAnalyser(hasAnalyser); + function onLegendSelectionChange(toggleAnalizer, ctrlKey) { + const lockAnalyserHide = ctrlKey == true || + graph.hasMultiSpectrumAnalyser() + hasAnalyser = toggleAnalizer ? !hasAnalyser || lockAnalyserHide : true; // Do not hide analyser when ctrlKey is pressed or it has much spectrums + graph.setDrawAnalyser(hasAnalyser, ctrlKey); html.toggleClass("has-analyser", hasAnalyser); prefs.set("hasAnalyser", hasAnalyser); invalidateGraph(); From 879d9509768175ffd4226c9cdd9d3de234cc75a6 Mon Sep 17 00:00:00 2001 From: demvlad Date: Sat, 19 Jul 2025 15:22:28 +0300 Subject: [PATCH 19/44] Code style improvement --- src/graph_spectrum.js | 2 +- src/grapher.js | 2 +- src/main.js | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 92a2e79d..195c1f38 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -173,7 +173,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { dataLoad(fieldIndex, curve, fieldName); GraphSpectrumPlot.setData(fftData, userSettings.spectrumType); } - if (addSpectrumToImport == true) { + if (addSpectrumToImport) { this.addCurrentSpectrumIntoImport(); addSpectrumToImport = false; } diff --git a/src/grapher.js b/src/grapher.js index a3bbbd9f..3eb40a96 100644 --- a/src/grapher.js +++ b/src/grapher.js @@ -1241,7 +1241,7 @@ export function FlightLogGrapher( // Add option toggling this.setDrawAnalyser = function (state, ctrlKey = false) { - if (state == true && ctrlKey == true) { + if (state && ctrlKey) { analyser.prepareSpectrumForImport(); } options.drawAnalyser = state; diff --git a/src/main.js b/src/main.js index 18743266..c2bb8247 100644 --- a/src/main.js +++ b/src/main.js @@ -962,8 +962,7 @@ function BlackboxLogViewer() { } function onLegendSelectionChange(toggleAnalizer, ctrlKey) { - const lockAnalyserHide = ctrlKey == true || - graph.hasMultiSpectrumAnalyser() + const lockAnalyserHide = ctrlKey || graph.hasMultiSpectrumAnalyser(); hasAnalyser = toggleAnalizer ? !hasAnalyser || lockAnalyserHide : true; // Do not hide analyser when ctrlKey is pressed or it has much spectrums graph.setDrawAnalyser(hasAnalyser, ctrlKey); html.toggleClass("has-analyser", hasAnalyser); From 58d2721c7df1a90045911f8a634e73e3a7062227 Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 21 Jul 2025 14:43:21 +0300 Subject: [PATCH 20/44] The imported spectrums are removed by simple mouse click at the curves legend --- src/grapher.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/grapher.js b/src/grapher.js index 3eb40a96..b4402460 100644 --- a/src/grapher.js +++ b/src/grapher.js @@ -1241,9 +1241,14 @@ export function FlightLogGrapher( // Add option toggling this.setDrawAnalyser = function (state, ctrlKey = false) { - if (state && ctrlKey) { - analyser.prepareSpectrumForImport(); + if (state) { + if (ctrlKey) { + analyser.prepareSpectrumForImport(); + } else if (this.hasMultiSpectrumAnalyser()) { + analyser.removeImportedSpectrums(); // Remove imported spectrums by simple mouse click at the curves legend + } } + options.drawAnalyser = state; }; From f24abd1bb4be1fff33e674c032323df1e037015a Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 21 Jul 2025 14:57:36 +0300 Subject: [PATCH 21/44] The main curve is added into imported list when the second curve is selected for comparison --- src/graph_spectrum.js | 3 +++ src/grapher.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 195c1f38..ad561382 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -169,6 +169,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { this.plotSpectrum = function (fieldIndex, curve, fieldName) { // Detect change of selected field.... reload and redraw required. if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) { + if (addSpectrumToImport && fftData != null && !this.isMultiSpectrum() && !dataReload) { + this.addCurrentSpectrumIntoImport(); //The main curve is added into imported list when the second curve is selected for comparison + } dataReload = false; dataLoad(fieldIndex, curve, fieldName); GraphSpectrumPlot.setData(fftData, userSettings.spectrumType); diff --git a/src/grapher.js b/src/grapher.js index b4402460..81ce2f40 100644 --- a/src/grapher.js +++ b/src/grapher.js @@ -1245,7 +1245,7 @@ export function FlightLogGrapher( if (ctrlKey) { analyser.prepareSpectrumForImport(); } else if (this.hasMultiSpectrumAnalyser()) { - analyser.removeImportedSpectrums(); // Remove imported spectrums by simple mouse click at the curves legend + analyser.removeImportedSpectrums(); // Remove imported spectrums by simple mouse click at the any curves legend } } From 674eb18b3224253ae08309dd7225242a76dedd78 Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 21 Jul 2025 18:19:30 +0300 Subject: [PATCH 22/44] The main curve is added into imported list when the second curve is imported from external file --- src/graph_spectrum_plot.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 80d1b27f..b68a351e 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1785,6 +1785,9 @@ GraphSpectrumPlot.importCurvesFromCSV = function(files) { this._importedSpectrums.importCurvesFromCSV(files); break; case SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY: + if (this._importedPSD.curvesCount() == 0) { + this.addCurrentSpectrumIntoImport(); + } this._importedPSD.importCurvesFromCSV(files); break; default: From 0a26c66ecbbcf0dfa5ee5ba7bb7e142221899509 Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 21 Jul 2025 18:23:02 +0300 Subject: [PATCH 23/44] Imported spectrums count is increased to 6 --- src/graph_imported_curves.js | 2 +- src/graph_spectrum_plot.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index f8177672..be869c0e 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -1,5 +1,5 @@ export function ImportedCurves(curvesChanged) { - const maxImportCount = 5; + const maxImportCount = 6; const _curvesData = []; const _that = this; this.minX = Number.MAX_VALUE; diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index b68a351e..1009b7bd 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -60,6 +60,7 @@ export const GraphSpectrumPlot = window.GraphSpectrumPlot || { _importedSpectrums: null, _importedPSD: null, curvesColors : [ + "White", "Blue", "Purple", "DeepPink", From 365932e4a317cb80be38997df8290699a71106f5 Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 21 Jul 2025 21:46:37 +0300 Subject: [PATCH 24/44] The spectrum comparison Add button and Insert key action are removed as lessfull --- index.html | 1 - src/main.js | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/index.html b/index.html index 0958b82b..2724ecc6 100644 --- a/index.html +++ b/index.html @@ -477,7 +477,6 @@

Workspace

- diff --git a/src/main.js b/src/main.js index c2bb8247..6b187eeb 100644 --- a/src/main.js +++ b/src/main.js @@ -1738,13 +1738,6 @@ function BlackboxLogViewer() { e.preventDefault(); }); - $("#btn-spectrum-add").click(function (e) { - if (hasAnalyser) { - graph.getAnalyser().addCurrentSpectrumIntoImport(); - } - e.preventDefault(); - }); - $("#btn-spectrum-export").click(function (e) { exportSpectrumToCsv(); e.preventDefault(); @@ -2462,12 +2455,6 @@ function BlackboxLogViewer() { logJumpEnd(); e.preventDefault(); break; - case 45: // Insert key - add current spectrum PSD curve into import list - if (hasAnalyser) { - graph.getAnalyser().addCurrentSpectrumIntoImport(); - } - e.preventDefault(); - break; } } }); From 9885b71a3e6344d50977b6dc58276b099a9aa800 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Tue, 22 Jul 2025 14:04:47 +0300 Subject: [PATCH 25/44] Imported PSD curves drawing start point is improved --- src/graph_spectrum_plot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 1009b7bd..3f7fa04c 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -378,7 +378,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { canvasCtx.beginPath(); canvasCtx.lineWidth = 1; canvasCtx.strokeStyle = this.getCurveColor(spectrumNum); - canvasCtx.moveTo(0, HEIGHT); + canvasCtx.moveTo(0, 0); for (const point of curvesPonts) { if(point.x > MAXIMAL_PLOTTED_FREQUENCY) { break; From 914f09c24dd98a17665cd5e513e9df17ebf505f2 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 19:34:24 +0300 Subject: [PATCH 26/44] Wrong IndexError exception is changed to RangeError --- src/graph_imported_curves.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index be869c0e..209d36bc 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -15,7 +15,7 @@ export function ImportedCurves(curvesChanged) { if (index < _curvesData.length) { return _curvesData[index]; } else { - throw new IndexError("The imported curves index has exceeded maximal value"); + throw new RangeError("The imported curves index has exceeded maximal value"); } }; From db0421fedb33b5e2c295c0f04672126618659cf4 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 19:47:29 +0300 Subject: [PATCH 27/44] Code style improvement --- src/graph_imported_curves.js | 8 ++++---- src/graph_spectrum_plot.js | 14 +++++++------- src/main.js | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index 209d36bc..bb35e080 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -79,10 +79,10 @@ export function ImportedCurves(curvesChanged) { points: points, }); for (const point of points) { - this.minX = Math.min(point.x, _that.minX); - this.maxX = Math.max(point.x, _that.maxX); - this.minY = Math.min(point.y, _that.minY); - this.maxY = Math.max(point.y, _that.maxY); + this.minX = Math.min(point.x, this.minX); + this.maxX = Math.max(point.x, this.maxX); + this.minY = Math.min(point.y, this.minY); + this.maxY = Math.max(point.y, this.maxY); } curvesChanged(); } diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 3f7fa04c..bb5eca9d 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -269,8 +269,8 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) { const scaleX = WIDTH / MAXIMAL_PLOTTED_FREQUENCY; const spectrumCount = this._importedSpectrums.curvesCount(); for (let spectrumNum = 0; spectrumNum < spectrumCount; spectrumNum++) { - const curvesPonts = this._importedSpectrums.getCurve(spectrumNum).points; - const pointsCount = curvesPonts.length; + const curvesPoints = this._importedSpectrums.getCurve(spectrumNum).points; + const pointsCount = curvesPoints.length; canvasCtx.beginPath(); canvasCtx.lineWidth = 1; @@ -293,11 +293,11 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) { } let middleValue = 0; for (let i = filterStartPoint; i < filterStopPoint; i++) { - middleValue += curvesPonts[i].y; + middleValue += curvesPoints[i].y; } middleValue /= filterPointsCount; - canvasCtx.lineTo(curvesPonts[pointNum].x * scaleX, HEIGHT - middleValue * fftScale); + canvasCtx.lineTo(curvesPoints[pointNum].x * scaleX, HEIGHT - middleValue * fftScale); } canvasCtx.stroke(); } @@ -373,13 +373,13 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { const spectrumCount = this._importedPSD.curvesCount(); for (let spectrumNum = 0; spectrumNum < spectrumCount; spectrumNum++) { - const curvesPonts = this._importedPSD.getCurve(spectrumNum).points; + const curvesPoints = this._importedPSD.getCurve(spectrumNum).points; canvasCtx.beginPath(); canvasCtx.lineWidth = 1; canvasCtx.strokeStyle = this.getCurveColor(spectrumNum); canvasCtx.moveTo(0, 0); - for (const point of curvesPonts) { + for (const point of curvesPoints) { if(point.x > MAXIMAL_PLOTTED_FREQUENCY) { break; } @@ -436,7 +436,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { }; GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurves) { - if (!userSettings?.analyser_legend?.left || !userSettings?.analyser_legend?.top || !userSettings?.analyser_legend?.width) { + if (userSettings?.analyser_legend?.left == null || userSettings?.analyser_legend?.top == null || userSettings?.analyser_legend?.width == null) { return; } const spectrumCount = importedCurves.curvesCount(), diff --git a/src/main.js b/src/main.js index 6b187eeb..2211f06e 100644 --- a/src/main.js +++ b/src/main.js @@ -963,7 +963,7 @@ function BlackboxLogViewer() { function onLegendSelectionChange(toggleAnalizer, ctrlKey) { const lockAnalyserHide = ctrlKey || graph.hasMultiSpectrumAnalyser(); - hasAnalyser = toggleAnalizer ? !hasAnalyser || lockAnalyserHide : true; // Do not hide analyser when ctrlKey is pressed or it has much spectrums + hasAnalyser = toggleAnalizer ? !hasAnalyser || lockAnalyserHide : true; // Do not hide analyser when ctrlKey is pressed or it has many spectrums graph.setDrawAnalyser(hasAnalyser, ctrlKey); html.toggleClass("has-analyser", hasAnalyser); prefs.set("hasAnalyser", hasAnalyser); From e037582d60d194218f6e51ea6119bd96f6b6b58b Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 19:57:55 +0300 Subject: [PATCH 28/44] The imported curves drawing start position is improved by using moveTo --- src/graph_spectrum_plot.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index bb5eca9d..ef784c2f 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -360,14 +360,17 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { canvasCtx.beginPath(); canvasCtx.lineWidth = 1; canvasCtx.strokeStyle = "white"; - canvasCtx.moveTo(0, 0); for (let pointNum = 0; pointNum < pointsCount; pointNum++) { const freq = this._fftData.blackBoxRate / 2 * pointNum / pointsCount; if(freq > MAXIMAL_PLOTTED_FREQUENCY) { break; } const y = HEIGHT - (this._fftData.fftOutput[pointNum] - minY) * scaleY; - canvasCtx.lineTo(freq * scaleX, y); + if (pointNum == 0) { + canvasCtx.moveTo(freq * scaleX, y); + } else { + canvasCtx.lineTo(freq * scaleX, y); + } } canvasCtx.stroke(); @@ -378,12 +381,17 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { canvasCtx.beginPath(); canvasCtx.lineWidth = 1; canvasCtx.strokeStyle = this.getCurveColor(spectrumNum); - canvasCtx.moveTo(0, 0); + let isFirstPoint = true; for (const point of curvesPoints) { - if(point.x > MAXIMAL_PLOTTED_FREQUENCY) { + if (point.x > MAXIMAL_PLOTTED_FREQUENCY) { break; } - canvasCtx.lineTo(point.x * scaleX, HEIGHT - (point.y - minY) * scaleY); + if (isFirstPoint) { + canvasCtx.moveTo(point.x * scaleX, HEIGHT - (point.y - minY) * scaleY); + isFirstPoint = false; + } else { + canvasCtx.lineTo(point.x * scaleX, HEIGHT - (point.y - minY) * scaleY); + } } canvasCtx.stroke(); } From c25e56b95eba08bbf5d8d60810363208d1bfce41 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 20:14:53 +0300 Subject: [PATCH 29/44] Using === !== instead of == != --- src/graph_imported_curves.js | 4 ++-- src/graph_spectrum_plot.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index bb35e080..9599f196 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -32,7 +32,7 @@ export function ImportedCurves(curvesChanged) { const stringRows = e.target.result.split("\n"); const header = stringRows[0].split(","); - if (header.length != 2 || header[0].trim() != "x" || header[1].trim() != "y") { + if (header.length !== 2 || header[0].trim() !== "x" || header[1].trim() !== "y") { throw new SyntaxError("Wrong curves CSV data format"); } @@ -90,7 +90,7 @@ export function ImportedCurves(curvesChanged) { this.isNewCurve = function(name) { for (const curve of _curvesData) { - if (curve.name == name) { + if (curve.name === name) { return false; } } diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index ef784c2f..ed726c3d 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -366,7 +366,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { break; } const y = HEIGHT - (this._fftData.fftOutput[pointNum] - minY) * scaleY; - if (pointNum == 0) { + if (pointNum === 0) { canvasCtx.moveTo(freq * scaleX, y); } else { canvasCtx.lineTo(freq * scaleX, y); @@ -1794,7 +1794,7 @@ GraphSpectrumPlot.importCurvesFromCSV = function(files) { this._importedSpectrums.importCurvesFromCSV(files); break; case SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY: - if (this._importedPSD.curvesCount() == 0) { + if (this._importedPSD.curvesCount() === 0) { this.addCurrentSpectrumIntoImport(); } this._importedPSD.importCurvesFromCSV(files); From cbfc72911138cce4906f1e7070f8ab23a8f622ff Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 20:18:35 +0300 Subject: [PATCH 30/44] Improved spectrums legend vertical centering --- src/graph_spectrum_plot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index ed726c3d..4402f993 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -463,6 +463,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv canvasCtx.strokeRect(legendPosX, legendPosY, legendWidth, legendHeight); canvasCtx.font = `${this._drawingParams.fontSizeFrameLabelFullscreen}pt ${DEFAULT_FONT_FACE}`; canvasCtx.textAlign = "left"; + canvasCtx.textBaseline = "middle"; // Ensure proper vertical centering for (let row = 0; row < spectrumCount; row++) { const curvesName = importedCurves.getCurve(row).name; const Y = legendPosY + padding + rowHeight * row + rowHeight / 2; // Center text vertically From b0dac04c7b84b24805c071de3aed977b597f7b06 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 20:45:44 +0300 Subject: [PATCH 31/44] Added comments for const values --- src/graph_imported_curves.js | 2 +- src/graph_spectrum_plot.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index 9599f196..fba0c67e 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -1,5 +1,5 @@ export function ImportedCurves(curvesChanged) { - const maxImportCount = 6; + const maxImportCount = 6; // This value is limited by legends size and curves colors visibility. Maybe increased, if it will need for users const _curvesData = []; const _that = this; this.minX = Number.MAX_VALUE; diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 4402f993..5322512c 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -60,7 +60,7 @@ export const GraphSpectrumPlot = window.GraphSpectrumPlot || { _importedSpectrums: null, _importedPSD: null, curvesColors : [ - "White", + "White", // The first imported curve duplicates existing main curve, therefore it must have same white color "Blue", "Purple", "DeepPink", From 3fb7ae2dd8d7ecbd87fc2cfb4385bf0c10a999b4 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Tue, 22 Jul 2025 20:48:47 +0300 Subject: [PATCH 32/44] The code refactoring for graph hasAnalyser variable condition Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/main.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 2211f06e..0ae00a79 100644 --- a/src/main.js +++ b/src/main.js @@ -963,7 +963,15 @@ function BlackboxLogViewer() { function onLegendSelectionChange(toggleAnalizer, ctrlKey) { const lockAnalyserHide = ctrlKey || graph.hasMultiSpectrumAnalyser(); - hasAnalyser = toggleAnalizer ? !hasAnalyser || lockAnalyserHide : true; // Do not hide analyser when ctrlKey is pressed or it has many spectrums + if (toggleAnalizer) { + if (lockAnalyserHide) { + hasAnalyser = true; // Do not hide analyser when ctrlKey is pressed or it has many spectrums + } else { + hasAnalyser = !hasAnalyser; // Toggle the analyser state + } + } else { + hasAnalyser = true; // Default to true when toggleAnalizer is false + } graph.setDrawAnalyser(hasAnalyser, ctrlKey); html.toggleClass("has-analyser", hasAnalyser); prefs.set("hasAnalyser", hasAnalyser); From 48e7039716180b37d98ccf6611ef98666d1d3e34 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Tue, 22 Jul 2025 20:49:43 +0300 Subject: [PATCH 33/44] Improved errors message for RangeError exception Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/graph_imported_curves.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index fba0c67e..fe45db8b 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -15,7 +15,7 @@ export function ImportedCurves(curvesChanged) { if (index < _curvesData.length) { return _curvesData[index]; } else { - throw new RangeError("The imported curves index has exceeded maximal value"); + throw new RangeError(`The imported curves index (${index}) exceeds the maximum allowed value (${_curvesData.length - 1})`); } }; From 26a62c84c6b3230b7a27c4d9b92253874a771713 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 21:02:44 +0300 Subject: [PATCH 34/44] The comments text is improved --- src/graph_imported_curves.js | 2 +- src/graph_spectrum.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index fe45db8b..c976fd98 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -1,5 +1,5 @@ export function ImportedCurves(curvesChanged) { - const maxImportCount = 6; // This value is limited by legends size and curves colors visibility. Maybe increased, if it will need for users + const maxImportCount = 6; // This value is limited by legends size and curves colors visibility. May be increased if needed by users const _curvesData = []; const _that = this; this.minX = Number.MAX_VALUE; diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index ad561382..52225270 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -170,7 +170,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { // Detect change of selected field.... reload and redraw required. if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) { if (addSpectrumToImport && fftData != null && !this.isMultiSpectrum() && !dataReload) { - this.addCurrentSpectrumIntoImport(); //The main curve is added into imported list when the second curve is selected for comparison + this.addCurrentSpectrumIntoImport(); // The main curve is added into imported list when the second curve is selected for comparison } dataReload = false; dataLoad(fieldIndex, curve, fieldName); From 8bda7d19f44ec9f065c5f6e6aba3fe589002580f Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 21:19:55 +0300 Subject: [PATCH 35/44] Code refactoring for main spectrum curve color --- src/graph_spectrum_plot.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 5322512c..0731ea4c 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -349,6 +349,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { max: maxY, }; + const mainCurveColor = this.getCurveColor(0); // The main curve must have color like the first imported curves - White. const ticksCount = (maxY - minY) / dbStep; const pointsCount = this._fftData.fftLength; const scaleX = WIDTH / MAXIMAL_PLOTTED_FREQUENCY; @@ -359,7 +360,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { canvasCtx.beginPath(); canvasCtx.lineWidth = 1; - canvasCtx.strokeStyle = "white"; + canvasCtx.strokeStyle = mainCurveColor; for (let pointNum = 0; pointNum < pointsCount; pointNum++) { const freq = this._fftData.blackBoxRate / 2 * pointNum / pointsCount; if(freq > MAXIMAL_PLOTTED_FREQUENCY) { From b55b8875653b73cceaee9a4da60de5169d48d35c Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 21:28:25 +0300 Subject: [PATCH 36/44] The spectrums legend positions setup refactoring --- src/graph_spectrum_plot.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 0731ea4c..a184e74a 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -445,15 +445,18 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { }; GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurves) { - if (userSettings?.analyser_legend?.left == null || userSettings?.analyser_legend?.top == null || userSettings?.analyser_legend?.width == null) { + const left = parseFloat(userSettings?.analyser_legend?.left); + const top = parseFloat(userSettings?.analyser_legend?.top); + const width = parseFloat(userSettings?.analyser_legend?.width); + if (!Number.isFinite(left) || !Number.isFinite(top) || !Number.isFinite(width)) { return; } const spectrumCount = importedCurves.curvesCount(), - legendPosX = parseInt(userSettings.analyser_legend.left) / 100 * WIDTH, - legendPosY = parseInt(userSettings.analyser_legend.top) / 100 * HEIGHT, + legendPosX = left / 100 * WIDTH, + legendPosY = top / 100 * HEIGHT, rowHeight = 16, padding = 4, - legendWidth = parseInt(userSettings.analyser_legend.width) / 100 * WIDTH, + legendWidth = width / 100 * WIDTH, legendHeight = spectrumCount * rowHeight + padding, legendArea = new Path2D(); From 7f0846eaad5d725690e1c53f8763948a3c463ac7 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 21:35:10 +0300 Subject: [PATCH 37/44] The code refactoring for adding main spectrum curve to imported list --- src/graph_spectrum.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 52225270..d77fcd3c 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -163,13 +163,17 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { } }; + this.shouldAddCurrentSpectrumBeforeReload = function () { + return addSpectrumToImport && fftData != null && !this.isMultiSpectrum() && !dataReload; + }; + /* This function is called from the canvas drawing routines within grapher.js 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) { // Detect change of selected field.... reload and redraw required. if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) { - if (addSpectrumToImport && fftData != null && !this.isMultiSpectrum() && !dataReload) { + if (this.shouldAddCurrentSpectrumBeforeReload()) { this.addCurrentSpectrumIntoImport(); // The main curve is added into imported list when the second curve is selected for comparison } dataReload = false; From 8965447c76a745d75d9e5a3b1a56f291a8ce064a Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 22 Jul 2025 21:48:32 +0300 Subject: [PATCH 38/44] Added comment for first spectrums csv file import --- src/graph_spectrum_plot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index a184e74a..265f1167 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1800,7 +1800,7 @@ GraphSpectrumPlot.importCurvesFromCSV = function(files) { break; case SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY: if (this._importedPSD.curvesCount() === 0) { - this.addCurrentSpectrumIntoImport(); + this.addCurrentSpectrumIntoImport(); // Add current main spectrum to import for the first imported file to have same behavior like first Ctrl+Mouse click selection. } this._importedPSD.importCurvesFromCSV(files); break; From 9ec215be60b87dcd8dec25ac1036edf122be5e1a Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 23 Jul 2025 10:58:13 +0300 Subject: [PATCH 39/44] Locked the curves PSD spectrum selection while import has maximal curves count --- src/graph_imported_curves.js | 8 ++++++++ src/graph_spectrum.js | 6 +++++- src/graph_spectrum_plot.js | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index c976fd98..a621538c 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -105,4 +105,12 @@ export function ImportedCurves(curvesChanged) { this.maxY = -Number.MAX_VALUE; curvesChanged(); }; + + this.isFull = function() { + return this.curvesCount() === maxImportCount; + }; + + this.isEmpty = function() { + return this.curvesCount() === 0; + }; } diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index d77fcd3c..f333b824 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -172,7 +172,11 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { analyser on screen*/ this.plotSpectrum = function (fieldIndex, curve, fieldName) { // Detect change of selected field.... reload and redraw required. - if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) { + const isMaxCountOfImportedPSD = GraphSpectrumPlot.isImportedCurvesMaxCount() && userSettings.spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY; + const shouldReload = fftData == null || + fieldIndex != fftData.fieldIndex && !isMaxCountOfImportedPSD || // Lock spectrum data reload while PSD curves import is full + dataReload; + if (shouldReload) { if (this.shouldAddCurrentSpectrumBeforeReload()) { this.addCurrentSpectrumIntoImport(); // The main curve is added into imported list when the second curve is selected for comparison } diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 265f1167..5d846590 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1839,6 +1839,9 @@ GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { }; GraphSpectrumPlot.isMultiSpectrum = function() { - return this._importedPSD.curvesCount() > 0; + return !this._importedPSD.isEmpty(); }; +GraphSpectrumPlot.isImportedCurvesMaxCount = function() { + return this._importedPSD.isFull(); +}; From c9477579d96becc3dc59a6a50dae89d7ffcd65a5 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 23 Jul 2025 11:09:59 +0300 Subject: [PATCH 40/44] Added removeCurve and other helper methods into ImportedCurves --- src/graph_imported_curves.js | 64 +++++++++++++++++++++++++++++------- src/graph_spectrum_plot.js | 4 +-- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index a621538c..02862c3d 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -72,18 +72,52 @@ export function ImportedCurves(curvesChanged) { } }; + const getCurveRange = function(points) { + let minX = Number.MAX_VALUE, + maxX = -Number.MAX_VALUE, + minY = Number.MAX_VALUE, + maxY = -Number.MAX_VALUE; + for (const point of points) { + minX = Math.min(point.x, minX); + maxX = Math.max(point.x, maxX); + minY = Math.min(point.y, minY); + maxY = Math.max(point.y, maxY); + } + return { + minX: minX, + maxX: maxX, + minY: minY, + maxY: maxY, + }; + }; + + const computeGlobalCurvesRange = function () { + _that.minX = Number.MAX_VALUE; + _that.maxX = -Number.MAX_VALUE; + _that.minY = Number.MAX_VALUE; + _that.maxY = -Number.MAX_VALUE; + for (const curve of _curvesData) { + _that.minX = Math.min(curve.range.minX, _that.minX); + _that.maxX = Math.max(curve.range.maxX, _that.maxX); + _that.minY = Math.min(curve.range.minY, _that.minY); + _that.maxY = Math.max(curve.range.maxY, _that.maxY); + } + }; + this.addCurve = function(points, name) { if (this.curvesCount() < maxImportCount) { + const range = getCurveRange(points); _curvesData.push({ name: name, points: points, + range: range, }); - for (const point of points) { - this.minX = Math.min(point.x, this.minX); - this.maxX = Math.max(point.x, this.maxX); - this.minY = Math.min(point.y, this.minY); - this.maxY = Math.max(point.y, this.maxY); - } + + this.minX = Math.min(range.minX, this.minX); + this.maxX = Math.max(range.maxX, this.maxX); + this.minY = Math.min(range.minY, this.minY); + this.maxY = Math.max(range.maxY, this.maxY); + curvesChanged(); } }; @@ -97,15 +131,23 @@ export function ImportedCurves(curvesChanged) { return true; }; - this.removeCurves = function() { + this.removeAllCurves = function() { _curvesData.length = 0; - this.minX = Number.MAX_VALUE; - this.maxX = -Number.MAX_VALUE; - this.minY = Number.MAX_VALUE; - this.maxY = -Number.MAX_VALUE; + computeGlobalCurvesRange(); curvesChanged(); }; + this.removeCurve = function(name) { + for (let index = 0; index < _curvesData.length; index++) { + if (_curvesData[index].name === name) { + _curvesData.splice(index, 1); + computeGlobalCurvesRange(); + curvesChanged(); + break; + } + } + }; + this.isFull = function() { return this.curvesCount() === maxImportCount; }; diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 5d846590..6c015ac9 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1813,10 +1813,10 @@ GraphSpectrumPlot.importCurvesFromCSV = function(files) { GraphSpectrumPlot.removeImportedCurves = function() { switch (this._spectrumType) { case SPECTRUM_TYPE.FREQUENCY: - this._importedSpectrums.removeCurves(); + this._importedSpectrums.removeAllCurves(); break; case SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY: - this._importedPSD.removeCurves(); + this._importedPSD.removeAllCurves(); break; } }; From 3208711dbbabace0fea83a7fcce274694d1c7a1d Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 23 Jul 2025 18:02:08 +0300 Subject: [PATCH 41/44] The spectrum curve is deleted by Ctrl+Mouse click --- src/graph_spectrum.js | 21 +++++++++------- src/graph_spectrum_plot.js | 50 ++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index f333b824..215c0b7e 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -173,19 +173,26 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { this.plotSpectrum = function (fieldIndex, curve, fieldName) { // Detect change of selected field.... reload and redraw required. const isMaxCountOfImportedPSD = GraphSpectrumPlot.isImportedCurvesMaxCount() && userSettings.spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY; - const shouldReload = fftData == null || - fieldIndex != fftData.fieldIndex && !isMaxCountOfImportedPSD || // Lock spectrum data reload while PSD curves import is full - dataReload; + let shouldReload = fftData == null || + fieldIndex != fftData.fieldIndex && !isMaxCountOfImportedPSD || // Lock spectrum data reload while PSD curves import is full + dataReload; + + if (addSpectrumToImport && !GraphSpectrumPlot.isNewComparedCurve(fieldName)) { + GraphSpectrumPlot.removeComparedCurve(fieldName); + addSpectrumToImport = false; + shouldReload = false; // Do not load if spectrum was deleted + } + if (shouldReload) { if (this.shouldAddCurrentSpectrumBeforeReload()) { - this.addCurrentSpectrumIntoImport(); // The main curve is added into imported list when the second curve is selected for comparison + GraphSpectrumPlot.addCurrentSpectrumIntoImport(); // The main curve is added into imported list when the second curve is selected for comparison } dataReload = false; dataLoad(fieldIndex, curve, fieldName); GraphSpectrumPlot.setData(fftData, userSettings.spectrumType); } if (addSpectrumToImport) { - this.addCurrentSpectrumIntoImport(); + GraphSpectrumPlot.addCurrentSpectrumIntoImport(); addSpectrumToImport = false; } that.draw(); // draw the analyser on the canvas.... @@ -462,10 +469,6 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { return fileName; }; - this.addCurrentSpectrumIntoImport = function() { - GraphSpectrumPlot.addCurrentSpectrumIntoImport(); - }; - this.isMultiSpectrum = function() { return GraphSpectrumPlot.isMultiSpectrum(); }; diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 6c015ac9..15c3a9b5 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -358,25 +358,29 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { canvasCtx.translate(LEFT, TOP); this._drawGradientBackground(canvasCtx, WIDTH, HEIGHT); - canvasCtx.beginPath(); - canvasCtx.lineWidth = 1; - canvasCtx.strokeStyle = mainCurveColor; - for (let pointNum = 0; pointNum < pointsCount; pointNum++) { - const freq = this._fftData.blackBoxRate / 2 * pointNum / pointsCount; - if(freq > MAXIMAL_PLOTTED_FREQUENCY) { - break; - } - const y = HEIGHT - (this._fftData.fftOutput[pointNum] - minY) * scaleY; - if (pointNum === 0) { - canvasCtx.moveTo(freq * scaleX, y); - } else { - canvasCtx.lineTo(freq * scaleX, y); + const comparedSpectrumCount = this._importedPSD.curvesCount(); + + if (comparedSpectrumCount === 0) { // Draw main spectrum curve when there are no spectrums comparison only + canvasCtx.beginPath(); + canvasCtx.lineWidth = 1; + canvasCtx.strokeStyle = mainCurveColor; + for (let pointNum = 0; pointNum < pointsCount; pointNum++) { + const freq = this._fftData.blackBoxRate / 2 * pointNum / pointsCount; + if(freq > MAXIMAL_PLOTTED_FREQUENCY) { + break; + } + const y = HEIGHT - (this._fftData.fftOutput[pointNum] - minY) * scaleY; + if (pointNum === 0) { + canvasCtx.moveTo(freq * scaleX, y); + } else { + canvasCtx.lineTo(freq * scaleX, y); + } } + canvasCtx.stroke(); } - canvasCtx.stroke(); - const spectrumCount = this._importedPSD.curvesCount(); - for (let spectrumNum = 0; spectrumNum < spectrumCount; spectrumNum++) { + + for (let spectrumNum = 0; spectrumNum < comparedSpectrumCount; spectrumNum++) { const curvesPoints = this._importedPSD.getCurve(spectrumNum).points; canvasCtx.beginPath(); @@ -398,7 +402,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) { } //Legend draw - if (this._isFullScreen && spectrumCount > 0) { + if (this._isFullScreen && comparedSpectrumCount > 0) { this._drawLegend(canvasCtx, WIDTH, HEIGHT, this._importedPSD); } @@ -1821,9 +1825,13 @@ GraphSpectrumPlot.removeImportedCurves = function() { } }; +GraphSpectrumPlot.isNewComparedCurve = function(name) { + return this._importedPSD.isNewCurve(name); +} + GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY && - this._importedPSD.isNewCurve(this._fftData.fieldName)) { + this.isNewComparedCurve(this._fftData.fieldName)) { const fftLength = this._fftData.fftLength; const frequencyStep = 0.5 * this._fftData.blackBoxRate / fftLength; const points = []; @@ -1838,6 +1846,12 @@ GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { } }; +GraphSpectrumPlot.removeComparedCurve = function(name) { + this._importedPSD.removeCurve(name); + if (this._importedPSD.curvesCount() == 1 && this._importedPSD.getCurve(0).name !== this._fftData.fieldName) { + } +} + GraphSpectrumPlot.isMultiSpectrum = function() { return !this._importedPSD.isEmpty(); }; From 82b20409b5631d350f353db9da7e48b584183148 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 23 Jul 2025 18:07:58 +0300 Subject: [PATCH 42/44] Code refactoring: SpectrumForImport renamed to SpectrumForComparison --- src/graph_spectrum.js | 16 ++++++++-------- src/grapher.js | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 215c0b7e..0038852f 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -22,7 +22,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { analyserZoomY = 1.0 /* 100% */, dataReload = false, fftData = null, - addSpectrumToImport = false; + addSpectrumForComparison = false; try { let isFullscreen = false; @@ -48,9 +48,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { that.resize(); }; - this.prepareSpectrumForImport = function () { + this.prepareSpectrumForComparison = function () { if (userSettings.spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) { - addSpectrumToImport = true; + addSpectrumForComparison = true; } }; @@ -164,7 +164,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { }; this.shouldAddCurrentSpectrumBeforeReload = function () { - return addSpectrumToImport && fftData != null && !this.isMultiSpectrum() && !dataReload; + return addSpectrumForComparison && fftData != null && !this.isMultiSpectrum() && !dataReload; }; /* This function is called from the canvas drawing routines within grapher.js @@ -177,9 +177,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { fieldIndex != fftData.fieldIndex && !isMaxCountOfImportedPSD || // Lock spectrum data reload while PSD curves import is full dataReload; - if (addSpectrumToImport && !GraphSpectrumPlot.isNewComparedCurve(fieldName)) { + if (addSpectrumForComparison && !GraphSpectrumPlot.isNewComparedCurve(fieldName)) { GraphSpectrumPlot.removeComparedCurve(fieldName); - addSpectrumToImport = false; + addSpectrumForComparison = false; shouldReload = false; // Do not load if spectrum was deleted } @@ -191,9 +191,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { dataLoad(fieldIndex, curve, fieldName); GraphSpectrumPlot.setData(fftData, userSettings.spectrumType); } - if (addSpectrumToImport) { + if (addSpectrumForComparison) { GraphSpectrumPlot.addCurrentSpectrumIntoImport(); - addSpectrumToImport = false; + addSpectrumForComparison = false; } that.draw(); // draw the analyser on the canvas.... }; diff --git a/src/grapher.js b/src/grapher.js index 81ce2f40..4207fc2c 100644 --- a/src/grapher.js +++ b/src/grapher.js @@ -1243,7 +1243,7 @@ export function FlightLogGrapher( this.setDrawAnalyser = function (state, ctrlKey = false) { if (state) { if (ctrlKey) { - analyser.prepareSpectrumForImport(); + analyser.prepareSpectrumForComparison(); } else if (this.hasMultiSpectrumAnalyser()) { analyser.removeImportedSpectrums(); // Remove imported spectrums by simple mouse click at the any curves legend } From 1044f5b78447bedbf52c8cb55d8b75e279245c60 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 23 Jul 2025 18:18:32 +0300 Subject: [PATCH 43/44] Code issues are resolved --- src/graph_spectrum_plot.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/graph_spectrum_plot.js b/src/graph_spectrum_plot.js index 15c3a9b5..beeae463 100644 --- a/src/graph_spectrum_plot.js +++ b/src/graph_spectrum_plot.js @@ -1827,7 +1827,7 @@ GraphSpectrumPlot.removeImportedCurves = function() { GraphSpectrumPlot.isNewComparedCurve = function(name) { return this._importedPSD.isNewCurve(name); -} +}; GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY && @@ -1848,9 +1848,7 @@ GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() { GraphSpectrumPlot.removeComparedCurve = function(name) { this._importedPSD.removeCurve(name); - if (this._importedPSD.curvesCount() == 1 && this._importedPSD.getCurve(0).name !== this._fftData.fieldName) { - } -} +}; GraphSpectrumPlot.isMultiSpectrum = function() { return !this._importedPSD.isEmpty(); From f3157a35a59cd795c9ae459fec5894896eda2e4b Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 23 Jul 2025 19:59:48 +0300 Subject: [PATCH 44/44] Code style improvement --- src/graph_imported_curves.js | 8 ++++---- src/graph_spectrum.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/graph_imported_curves.js b/src/graph_imported_curves.js index 02862c3d..3c27dd30 100644 --- a/src/graph_imported_curves.js +++ b/src/graph_imported_curves.js @@ -1,5 +1,5 @@ export function ImportedCurves(curvesChanged) { - const maxImportCount = 6; // This value is limited by legends size and curves colors visibility. May be increased if needed by users + const MAX_IMPORT_COUNT = 6; // This value is limited by legends size and curves colors visibility. May be increased if needed by users const _curvesData = []; const _that = this; this.minX = Number.MAX_VALUE; @@ -20,7 +20,7 @@ export function ImportedCurves(curvesChanged) { }; this.importCurvesFromCSV = function(files) { - let importsLeft = maxImportCount - _curvesData.length; + let importsLeft = MAX_IMPORT_COUNT - _curvesData.length; for (const file of files) { if (importsLeft-- == 0) { @@ -105,7 +105,7 @@ export function ImportedCurves(curvesChanged) { }; this.addCurve = function(points, name) { - if (this.curvesCount() < maxImportCount) { + if (this.curvesCount() < MAX_IMPORT_COUNT) { const range = getCurveRange(points); _curvesData.push({ name: name, @@ -149,7 +149,7 @@ export function ImportedCurves(curvesChanged) { }; this.isFull = function() { - return this.curvesCount() === maxImportCount; + return this.curvesCount() === MAX_IMPORT_COUNT; }; this.isEmpty = function() { diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index 0038852f..99355af8 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -164,7 +164,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { }; this.shouldAddCurrentSpectrumBeforeReload = function () { - return addSpectrumForComparison && fftData != null && !this.isMultiSpectrum() && !dataReload; + return addSpectrumForComparison && fftData !== null && !this.isMultiSpectrum() && !dataReload; }; /* This function is called from the canvas drawing routines within grapher.js