From ddc4190573507e0282ffa118ebb0e4ed02aee256 Mon Sep 17 00:00:00 2001 From: Alex S Date: Tue, 28 Sep 2021 09:58:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Corrige=20la=20lisibilit=C3=A9?= =?UTF-8?q?=20du=20charte=20d'usage=20des=20simulateurs=20(#1743)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexandre Valsamou-Stanislawski --- .../source/components/charts/PagesCharts.tsx | 138 ++++++++++++++++++ mon-entreprise/source/pages/Stats/Stats.tsx | 12 +- 2 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 mon-entreprise/source/components/charts/PagesCharts.tsx diff --git a/mon-entreprise/source/components/charts/PagesCharts.tsx b/mon-entreprise/source/components/charts/PagesCharts.tsx new file mode 100644 index 000000000..1eae83fa6 --- /dev/null +++ b/mon-entreprise/source/components/charts/PagesCharts.tsx @@ -0,0 +1,138 @@ +import { formatValue } from 'publicodes' +import { + Bar, + ComposedChart, + Legend, + ResponsiveContainer, + Tooltip, + TooltipProps, + XAxis, + YAxis, +} from 'recharts' + +type Data = + | Array<{ date: string; nombre: number }> + | Array<{ date: string; nombre: Record }> + +type PagesChartProps = { + sync?: boolean + data: Data +} +const Palette = [ + '#1ea0f5', + '#697ad5', + '#b453b6', + '#ff2d96', + '#fd667f', + '#fc9e67', + '#fad750', + '#bed976', + '#82da9d', + '#46dcc3', +] + +function getColor(i: number): string { + return Palette[i % Palette.length] +} + +export default function PagesChart({ data, sync = true }: PagesChartProps) { + if (!data.length) { + return null + } + + const dataKeys = Object.keys(data[0].nombre) + const flattenedData = (data as any).map((d: any) => ({ ...d, ...d.nombre })) + + return ( + + + + + + + + } /> + + {dataKeys.map((k, i) => ( + + ))} + + + ) +} + +function formatMonth(date: string | Date) { + return new Date(date).toLocaleString('default', { + month: 'short', + year: '2-digit', + }) +} + +const CustomTooltip = ({ active, payload }: TooltipProps) => { + if (!active || !payload) { + return null + } + + const data = payload[0].payload + + return ( +

+ {formatMonth(data.date)} +
+ {payload + .map(({ color, value, name }) => ( +

+
+ + {typeof value === 'number' ? formatValue(value) : value} + +
{formatLegend(name)}
+
+
+ )) + .reverse()} +

+ ) +} + +const formatLegend = (key: string) => + key.replace('simulateurs / ', '').replace(/_/g, ' ') diff --git a/mon-entreprise/source/pages/Stats/Stats.tsx b/mon-entreprise/source/pages/Stats/Stats.tsx index faed49892..2e2cd7091 100644 --- a/mon-entreprise/source/pages/Stats/Stats.tsx +++ b/mon-entreprise/source/pages/Stats/Stats.tsx @@ -1,4 +1,5 @@ import classnames from 'classnames' +import PagesChart from 'Components/charts/PagesCharts' import Privacy from 'Components/layout/Footer/Privacy' import MoreInfosOnUs from 'Components/MoreInfosOnUs' import InfoBulle from 'Components/ui/InfoBulle' @@ -285,15 +286,8 @@ const StatsDetail = () => { )} {chapter2 === '' && period === 'mois' && ( <> -

Principales pages

- +

Simulateurs principaux

+ )}