Skip to content

Commit 4d98eef

Browse files
demvladhaslinghuisnerdCopter
authored
Actual log rate computing and bad rpm values filtration for spectrum chart. (#711)
* added actual log rate computing * added: the warning is showed if actual and config log rate has big difference * code style improvement * Update js/graph_spectrum.js Co-authored-by: nerdCopter <[email protected]> * Update js/graph_spectrum_plot.js * added checking of RPM values in the spectrum charts * Update js/graph_spectrum.js The code style imprivement Co-authored-by: Mark Haslinghuis <[email protected]> * Update js/graph_spectrum_calc.js Code style improvement Co-authored-by: Mark Haslinghuis <[email protected]> * Update js/graph_spectrum_plot.js * Update js/graph_spectrum_calc.js --------- Co-authored-by: Mark Haslinghuis <[email protected]> Co-authored-by: nerdCopter <[email protected]>
1 parent cb53f08 commit 4d98eef

File tree

4 files changed

+171
-111
lines changed

4 files changed

+171
-111
lines changed

js/graph_config_dialog.js

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,41 @@ function GraphConfigurationDialog(dialog, onSave) {
77
offeredFieldNames = [],
88
exampleGraphs = [],
99
activeFlightLog;
10-
10+
1111

1212
function chooseColor(currentSelection) {
13-
var selectColor = $('<select class="color-picker"></select>');
14-
for(var i=0; i<GraphConfig.PALETTE.length; i++) {
15-
var option = $('<option></option>')
16-
.text(GraphConfig.PALETTE[i].name)
17-
.attr('value', GraphConfig.PALETTE[i].color)
18-
.css('color', GraphConfig.PALETTE[i].color);
19-
if(currentSelection == GraphConfig.PALETTE[i].color) {
20-
option.attr('selected', 'selected');
21-
selectColor.css('background', GraphConfig.PALETTE[i].color)
22-
.css('color', GraphConfig.PALETTE[i].color);
23-
}
24-
selectColor.append(option);
25-
}
26-
27-
return selectColor;
13+
var selectColor = $('<select class="color-picker"></select>');
14+
for(var i=0; i<GraphConfig.PALETTE.length; i++) {
15+
var option = $('<option></option>')
16+
.text(GraphConfig.PALETTE[i].name)
17+
.attr('value', GraphConfig.PALETTE[i].color)
18+
.css('color', GraphConfig.PALETTE[i].color);
19+
if(currentSelection == GraphConfig.PALETTE[i].color) {
20+
option.attr('selected', 'selected');
21+
selectColor.css('background', GraphConfig.PALETTE[i].color)
22+
.css('color', GraphConfig.PALETTE[i].color);
23+
}
24+
selectColor.append(option);
25+
}
26+
27+
return selectColor;
2828
}
29-
29+
3030
function chooseHeight(currentSelection) {
3131
var MAX_HEIGHT = 5;
3232

33-
var selectHeight = $('<select class="form-control graph-height"></select>');
34-
for(var i=1; i<=MAX_HEIGHT; i++) {
35-
var option = $('<option></option>')
36-
.text(i)
37-
.attr('value', i);
38-
if(currentSelection == i || (currentSelection==null && i==1)) {
39-
option.attr('selected', 'selected');
40-
}
41-
selectHeight.append(option);
42-
}
43-
44-
return selectHeight;
33+
var selectHeight = $('<select class="form-control graph-height"></select>');
34+
for(var i=1; i<=MAX_HEIGHT; i++) {
35+
var option = $('<option></option>')
36+
.text(i)
37+
.attr('value', i);
38+
if(currentSelection == i || (currentSelection==null && i==1)) {
39+
option.attr('selected', 'selected');
40+
}
41+
selectHeight.append(option);
42+
}
43+
44+
return selectHeight;
4545
}
4646

4747
// Show/Hide remove all button
@@ -67,18 +67,18 @@ function GraphConfigurationDialog(dialog, onSave) {
6767
}
6868

6969
function renderFieldOption(fieldName, selectedName) {
70-
var
70+
var
7171
option = $("<option></option>")
7272
.text(FlightLogFieldPresenter.fieldNameToFriendly(fieldName, activeFlightLog.getSysConfig().debug_mode))
7373
.attr("value", fieldName);
74-
74+
7575
if (fieldName == selectedName) {
7676
option.attr("selected", "selected");
7777
}
78-
78+
7979
return option;
8080
}
81-
81+
8282
// Set the current smoothing options for a field
8383
function renderSmoothingOptions(elem, flightLog, field) {
8484
if(elem) {
@@ -100,7 +100,7 @@ function GraphConfigurationDialog(dialog, onSave) {
100100
* initial selection.
101101
*/
102102
function renderField(flightLog, field, color) {
103-
var
103+
var
104104
elem = $(
105105
'<tr class="config-graph-field">'
106106
+ '<td><select class="form-control"><option value="">(choose a field)</option></select></td>'
@@ -116,11 +116,11 @@ function GraphConfigurationDialog(dialog, onSave) {
116116
select = $('select.form-control', elem),
117117
selectedFieldName = field ?field.name : false,
118118
i;
119-
119+
120120
for (i = 0; i < offeredFieldNames.length; i++) {
121121
select.append(renderFieldOption(offeredFieldNames[i], selectedFieldName));
122122
}
123-
123+
124124
// Set the smoothing values
125125
renderSmoothingOptions(elem, flightLog, field);
126126

@@ -132,7 +132,7 @@ function GraphConfigurationDialog(dialog, onSave) {
132132

133133
//Populate the Color Picker
134134
$('select.color-picker', elem).replaceWith(chooseColor(color));
135-
135+
136136

137137
// Add event when selection changed to retrieve the current smoothing settings.
138138
$('select.form-control', elem).change( function() {
@@ -147,13 +147,13 @@ function GraphConfigurationDialog(dialog, onSave) {
147147
$(this).css('background', $('select.color-picker option:selected', elem).val())
148148
.css('color', $('select.color-picker option:selected', elem).val());
149149
});
150-
150+
151151

152152
return elem;
153153
}
154-
154+
155155
function renderGraph(flightLog, index, graph) {
156-
var
156+
var
157157
graphElem = $(
158158
'<li class="config-graph" id="'+index+'">'
159159
+ '<dl>'
@@ -201,9 +201,9 @@ function GraphConfigurationDialog(dialog, onSave) {
201201
+ '</li>'
202202
),
203203
fieldList = $(".config-graph-field-list", graphElem);
204-
204+
205205
$("input", graphElem).val(graph.label);
206-
206+
207207
var fieldCount = graph.fields.length;
208208

209209
// "Add field" button
@@ -221,23 +221,23 @@ function GraphConfigurationDialog(dialog, onSave) {
221221
});
222222

223223
//Populate the Height seletor
224-
$('select.graph-height', graphElem).replaceWith(chooseHeight(graph.height?(graph.height):1));
224+
$('select.graph-height', graphElem).replaceWith(chooseHeight(graph.height?(graph.height):1));
225225

226226
// Add Field List
227227
for (var i = 0; i < graph.fields.length; i++) {
228-
var
228+
var
229229
field = graph.fields[i],
230230
fieldElem = renderField(flightLog, field, field.color?(field.color):(GraphConfig.PALETTE[i].color));
231-
231+
232232
fieldList.append(fieldElem);
233233
}
234-
234+
235235
fieldList.on('click', 'button', function(e) {
236236
var
237237
parentGraph = $(this).parents('.config-graph');
238-
238+
239239
$(this).parents('.config-graph-field').remove();
240-
240+
241241
// Remove the graph upon removal of the last field
242242
if ($(".config-graph-field", parentGraph).length === 0) {
243243
parentGraph.remove();
@@ -248,67 +248,67 @@ function GraphConfigurationDialog(dialog, onSave) {
248248
});
249249

250250
updateRemoveAllButton();
251-
251+
252252
return graphElem;
253253
}
254-
254+
255255
function renderGraphs(flightLog, graphs) {
256256
var
257257
graphList = $(".config-graphs-list", dialog);
258-
258+
259259
graphList.empty();
260-
260+
261261
for (var i = 0; i < graphs.length; i++) {
262262
graphList.append(renderGraph(flightLog, i, graphs[i]));
263263
}
264264
}
265-
265+
266266
function populateExampleGraphs(flightLog, menu) {
267267
var
268268
i;
269-
269+
270270
menu.empty();
271-
271+
272272
exampleGraphs = GraphConfig.getExampleGraphConfigs(flightLog);
273-
273+
274274
exampleGraphs.unshift({
275275
label: "Custom graph",
276276
fields: [{name:""}],
277277
dividerAfter: true
278278
});
279-
279+
280280
for (i = 0; i < exampleGraphs.length; i++) {
281-
var
281+
var
282282
graph = exampleGraphs[i],
283283
li = $('<li><a href="#"></a></li>');
284-
284+
285285
$('a', li)
286286
.text(graph.label)
287287
.data('graphIndex', i);
288-
288+
289289
menu.append(li);
290-
290+
291291
if (graph.dividerAfter) {
292292
menu.append('<li class="divider"></li>');
293293
}
294294
}
295295
}
296-
296+
297297
function convertUIToGraphConfig() {
298-
var
298+
var
299299
graphs = [],
300300
graph,
301301
field;
302-
302+
303303
$(".config-graph", dialog).each(function() {
304304
graph = {
305305
fields: [],
306306
height: 1
307307
};
308-
308+
309309
graph.label = $("input[type='text']", this).val();
310310
graph.height = parseInt($('select.graph-height option:selected', this).val());
311-
311+
312312
$(".config-graph-field", this).each(function() {
313313
field = {
314314
name: $("select", this).val(),
@@ -326,15 +326,15 @@ function GraphConfigurationDialog(dialog, onSave) {
326326
lineWidth: parseInt($("input[name=linewidth]", this).val()),
327327
grid: $('input[name=grid]', this).is(':checked'),
328328
};
329-
329+
330330
if (field.name.length > 0) {
331331
graph.fields.push(field);
332332
}
333333
});
334334

335335
graphs.push(graph);
336336
});
337-
337+
338338
return graphs;
339339
}
340340

@@ -345,64 +345,64 @@ function GraphConfigurationDialog(dialog, onSave) {
345345
lastRoot = null,
346346
fieldNames = flightLog.getMainFieldNames(),
347347
fieldsSeen = {};
348-
348+
349349
offeredFieldNames = [];
350-
350+
351351
for (i = 0; i < fieldNames.length; i++) {
352352
// For fields with multiple bracketed x[0], x[1] versions, add an "[all]" option
353-
var
353+
var
354354
fieldName = fieldNames[i],
355355
matches = fieldName.match(/^(.+)\[[0-9]+\]$/);
356-
356+
357357
if (BLACKLISTED_FIELDS[fieldName])
358358
continue;
359-
359+
360360
if (matches) {
361361
if (matches[1] != lastRoot) {
362362
lastRoot = matches[1];
363-
363+
364364
offeredFieldNames.push(lastRoot + "[all]");
365365
fieldsSeen[lastRoot + "[all]"] = true;
366366
}
367367
} else {
368368
lastRoot = null;
369369
}
370-
370+
371371
offeredFieldNames.push(fieldName);
372372
fieldsSeen[fieldName] = true;
373373
}
374-
375-
/*
374+
375+
/*
376376
* If the graph config has any fields in it that we don't have available in our flight log, add them to
377377
* the GUI anyway. (This way we can build a config when using a tricopter (which includes a tail servo) and
378378
* keep that tail servo in the config when we're viewing a quadcopter).
379379
*/
380380
for (i = 0; i < config.length; i++) {
381-
var
381+
var
382382
graph = config[i];
383-
383+
384384
for (j = 0; j < graph.fields.length; j++) {
385-
var
385+
var
386386
field = graph.fields[j];
387-
387+
388388
if (!fieldsSeen[field.name]) {
389389
offeredFieldNames.push(field.name);
390390
}
391391
}
392392
}
393393
}
394-
394+
395395
this.show = function(flightLog, config) {
396396
dialog.modal('show');
397-
397+
398398
activeFlightLog = flightLog;
399-
399+
400400
buildOfferedFieldNamesList(flightLog, config);
401401

402402
populateExampleGraphs(flightLog, exampleGraphsMenu);
403403
renderGraphs(flightLog, config);
404404
};
405-
405+
406406
$(".graph-configuration-dialog-save").click(function() {
407407
onSave(convertUIToGraphConfig());
408408
});
@@ -424,16 +424,16 @@ function GraphConfigurationDialog(dialog, onSave) {
424424

425425
exampleGraphsButton.dropdown();
426426
exampleGraphsMenu.on("click", "a", function(e) {
427-
var
427+
var
428428
graph = exampleGraphs[$(this).data("graphIndex")],
429429
graphElem = renderGraph(activeFlightLog, $(".config-graph", dialog).length, graph);
430-
430+
431431
$(configGraphsList, dialog).append(graphElem);
432432
updateRemoveAllButton();
433-
433+
434434
// Dismiss the dropdown button
435435
exampleGraphsButton.dropdown("toggle");
436-
436+
437437
e.preventDefault();
438438
});
439439

0 commit comments

Comments
 (0)