Skip to content

Auto fill of curves table by selecting group curves names on Chart setup dialog box #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
160 changes: 81 additions & 79 deletions src/graph_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -44,18 +44,73 @@ 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 (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;
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;
}

let 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 {
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) {
var
logFieldNames = flightLog.getMainFieldNames(),

this.adaptGraphs = function(flightLog, graphs) {
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:
Expand All @@ -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);
Expand Down Expand Up @@ -173,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;

Expand Down Expand Up @@ -214,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'):
Expand All @@ -231,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,
Expand All @@ -250,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 =
Expand All @@ -264,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 =
Expand Down Expand Up @@ -417,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) {
Expand Down Expand Up @@ -558,7 +560,7 @@ GraphConfig.load = function(config) {
max: 50
}
};
case 'debug[3]': // Vario
case 'debug[3]': // letio
return {
power: 1.0,
MinMax: {
Expand Down Expand Up @@ -1345,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;

Expand Down Expand Up @@ -1397,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,
Expand All @@ -1421,7 +1423,7 @@ GraphConfig.load = function(config) {
}

for (j = 0; j < srcGraph.fields.length; j++) {
var
let
srcFieldName = srcGraph.fields[j],
destField = {
name: srcFieldName
Expand Down
Loading