Skip to content

Commit d5bd7a7

Browse files
authored
The multi-file spectrum comparison (#782)
* Multiple spectrums file adding and curves showing are made * The clearImportedSpectrums method is added * The spectrum comparison Users interface improvement * Added 'Clear' button to remove imported cpectrums * Spectrum comparison users interface is visile in spectrum by frequency mode only * Spectrum comparison buttons style is improved * missing semicoma issue is resolved
1 parent 576a7d7 commit d5bd7a7

File tree

5 files changed

+95
-69
lines changed

5 files changed

+95
-69
lines changed

index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,14 @@ <h4>Workspace</h4>
472472
<option value="5">Auto</option>
473473
</select>
474474
</div>
475-
<div id="spectrumExport" data-toggle="tooltip" title="Export spectrum to CSV">
476-
<button id="btn-spectrum-export" type="button">Export to CSV</button>
477-
</div>
478-
<div id="spectrumImport" data-toggle="tooltip" title="Import spectrum from CSV">
479-
<button type="button" onclick="document.getElementById('btn-spectrum-import').click()">Import from CSV</button>
480-
<input type="file" id="btn-spectrum-import" accept=".csv" style="display:none" multiple/>
475+
476+
<div id="spectrumComparison" data-toggle="tooltip" title="Spectrum comparison">
477+
<button id="btn-spectrum-export" type="button" class="spectrum-comparasion-button" title="Export spectrum to CSV">Export</button>
478+
<button type="button" class="spectrum-comparasion-button" onclick="document.getElementById('btn-spectrum-import').click()" title="Import spectrum from CSV">Import</button>
479+
<input type="file" id="btn-spectrum-import" accept=".csv" style="display:none" multiple/>
480+
<button type="button" id="btn-spectrum-clear" class="spectrum-comparasion-button" title="Clear imported spectrums">Clear</button>
481481
</div>
482+
482483
<div id="analyserResize" class="btn-nobg view-analyser-fullscreen" data-toggle="tooltip" title="Zoom Analyser Window">
483484
<span class="glyphicon glyphicon-resize-full"></span>
484485
<span class="glyphicon glyphicon-resize-small"></span>
@@ -745,7 +746,7 @@ <h5 class="modal-title-revision"></h5>
745746
<script>
746747
const axes = ['Roll', 'Pitch', 'Yaw'];
747748
const pidTbody = document.getElementById('pid_tbody');
748-
749+
749750
axes.forEach(axis => {
750751
const row = `<tr class="${axis.toLowerCase()}PID">
751752
<td>${axis}</td>

src/css/main.css

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,13 @@ html.has-analyser-fullscreen.has-analyser
629629
color: black;
630630
}
631631

632-
.analyser:hover .non-shift #spectrumExport {
632+
.analyser:hover .non-shift #spectrumComparison {
633633
opacity: 1;
634634
height: auto;
635635
transition: opacity 500ms ease-in;
636636
}
637637

638-
.analyser #spectrumExport {
638+
.analyser #spectrumComparison {
639639
height: 0;
640640
overflow: hidden;
641641
opacity: 0;
@@ -644,37 +644,22 @@ html.has-analyser-fullscreen.has-analyser
644644
z-index: 9;
645645
position: absolute;
646646
font-size: 9px;
647+
border: gray;
648+
border-style: solid;
649+
border-width: 1px;
647650
}
648651

649-
.analyser #spectrumExport select {
652+
.analyser #spectrumComparison select {
650653
border-radius: 3px;
651654
padding: 0px 5px;
652655
color: black;
653656
}
654657

655-
.analyser:hover .non-shift #spectrumImport {
656-
opacity: 1;
657-
height: auto;
658-
transition: opacity 500ms ease-in;
659-
}
660-
661-
.analyser #spectrumImport {
662-
height: 0;
663-
width: 55px;
664-
overflow: hidden;
665-
opacity: 0;
666-
left: 310px;
667-
float: left;
668-
z-index: 9;
669-
position: absolute;
670-
font-size: 9px;
671-
}
672-
673-
.analyser #spectrumImport select {
658+
.spectrum-comparasion-button {
659+
width: 100%;
674660
border-radius: 3px;
675-
padding: 0px 5px;
676-
color: black;
677661
}
662+
678663
.analyser input#analyserZoomX {
679664
width: 100px;
680665
height: 10px;

src/graph_spectrum.js

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
226226
pidErrorVsSetpointSelected
227227
);
228228

229-
$("#btn-spectrum-export").attr("disabled", optionSelected != 0);
229+
$("#spectrumComparison").css("visibility", (optionSelected == 0 ? "visible" : "hidden"));
230230
})
231231
.change();
232232

@@ -289,35 +289,49 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
289289
this.exportSpectrumToCSV = function(onSuccess, options) {
290290
SpectrumExporter(fftData, options).dump(onSuccess);
291291
};
292+
292293
this.importSpectrumFromCSV = function(files) {
293-
const reader = new FileReader();
294-
reader.onload = function (e) {
295-
try {
296-
const stringRows = e.target.result.split("\n");
297-
298-
const header = stringRows[0].split(",");
299-
if (header.length != 2 || header[0] != "freq" || header[1] != "value") {
300-
throw new SyntaxError("Wrong spectrum CSV data format");
294+
const maxImportCount = 5;
295+
for (const file of files) {
296+
if (GraphSpectrumPlot.getImportedSpectrumCount() == maxImportCount) {
297+
break;
298+
}
299+
300+
const reader = new FileReader();
301+
reader.onload = function (e) {
302+
try {
303+
const stringRows = e.target.result.split("\n");
304+
305+
const header = stringRows[0].split(",");
306+
if (header.length != 2 || header[0] != "freq" || header[1] != "value") {
307+
throw new SyntaxError("Wrong spectrum CSV data format");
308+
}
309+
310+
stringRows.shift();
311+
const spectrumData = stringRows.map( function(row) {
312+
const data = row.split(",");
313+
return {
314+
freq: parseFloat(data[0]),
315+
value: parseFloat(data[1]),
316+
};
317+
});
318+
319+
GraphSpectrumPlot.addImportedSpectrumData(spectrumData);
320+
} catch (e) {
321+
alert('Spectrum data import error: ' + e.message);
322+
return;
301323
}
324+
};
302325

303-
stringRows.shift();
304-
const spectrumData = stringRows.map( function(row) {
305-
const data = row.split(",");
306-
return {
307-
freq: parseFloat(data[0]),
308-
value: parseFloat(data[1]),
309-
};
310-
});
311-
GraphSpectrumPlot.setImportedSpectrumData(spectrumData);
312-
} catch (e) {
313-
alert('Spectrum data import error: ' + e.message);
314-
return;
315-
}
316-
};
317-
reader.readAsText(files[0]);
326+
reader.readAsText(file);
327+
}
318328
};
319329

320330
} catch (e) {
321331
console.log(`Failed to create analyser... error: ${e}`);
322332
}
333+
334+
this.clearImportedSpectrums = function() {
335+
GraphSpectrumPlot.clearImportedSpectrums();
336+
};
323337
}

src/graph_spectrum_plot.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const GraphSpectrumPlot = window.GraphSpectrumPlot || {
4747
fontSizeFrameLabel: "6",
4848
fontSizeFrameLabelFullscreen: "9",
4949
},
50+
_importedSpectrumsData: [],
5051
};
5152

5253
GraphSpectrumPlot.initialize = function (canvas, sysConfig) {
@@ -57,7 +58,6 @@ GraphSpectrumPlot.initialize = function (canvas, sysConfig) {
5758
this._logRateWarning = undefined;
5859
this._zoomX = 1;
5960
this._zoomY = 1;
60-
this._importedSpectrumData = null;
6161
};
6262

6363
GraphSpectrumPlot.setZoom = function (zoomX, zoomY) {
@@ -90,12 +90,24 @@ GraphSpectrumPlot.setData = function (fftData, spectrumType) {
9090
this._invalidateDataCache();
9191
};
9292

93-
GraphSpectrumPlot.setImportedSpectrumData = function (curvesData) {
94-
this._importedSpectrumData = curvesData;
93+
GraphSpectrumPlot.getImportedSpectrumCount = function () {
94+
return this._importedSpectrumsData.length;
95+
};
96+
97+
GraphSpectrumPlot.addImportedSpectrumData = function (curvesData) {
98+
this._importedSpectrumsData.push(curvesData);
99+
this._invalidateCache();
100+
this._invalidateDataCache();
101+
GraphSpectrumPlot.draw();
102+
};
103+
104+
GraphSpectrumPlot.clearImportedSpectrums = function (curvesData) {
105+
this._importedSpectrumsData.length = 0;
95106
this._invalidateCache();
96107
this._invalidateDataCache();
97108
GraphSpectrumPlot.draw();
98109
};
110+
99111
GraphSpectrumPlot.setOverdraw = function (overdrawType) {
100112
this._overdrawType = overdrawType;
101113
this._invalidateCache();
@@ -204,19 +216,27 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) {
204216
}
205217

206218

207-
//Draw imported spectrum
208-
if (this._importedSpectrumData) {
209-
const curvesPonts = this._importedSpectrumData;
219+
//Draw imported spectrums
220+
const curvesColors = [
221+
"Blue",
222+
"Purple",
223+
"DeepPink",
224+
"DarkCyan",
225+
"Chocolate",
226+
];
227+
228+
for (let spectrumNum = 0; spectrumNum < this._importedSpectrumsData.length; spectrumNum++) {
229+
const curvesPonts = this._importedSpectrumsData[spectrumNum];
210230
const pointsCount = curvesPonts.length;
211231
const scaleX = 2 * WIDTH / PLOTTED_BLACKBOX_RATE * this._zoomX;
212232

213233
canvasCtx.beginPath();
214-
canvasCtx.strokeStyle = "blue";
234+
canvasCtx.strokeStyle = curvesColors[spectrumNum];
215235
canvasCtx.moveTo(0, HEIGHT);
216-
const filterPointsCount = 20;
217-
for (let i = 0; i < pointsCount; i++) {
236+
const filterPointsCount = 50;
237+
for (let pointNum = 0; pointNum < pointsCount; pointNum++) {
218238
// Apply moving average filter at spectrum points to get visible line
219-
let filterStartPoint = i - filterPointsCount / 2;
239+
let filterStartPoint = pointNum - filterPointsCount / 2;
220240
if (filterStartPoint < 0) {
221241
filterStartPoint = 0;
222242
}
@@ -229,15 +249,16 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) {
229249
}
230250
}
231251
let middleValue = 0;
232-
for (let j = filterStartPoint; j < filterStopPoint; j++) {
233-
middleValue += curvesPonts[j].value;
252+
for (let i = filterStartPoint; i < filterStopPoint; i++) {
253+
middleValue += curvesPonts[i].value;
234254
}
235255
middleValue /= filterPointsCount;
236256

237-
canvasCtx.lineTo(curvesPonts[i].freq * scaleX, HEIGHT - middleValue * fftScale);
257+
canvasCtx.lineTo(curvesPonts[pointNum].freq * scaleX, HEIGHT - middleValue * fftScale);
238258
}
239259
canvasCtx.stroke();
240260
}
261+
241262
this._drawAxisLabel(
242263
canvasCtx,
243264
this._fftData.fieldName,

src/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,6 @@ function BlackboxLogViewer() {
17311731
});
17321732

17331733
$("#btn-spectrum-export").click(function (e) {
1734-
setGraphState(GRAPH_STATE_PAUSED);
17351734
exportSpectrumToCsv("bf_spectrum");
17361735
e.preventDefault();
17371736
});
@@ -1741,6 +1740,12 @@ function BlackboxLogViewer() {
17411740
e.preventDefault();
17421741
e.target.value = "";
17431742
});
1743+
1744+
$("#btn-spectrum-clear").click(function (e) {
1745+
graph.getAnalyser().clearImportedSpectrums();
1746+
e.preventDefault();
1747+
});
1748+
17441749
$(".btn-gpx-export").click(function (e) {
17451750
setGraphState(GRAPH_STATE_PAUSED);
17461751
exportGpx();

0 commit comments

Comments
 (0)