2023-05-25 19:26:00 +02:00
|
|
|
import { useMemo } from 'react';
|
2020-08-26 18:58:24 +02:00
|
|
|
import BarChart from './BarChart';
|
2023-05-25 19:26:00 +02:00
|
|
|
import { useLocale, useTheme, useMessages } from 'hooks';
|
2023-06-16 05:15:31 +02:00
|
|
|
import { renderDateLabels, renderStatusTooltipPopup } from 'lib/charts';
|
2020-07-26 09:12:42 +02:00
|
|
|
|
2023-05-25 06:40:02 +02:00
|
|
|
export function PageviewsChart({ websiteId, data, unit, className, loading, ...props }) {
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-05-25 06:40:02 +02:00
|
|
|
const { colors } = useTheme();
|
2023-04-19 20:41:31 +02:00
|
|
|
const { locale } = useLocale();
|
2023-03-09 01:37:43 +01:00
|
|
|
|
2023-03-26 13:15:08 +02:00
|
|
|
const datasets = useMemo(() => {
|
|
|
|
if (!data) return [];
|
2020-07-29 06:50:29 +02:00
|
|
|
|
2023-03-26 13:15:08 +02:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: formatMessage(labels.uniqueVisitors),
|
|
|
|
data: data.sessions,
|
|
|
|
borderWidth: 1,
|
2023-05-25 06:40:02 +02:00
|
|
|
...colors.chart.visitors,
|
2023-03-26 13:15:08 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: formatMessage(labels.pageViews),
|
|
|
|
data: data.pageviews,
|
|
|
|
borderWidth: 1,
|
2023-05-25 06:40:02 +02:00
|
|
|
...colors.chart.views,
|
2023-03-26 13:15:08 +02:00
|
|
|
},
|
|
|
|
];
|
2023-04-19 20:41:31 +02:00
|
|
|
}, [data, locale, colors]);
|
2023-03-15 06:37:50 +01:00
|
|
|
|
2020-07-26 09:12:42 +02:00
|
|
|
return (
|
2023-04-03 12:12:12 +02:00
|
|
|
<BarChart
|
|
|
|
{...props}
|
|
|
|
key={websiteId}
|
|
|
|
className={className}
|
|
|
|
datasets={datasets}
|
|
|
|
unit={unit}
|
|
|
|
loading={loading}
|
2023-05-25 19:26:00 +02:00
|
|
|
renderXLabel={renderDateLabels(unit, locale)}
|
2023-06-16 05:15:31 +02:00
|
|
|
renderTooltipPopup={renderStatusTooltipPopup(unit, locale)}
|
2023-04-03 12:12:12 +02:00
|
|
|
/>
|
2020-07-26 09:12:42 +02:00
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default PageviewsChart;
|