(
concreteSeries: ConcreteSeries[],
definitions: Array<{
id?: string;
type: 'event' | 'formula';
displayName?: string;
formula?: string;
name?: string;
hideSeries?: string[];
}>,
includeAlphaIds: boolean,
previousSeries: ConcreteSeries[] | null = null,
limit: number | undefined = undefined
)
| 16 | * TODO: Migrate frontend to use cleaner ChartResponse format |
| 17 | */ |
| 18 | export function format( |
| 19 | concreteSeries: ConcreteSeries[], |
| 20 | definitions: Array<{ |
| 21 | id?: string; |
| 22 | type: 'event' | 'formula'; |
| 23 | displayName?: string; |
| 24 | formula?: string; |
| 25 | name?: string; |
| 26 | hideSeries?: string[]; |
| 27 | }>, |
| 28 | includeAlphaIds: boolean, |
| 29 | previousSeries: ConcreteSeries[] | null = null, |
| 30 | limit: number | undefined = undefined |
| 31 | ): FinalChart { |
| 32 | // Collect definition indices that should be hidden from the chart. |
| 33 | // A formula can opt to hide any of the series it references (by alpha ID) |
| 34 | // so the chart only shows the formula result without the input series. |
| 35 | const hiddenDefinitionIndices = new Set<number>(); |
| 36 | for (const definition of definitions) { |
| 37 | if (definition.type !== 'formula' || !definition.hideSeries?.length) { |
| 38 | continue; |
| 39 | } |
| 40 | for (const alphaId of definition.hideSeries) { |
| 41 | const index = alphabetIds.indexOf(alphaId as (typeof alphabetIds)[number]); |
| 42 | if (index >= 0) { |
| 43 | hiddenDefinitionIndices.add(index); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | const visibleConcreteSeries = |
| 49 | hiddenDefinitionIndices.size > 0 |
| 50 | ? concreteSeries.filter( |
| 51 | (cs) => !hiddenDefinitionIndices.has(cs.definitionIndex) |
| 52 | ) |
| 53 | : concreteSeries; |
| 54 | |
| 55 | const series = visibleConcreteSeries.map((cs) => { |
| 56 | // Find definition for this series |
| 57 | const definition = definitions[cs.definitionIndex]; |
| 58 | const alphaId = includeAlphaIds |
| 59 | ? alphabetIds[cs.definitionIndex] |
| 60 | : undefined; |
| 61 | |
| 62 | // Build display name with optional alpha ID |
| 63 | let displayName: string[]; |
| 64 | |
| 65 | // Replace the first name (which is the event name) with the display name if it exists |
| 66 | const names = cs.name.slice(0); |
| 67 | if (cs.definition.displayName) { |
| 68 | names.splice(0, 1, cs.definition.displayName); |
| 69 | } |
| 70 | // Add the alpha ID to the first name if it exists |
| 71 | if (alphaId) { |
| 72 | displayName = [`(${alphaId}) ${names[0]}`, ...names.slice(1)]; |
| 73 | } else { |
| 74 | displayName = names; |
| 75 | } |
no test coverage detected