one-click-accessibility/modules/settings/assets/js/components/analytics/charts/line-chart.js
VasylD 38bdaef8b6
[APP-1107] Add dashboard for analytics (#204)
* [APP-1108][APP-1109][APP-1110] Add analytics backend logic

* [APP-1108][APP-1109][APP-1110] Add analytics backend logic

* Add nonce to the widget settings

* Update routes and DB table

* Fix comments

* Fix comments

* Fix comments

* Fix comments

* Fix comments

* Fix comments

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1201] add accessibility rules

* [APP-1107] fixed API endpoint

* [APP-1107] fixed API endpoint

* [APP-1107] fixed API endpoint

* [APP-1107] add check for is_active

* update to the latest

* update to the latest

* update to the latest

* fix bugs, add changes

* fix bugs, add changes

* fix bugs, add changes

* fix bugs, add changes
2025-03-17 12:26:52 +02:00

67 lines
1.8 KiB
JavaScript

import { useTheme } from '@elementor/ui';
import Card from '@elementor/ui/Card';
import CardHeader from '@elementor/ui/CardHeader';
import Typography from '@elementor/ui/Typography';
import { LineChart as MuiLineChart } from '@mui/x-charts/LineChart';
import { LineChartTitle } from '@ea11y/components/analytics/components/line-chart-title';
import { LineTooltip } from '@ea11y/components/analytics/components/line-tooltip';
import { NoData } from '@ea11y/components/analytics/components/no-data';
import { dateI18n } from '@wordpress/date';
import { useAnalyticsContext } from '../../../contexts/analytics-context';
export const LineChart = () => {
const theme = useTheme();
const { stats } = useAnalyticsContext();
const totalOpen = stats.dates.reduce(
(sum, item) => sum + Number(item.total),
0,
);
const showChart = stats.dates.length > 0;
return (
<Card variant="outlined" sx={{ height: '100%' }}>
<CardHeader
title={<LineChartTitle />}
subheader={
totalOpen > 0 ? (
<Typography variant="h3" sx={{ height: '50px' }}>
{totalOpen.toString()}
</Typography>
) : null
}
sx={{ pb: 0 }}
/>
{showChart && (
<MuiLineChart
series={[
{
type: 'line',
curve: 'linear',
data: stats.dates.map((item) => item.total),
color: theme.palette.info.main,
},
]}
xAxis={[
{
scaleType: 'point',
data: stats.dates.map((item) => item.date),
valueFormatter: (item, context) =>
context.location === 'tick'
? dateI18n('d.m', item, false)
: item,
},
]}
slots={{
axisContent: LineTooltip,
}}
tooltip={{
trigger: totalOpen ? 'axis' : 'none',
}}
height={250}
/>
)}
{stats.dates.length === 0 && <NoData />}
</Card>
);
};