import React from 'react';
import cn from 'classnames';
import { CompareTag } from './CustomChartTooltip';
interface Props {
colors: any;
yaxis?: any;
label?: string;
hideLegend?: boolean;
values: {
value: number;
compData?: number;
series: string;
valueLabel?: string;
}[];
onSeriesFocus?: (name: string) => void;
}
function BigNumChart(props: Props) {
const {
colors,
label = 'Number of Sessions',
values,
onSeriesFocus,
hideLegend,
} = props;
return (
{values.map((val, i) => (
))}
);
}
function BigNum({
color,
series,
value,
label,
compData,
valueLabel,
onSeriesFocus,
hideLegend,
}: {
color: string;
series: string;
value: number;
label: string;
compData?: number;
valueLabel?: string;
onSeriesFocus?: (name: string) => void;
hideLegend?: boolean;
}) {
const formattedNumber = (num: number) => Intl.NumberFormat().format(num);
const changePercent = React.useMemo(() => {
if (!compData || compData === 0) return '0';
return `${(((value - compData) / compData) * 100).toFixed(2)}`;
}, [value, compData]);
const change = React.useMemo(() => {
if (!compData) return 0;
return value - compData;
}, [value, compData]);
return (
onSeriesFocus?.(series)}
className={cn(
'flex flex-col flex-auto justify-center items-center rounded-lg transition-all',
'hover:transition-all ease-in-out hover:ease-in-out hover:bg-teal/5 hover:cursor-pointer',
)}
>
{hideLegend ? null : (
)}
{formattedNumber(value)}
{valueLabel ? `${valueLabel}` : null}
{label}
{compData ? (
compData}
absDelta={change}
delta={changePercent}
/>
) : null}
);
}
export default BigNumChart;