Files
cally/components/pages/todos/user-chores/UserChart.tsx
2024-12-30 12:54:04 +01:00

62 lines
1.7 KiB
TypeScript

import React, {useEffect, useState} from "react";
import { BarChart } from "react-native-gifted-charts";
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
import {chartDayMap, weekOrder} from "@/constants/common";
const UserChart = ({ profileData }: {
profileData: UserProfile | undefined;
}) => {
const [dataList, setDataList] = useState([]);
const barColor = "#05a8b6";
useEffect(() => {
let weeklyDayPoints = profileData?.weeklyDayPoints || {
Monday: 0,
Tuesday: 0,
Wednesday: 0,
Thursday: 0,
Friday: 0,
Saturday: 0,
Sunday: 0,
};
// Sort by day
const sortedWeeklyPoints = Object.fromEntries(
weekOrder.map(day => [day, weeklyDayPoints[day]])
);
const data = Object.keys(sortedWeeklyPoints).map((day) => {
const value = weeklyDayPoints[day];
return {
value: value,
frontColor: barColor,
label: chartDayMap[day],
}
});
setDataList(data);
}, [])
return (
<BarChart
data={dataList}
width={255}
height={150} // Height of the chart
barWidth={20} // Width of each bar
noOfSections={5} // Number of horizontal sections (for 0 to 1000 in steps of 200)
maxValue={1000} // Max value on the chart
stepValue={200} // Step size for horizontal lines
yAxisThickness={0} // Hide the Y-axis line
// yAxisLabelTexts={["0", "200", "400", "600", "800", "1000"]} // Custom Y-axis labels
hideRules={false} // Show the horizontal lines
rulesColor="#dadada" // Color for the horizontal lines
barBorderTopLeftRadius={5} // Round the bars
barBorderTopRightRadius={5} // Round the bars
spacing={16}
disableScroll
/>
);
};
export default UserChart;