Squashed commit of the following:
commit 980e9c2f37640ee204ce0365f6c3bcc74741cc7c
Merge: cb4cae82b 394fc5a9d
Author: Artem Baskal <a.baskal@adguard.com>
Date: Mon Nov 16 14:52:26 2020 +0300
Merge branch 'master' into fix/2237
commit cb4cae82b5b605894d123d6442ea23b24cc90c12
Author: ArtemBaskal <asbaskal@miem.hse.ru>
Date: Thu Nov 12 12:07:49 2020 +0300
minor
commit 5c07dac48067b4ed201aeb59a44e8592ed2b0b67
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Wed Nov 11 19:47:38 2020 +0300
minor
commit 53f60762e520427a080bdfcd94b08b9ed3a63ca4
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Wed Nov 11 19:06:06 2020 +0300
Adapt mobile version
commit 7659ac733ce4606f6fadf30e0eaddbeefd6095d6
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Wed Nov 11 18:31:53 2020 +0300
Fix empty graph offset, return background area below graph
commit 45499adb20a90024dba4b0b4e44ad4f01a1782d5
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Tue Nov 10 17:46:47 2020 +0300
- client: 2237 Update graph drawing library
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
import React from 'react';
|
|
import { ResponsiveLine } from '@nivo/line';
|
|
import addDays from 'date-fns/add_days';
|
|
import addHours from 'date-fns/add_hours';
|
|
import subDays from 'date-fns/sub_days';
|
|
import subHours from 'date-fns/sub_hours';
|
|
import dateFormat from 'date-fns/format';
|
|
import round from 'lodash/round';
|
|
import { useSelector } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import './Line.css';
|
|
|
|
const Line = ({
|
|
data, color = 'black',
|
|
}) => {
|
|
const interval = useSelector((state) => state.stats.interval);
|
|
|
|
return <ResponsiveLine
|
|
enableArea
|
|
animate
|
|
enableSlices="x"
|
|
curve="linear"
|
|
colors={[color]}
|
|
data={data}
|
|
theme={{
|
|
crosshair: {
|
|
line: {
|
|
stroke: 'black',
|
|
strokeWidth: 1,
|
|
strokeOpacity: 0.35,
|
|
},
|
|
},
|
|
}}
|
|
xScale={{
|
|
type: 'linear',
|
|
min: 0,
|
|
max: 'auto',
|
|
}}
|
|
crosshairType="x"
|
|
axisLeft={false}
|
|
axisBottom={false}
|
|
enableGridX={false}
|
|
enableGridY={false}
|
|
enablePoints={false}
|
|
xFormat={(x) => {
|
|
if (interval === 1 || interval === 7) {
|
|
const hoursAgo = subHours(Date.now(), 24 * interval);
|
|
return dateFormat(addHours(hoursAgo, x), 'D MMM HH:00');
|
|
}
|
|
|
|
const daysAgo = subDays(Date.now(), interval - 1);
|
|
return dateFormat(addDays(daysAgo, x), 'D MMM YYYY');
|
|
}}
|
|
yFormat={(y) => round(y, 2)}
|
|
sliceTooltip={(slice) => {
|
|
const { xFormatted, yFormatted } = slice.slice.points[0].data;
|
|
return <div className="line__tooltip">
|
|
<span className="line__tooltip-text">
|
|
<strong>{yFormatted}</strong>
|
|
<br />
|
|
<small>{xFormatted}</small>
|
|
</span>
|
|
</div>;
|
|
}}
|
|
/>;
|
|
};
|
|
|
|
Line.propTypes = {
|
|
data: PropTypes.array.isRequired,
|
|
color: PropTypes.string,
|
|
width: PropTypes.number,
|
|
height: PropTypes.number,
|
|
};
|
|
|
|
export default Line;
|