-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to graph nested serializable types (#31)
* saba-ja: added support for graphing serilizables * saba-ja: code format * lestarch: adding in missspelling break Co-authored-by: M Starch <LeStarch@googlemail.com>
- Loading branch information
Showing
5 changed files
with
172 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,6 +679,7 @@ xcode | |
xhtml | ||
xhttp | ||
xl | ||
xls | ||
xlsx | ||
xml | ||
xy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/fprime_gds/flask/static/addons/chart-display/modified-vendor/flat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* BSD 3-Clause "New" or "Revised" License | ||
* Source: https://github.com/hughsk/flat | ||
* Copyright (c) 2014, Hugh Kennedy | ||
The module has been modified to support F Prime GDS tasks | ||
*/ | ||
|
||
function isBuffer(obj) { | ||
return ( | ||
obj && | ||
obj.constructor && | ||
typeof obj.constructor.isBuffer === "function" && | ||
obj.constructor.isBuffer(obj) | ||
); | ||
} | ||
|
||
function keyIdentity(key) { | ||
return key; | ||
} | ||
|
||
/** | ||
* | ||
* @param {json} target : channel object | ||
* @param {json} opts : config options | ||
* @returns list of flatten paths | ||
*/ | ||
function flatten(target, opts) { | ||
opts = opts || {}; | ||
// Default supported F Prime types | ||
const supportedTypes = | ||
["U8", "U16", "U32", "U64", "I8", "I16", "I32", "I64", "F32", "F64"] || | ||
opts.supportedTypes; | ||
|
||
const prefix = opts.prefix || ""; | ||
const delimiter = opts.delimiter || "."; | ||
const maxDepth = opts.maxDepth; | ||
const transformKey = opts.transformKey || keyIdentity; | ||
const output = {}; | ||
|
||
function step(object, prev, currentDepth) { | ||
currentDepth = currentDepth || 1; | ||
|
||
Object.keys(object).forEach(function (key) { | ||
const value = object[key]; | ||
const isarray = opts.safe && Array.isArray(value); | ||
const type = Object.prototype.toString.call(value); | ||
const isbuffer = isBuffer(value); | ||
const isobject = | ||
type === "[object Object]" || type === "[object Array]"; | ||
|
||
const newKey = prev | ||
? prev + delimiter + transformKey(key) | ||
: transformKey(key); | ||
|
||
if ( | ||
!isarray && | ||
!isbuffer && | ||
isobject && | ||
Object.keys(value).length && | ||
(!opts.maxDepth || currentDepth < maxDepth) | ||
) { | ||
return step(value, newKey, currentDepth + 1); | ||
} | ||
|
||
if (supportedTypes.indexOf(value) !== -1) { | ||
let keyId = ""; | ||
if (prefix) { | ||
keyId = keyId.concat(prefix, delimiter, newKey); | ||
} else { | ||
keyId = newKey; | ||
} | ||
output[keyId] = value; | ||
} | ||
}); | ||
} | ||
|
||
step(target); | ||
|
||
// Get unique parent of each path | ||
const output_set = new Set(); | ||
for (const [key, value] of Object.entries(output)) { | ||
output_set.add(key.split(delimiter).slice(0, -1).join(delimiter)); | ||
} | ||
|
||
// Sort and return a list of flatten json paths | ||
let output_list = Array.from(output_set).sort(); | ||
return output_list; | ||
} | ||
|
||
export { flatten }; |