MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / format

Function format

packages/db/src/engine/format.ts:18–171  ·  view source on GitHub ↗
(
  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
)

Source from the content-addressed store, hash-verified

16 * TODO: Migrate frontend to use cleaner ChartResponse format
17 */
18export 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 }

Callers 15

executeChartFunction · 0.90
executeAggregateChartFunction · 0.90
overview.tsFile · 0.85
fmtFunction · 0.85
fmtFunction · 0.85
cron.onboarding.tsFile · 0.85
TimeWindowPickerFunction · 0.85
MonthCalendarFunction · 0.85
DeleteProjectFunction · 0.85
DeleteOrganizationFunction · 0.85
EventsTableToolbarFunction · 0.85

Calls 11

sumFunction · 0.90
roundFunction · 0.90
averageFunction · 0.90
minFunction · 0.90
maxFunction · 0.90
slugFunction · 0.90
getPreviousMetricFunction · 0.90
hasMethod · 0.80
joinMethod · 0.80
addMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected