-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/alerts recap charts #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c73d76
feat(alerts,chart): first version donut chart
tristan-gueguen ba9df18
feat(alerts,chart,admin): have a dummy segmented control to display c…
tristan-gueguen c31e88c
feat(alerts,chart,admin): dummy table
tristan-gueguen 9aaaaed
feat(charts,alerts): refacto, style
tristan-gueguen 4c2369f
feat(charts,alerts): bold legend
tristan-gueguen 711924f
feat(charts,alerts): min height to avoid jump when switching tab
tristan-gueguen d938399
feat(charts,alerts): graphe -> graphique, bigger inner text
tristan-gueguen 1c01dd8
feat(alerts,charts): do not display chart if there are 0 alerts
tristan-gueguen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .alerts-chart { | ||
| .recharts-legend-item-text { | ||
| font-size: 0.75rem; | ||
| color: var(--background-flat-grey) !important; | ||
| font-weight: 700; | ||
| } | ||
| .inner-text { | ||
| font-weight: 400; | ||
| font-size: 2rem; | ||
| } | ||
| } | ||
|
|
||
| .fr-tile.alerts-chart { | ||
| padding-left: 0px; | ||
| padding-right: 0px; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import React from "react"; | ||
| import { | ||
| Legend, | ||
| Pie, | ||
| PieChart, | ||
| ResponsiveContainer, | ||
| Tooltip, | ||
| Sector | ||
| } from "recharts"; | ||
| const renderActiveShape = ({ | ||
| cx, | ||
| cy, | ||
| innerRadius, | ||
| outerRadius, | ||
| startAngle, | ||
| endAngle, | ||
| fill, | ||
| payload | ||
| }) => { | ||
| return ( | ||
| <g> | ||
| <text | ||
| x={cx} | ||
| y={cy} | ||
| dy={8} | ||
| textAnchor="middle" | ||
| fill={fill} | ||
| className="inner-text" | ||
| > | ||
| {payload.value} | ||
| </text> | ||
| <Sector | ||
| cx={cx} | ||
| cy={cy} | ||
| innerRadius={innerRadius} | ||
| outerRadius={outerRadius} | ||
| startAngle={startAngle} | ||
| endAngle={endAngle} | ||
| fill={fill} | ||
| /> | ||
| <Sector | ||
| cx={cx} | ||
| cy={cy} | ||
| startAngle={startAngle} | ||
| endAngle={endAngle} | ||
| innerRadius={(outerRadius ?? 0) + 6} | ||
| outerRadius={(outerRadius ?? 0) + 10} | ||
| fill={fill} | ||
| /> | ||
| </g> | ||
| ); | ||
| }; | ||
|
|
||
| export const Chart = ({ data }) => { | ||
| return ( | ||
| <ResponsiveContainer width="100%" aspect={1}> | ||
| <PieChart> | ||
| <Pie | ||
| activeShape={renderActiveShape} | ||
| data={data} | ||
| cx="50%" | ||
| cy="50%" | ||
| innerRadius="50%" | ||
| outerRadius="90%" | ||
| fill="#8884d8" | ||
| dataKey="value" | ||
| isAnimationActive={true} | ||
| /> | ||
| <Tooltip content={() => null} /> | ||
tristan-gueguen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Legend /> | ||
| </PieChart> | ||
| </ResponsiveContainer> | ||
| ); | ||
| }; | ||
98 changes: 95 additions & 3 deletions
98
web/admin/panels/RegulatoryRespect/RegulatoryRespectChart.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,97 @@ | ||
| import React from "react"; | ||
| import React, { useState } from "react"; | ||
| import { Box, Typography } from "@mui/material"; | ||
| import { useRegulatoryAlertsSummaryContext } from "../../utils/contextRegulatoryAlertsSummary"; | ||
| import { SegmentedControl } from "@codegouvfr/react-dsfr/SegmentedControl"; | ||
| import { Table } from "@codegouvfr/react-dsfr/Table"; | ||
| import { Chart } from "./Chart"; | ||
|
|
||
| export const Chart = () => { | ||
| return null; | ||
| const ALERTS_DATA = { | ||
| maximumWorkedDaysInWeek: { | ||
| label: "Repos hebdomadaire", | ||
| color: "#81EEF5" | ||
| }, | ||
| maximumWorkInCalendarWeek: { | ||
| label: "Durée du travail hebdomadaire", | ||
| color: "#B478F1" | ||
| }, | ||
| minimumDailyRest: { | ||
| label: "Repos journalier", | ||
| color: "#31A7AE" | ||
| }, | ||
| not_enough_break: { | ||
| label: "Temps de pause", | ||
| color: "#5C68E5" | ||
| }, | ||
| too_much_uninterrupted_work_time: { | ||
| label: "Durée maximale de travail ininterrompu", | ||
| color: "#29598F" | ||
| }, | ||
| maximumWorkDayTime: { | ||
| label: "Durée du travail quotidien", | ||
| color: "#115ADF" | ||
| } | ||
| }; | ||
|
|
||
| export const RegulatoryRespectChart = () => { | ||
| const { summary } = useRegulatoryAlertsSummaryContext(); | ||
| const [selectedView, setSelectedView] = useState("chart"); | ||
| const data = [...summary.dailyAlerts, ...summary.weeklyAlerts] | ||
| .filter((alert) => alert.alertsType in ALERTS_DATA) | ||
| .map((alert) => ({ | ||
| name: ALERTS_DATA[alert.alertsType].label, | ||
| value: alert.nbAlerts, | ||
| fill: ALERTS_DATA[alert.alertsType].color | ||
| })) | ||
| .filter((d) => d.value > 0); | ||
|
|
||
| if (data.length === 0) { | ||
| return; | ||
| } | ||
| return ( | ||
| <Box className="fr-tile alerts-chart" minHeight="470px"> | ||
| <Typography | ||
| fontWeight="bold" | ||
| fontSize="1.2rem" | ||
| textAlign="left" | ||
| lineHeight="1.75rem" | ||
| paddingX={4} | ||
| > | ||
| Répartition des dépassements de seuils | ||
| </Typography> | ||
| {selectedView === "chart" ? ( | ||
| <Chart data={data} /> | ||
| ) : ( | ||
| <Box paddingX={4}> | ||
| <Table | ||
| caption="Répartition des dépassements de seuils" | ||
| data={data.map((d) => [d.name, d.value])} | ||
| headers={["Alerte", "#"]} | ||
| /> | ||
| </Box> | ||
| )} | ||
| <Box paddingX={4} mt={2}> | ||
| <SegmentedControl | ||
| segments={[ | ||
| { | ||
| iconId: "fr-icon-pie-chart-2-fill", | ||
| label: "Graphique", | ||
| nativeInputProps: { | ||
| value: "chart", | ||
| defaultChecked: true, | ||
| onChange: () => setSelectedView("chart") | ||
| } | ||
| }, | ||
| { | ||
| iconId: "fr-icon-table-line", | ||
| label: "Tableau", | ||
| nativeInputProps: { | ||
| value: "table", | ||
| onChange: () => setSelectedView("table") | ||
| } | ||
| } | ||
| ]} | ||
| /> | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.