-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathutil.ts
More file actions
68 lines (57 loc) · 1.77 KB
/
util.ts
File metadata and controls
68 lines (57 loc) · 1.77 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { isFieldConfig } from "@rilldata/web-common/features/components/charts/util";
import { TDDChart } from "@rilldata/web-common/features/dashboards/time-dimension-details/types";
import { type ChartType } from "../../../components/charts/types";
import { type CanvasChartSpec } from "./";
const allowedTimeDimensionDetailTypes = [
"line_chart",
"area_chart",
"stacked_bar",
"stacked_bar_normalized",
"bar_chart",
];
export const CanvasChartTypeToTDDChartType = {
line_chart: TDDChart.DEFAULT,
area_chart: TDDChart.STACKED_AREA,
stacked_bar: TDDChart.STACKED_BAR,
stacked_bar_normalized: TDDChart.STACKED_BAR,
bar_chart: TDDChart.GROUPED_BAR,
};
export function getLinkStateForTimeDimensionDetail(
spec: CanvasChartSpec,
type: ChartType,
): {
canLink: boolean;
measureName?: string;
dimensionName?: string;
} {
if (!allowedTimeDimensionDetailTypes.includes(type))
return { canLink: false };
const hasXAxis = "x" in spec;
const hasYAxis = "y" in spec;
if (!hasXAxis || !hasYAxis)
return { canLink: false };
const xAxis = spec.x;
const yAxis = spec.y;
if (!isFieldConfig(xAxis) || !isFieldConfig(yAxis))
return { canLink: false };
if (yAxis.fields && yAxis.fields.length > 1)
return { canLink: false };
const colorDimension = spec.color;
const hasDimensionBreakout =
isFieldConfig(colorDimension) &&
colorDimension.type !== "quantitative" &&
colorDimension.type !== "value";
if (hasDimensionBreakout && xAxis.type === "nominal")
return { canLink: false };
if (hasDimensionBreakout) {
return {
canLink: xAxis.type === "temporal",
measureName: yAxis.field,
dimensionName: colorDimension.field,
};
}
return {
canLink: xAxis.type === "temporal",
measureName: yAxis.field,
};
}