-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtitle.ts
More file actions
37 lines (33 loc) · 1.71 KB
/
title.ts
File metadata and controls
37 lines (33 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { t } from "@lingui/macro";
import { ChartConfig } from "@/config-types";
import { Dimension, Measure } from "@/domain/data";
export function generateChartTitle(
chartInfo: ChartConfig,
dimensionsByIri: Record<string, Dimension | Measure>
): string {
const { chartType } = chartInfo;
const getLabel = (type: "x" | "y" | "segment") => {
const field = chartInfo.fields[type as keyof (typeof chartInfo)["fields"]];
// @ts-ignore
const iri = field?.componentIri;
const dimension = dimensionsByIri[iri];
return dimension?.label ?? "";
};
// prettier-ignore
const chartTitleLocales = {
column: t({ id: "columnChart", message: `${getLabel("y")} per ${getLabel("x")}` }),
line: t({ id: "lineChart", message: `Evolution of the ${getLabel("y")}` }),
area: t({ id: "areaChart", message: `Distribution of ${getLabel("y")} over ${getLabel("x")}` }),
areaSegmented: t({ id: `Shares of ${getLabel("y")} by ${getLabel("segment")}` }),
pie: t({ id: "pieChart", message: `${getLabel("y")} per ${getLabel("segment")}` }),
map: t({ id: "mapChart", message: `Geographical distribution of ${getLabel("y")}` }),
scatterplot: t({ id: "scatterplotChart", message: `${getLabel("y")} against ${getLabel("x")}` }),
table: t({ id: "tableChart", message: `Table` }),
comboLineSingle: t({ id: "comboLineSingleChart", message: `Combo line single chart` }),
comboLineDual: t({ id: "comboLineDuoChart", message: `Combo line dual chart` }),
comboLineColumn: t({ id: "comboLineSingleChart", message: `Combo line column chart` }),
};
const defaultChartTitle = `${chartType} Chart`;
const chartTitle = chartTitleLocales[chartType] || defaultChartTitle;
return chartTitle;
}