umami/components/metrics/PageviewsChart.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

import { useMemo } from 'react';
2020-08-26 18:58:24 +02:00
import BarChart from './BarChart';
import { useLocale, useTheme, useMessages } from 'hooks';
import { renderDateLabels, renderStatusTooltip } from 'lib/charts';
2020-07-26 09:12:42 +02:00
export function PageviewsChart({ websiteId, data, unit, className, loading, ...props }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
const { colors } = useTheme();
2023-04-19 20:41:31 +02:00
const { locale } = useLocale();
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,
...colors.chart.visitors,
2023-03-26 13:15:08 +02:00
},
{
label: formatMessage(labels.pageViews),
data: data.pageviews,
borderWidth: 1,
...colors.chart.views,
2023-03-26 13:15:08 +02:00
},
];
2023-04-19 20:41:31 +02:00
}, [data, locale, colors]);
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}
renderXLabel={renderDateLabels(unit, locale)}
renderTooltip={renderStatusTooltip(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;