2024-02-03 20:23:31 -07:00
|
|
|
import React from "react";
|
|
|
|
import { Path } from "react-native-svg";
|
2024-01-10 13:30:46 -07:00
|
|
|
|
2024-02-03 20:23:31 -07:00
|
|
|
import { calculateBarOrigin, drawBarPath } from "./custom-bar-utils";
|
|
|
|
import { ScaleBandType, ScaleLinearType } from "./graph-types";
|
2024-01-10 13:30:46 -07:00
|
|
|
|
|
|
|
interface BarProps {
|
2024-02-03 20:23:31 -07:00
|
|
|
scaleX: ScaleBandType;
|
|
|
|
scaleY: ScaleLinearType;
|
|
|
|
data: { value: number };
|
|
|
|
barNumber: number;
|
|
|
|
index: number;
|
|
|
|
fill: string;
|
|
|
|
barWidth: number;
|
|
|
|
gap: number;
|
|
|
|
roundedRadius: number;
|
2024-01-10 13:30:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export const Bar: React.FC<BarProps> = ({
|
2024-02-03 20:23:31 -07:00
|
|
|
scaleX,
|
|
|
|
scaleY,
|
|
|
|
data,
|
|
|
|
barNumber,
|
|
|
|
index,
|
|
|
|
fill,
|
|
|
|
barWidth,
|
|
|
|
gap,
|
|
|
|
roundedRadius,
|
2024-01-10 13:30:46 -07:00
|
|
|
}) => {
|
2024-02-03 20:23:31 -07:00
|
|
|
const { xOrigin, yOrigin, height } = calculateBarOrigin({
|
|
|
|
scaleX,
|
|
|
|
scaleY,
|
|
|
|
index,
|
|
|
|
data,
|
|
|
|
barNumber,
|
|
|
|
barWidth,
|
|
|
|
gap,
|
|
|
|
});
|
2024-01-10 13:30:46 -07:00
|
|
|
|
2024-02-03 20:23:31 -07:00
|
|
|
return (
|
|
|
|
<Path
|
|
|
|
key={`bar-path-${barNumber}-${index}`}
|
|
|
|
d={drawBarPath(xOrigin, yOrigin, barWidth, height, roundedRadius)}
|
|
|
|
fill={fill}
|
|
|
|
testID={`bar-${barNumber}-${index}`}
|
|
|
|
/>
|
|
|
|
);
|
2024-01-10 13:30:46 -07:00
|
|
|
};
|