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" // RadarChart configurations import configs from "~/components/elements/Charts/RadarChart/configs" // ThreeD Garden Base Styles import colors from "~/themes/theme-light/base/colors" // ThreeD Garden Helper Functions import rgba from "~/themes/theme-light/functions/rgba" // react-chartjs-2 components import { Radar } from "react-chartjs-2" import { Chart as ChartJS, RadialLinearScale, PointElement, LineElement, Filler, Title, Tooltip, Legend } from "chart.js" ChartJS.register( RadialLinearScale, PointElement, LineElement, Filler, Title, Tooltip, Legend ) // Declaring props types for RadarChart interface Props { icon?: { color?: | "primary" | "secondary" | "info" | "success" | "warning" | "error" | "light" | "dark" component: ReactNode } title?: string description?: string | ReactNode chart: { labels: string[] datasets: { label: string color: | "primary" | "secondary" | "info" | "success" | "warning" | "error" | "light" | "dark" data: number[] borderDash?: number[] }[] } [key: string]: any } function RadarChart({ icon, title, description, chart }: Props): JSX.Element { const chartDatasets = chart.datasets ? chart.datasets.map((dataset) => ({ ...dataset, backgroundColor: colors[dataset.color] ? rgba(colors[dataset.color || "dark"].main, 0.2) : rgba(colors.dark.main, 0.2), })) : [] const { data, options } = configs(chart.labels || [], chartDatasets) const renderChart = ( {title || description ? ( {icon.component && ( {icon.component} )} {title && {title}} {description} ) : null} {useMemo( () => ( {/* options={options} */} ), [chart] )} ) return title || description ? {renderChart} : renderChart } // Declaring default props for RadarChart RadarChart.defaultProps = { icon: { color: "info", component: "" }, title: "", description: "", } export default RadarChart