-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcombo-line-container.tsx
More file actions
37 lines (30 loc) · 1.28 KB
/
combo-line-container.tsx
File metadata and controls
37 lines (30 loc) · 1.28 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 { ReactNode } from "react";
import { getTextHeight, getTextWidth } from "@/utils/get-text-width";
import { TICK_PADDING } from "../shared/axis-height-linear";
import { useChartState } from "../shared/chart-state";
import { useChartTheme } from "../shared/use-chart-theme";
import { ComboLineColumnState } from "./combo-line-column-state";
import { ComboLineDualState } from "./combo-line-dual-state";
export const TITLE_VPADDING = 4;
export const ComboLineContainer = ({ children }: { children: ReactNode }) => {
const { axisLabelFontSize } = useChartTheme();
const { y, bounds } = useChartState() as
| ComboLineDualState
| ComboLineColumnState;
const axisTitle = y.left.label;
const axisTitleWidth =
getTextWidth(axisTitle, { fontSize: axisLabelFontSize }) + TICK_PADDING;
const otherAxisTitle = y.right.label;
const otherAxisTitleWidth =
getTextWidth(otherAxisTitle, { fontSize: axisLabelFontSize }) +
TICK_PADDING;
const overLappingTitles =
axisTitleWidth + otherAxisTitleWidth > bounds.chartWidth;
const axisLabelHeight = getTextHeight(axisTitle, {
fontSize: axisLabelFontSize,
});
const yAdjustment = overLappingTitles
? (axisLabelHeight + TITLE_VPADDING) * 2
: 0;
return <g transform={`translate(0, ${yAdjustment})`}>{children}</g>;
};