2020-08-27 12:42:24 +02:00
|
|
|
import React from 'react';
|
2020-08-02 06:20:52 +02:00
|
|
|
import classNames from 'classnames';
|
2020-08-26 18:58:24 +02:00
|
|
|
import BarChart from './BarChart';
|
2020-07-29 06:50:29 +02:00
|
|
|
import styles from './PageviewsChart.module.css';
|
2020-07-26 09:12:42 +02:00
|
|
|
|
2020-08-26 18:58:24 +02:00
|
|
|
export default function PageviewsChart({ websiteId, data, unit, className, animationDuration }) {
|
|
|
|
const handleUpdate = chart => {
|
|
|
|
const {
|
|
|
|
data: { datasets },
|
|
|
|
options,
|
|
|
|
} = chart;
|
2020-07-29 06:50:29 +02:00
|
|
|
|
2020-08-26 18:58:24 +02:00
|
|
|
datasets[0].data = data.uniques;
|
|
|
|
datasets[1].data = data.pageviews;
|
|
|
|
options.animation.duration = animationDuration;
|
2020-07-31 08:08:33 +02:00
|
|
|
|
2020-08-26 18:58:24 +02:00
|
|
|
chart.update();
|
2020-07-29 06:50:29 +02:00
|
|
|
};
|
2020-07-26 09:12:42 +02:00
|
|
|
|
2020-08-26 18:58:24 +02:00
|
|
|
if (!data) {
|
|
|
|
return null;
|
2020-07-26 09:12:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-08-26 18:58:24 +02:00
|
|
|
<div className={classNames(styles.chart, className)}>
|
|
|
|
<BarChart
|
|
|
|
chartId={websiteId}
|
|
|
|
datasets={[
|
|
|
|
{
|
|
|
|
label: 'unique visitors',
|
|
|
|
data: data.uniques,
|
|
|
|
lineTension: 0,
|
|
|
|
backgroundColor: 'rgb(38, 128, 235, 0.4)',
|
|
|
|
borderColor: 'rgb(13, 102, 208, 0.4)',
|
|
|
|
borderWidth: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'page views',
|
|
|
|
data: data.pageviews,
|
|
|
|
lineTension: 0,
|
|
|
|
backgroundColor: 'rgb(38, 128, 235, 0.2)',
|
|
|
|
borderColor: 'rgb(13, 102, 208, 0.2)',
|
|
|
|
borderWidth: 1,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
unit={unit}
|
|
|
|
records={data.pageviews.length}
|
|
|
|
onUpdate={handleUpdate}
|
|
|
|
/>
|
2020-07-26 09:12:42 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|