Add an automatic way to exclude default values from graphs.

This commit is contained in:
Bauke 2022-03-07 22:32:24 +01:00
parent 243e53c413
commit 3829018f06
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 10 additions and 1 deletions

View File

@ -17,10 +17,19 @@ export abstract class BaseOperation<P> {
this.parameters = parameters; this.parameters = parameters;
} }
public graph(): string[] { public graph(includeDefaults = false): string[] {
const defaults = this.default;
const graph: string[] = [this.name]; const graph: string[] = [this.name];
for (const [key, value] of Object.entries(this.parameters)) { for (const [key, value] of Object.entries(this.parameters)) {
if (
includeDefaults &&
key in defaults &&
(defaults as Record<string, any>)[key] === value
) {
continue;
}
const kebabCasedKey = key.replace(/([A-Z])/g, '-$1').toLowerCase(); const kebabCasedKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
graph.push(`${kebabCasedKey}=${value as string}`); graph.push(`${kebabCasedKey}=${value as string}`);
} }