47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
type Domain =
|
|
| "INPUT" | "SAH" | "ALLOCATION" | "RULES" | "CHARGEABILITY" | "BUDGET"
|
|
| "ESTIMATE" | "COMMERCIAL" | "EXPERIENCE" | "EFFORT" | "SPREAD";
|
|
|
|
export interface GraphNode {
|
|
id: string;
|
|
label: string;
|
|
value: number | string;
|
|
unit: string;
|
|
domain: Domain;
|
|
description: string;
|
|
formula?: string;
|
|
level: number;
|
|
}
|
|
|
|
export interface GraphLink {
|
|
source: string;
|
|
target: string;
|
|
formula: string;
|
|
weight: number;
|
|
}
|
|
|
|
export function n(
|
|
id: string,
|
|
label: string,
|
|
value: number | string,
|
|
unit: string,
|
|
domain: Domain,
|
|
description: string,
|
|
level: number,
|
|
formula?: string,
|
|
): GraphNode {
|
|
return { id, label, value, unit, domain, description, level, ...(formula ? { formula } : {}) };
|
|
}
|
|
|
|
export function l(source: string, target: string, formula: string, weight = 1): GraphLink {
|
|
return { source, target, formula, weight };
|
|
}
|
|
|
|
export function fmtPct(ratio: number): string {
|
|
return `${(ratio * 100).toFixed(1)}%`;
|
|
}
|
|
|
|
export function fmtNum(value: number, decimals = 1): string {
|
|
return value.toFixed(decimals);
|
|
}
|