Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3445871
Added sceletion of code to add PSD curves into import list by press I…
demvlad Jul 16, 2025
29d6d7b
Added one log PSD curves into import list by press Insert key to spec…
demvlad Jul 16, 2025
7104be8
Code issues improvement
demvlad Jul 16, 2025
4606c37
Code style improvement
demvlad Jul 16, 2025
bade57d
Code style improvement
demvlad Jul 16, 2025
91f8c4c
Added Add button to compare spectrums
demvlad Jul 16, 2025
6c52354
The Import Export Clear buttons captions are changed to short Exp,Imp…
demvlad Jul 16, 2025
0025b94
The spectrums legend height is improved
demvlad Jul 16, 2025
978f027
The spectrum Add button is visible for PSD curve only
demvlad Jul 16, 2025
4598757
Using of toggle method to change css property
demvlad Jul 16, 2025
45a620c
Added checking of maximal imported curves count
demvlad Jul 18, 2025
db9d05f
Code refactoring: using of getCurve method instead of direct _curvesD…
demvlad Jul 18, 2025
ed3fbc3
Code refactoring in graph_spectrum_plot: using getCurveColor method i…
demvlad Jul 18, 2025
a6f97c1
Code refactoring in graph_imported_curves.js: added using of trim method
demvlad Jul 18, 2025
3cb9365
Semi comma issue is resolved
demvlad Jul 18, 2025
f7f9861
Added IndexError exeption
demvlad Jul 18, 2025
2639ebc
Resolved missing operator new issue
demvlad Jul 18, 2025
6835774
Added Ctrl+Mouse click at curves legend action to show and compare it
demvlad Jul 19, 2025
879d950
Code style improvement
demvlad Jul 19, 2025
58d2721
The imported spectrums are removed by simple mouse click at the curve…
demvlad Jul 21, 2025
f24abd1
The main curve is added into imported list when the second curve is s…
demvlad Jul 21, 2025
674eb18
The main curve is added into imported list when the second curve is i…
demvlad Jul 21, 2025
0a26c66
Imported spectrums count is increased to 6
demvlad Jul 21, 2025
365932e
The spectrum comparison Add button and Insert key action are removed …
demvlad Jul 21, 2025
9885b71
Imported PSD curves drawing start point is improved
demvlad Jul 22, 2025
914f09c
Wrong IndexError exception is changed to RangeError
demvlad Jul 22, 2025
db0421f
Code style improvement
demvlad Jul 22, 2025
e037582
The imported curves drawing start position is improved by using moveTo
demvlad Jul 22, 2025
c25e56b
Using === !== instead of == !=
demvlad Jul 22, 2025
cbfc729
Improved spectrums legend vertical centering
demvlad Jul 22, 2025
b0dac04
Added comments for const values
demvlad Jul 22, 2025
3fb7ae2
The code refactoring for graph hasAnalyser variable condition
demvlad Jul 22, 2025
48e7039
Improved errors message for RangeError exception
demvlad Jul 22, 2025
26a62c8
The comments text is improved
demvlad Jul 22, 2025
8bda7d1
Code refactoring for main spectrum curve color
demvlad Jul 22, 2025
b55b887
The spectrums legend positions setup refactoring
demvlad Jul 22, 2025
7f0846e
The code refactoring for adding main spectrum curve to imported list
demvlad Jul 22, 2025
8965447
Added comment for first spectrums csv file import
demvlad Jul 22, 2025
9ec215b
Locked the curves PSD spectrum selection while import has maximal cur…
demvlad Jul 23, 2025
c947757
Added removeCurve and other helper methods into ImportedCurves
demvlad Jul 23, 2025
3208711
The spectrum curve is deleted by Ctrl+Mouse click
demvlad Jul 23, 2025
82b2040
Code refactoring: SpectrumForImport renamed to SpectrumForComparison
demvlad Jul 23, 2025
1044f5b
Code issues are resolved
demvlad Jul 23, 2025
f3157a3
Code style improvement
demvlad Jul 23, 2025
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
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,10 @@ <h4>Workspace</h4>
</div>

<div id="spectrumComparison" data-toggle="tooltip" title="Spectrum comparison">
<button id="btn-spectrum-export" type="button" title="Export spectrum to CSV">Export</button>
<button type="button" onclick="document.getElementById('btn-spectrum-import').click()" title="Import spectrum from CSV">Import</button>
<button id="btn-spectrum-export" type="button" title="Export spectrum to CSV">Exp</button>
<button type="button" onclick="document.getElementById('btn-spectrum-import').click()" title="Import spectrum from CSV">Imp</button>
<input type="file" id="btn-spectrum-import" accept=".csv" style="display:none" multiple/>
<button type="button" id="btn-spectrum-clear" title="Clear imported spectrums">Clear</button>
<button type="button" id="btn-spectrum-clear" title="Clear imported spectrums">Clr</button>
</div>

<div id="analyserResize" class="btn-nobg view-analyser-fullscreen" data-toggle="tooltip" title="Zoom Analyser Window">
Expand Down
197 changes: 140 additions & 57 deletions src/graph_imported_curves.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,158 @@
export function ImportedCurves(curvesChanged) {
const maxImportCount = 5;
this._curvesData = [];
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;
this.maxX = -Number.MAX_VALUE;
this.minY = Number.MAX_VALUE;
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 new RangeError(`The imported curves index (${index}) exceeds the maximum allowed value (${_curvesData.length - 1})`);
}
};

this.importCurvesFromCSV = function(files) {
let importsLeft = maxImportCount - this._curvesData.length;
let importsLeft = MAX_IMPORT_COUNT - _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");
}

stringRows.shift();
//remove bad last row
if (stringRows.at(-1) == "") {
stringRows.pop();
}

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,
};
});

const curve = {
name: file.name.split('.')[0],
points: curvesData,
};
_that._curvesData.push(curve);
curvesChanged();
} catch (e) {
alert('Curves data import error: ' + e.message);
return;
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].trim() !== "x" || header[1].trim() !== "y") {
throw new SyntaxError("Wrong curves CSV data format");
}
};

reader.readAsText(file);
}
stringRows.shift();
//remove bad last row
if (stringRows.at(-1) == "") {
stringRows.pop();
}

const curvesData = stringRows.map( function(row) {
const data = row.split(","),
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);
_that.maxY = Math.max(y, _that.maxY);
return {
x: x,
y: y,
};
});

const curve = {
name: file.name.split('.')[0],
points: curvesData,
};
_curvesData.push(curve);
curvesChanged();
} catch (e) {
alert('Curves data import error: ' + e.message);
return;
}
};

reader.readAsText(file);
}
};

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,
};
};

this.removeCurves = function() {
this._curvesData.length = 0;
this.minX = Number.MAX_VALUE;
this.maxX = -Number.MAX_VALUE;
this.minY = Number.MAX_VALUE;
this.maxY = -Number.MAX_VALUE;
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() < MAX_IMPORT_COUNT) {
const range = getCurveRange(points);
_curvesData.push({
name: name,
points: points,
range: range,
});

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();
}
};

this.isNewCurve = function(name) {
for (const curve of _curvesData) {
if (curve.name === name) {
return false;
}
}
return true;
};

this.removeAllCurves = function() {
_curvesData.length = 0;
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() === MAX_IMPORT_COUNT;
};

this.isEmpty = function() {
return this.curvesCount() === 0;
};
}
4 changes: 2 additions & 2 deletions src/graph_legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
41 changes: 38 additions & 3 deletions src/graph_spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
addSpectrumForComparison = false;

try {
let isFullscreen = false;
Expand All @@ -47,6 +48,12 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
that.resize();
};

this.prepareSpectrumForComparison = function () {
if (userSettings.spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) {
addSpectrumForComparison = true;
}
};

this.setInTime = function (time) {
dataReload = true;
return GraphSpectrumCalc.setInTime(time);
Expand Down Expand Up @@ -156,17 +163,38 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
}
};

this.shouldAddCurrentSpectrumBeforeReload = function () {
return addSpectrumForComparison && 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) {
const isMaxCountOfImportedPSD = GraphSpectrumPlot.isImportedCurvesMaxCount() && userSettings.spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY;
let shouldReload = fftData == null ||
fieldIndex != fftData.fieldIndex && !isMaxCountOfImportedPSD || // Lock spectrum data reload while PSD curves import is full
dataReload;

if (addSpectrumForComparison && !GraphSpectrumPlot.isNewComparedCurve(fieldName)) {
GraphSpectrumPlot.removeComparedCurve(fieldName);
addSpectrumForComparison = false;
shouldReload = false; // Do not load if spectrum was deleted
}

if (shouldReload) {
if (this.shouldAddCurrentSpectrumBeforeReload()) {
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 (addSpectrumForComparison) {
GraphSpectrumPlot.addCurrentSpectrumIntoImport();
addSpectrumForComparison = false;
}
that.draw(); // draw the analyser on the canvas....
};

Expand Down Expand Up @@ -354,6 +382,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").toggle(showAddSpectrumButton);
})
.change();

Expand Down Expand Up @@ -438,6 +469,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
return fileName;
};

this.isMultiSpectrum = function() {
return GraphSpectrumPlot.isMultiSpectrum();
};

} catch (e) {
console.error(`Failed to create analyser... error: ${e}`);
}
Expand Down
Loading