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" // BubbleChart configurations import configs from "~/components/elements/Charts/BubbleChart/configs" // ThreeD Garden Base Styles import colors from "~/themes/theme-light/base/colors" // react-chartjs-2 components import { Bubble } from "react-chartjs-2" import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, Title, Tooltip, Legend } from "chart.js" ChartJS.register( CategoryScale, LinearScale, PointElement, Title, Tooltip, Legend ) // Declaring props types for BubbleChart 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: { x: number y: number r: number }[] }[] } [key: string]: any } function BubbleChart({ icon, title, description, height, chart, }: Props): JSX.Element { const chartDatasets = chart.datasets ? chart.datasets.map((dataset) => ({ ...dataset, tension: 0.4, borderWidth: 3, pointRadius: 2, backgroundColor: colors[dataset.color] ? colors[dataset.color || "dark"].main : colors.dark.main, borderColor: colors[dataset.color] ? colors[dataset.color || "dark"].main : colors.dark.main, maxBarThickness: 6, })) : [] 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 BubbleChart BubbleChart.defaultProps = { icon: { color: "info", component: "" }, title: "", description: "", height: "100%", } export default BubbleChart