import { useMemo, ReactNode } from "react" // @mui material components import Card from "@mui/material/Card" import Icon from "@mui/material/Icon" // ThreeD Garden components import MDBox from "~/components/mui/MDBox" import MDTypography from "~/components/mui/MDTypography" // VerticalBarChart configurations import configs from "~/components/elements/Charts/BarCharts/VerticalBarChart/configs" // ThreeD Garden Base Styles import colors from "~/themes/theme-light/base/colors" // react-chartjs-2 components import { Bar } from "react-chartjs-2" import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend } from "chart.js" ChartJS.register( CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend ) // Declaring props types for HorizontalBarChart interface Props { icon?: { color?: | "primary" | "secondary" | "info" | "success" | "warning" | "error" | "light" | "dark" component: ReactNode } title?: string description?: string | ReactNode height?: string | number chart: { labels: string[] datasets: { label: string color: | "primary" | "secondary" | "info" | "success" | "warning" | "error" | "light" | "dark" data: number[] }[] } [key: string]: any } function VerticalBarChart({ icon, title, description, height, chart, }: Props): JSX.Element { const chartDatasets = chart.datasets ? chart.datasets.map((dataset) => ({ ...dataset, weight: 5, borderWidth: 0, borderRadius: 4, backgroundColor: colors[dataset.color] ? colors[dataset.color || "dark"].main : colors.dark.main, fill: false, maxBarThickness: 35, })) : [] const { data, options } = configs(chart.labels || [], chartDatasets) const renderChart = ( {title || description ? ( {icon.component && ( {icon.component} )} {title && {title}} {description} ) : null} {useMemo( () => ( {/* options={options} */} ), [chart, height] )} ) return title || description ? {renderChart} : renderChart } // Declaring default props for VerticalBarChart VerticalBarChart.defaultProps = { icon: { color: "info", component: "" }, title: "", description: "", height: "19.125rem", } export default VerticalBarChart