2023-05-12 01:42:58 +02:00
|
|
|
import FunnelGraph from 'funnel-graph-js/dist/js/funnel-graph';
|
|
|
|
import { useEffect, useRef } from 'react';
|
2023-05-15 06:38:03 +02:00
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
|
|
|
import useMessages from 'hooks/useMessages';
|
2023-05-15 23:03:42 +02:00
|
|
|
import styles from './FunnelChart.module.css';
|
|
|
|
import classNames from 'classnames';
|
2023-05-12 01:42:58 +02:00
|
|
|
|
2023-05-15 06:38:03 +02:00
|
|
|
export default function FunnelChart({ data }) {
|
|
|
|
const { formatMessage, labels, messages } = useMessages();
|
2023-05-12 01:42:58 +02:00
|
|
|
const funnel = useRef(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-05-15 06:38:03 +02:00
|
|
|
if (data && data.length > 0) {
|
|
|
|
funnel.current.innerHTML = '';
|
2023-05-12 01:42:58 +02:00
|
|
|
|
2023-05-15 06:38:03 +02:00
|
|
|
const chartData = {
|
|
|
|
labels: data.map(a => a.url),
|
|
|
|
colors: ['#147af3', '#e0f2ff'],
|
|
|
|
values: data.map(a => a.count),
|
|
|
|
};
|
2023-05-12 01:42:58 +02:00
|
|
|
|
2023-05-15 06:38:03 +02:00
|
|
|
const graph = new FunnelGraph({
|
|
|
|
container: '.funnel',
|
|
|
|
gradientDirection: 'horizontal',
|
|
|
|
data: chartData,
|
|
|
|
displayPercent: true,
|
|
|
|
direction: 'Vertical',
|
|
|
|
width: 1000,
|
|
|
|
height: 350,
|
|
|
|
});
|
2023-05-12 01:42:58 +02:00
|
|
|
|
2023-05-15 06:38:03 +02:00
|
|
|
graph.draw();
|
|
|
|
}
|
|
|
|
}, [data]);
|
2023-05-12 01:42:58 +02:00
|
|
|
|
|
|
|
return (
|
2023-05-15 06:38:03 +02:00
|
|
|
<>
|
2023-05-15 23:03:42 +02:00
|
|
|
{data?.length > 0 && <div className={classNames(styles.funnel, 'funnel')} ref={funnel} />}
|
2023-05-15 06:38:03 +02:00
|
|
|
{data?.length === 0 && <EmptyPlaceholder message={formatMessage(messages.noResultsFound)} />}
|
|
|
|
</>
|
2023-05-12 01:42:58 +02:00
|
|
|
);
|
|
|
|
}
|