2023-05-11 11:41:04 +00:00
|
|
|
// nivo
|
|
|
|
import { ResponsiveLine, LineSvgProps } from "@nivo/line";
|
2023-05-15 05:52:06 +00:00
|
|
|
// helpers
|
|
|
|
import { generateYAxisTickValues } from "helpers/graph.helper";
|
2023-05-11 11:41:04 +00:00
|
|
|
// types
|
|
|
|
import { TGraph } from "./types";
|
|
|
|
// constants
|
|
|
|
import { CHARTS_THEME, DEFAULT_MARGIN } from "constants/graph";
|
|
|
|
|
2023-05-15 05:52:06 +00:00
|
|
|
type Props = {
|
|
|
|
customYAxisTickValues?: number[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const LineGraph: React.FC<Props & TGraph & LineSvgProps> = ({
|
|
|
|
customYAxisTickValues,
|
2023-05-11 11:41:04 +00:00
|
|
|
height = "400px",
|
|
|
|
width = "100%",
|
|
|
|
margin,
|
|
|
|
theme,
|
|
|
|
...rest
|
|
|
|
}) => (
|
|
|
|
<div style={{ height, width }}>
|
|
|
|
<ResponsiveLine
|
2023-05-11 12:08:46 +00:00
|
|
|
margin={{ ...DEFAULT_MARGIN, ...(margin ?? {}) }}
|
2023-05-15 05:52:06 +00:00
|
|
|
axisLeft={{
|
|
|
|
tickSize: 0,
|
|
|
|
tickPadding: 10,
|
|
|
|
tickValues: customYAxisTickValues
|
|
|
|
? generateYAxisTickValues(customYAxisTickValues)
|
|
|
|
: undefined,
|
|
|
|
}}
|
2023-05-11 12:08:46 +00:00
|
|
|
theme={{ ...CHARTS_THEME, ...(theme ?? {}) }}
|
2023-11-01 07:00:21 +00:00
|
|
|
animate
|
2023-05-11 11:41:04 +00:00
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|