From 7cb31bc9c7b2bf467efb6b5b3cbbbfb7cb531334 Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 20 May 2024 21:31:20 +0300 Subject: [PATCH 01/19] added group fields name extender function in graph_config.js --- src/graph_config.js | 122 +++++++++++++++++++------------------ src/graph_config_dialog.js | 21 ++++++- src/main.js | 4 +- 3 files changed, 84 insertions(+), 63 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index 8e990f4e..671bf0f8 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -44,13 +44,68 @@ export function GraphConfig(graphConfig) { } }; + this.extendFields = function(flightLog, field) { + const matches = field.name.match(/^(.+)\[all\]$/); + const logFieldNames = flightLog.getMainFieldNames(); + const fields = []; + if (matches) { + const + nameRoot = matches[1], + nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"); + let colorIndexOffset = 0; + + for (var k = 0; k < logFieldNames.length; k++) { + if (logFieldNames[k].match(nameRegex)) { + // forceNewCurve must be true for min max computing extended curves. + const forceNewCurve = true; + fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), name: logFieldNames[k], friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(logFieldNames[k], flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); + colorIndexOffset++; + } + } + } else { + // Don't add fields if they don't exist in this log + if (flightLog.getMainFieldIndexByName(field.name) !== undefined) { + fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(field.name, flightLog.getSysConfig().debug_mode)}))); + } + } + return fields; + } + + var adaptField = function(flightLog, field, colorIndexOffset, forceNewCurve) { + const defaultCurve = GraphConfig.getDefaultCurveForField(flightLog, field.name); + + if (field.curve === undefined || forceNewCurve) { + field.curve = defaultCurve; + } else { + if (field.curve.MinMax == undefined) + field.curve.MinMax = defaultCurve.MinMax; + } + + if(colorIndexOffset!=null && field.color != undefined) { // auto offset the actual color (to expand [all] selections) + let index; + for(index=0; index < GraphConfig.PALETTE.length; index++) { + if(GraphConfig.PALETTE[index].color == field.color) break; + } + field.color = GraphConfig.PALETTE[(index + colorIndexOffset) % GraphConfig.PALETTE.length].color + } + + if (field.color === undefined) { + field.color = GraphConfig.PALETTE[colorIndex % GraphConfig.PALETTE.length].color; + colorIndex++; + } + + if (field.smoothing === undefined) { + field.smoothing = GraphConfig.getDefaultSmoothingForField(flightLog, field.name); + } + + return field; + }; + /** * Convert the given graph configs to make them appropriate for the given flight log. */ - this.adaptGraphs = function(flightLog, graphs, isNewLog) { + this.adaptGraphs = function(flightLog, graphs) { var - logFieldNames = flightLog.getMainFieldNames(), - // Make copies of graphs into here so we can modify them without wrecking caller's copy newGraphs = []; @@ -71,63 +126,10 @@ export function GraphConfig(graphConfig) { ), colorIndex = 0; - for (var j = 0; j < graph.fields.length; j++) { - var - field = graph.fields[j], - matches; - - var adaptField = function(field, colorIndexOffset, forceNewCurve) { - const defaultCurve = GraphConfig.getDefaultCurveForField(flightLog, field.name); - - if (field.curve === undefined || forceNewCurve) { - field.curve = defaultCurve; - } - else { - if (field.curve.MinMax == undefined) - field.curve.MinMax = defaultCurve.MinMax; - } - - if(colorIndexOffset!=null && field.color != undefined) { // auto offset the actual color (to expand [all] selections) - var index; - for(index=0; index < GraphConfig.PALETTE.length; index++) - { - if(GraphConfig.PALETTE[index].color == field.color) break; - } - field.color = GraphConfig.PALETTE[(index + colorIndexOffset) % GraphConfig.PALETTE.length].color - } - - if (field.color === undefined) { - field.color = GraphConfig.PALETTE[colorIndex % GraphConfig.PALETTE.length].color; - colorIndex++; - } - - if (field.smoothing === undefined) { - field.smoothing = GraphConfig.getDefaultSmoothingForField(flightLog, field.name); - } - - return field; - }; - - if ((matches = field.name.match(/^(.+)\[all\]$/))) { - var - nameRoot = matches[1], - nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"), - colorIndexOffset = 0; - - for (var k = 0; k < logFieldNames.length; k++) { - if (logFieldNames[k].match(nameRegex)) { - // forceNewCurve must be true for min max computing extended curves. - let forceNewCurve = true; - newGraph.fields.push(adaptField($.extend({}, field, {curve: $.extend({}, field.curve), name: logFieldNames[k], friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(logFieldNames[k], flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); - colorIndexOffset++; - } - } - } else { - // Don't add fields if they don't exist in this log - if (flightLog.getMainFieldIndexByName(field.name) !== undefined) { - newGraph.fields.push(adaptField($.extend({}, field, {curve: $.extend({}, field.curve), friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(field.name, flightLog.getSysConfig().debug_mode)}))); - } - } + for (let j = 0; j < graph.fields.length; j++) { + const field = graph.fields[j]; + const fields = this.extendFields(flightLog, field); + newGraph.fields = newGraph.fields.concat(fields); } newGraphs.push(newGraph); diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 5675fb6c..30c6eab9 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -149,8 +149,27 @@ export function GraphConfigurationDialog(dialog, onSave) { $('select.form-control', elem).change( function() { var selectedField = { name: $('select.form-control option:selected', elem).val() - }; + }, matches; + var + logFieldNames = flightLog.getMainFieldNames(); + if ((matches = selectedField.name.match(/^(.+)\[all\]$/))) { + var + nameRoot = matches[1], + nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"), + colorIndexOffset = 0; + + for (var k = 0; k < logFieldNames.length; k++) { + if (logFieldNames[k].match(nameRegex)) { + // forceNewCurve must be true for min max computing extended curves. + let forceNewCurve = true; + newGraph.fields.push(adaptField($.extend({}, field, {curve: $.extend({}, field.curve), name: logFieldNames[k], friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(logFieldNames[k], flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); + colorIndexOffset++; + } + } + } renderSmoothingOptions(elem, activeFlightLog, selectedField); + let row = renderField(flightLog, selectedField, color) ; + elem.after(row); RefreshCharts(); }); diff --git a/src/main.js b/src/main.js index f43c0bd3..f2f13500 100644 --- a/src/main.js +++ b/src/main.js @@ -675,7 +675,7 @@ function BlackboxLogViewer() { setVideoInTime(false); setVideoOutTime(false); - activeGraphConfig.adaptGraphs(flightLog, graphConfig, true); + activeGraphConfig.adaptGraphs(flightLog, graphConfig); graph.onSeek = function(offset) { //Seek faster @@ -1006,7 +1006,7 @@ function BlackboxLogViewer() { lastGraphConfig = graphConfig; // Remember the last configuration. graphConfig = newConfig; activeGraphConfig.setRedrawChart(noRedraw ? false : true); - activeGraphConfig.adaptGraphs(flightLog, graphConfig, false); + activeGraphConfig.adaptGraphs(flightLog, graphConfig); prefs.set('graphConfig', graphConfig); } From 3dd794c5477dd32f7456436bbb34c9c62407bf1b Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 21 May 2024 14:04:53 +0300 Subject: [PATCH 02/19] The group curves selection is self extended in charts setup dialog box --- src/graph_config.js | 14 ++++++------- src/graph_config_dialog.js | 41 +++++++++++++++++--------------------- src/main.js | 2 +- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index 671bf0f8..e79c9c8b 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -55,12 +55,12 @@ export function GraphConfig(graphConfig) { let colorIndexOffset = 0; for (var k = 0; k < logFieldNames.length; k++) { - if (logFieldNames[k].match(nameRegex)) { - // forceNewCurve must be true for min max computing extended curves. - const forceNewCurve = true; - fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), name: logFieldNames[k], friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(logFieldNames[k], flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); - colorIndexOffset++; - } + if (logFieldNames[k].match(nameRegex)) { + // forceNewCurve must be true for min max computing extended curves. + const forceNewCurve = true; + fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), name: logFieldNames[k], friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(logFieldNames[k], flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); + colorIndexOffset++; + } } } else { // Don't add fields if they don't exist in this log @@ -73,7 +73,7 @@ export function GraphConfig(graphConfig) { var adaptField = function(flightLog, field, colorIndexOffset, forceNewCurve) { const defaultCurve = GraphConfig.getDefaultCurveForField(flightLog, field.name); - + let colorIndex = 0; if (field.curve === undefined || forceNewCurve) { field.curve = defaultCurve; } else { diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 30c6eab9..3e27d3fc 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -13,6 +13,7 @@ export function GraphConfigurationDialog(dialog, onSave) { activeFlightLog, logGrapher = null, prevCfg = null, + activeGraphConfig = null, cfgMustBeRestored = false; function chooseColor(currentSelection) { @@ -128,7 +129,7 @@ export function GraphConfigurationDialog(dialog, onSave) { + '' ), select = $('select.form-control', elem), - selectedFieldName = field ?field.name : false, + selectedFieldName = field ? field.name : false, i; for (i = 0; i < offeredFieldNames.length; i++) { @@ -147,29 +148,21 @@ export function GraphConfigurationDialog(dialog, onSave) { // Add event when selection changed to retrieve the current smoothing settings. $('select.form-control', elem).change( function() { - var selectedField = { + const selectedField = { name: $('select.form-control option:selected', elem).val() - }, matches; - var - logFieldNames = flightLog.getMainFieldNames(); - if ((matches = selectedField.name.match(/^(.+)\[all\]$/))) { - var - nameRoot = matches[1], - nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"), - colorIndexOffset = 0; - - for (var k = 0; k < logFieldNames.length; k++) { - if (logFieldNames[k].match(nameRegex)) { - // forceNewCurve must be true for min max computing extended curves. - let forceNewCurve = true; - newGraph.fields.push(adaptField($.extend({}, field, {curve: $.extend({}, field.curve), name: logFieldNames[k], friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(logFieldNames[k], flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); - colorIndexOffset++; - } - } + }; + const fields = activeGraphConfig.extendFields(activeFlightLog, selectedField); + if (fields.length === 1) { + renderSmoothingOptions(elem, activeFlightLog, fields[0]); + } else { + for (let i = 0; i < fields.length - 1; ++i) { + const row = renderField(flightLog, fields[i], fields[i].color) ; + elem.before(row); } - renderSmoothingOptions(elem, activeFlightLog, selectedField); - let row = renderField(flightLog, selectedField, color) ; - elem.after(row); + const index = $('select.form-control', elem).prop('selectedIndex'); + $('select.form-control', elem).prop('selectedIndex', index + fields.length); + renderSmoothingOptions(elem, activeFlightLog, fields[fields.length - 1]); + } RefreshCharts(); }); @@ -468,10 +461,12 @@ export function GraphConfigurationDialog(dialog, onSave) { } } - this.show = function(flightLog, config, grapher) { + this.show = function(flightLog, graphConfig, grapher) { dialog.modal('show'); activeFlightLog = flightLog; logGrapher = grapher; + activeGraphConfig = graphConfig; + const config = activeGraphConfig.getGraphs() buildOfferedFieldNamesList(flightLog, config); diff --git a/src/main.js b/src/main.js index f2f13500..cca03d86 100644 --- a/src/main.js +++ b/src/main.js @@ -1446,7 +1446,7 @@ function BlackboxLogViewer() { $(".open-graph-configuration-dialog").click(function(e) { e.preventDefault(); - graphConfigDialog.show(flightLog, activeGraphConfig.getGraphs(), graph); + graphConfigDialog.show(flightLog, activeGraphConfig, graph); }); $(".open-header-dialog").click(function(e) { From 7ae4422d03208f597ac8c9c50f8f266506ef5670 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 21 May 2024 14:36:22 +0300 Subject: [PATCH 03/19] Code style improvement --- src/graph_config.js | 4 ++-- src/graph_config_dialog.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index e79c9c8b..6067afb7 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -81,10 +81,10 @@ export function GraphConfig(graphConfig) { field.curve.MinMax = defaultCurve.MinMax; } - if(colorIndexOffset!=null && field.color != undefined) { // auto offset the actual color (to expand [all] selections) + if (colorIndexOffset!=null && field.color != undefined) { // auto offset the actual color (to expand [all] selections) let index; for(index=0; index < GraphConfig.PALETTE.length; index++) { - if(GraphConfig.PALETTE[index].color == field.color) break; + if (GraphConfig.PALETTE[index].color == field.color) break; } field.color = GraphConfig.PALETTE[(index + colorIndexOffset) % GraphConfig.PALETTE.length].color } diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 3e27d3fc..83702e6e 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -23,7 +23,7 @@ export function GraphConfigurationDialog(dialog, onSave) { .text(GraphConfig.PALETTE[i].name) .attr('value', GraphConfig.PALETTE[i].color) .css('color', GraphConfig.PALETTE[i].color); - if(currentSelection == GraphConfig.PALETTE[i].color) { + if (currentSelection == GraphConfig.PALETTE[i].color) { option.attr('selected', 'selected'); selectColor.css('background', GraphConfig.PALETTE[i].color) .css('color', GraphConfig.PALETTE[i].color); @@ -42,7 +42,7 @@ export function GraphConfigurationDialog(dialog, onSave) { const option = $('') .text(i) .attr('value', i); - if(currentSelection == i || (currentSelection==null && i==1)) { + if (currentSelection == i || (currentSelection==null && i==1)) { option.attr('selected', 'selected'); } selectHeight.append(option); @@ -88,7 +88,7 @@ export function GraphConfigurationDialog(dialog, onSave) { // Set the current smoothing options for a field function renderSmoothingOptions(elem, flightLog, field) { - if(elem) { + if (elem) { // the smoothing is in uS rather than %, scale the value somewhere between 0 and 10000uS $('input[name=smoothing]',elem).val((field.smoothing!=null)?(field.smoothing/100).toFixed(0)+'%':(GraphConfig.getDefaultSmoothingForField(flightLog, field.name)/100)+'%'); if (field.curve != null) { @@ -140,7 +140,7 @@ export function GraphConfigurationDialog(dialog, onSave) { renderSmoothingOptions(elem, flightLog, field); // Set the line width values - $('input[name=linewidth]',elem).val((field.lineWidth)?field.lineWidth:1); + $('input[name=linewidth]',elem).val((field.lineWidth) ? field.lineWidth : 1); //Populate the Color Picker $('select.color-picker', elem).replaceWith(chooseColor(color)); From 67c7591958c8ce9517cd48dbcf80f06e1d755a15 Mon Sep 17 00:00:00 2001 From: demvlad Date: Tue, 21 May 2024 22:08:39 +0300 Subject: [PATCH 04/19] added curves auto color after extend of curves group --- src/graph_config_dialog.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 83702e6e..59d2ff27 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -155,8 +155,9 @@ export function GraphConfigurationDialog(dialog, onSave) { if (fields.length === 1) { renderSmoothingOptions(elem, activeFlightLog, fields[0]); } else { + let fieldCount = elem.parent()[0].childElementCount; for (let i = 0; i < fields.length - 1; ++i) { - const row = renderField(flightLog, fields[i], fields[i].color) ; + const row = renderField(flightLog, fields[i], GraphConfig.PALETTE[fieldCount++].color) ; elem.before(row); } const index = $('select.form-control', elem).prop('selectedIndex'); @@ -264,7 +265,7 @@ export function GraphConfigurationDialog(dialog, onSave) { $("input", graphElem).val(graph.label); - var fieldCount = graph.fields.length; + let fieldCount = graph.fields.length; // "Add field" button $(".add-field-button", graphElem).click(function(e) { From 608c6d8b088f1c54841d7eb49b0088724b1cca07 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 22 May 2024 13:49:43 +0300 Subject: [PATCH 05/19] added group fields auto fill after charts samples selection --- src/graph_config_dialog.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 59d2ff27..6342a0ec 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -286,16 +286,24 @@ export function GraphConfigurationDialog(dialog, onSave) { $('select.graph-height', graphElem).replaceWith(chooseHeight(graph.height?(graph.height):1)); // Add Field List - for (var i = 0; i < graph.fields.length; i++) { - var - field = graph.fields[i], + for (let i = 0; i < graph.fields.length; i++) { + let fieldElem; + const field = graph.fields[i]; + const fields = activeGraphConfig.extendFields(activeFlightLog, field); + if (fields.length === 1) { fieldElem = renderField(flightLog, field, field.color?(field.color):(GraphConfig.PALETTE[i].color)); - - fieldList.append(fieldElem); + fieldList.append(fieldElem); + } else { + let fieldCount = i + 1; + for (let i = 0; i < fields.length; ++i) { + fieldElem = renderField(flightLog, fields[i], GraphConfig.PALETTE[fieldCount++].color) ; + fieldList.append(fieldElem); + } + } } fieldList.on('click', 'button', function(e) { - var + let parentGraph = $(this).parents('.config-graph'); $(this).parents('.config-graph-field').remove(); From ef3133125151d645edc56999bcc52678ba08e395 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 22 May 2024 14:02:22 +0300 Subject: [PATCH 06/19] code style improvement --- src/graph_config.js | 42 ++++++++++++++-------------- src/graph_config_dialog.js | 56 ++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index 6067afb7..9d96b2c8 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -3,13 +3,13 @@ import { DSHOT_MIN_VALUE, DSHOT_RANGE, RATES_TYPE, DEBUG_MODE } from "./flightlo import { escapeRegExp } from "./tools"; export function GraphConfig(graphConfig) { - var + let graphs = graphConfig ? graphConfig : [], listeners = [], that = this; function notifyListeners() { - for (var i = 0; i < listeners.length; i++) { + for (let i = 0; i < listeners.length; i++) { listeners[i](that); } } @@ -54,7 +54,7 @@ export function GraphConfig(graphConfig) { nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"); let colorIndexOffset = 0; - for (var k = 0; k < logFieldNames.length; k++) { + for (let k = 0; k < logFieldNames.length; k++) { if (logFieldNames[k].match(nameRegex)) { // forceNewCurve must be true for min max computing extended curves. const forceNewCurve = true; @@ -71,7 +71,7 @@ export function GraphConfig(graphConfig) { return fields; } - var adaptField = function(flightLog, field, colorIndexOffset, forceNewCurve) { + let adaptField = function(flightLog, field, colorIndexOffset, forceNewCurve) { const defaultCurve = GraphConfig.getDefaultCurveForField(flightLog, field.name); let colorIndex = 0; if (field.curve === undefined || forceNewCurve) { @@ -105,12 +105,12 @@ export function GraphConfig(graphConfig) { * Convert the given graph configs to make them appropriate for the given flight log. */ this.adaptGraphs = function(flightLog, graphs) { - var + let // Make copies of graphs into here so we can modify them without wrecking caller's copy newGraphs = []; - for (var i = 0; i < graphs.length; i++) { - var + for (let i = 0; i < graphs.length; i++) { + let graph = graphs[i], newGraph = $.extend( // Default values for missing properties: @@ -175,11 +175,11 @@ GraphConfig.PALETTE = [ GraphConfig.load = function(config) { // Upgrade legacy configs to suit the newer standard by translating field names if (config) { - for (var i = 0; i < config.length; i++) { - var graph = config[i]; + for (let i = 0; i < config.length; i++) { + let graph = config[i]; - for (var j = 0; j < graph.fields.length; j++) { - var + for (let j = 0; j < graph.fields.length; j++) { + let field = graph.fields[j], matches; @@ -216,10 +216,10 @@ GraphConfig.load = function(config) { }; GraphConfig.getDefaultCurveForField = function(flightLog, fieldName) { - var + let sysConfig = flightLog.getSysConfig(); - var maxDegreesSecond = function(scale) { + let maxDegreesSecond = function(scale) { switch(sysConfig["rates_type"]){ case RATES_TYPE.indexOf('ACTUAL'): case RATES_TYPE.indexOf('QUICK'): @@ -233,7 +233,7 @@ GraphConfig.load = function(config) { } } - var getMinMaxForFields = function(/* fieldName1, fieldName2, ... */) { + let getMinMaxForFields = function(/* fieldName1, fieldName2, ... */) { // helper to make a curve scale based on the combined min/max of one or more fields let min = Number.MAX_VALUE, @@ -252,7 +252,7 @@ GraphConfig.load = function(config) { return {min:-500, max:500}; } - var getCurveForMinMaxFields = function(/* fieldName1, fieldName2, ... */) { + let getCurveForMinMaxFields = function(/* fieldName1, fieldName2, ... */) { const mm = getMinMaxForFields.apply(null, arguments); // added convertation min max values from log file units to friendly chart const mmChartUnits = @@ -266,7 +266,7 @@ GraphConfig.load = function(config) { }; } - var getCurveForMinMaxFieldsZeroOffset = function(/* fieldName1, fieldName2, ... */) { + let getCurveForMinMaxFieldsZeroOffset = function(/* fieldName1, fieldName2, ... */) { const mm = getMinMaxForFields.apply(null, arguments); // added convertation min max values from log file units to friendly chart let mmChartUnits = @@ -419,7 +419,7 @@ GraphConfig.load = function(config) { }; } else if (fieldName.match(/^debug.*/) && sysConfig.debug_mode!=null) { - var debugModeName = DEBUG_MODE[sysConfig.debug_mode]; + let debugModeName = DEBUG_MODE[sysConfig.debug_mode]; switch (debugModeName) { case 'CYCLETIME': switch (fieldName) { @@ -560,7 +560,7 @@ GraphConfig.load = function(config) { max: 50 } }; - case 'debug[3]': // Vario + case 'debug[3]': // letio return { power: 1.0, MinMax: { @@ -1347,7 +1347,7 @@ GraphConfig.load = function(config) { * Supply an array of strings `graphNames` to only fetch the graph with the given names. */ GraphConfig.getExampleGraphConfigs = function(flightLog, graphNames) { - var + let result = [], i, j; @@ -1399,7 +1399,7 @@ GraphConfig.load = function(config) { } for (i = 0; i < EXAMPLE_GRAPHS.length; i++) { - var + let srcGraph = EXAMPLE_GRAPHS[i], destGraph = { label: srcGraph.label, @@ -1423,7 +1423,7 @@ GraphConfig.load = function(config) { } for (j = 0; j < srcGraph.fields.length; j++) { - var + let srcFieldName = srcGraph.fields[j], destField = { name: srcFieldName diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 6342a0ec..df477740 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -53,7 +53,7 @@ export function GraphConfigurationDialog(dialog, onSave) { // Show/Hide remove all button function updateRemoveAllButton() { - var graphCount = $('.config-graph').length; + let graphCount = $('.config-graph').length; if (graphCount > 0) { $('.config-graphs-remove-all-graphs').show(); @@ -65,16 +65,16 @@ export function GraphConfigurationDialog(dialog, onSave) { // Renumber the "Graph X" blocks after additions/deletions function renumberGraphIndexes() { - var graphIndexes = $('.graph-index-number'); - var graphCount = graphIndexes.length; - for (var i = 0; i < graphCount; i++) { - var currentGraphNumber = i+1; - $(graphIndexes[i]).html(currentGraphNumber); - } - } + let graphIndexes = $('.graph-index-number'); + let graphCount = graphIndexes.length; + for (let i = 0; i < graphCount; i++) { + let currentGraphNumber = i+1; + $(graphIndexes[i]).html(currentGraphNumber); + } + } function renderFieldOption(fieldName, selectedName) { - var + let option = $("") .text(FlightLogFieldPresenter.fieldNameToFriendly(fieldName, activeFlightLog.getSysConfig().debug_mode)) .attr("value", fieldName); @@ -115,7 +115,7 @@ export function GraphConfigurationDialog(dialog, onSave) { * initial selection. */ function renderField(flightLog, field, color) { - var + const elem = $( '' + '' @@ -129,10 +129,9 @@ export function GraphConfigurationDialog(dialog, onSave) { + '' ), select = $('select.form-control', elem), - selectedFieldName = field ? field.name : false, - i; + selectedFieldName = field ? field.name : false; - for (i = 0; i < offeredFieldNames.length; i++) { + for (let i = 0; i < offeredFieldNames.length; i++) { select.append(renderFieldOption(offeredFieldNames[i], selectedFieldName)); } @@ -207,7 +206,7 @@ export function GraphConfigurationDialog(dialog, onSave) { } function renderGraph(flightLog, index, graph) { - var + const graphElem = $( '
  • ' + '
    ' @@ -275,7 +274,7 @@ export function GraphConfigurationDialog(dialog, onSave) { // "Remove Graph" button $(".remove-single-graph-button", graphElem).click(function(e) { - var parentGraph = $(this).parents('.config-graph'); + let parentGraph = $(this).parents('.config-graph'); parentGraph.remove(); updateRemoveAllButton(); RefreshCharts(); @@ -323,20 +322,17 @@ export function GraphConfigurationDialog(dialog, onSave) { } function renderGraphs(flightLog, graphs) { - var + let graphList = $(".config-graphs-list", dialog); graphList.empty(); - for (var i = 0; i < graphs.length; i++) { + for (let i = 0; i < graphs.length; i++) { graphList.append(renderGraph(flightLog, i, graphs[i])); } } function populateExampleGraphs(flightLog, menu) { - var - i; - menu.empty(); exampleGraphs = GraphConfig.getExampleGraphConfigs(flightLog); @@ -347,8 +343,8 @@ export function GraphConfigurationDialog(dialog, onSave) { dividerAfter: true }); - for (i = 0; i < exampleGraphs.length; i++) { - var + for (let i = 0; i < exampleGraphs.length; i++) { + let graph = exampleGraphs[i], li = $('
  • '); @@ -365,7 +361,7 @@ export function GraphConfigurationDialog(dialog, onSave) { } function convertUIToGraphConfig() { - var + let graphs = [], graph, field; @@ -418,7 +414,7 @@ export function GraphConfigurationDialog(dialog, onSave) { // Decide which fields we should offer to the user function buildOfferedFieldNamesList(flightLog, config) { - var + let i, j, lastRoot = null, fieldNames = flightLog.getMainFieldNames(), @@ -428,7 +424,7 @@ export function GraphConfigurationDialog(dialog, onSave) { for (i = 0; i < fieldNames.length; i++) { // For fields with multiple bracketed x[0], x[1] versions, add an "[all]" option - var + let fieldName = fieldNames[i], matches = fieldName.match(/^(.+)\[[0-9]+\]$/); @@ -456,11 +452,11 @@ export function GraphConfigurationDialog(dialog, onSave) { * keep that tail servo in the config when we're viewing a quadcopter). */ for (i = 0; i < config.length; i++) { - var + let graph = config[i]; for (j = 0; j < graph.fields.length; j++) { - var + let field = graph.fields[j]; if (!fieldsSeen[field.name]) { @@ -527,7 +523,7 @@ export function GraphConfigurationDialog(dialog, onSave) { onSave(convertUIToGraphConfig(), noRedraw); } - var + let exampleGraphsButton = $(".config-graphs-add"), exampleGraphsMenu = $(".config-graphs-add ~ .dropdown-menu"), configGraphsList = $('.config-graphs-list'); @@ -543,7 +539,7 @@ export function GraphConfigurationDialog(dialog, onSave) { exampleGraphsButton.dropdown(); exampleGraphsMenu.on("click", "a", function(e) { - var + let graph = exampleGraphs[$(this).data("graphIndex")], graphElem = renderGraph(activeFlightLog, $(".config-graph", dialog).length, graph); @@ -559,7 +555,7 @@ export function GraphConfigurationDialog(dialog, onSave) { }); // Remove all Graphs button - var removeAllGraphsButton = $(".config-graphs-remove-all-graphs"); + let removeAllGraphsButton = $(".config-graphs-remove-all-graphs"); removeAllGraphsButton.on("click", function() { $('.config-graph').remove(); updateRemoveAllButton(); From 176de6896f6c424c89c3eff798ae63d7fef8fc88 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 22 May 2024 19:14:26 +0300 Subject: [PATCH 07/19] the code is simplified --- src/graph_config_dialog.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index df477740..aa6a4b78 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -289,15 +289,10 @@ export function GraphConfigurationDialog(dialog, onSave) { let fieldElem; const field = graph.fields[i]; const fields = activeGraphConfig.extendFields(activeFlightLog, field); - if (fields.length === 1) { - fieldElem = renderField(flightLog, field, field.color?(field.color):(GraphConfig.PALETTE[i].color)); + let fieldCount = i + 1; + for (let j = 0; j < fields.length; ++j) { + fieldElem = renderField(flightLog, fields[j], GraphConfig.PALETTE[fieldCount++].color) ; fieldList.append(fieldElem); - } else { - let fieldCount = i + 1; - for (let i = 0; i < fields.length; ++i) { - fieldElem = renderField(flightLog, fields[i], GraphConfig.PALETTE[fieldCount++].color) ; - fieldList.append(fieldElem); - } } } From 063cc62cae3179d0a08c72a577cf459eb4384a43 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 22 May 2024 21:19:39 +0300 Subject: [PATCH 08/19] Update graph_config.js Resolve code style issue --- src/graph_config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_config.js b/src/graph_config.js index 9d96b2c8..45969449 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -78,7 +78,7 @@ export function GraphConfig(graphConfig) { field.curve = defaultCurve; } else { if (field.curve.MinMax == undefined) - field.curve.MinMax = defaultCurve.MinMax; + field.curve.MinMax = defaultCurve.MinMax; } if (colorIndexOffset!=null && field.color != undefined) { // auto offset the actual color (to expand [all] selections) From 4c4263a6c099d28835cc9aa88a22d75e28e95c18 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 22 May 2024 21:28:22 +0300 Subject: [PATCH 09/19] Update graph_config.js Resolved semicolon issue --- src/graph_config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_config.js b/src/graph_config.js index 45969449..b60edc30 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -69,7 +69,7 @@ export function GraphConfig(graphConfig) { } } return fields; - } + }; let adaptField = function(flightLog, field, colorIndexOffset, forceNewCurve) { const defaultCurve = GraphConfig.getDefaultCurveForField(flightLog, field.name); From cbae3298903d1822fe57cb5b6c994fb3b4e7decf Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 22 May 2024 21:41:39 +0300 Subject: [PATCH 10/19] Update graph_config.js Removed unusing variable --- src/graph_config.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index b60edc30..a5920088 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -122,9 +122,8 @@ export function GraphConfig(graphConfig) { // New fields to replace the old ones: { fields:[], - }, - ), - colorIndex = 0; + } + ); for (let j = 0; j < graph.fields.length; j++) { const field = graph.fields[j]; From e8573c5ad965dc587f62bb0318008b1de6c30a0e Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 22 May 2024 21:47:02 +0300 Subject: [PATCH 11/19] Update graph_config.js Resolved code style issue --- src/graph_config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_config.js b/src/graph_config.js index a5920088..94fe7ca8 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -122,7 +122,7 @@ export function GraphConfig(graphConfig) { // New fields to replace the old ones: { fields:[], - } + }, ); for (let j = 0; j < graph.fields.length; j++) { From cd9a20c23cadfbbdbfbf2c0c5dff63e4fdb0261e Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 22 May 2024 21:50:42 +0300 Subject: [PATCH 12/19] Update graph_config_dialog.js Resolved semicoma missing --- src/graph_config_dialog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index aa6a4b78..2366a627 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -466,7 +466,7 @@ export function GraphConfigurationDialog(dialog, onSave) { activeFlightLog = flightLog; logGrapher = grapher; activeGraphConfig = graphConfig; - const config = activeGraphConfig.getGraphs() + const config = activeGraphConfig.getGraphs(); buildOfferedFieldNamesList(flightLog, config); @@ -556,4 +556,4 @@ export function GraphConfigurationDialog(dialog, onSave) { updateRemoveAllButton(); RefreshCharts(); }); -} \ No newline at end of file +} From 459f526e12576985a7d430f5544dfe458365ab70 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Wed, 22 May 2024 21:58:25 +0300 Subject: [PATCH 13/19] Update main.js Code style improvement --- src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index cca03d86..ce592312 100644 --- a/src/main.js +++ b/src/main.js @@ -38,7 +38,7 @@ import defaultWorkspaceGraphConfigs from './workspaces-ctzsnooze.json'; // TODO: this is a hack, once we move to web fix this globalThis.userSettings = null; -var VIEWER_VERSION = getManifestVersion(); // Current version +const VIEWER_VERSION = getManifestVersion(); // Current version // these values set the initial dimensions of a secondary window // which always opens at the centre of the user's screen From ced7b8f08ecae7ef987c2c8376744c25246dcf7e Mon Sep 17 00:00:00 2001 From: demvlad Date: Thu, 23 May 2024 20:08:33 +0300 Subject: [PATCH 14/19] Code style improvement: the for loops are changed to for of --- src/graph_config.js | 48 +++++++++++++++----------------------- src/graph_config_dialog.js | 41 ++++++++++++-------------------- 2 files changed, 34 insertions(+), 55 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index 94fe7ca8..1affb571 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -9,8 +9,8 @@ export function GraphConfig(graphConfig) { that = this; function notifyListeners() { - for (let i = 0; i < listeners.length; i++) { - listeners[i](that); + for (const listener of listeners) { + listener(that); } } @@ -54,11 +54,11 @@ export function GraphConfig(graphConfig) { nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"); let colorIndexOffset = 0; - for (let k = 0; k < logFieldNames.length; k++) { - if (logFieldNames[k].match(nameRegex)) { + for (const fieldName of logFieldNames) { + if (fieldName.match(nameRegex)) { // forceNewCurve must be true for min max computing extended curves. const forceNewCurve = true; - fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), name: logFieldNames[k], friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(logFieldNames[k], flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); + fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), name: fieldName, friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(fieldName, flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); colorIndexOffset++; } } @@ -105,14 +105,12 @@ export function GraphConfig(graphConfig) { * Convert the given graph configs to make them appropriate for the given flight log. */ this.adaptGraphs = function(flightLog, graphs) { - let + const // Make copies of graphs into here so we can modify them without wrecking caller's copy newGraphs = []; - for (let i = 0; i < graphs.length; i++) { - let - graph = graphs[i], - newGraph = $.extend( + for (const graph of graphs) { + const newGraph = $.extend( // Default values for missing properties: { height: 1, @@ -125,8 +123,7 @@ export function GraphConfig(graphConfig) { }, ); - for (let j = 0; j < graph.fields.length; j++) { - const field = graph.fields[j]; + for (const field of graph.fields) { const fields = this.extendFields(flightLog, field); newGraph.fields = newGraph.fields.concat(fields); } @@ -174,15 +171,10 @@ GraphConfig.PALETTE = [ GraphConfig.load = function(config) { // Upgrade legacy configs to suit the newer standard by translating field names if (config) { - for (let i = 0; i < config.length; i++) { - let graph = config[i]; - - for (let j = 0; j < graph.fields.length; j++) { - let - field = graph.fields[j], - matches; - - if ((matches = field.name.match(/^gyroData(.+)$/))) { + for (const graph of config) { + for (const field of graph.fields) { + const matches = field.name.match(/^gyroData(.+)$/); + if (matches) { field.name = "gyroADC" + matches[1]; } } @@ -238,8 +230,8 @@ GraphConfig.load = function(config) { min = Number.MAX_VALUE, max = -Number.MAX_VALUE; - for(let i in arguments) { - const mm = flightLog.getMinMaxForFieldDuringAllTime(arguments[i]); + for(const argument of arguments) { + const mm = flightLog.getMinMaxForFieldDuringAllTime(argument); min = Math.min(mm.min, min); max = Math.max(mm.max, max); } @@ -1409,8 +1401,8 @@ GraphConfig.load = function(config) { if (graphNames !== undefined) { found = false; - for (j = 0; j < graphNames.length; j++) { - if (srcGraph.label == graphNames[j]) { + for (const name of graphNames) { + if (srcGraph.label == name[j]) { found = true; break; } @@ -1421,10 +1413,8 @@ GraphConfig.load = function(config) { } } - for (j = 0; j < srcGraph.fields.length; j++) { - let - srcFieldName = srcGraph.fields[j], - destField = { + for (const srcFieldName of srcGraph.fields) { + const destField = { name: srcFieldName }; diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 2366a627..77658377 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -131,8 +131,8 @@ export function GraphConfigurationDialog(dialog, onSave) { select = $('select.form-control', elem), selectedFieldName = field ? field.name : false; - for (let i = 0; i < offeredFieldNames.length; i++) { - select.append(renderFieldOption(offeredFieldNames[i], selectedFieldName)); + for (const field of offeredFieldNames) { + select.append(renderFieldOption(field, selectedFieldName)); } // Set the smoothing values @@ -285,13 +285,12 @@ export function GraphConfigurationDialog(dialog, onSave) { $('select.graph-height', graphElem).replaceWith(chooseHeight(graph.height?(graph.height):1)); // Add Field List - for (let i = 0; i < graph.fields.length; i++) { + for (let i=0; i
  • '); + for (let i=0; i < exampleGraphs.length; ++i) { + const li = $('
  • '); $('a', li) - .text(graph.label) + .text(exampleGraphs[i].label) .data('graphIndex', i); menu.append(li); - if (graph.dividerAfter) { + if (exampleGraphs[i].dividerAfter) { menu.append('
  • '); } } @@ -417,11 +414,9 @@ export function GraphConfigurationDialog(dialog, onSave) { offeredFieldNames = []; - for (i = 0; i < fieldNames.length; i++) { + for (const fieldName of fieldNames) { // For fields with multiple bracketed x[0], x[1] versions, add an "[all]" option - let - fieldName = fieldNames[i], - matches = fieldName.match(/^(.+)\[[0-9]+\]$/); + const matches = fieldName.match(/^(.+)\[[0-9]+\]$/); if (BLACKLISTED_FIELDS[fieldName]) continue; @@ -446,14 +441,8 @@ export function GraphConfigurationDialog(dialog, onSave) { * the GUI anyway. (This way we can build a config when using a tricopter (which includes a tail servo) and * keep that tail servo in the config when we're viewing a quadcopter). */ - for (i = 0; i < config.length; i++) { - let - graph = config[i]; - - for (j = 0; j < graph.fields.length; j++) { - let - field = graph.fields[j]; - + for (const graph of config) { + for (const field of graph.fields) { if (!fieldsSeen[field.name]) { offeredFieldNames.push(field.name); } From 6ce74f1d927f8ec39f64b22503dcd366daf98791 Mon Sep 17 00:00:00 2001 From: demvlad Date: Thu, 23 May 2024 20:19:05 +0300 Subject: [PATCH 15/19] Code style improvement --- src/graph_config_dialog.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 77658377..9f71b1ef 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -406,8 +406,7 @@ export function GraphConfigurationDialog(dialog, onSave) { // Decide which fields we should offer to the user function buildOfferedFieldNamesList(flightLog, config) { - let - i, j, + let lastRoot = null, fieldNames = flightLog.getMainFieldNames(), fieldsSeen = {}; From 52b7551df81e9475b6a2378895726ec7ee05d438 Mon Sep 17 00:00:00 2001 From: demvlad Date: Thu, 23 May 2024 20:37:00 +0300 Subject: [PATCH 16/19] Code style improvement --- src/graph_config.js | 2 +- src/graph_config_dialog.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index 1affb571..01bf67cb 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -83,7 +83,7 @@ export function GraphConfig(graphConfig) { if (colorIndexOffset!=null && field.color != undefined) { // auto offset the actual color (to expand [all] selections) let index; - for(index=0; index < GraphConfig.PALETTE.length; index++) { + for(index = 0; index < GraphConfig.PALETTE.length; index++) { if (GraphConfig.PALETTE[index].color == field.color) break; } field.color = GraphConfig.PALETTE[(index + colorIndexOffset) % GraphConfig.PALETTE.length].color diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 9f71b1ef..7001437d 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -18,7 +18,7 @@ export function GraphConfigurationDialog(dialog, onSave) { function chooseColor(currentSelection) { const selectColor = $(''); - for(let i=0; i') .text(GraphConfig.PALETTE[i].name) .attr('value', GraphConfig.PALETTE[i].color) @@ -38,7 +38,7 @@ export function GraphConfigurationDialog(dialog, onSave) { const MAX_HEIGHT = 5; const selectHeight = $(''); - for(let i=1; i<=MAX_HEIGHT; i++) { + for(let i = 1; i <= MAX_HEIGHT; i++) { const option = $('') .text(i) .attr('value', i); @@ -155,7 +155,7 @@ export function GraphConfigurationDialog(dialog, onSave) { renderSmoothingOptions(elem, activeFlightLog, fields[0]); } else { let fieldCount = elem.parent()[0].childElementCount; - for (let i = 0; i < fields.length - 1; ++i) { + for (let i = 0; i < fields.length - 1; i++) { const row = renderField(flightLog, fields[i], GraphConfig.PALETTE[fieldCount++].color) ; elem.before(row); } @@ -285,7 +285,7 @@ export function GraphConfigurationDialog(dialog, onSave) { $('select.graph-height', graphElem).replaceWith(chooseHeight(graph.height?(graph.height):1)); // Add Field List - for (let i=0; i'); $('a', li) From 486fcd35c3a9cd69d3b041adf9ab3539c9a84dca Mon Sep 17 00:00:00 2001 From: demvlad Date: Sun, 26 May 2024 22:44:14 +0300 Subject: [PATCH 17/19] resolved issue of wrong curves color draw on Chart setup dialog box --- src/graph_config_dialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 7001437d..c688114c 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -290,7 +290,7 @@ export function GraphConfigurationDialog(dialog, onSave) { const extendedFields = activeGraphConfig.extendFields(activeFlightLog, graph.fields[i]); let fieldCount = i + 1; for (const extField of extendedFields) { - fieldElem = renderField(flightLog, extField, GraphConfig.PALETTE[fieldCount++].color) ; + fieldElem = renderField(flightLog, extField, extField.color ? (extField.color) : (GraphConfig.PALETTE[fieldCount++].color)) ; fieldList.append(fieldElem); } } From 594e34e4d0224d96d04da08ca9afde27122a381a Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 27 May 2024 19:04:19 +0300 Subject: [PATCH 18/19] Improve curves collor assign --- src/graph_config.js | 57 ++++++++++++------------------------ src/graph_config_dialog.js | 60 +++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 68 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index 01bf67cb..325ead24 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -3,10 +3,9 @@ import { DSHOT_MIN_VALUE, DSHOT_RANGE, RATES_TYPE, DEBUG_MODE } from "./flightlo import { escapeRegExp } from "./tools"; export function GraphConfig(graphConfig) { - let - graphs = graphConfig ? graphConfig : [], - listeners = [], - that = this; + const listeners = []; + const that = this; + let graphs = graphConfig ? graphConfig : []; function notifyListeners() { for (const listener of listeners) { @@ -52,14 +51,13 @@ export function GraphConfig(graphConfig) { const nameRoot = matches[1], nameRegex = new RegExp("^" + escapeRegExp(nameRoot) + "\[[0-9]+\]$"); - let colorIndexOffset = 0; for (const fieldName of logFieldNames) { if (fieldName.match(nameRegex)) { // forceNewCurve must be true for min max computing extended curves. const forceNewCurve = true; - fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), name: fieldName, friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(fieldName, flightLog.getSysConfig().debug_mode)}), colorIndexOffset, forceNewCurve)); - colorIndexOffset++; + field.color = undefined; + fields.push(adaptField(flightLog, $.extend({}, field, {curve: $.extend({}, field.curve), name: fieldName, friendlyName: FlightLogFieldPresenter.fieldNameToFriendly(fieldName, flightLog.getSysConfig().debug_mode)}), forceNewCurve)); } } } else { @@ -71,9 +69,8 @@ export function GraphConfig(graphConfig) { return fields; }; - let adaptField = function(flightLog, field, colorIndexOffset, forceNewCurve) { + let adaptField = function(flightLog, field, forceNewCurve) { const defaultCurve = GraphConfig.getDefaultCurveForField(flightLog, field.name); - let colorIndex = 0; if (field.curve === undefined || forceNewCurve) { field.curve = defaultCurve; } else { @@ -81,19 +78,6 @@ export function GraphConfig(graphConfig) { field.curve.MinMax = defaultCurve.MinMax; } - if (colorIndexOffset!=null && field.color != undefined) { // auto offset the actual color (to expand [all] selections) - let index; - for(index = 0; index < GraphConfig.PALETTE.length; index++) { - if (GraphConfig.PALETTE[index].color == field.color) break; - } - field.color = GraphConfig.PALETTE[(index + colorIndexOffset) % GraphConfig.PALETTE.length].color - } - - if (field.color === undefined) { - field.color = GraphConfig.PALETTE[colorIndex % GraphConfig.PALETTE.length].color; - colorIndex++; - } - if (field.smoothing === undefined) { field.smoothing = GraphConfig.getDefaultSmoothingForField(flightLog, field.name); } @@ -207,7 +191,7 @@ GraphConfig.load = function(config) { }; GraphConfig.getDefaultCurveForField = function(flightLog, fieldName) { - let + const sysConfig = flightLog.getSysConfig(); let maxDegreesSecond = function(scale) { @@ -260,7 +244,7 @@ GraphConfig.load = function(config) { let getCurveForMinMaxFieldsZeroOffset = function(/* fieldName1, fieldName2, ... */) { const mm = getMinMaxForFields.apply(null, arguments); // added convertation min max values from log file units to friendly chart - let mmChartUnits = + const mmChartUnits = { min: FlightLogFieldPresenter.ConvertFieldValue(flightLog, fieldName, true, mm.min), max: FlightLogFieldPresenter.ConvertFieldValue(flightLog, fieldName, true, mm.max) @@ -410,7 +394,7 @@ GraphConfig.load = function(config) { }; } else if (fieldName.match(/^debug.*/) && sysConfig.debug_mode!=null) { - let debugModeName = DEBUG_MODE[sysConfig.debug_mode]; + const debugModeName = DEBUG_MODE[sysConfig.debug_mode]; switch (debugModeName) { case 'CYCLETIME': switch (fieldName) { @@ -551,7 +535,7 @@ GraphConfig.load = function(config) { max: 50 } }; - case 'debug[3]': // letio + case 'debug[3]': // vario return { power: 1.0, MinMax: { @@ -1275,7 +1259,7 @@ GraphConfig.load = function(config) { const minTime = WindowCenterTime - WindowWidthTime/2; const maxTime = WindowCenterTime + WindowWidthTime/2; - let mm = flightLog.getMinMaxForFieldDuringTimeInterval(fieldName, minTime, maxTime); + const mm = flightLog.getMinMaxForFieldDuringTimeInterval(fieldName, minTime, maxTime); if (mm == undefined) return { min: -500, @@ -1302,7 +1286,7 @@ GraphConfig.load = function(config) { if (maxTime == false) maxTime = flightLog.getMaxTime(); - let mm = flightLog.getMinMaxForFieldDuringTimeInterval(fieldName, minTime, maxTime); + const mm = flightLog.getMinMaxForFieldDuringTimeInterval(fieldName, minTime, maxTime); if (mm == undefined) return { min: -500, @@ -1319,7 +1303,7 @@ GraphConfig.load = function(config) { * @param fieldName Name of the field */ GraphConfig.getMinMaxForFieldDuringAllTime = function(flightLog, fieldName) { - let mm = flightLog.getMinMaxForFieldDuringAllTime(fieldName); + const mm = flightLog.getMinMaxForFieldDuringAllTime(fieldName); if (mm.min == Number.MAX_VALUE || mm.max == -Number.MAX_VALUE) { return { min: -500, @@ -1338,10 +1322,7 @@ GraphConfig.load = function(config) { * Supply an array of strings `graphNames` to only fetch the graph with the given names. */ GraphConfig.getExampleGraphConfigs = function(flightLog, graphNames) { - let - result = [], - i, j; - + const result = []; const EXAMPLE_GRAPHS = []; if (!flightLog.isFieldDisabled().MOTORS) { @@ -1389,20 +1370,20 @@ GraphConfig.load = function(config) { EXAMPLE_GRAPHS.push({label: "GPS",fields: ["GPS_numSat", "GPS_altitude", "GPS_speed", "GPS_ground_course", "GPS_coord[all]"]}); } - for (i = 0; i < EXAMPLE_GRAPHS.length; i++) { - let + for (let i = 0; i < EXAMPLE_GRAPHS.length; i++) { + const srcGraph = EXAMPLE_GRAPHS[i], destGraph = { label: srcGraph.label, fields: [], height: srcGraph.height || 1 - }, - found; + }; + let found; if (graphNames !== undefined) { found = false; for (const name of graphNames) { - if (srcGraph.label == name[j]) { + if (srcGraph.label == name) { found = true; break; } diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index c688114c..04a170ea 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -53,7 +53,7 @@ export function GraphConfigurationDialog(dialog, onSave) { // Show/Hide remove all button function updateRemoveAllButton() { - let graphCount = $('.config-graph').length; + const graphCount = $('.config-graph').length; if (graphCount > 0) { $('.config-graphs-remove-all-graphs').show(); @@ -65,8 +65,8 @@ export function GraphConfigurationDialog(dialog, onSave) { // Renumber the "Graph X" blocks after additions/deletions function renumberGraphIndexes() { - let graphIndexes = $('.graph-index-number'); - let graphCount = graphIndexes.length; + const graphIndexes = $('.graph-index-number'); + const graphCount = graphIndexes.length; for (let i = 0; i < graphCount; i++) { let currentGraphNumber = i+1; $(graphIndexes[i]).html(currentGraphNumber); @@ -74,7 +74,7 @@ export function GraphConfigurationDialog(dialog, onSave) { } function renderFieldOption(fieldName, selectedName) { - let + const option = $("") .text(FlightLogFieldPresenter.fieldNameToFriendly(fieldName, activeFlightLog.getSysConfig().debug_mode)) .attr("value", fieldName); @@ -154,14 +154,20 @@ export function GraphConfigurationDialog(dialog, onSave) { if (fields.length === 1) { renderSmoothingOptions(elem, activeFlightLog, fields[0]); } else { - let fieldCount = elem.parent()[0].childElementCount; + let colorIndex = $('select.color-picker', elem).prop('selectedIndex') for (let i = 0; i < fields.length - 1; i++) { - const row = renderField(flightLog, fields[i], GraphConfig.PALETTE[fieldCount++].color) ; + const color = GraphConfig.PALETTE[colorIndex++ % GraphConfig.PALETTE.length].color; + const row = renderField(flightLog, fields[i], color) ; elem.before(row); } + const index = $('select.form-control', elem).prop('selectedIndex'); $('select.form-control', elem).prop('selectedIndex', index + fields.length); - renderSmoothingOptions(elem, activeFlightLog, fields[fields.length - 1]); + $('select.form-control', elem).trigger('change'); + + const colorPicker = $('select.color-picker', elem); + colorPicker.prop('selectedIndex', colorIndex % GraphConfig.PALETTE.length); + colorPicker.trigger('change'); } RefreshCharts(); }); @@ -264,17 +270,17 @@ export function GraphConfigurationDialog(dialog, onSave) { $("input", graphElem).val(graph.label); - let fieldCount = graph.fields.length; - // "Add field" button $(".add-field-button", graphElem).click(function(e) { - fieldList.append(renderField(flightLog, {}, GraphConfig.PALETTE[fieldCount++].color)); + const colorIndex = $("tbody", graphElem)[0].childElementCount; + const color = GraphConfig.PALETTE[colorIndex % GraphConfig.PALETTE.length].color; + fieldList.append(renderField(flightLog, {}, color)); e.preventDefault(); }); // "Remove Graph" button $(".remove-single-graph-button", graphElem).click(function(e) { - let parentGraph = $(this).parents('.config-graph'); + const parentGraph = $(this).parents('.config-graph'); parentGraph.remove(); updateRemoveAllButton(); RefreshCharts(); @@ -286,18 +292,17 @@ export function GraphConfigurationDialog(dialog, onSave) { // Add Field List for (let i = 0; i < graph.fields.length; i++) { - let fieldElem; const extendedFields = activeGraphConfig.extendFields(activeFlightLog, graph.fields[i]); - let fieldCount = i + 1; + let colorIndex = 0; for (const extField of extendedFields) { - fieldElem = renderField(flightLog, extField, extField.color ? (extField.color) : (GraphConfig.PALETTE[fieldCount++].color)) ; + const color = extField.color ?? GraphConfig.PALETTE[colorIndex++ % GraphConfig.PALETTE.length].color + const fieldElem = renderField(flightLog, extField, color); fieldList.append(fieldElem); } } fieldList.on('click', 'button', function(e) { - let - parentGraph = $(this).parents('.config-graph'); + const parentGraph = $(this).parents('.config-graph'); $(this).parents('.config-graph-field').remove(); @@ -316,7 +321,7 @@ export function GraphConfigurationDialog(dialog, onSave) { } function renderGraphs(flightLog, graphs) { - let + const graphList = $(".config-graphs-list", dialog); graphList.empty(); @@ -353,13 +358,9 @@ export function GraphConfigurationDialog(dialog, onSave) { } function convertUIToGraphConfig() { - let - graphs = [], - graph, - field; - + const graphs = []; $(".config-graph", dialog).each(function() { - graph = { + const graph = { fields: [], height: 1 }; @@ -371,7 +372,7 @@ export function GraphConfigurationDialog(dialog, onSave) { const fieldName = $("select", this).val(); const minimum = $("input[name=MinValue]", this).val(); const maximum = $("input[name=MaxValue]", this).val(); - field = { + const field = { name: fieldName, smoothing: parseInt($("input[name=smoothing]", this).val())*100, // Value 0-100% = 0-10000uS (higher values are more smooth, 30% is typical) curve: { @@ -406,10 +407,9 @@ export function GraphConfigurationDialog(dialog, onSave) { // Decide which fields we should offer to the user function buildOfferedFieldNamesList(flightLog, config) { - let - lastRoot = null, - fieldNames = flightLog.getMainFieldNames(), - fieldsSeen = {}; + let lastRoot = null; + const fieldNames = flightLog.getMainFieldNames(), + fieldsSeen = {}; offeredFieldNames = []; @@ -522,7 +522,7 @@ export function GraphConfigurationDialog(dialog, onSave) { exampleGraphsButton.dropdown(); exampleGraphsMenu.on("click", "a", function(e) { - let + const graph = exampleGraphs[$(this).data("graphIndex")], graphElem = renderGraph(activeFlightLog, $(".config-graph", dialog).length, graph); @@ -538,7 +538,7 @@ export function GraphConfigurationDialog(dialog, onSave) { }); // Remove all Graphs button - let removeAllGraphsButton = $(".config-graphs-remove-all-graphs"); + const removeAllGraphsButton = $(".config-graphs-remove-all-graphs"); removeAllGraphsButton.on("click", function() { $('.config-graph').remove(); updateRemoveAllButton(); From c19e2dd28b35a48b5f89c771ee089c91b01fca8e Mon Sep 17 00:00:00 2001 From: demvlad Date: Mon, 27 May 2024 19:27:27 +0300 Subject: [PATCH 19/19] Resolved code issue --- src/graph_config.js | 5 ++--- src/graph_config_dialog.js | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/graph_config.js b/src/graph_config.js index 325ead24..fd57108c 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -5,7 +5,7 @@ import { escapeRegExp } from "./tools"; export function GraphConfig(graphConfig) { const listeners = []; const that = this; - let graphs = graphConfig ? graphConfig : []; + let graphs = graphConfig ?? []; function notifyListeners() { for (const listener of listeners) { @@ -1370,9 +1370,8 @@ GraphConfig.load = function(config) { EXAMPLE_GRAPHS.push({label: "GPS",fields: ["GPS_numSat", "GPS_altitude", "GPS_speed", "GPS_ground_course", "GPS_coord[all]"]}); } - for (let i = 0; i < EXAMPLE_GRAPHS.length; i++) { + for (const srcGraph of EXAMPLE_GRAPHS) { const - srcGraph = EXAMPLE_GRAPHS[i], destGraph = { label: srcGraph.label, fields: [], diff --git a/src/graph_config_dialog.js b/src/graph_config_dialog.js index 04a170ea..eb5395a9 100644 --- a/src/graph_config_dialog.js +++ b/src/graph_config_dialog.js @@ -154,7 +154,7 @@ export function GraphConfigurationDialog(dialog, onSave) { if (fields.length === 1) { renderSmoothingOptions(elem, activeFlightLog, fields[0]); } else { - let colorIndex = $('select.color-picker', elem).prop('selectedIndex') + let colorIndex = $('select.color-picker', elem).prop('selectedIndex'); for (let i = 0; i < fields.length - 1; i++) { const color = GraphConfig.PALETTE[colorIndex++ % GraphConfig.PALETTE.length].color; const row = renderField(flightLog, fields[i], color) ; @@ -291,11 +291,11 @@ export function GraphConfigurationDialog(dialog, onSave) { $('select.graph-height', graphElem).replaceWith(chooseHeight(graph.height?(graph.height):1)); // Add Field List - for (let i = 0; i < graph.fields.length; i++) { - const extendedFields = activeGraphConfig.extendFields(activeFlightLog, graph.fields[i]); + for (const field of graph.fields) { + const extendedFields = activeGraphConfig.extendFields(activeFlightLog, field); let colorIndex = 0; for (const extField of extendedFields) { - const color = extField.color ?? GraphConfig.PALETTE[colorIndex++ % GraphConfig.PALETTE.length].color + const color = extField.color ?? GraphConfig.PALETTE[colorIndex++ % GraphConfig.PALETTE.length].color; const fieldElem = renderField(flightLog, extField, color); fieldList.append(fieldElem); }