diff --git a/Client/src/Components/Charts/PagespeedLineChart/index.css b/Client/src/Components/Charts/PagespeedLineChart/index.css new file mode 100644 index 000000000..e69de29bb diff --git a/Client/src/Components/Charts/PagespeedLineChart/index.jsx b/Client/src/Components/Charts/PagespeedLineChart/index.jsx new file mode 100644 index 000000000..de01e35ad --- /dev/null +++ b/Client/src/Components/Charts/PagespeedLineChart/index.jsx @@ -0,0 +1,55 @@ +import { LineChart } from "@mui/x-charts/LineChart"; +import PropTypes from "prop-types"; + +const PageSpeedLineChart = ({ pageSpeedChecks = [] }) => { + const keyToLabel = { + performance: "Performance", + seo: "SEO", + bestPractices: "Best practices", + accessibility: "Accessibility", + }; + + const colors = { + performance: "#2aa02b", + seo: "#9467bd", + bestPractices: "#ff7f0e", + accessibility: "#1f76b3", + }; + + const customize = { + legend: { position: { vertical: "bottom", horizontal: "middle" } }, + margin: { bottom: 75 }, + }; + + const xLabels = pageSpeedChecks.map((check) => { + return check.createdAt; + }); + + return ( + ({ + dataKey: key, + label: keyToLabel[key], + color: colors[key], + showMark: false, + }))} + yAxis={[{ min: 0, max: 100 }]} + xAxis={[ + { + scaleType: "point", + data: xLabels, + valueFormatter: (val) => new Date(val).toLocaleDateString(), + }, + ]} + dataset={pageSpeedChecks} + {...customize} + grid={{ vertical: true, horizontal: true }} + /> + ); +}; + +PageSpeedLineChart.propTypes = { + pageSpeedChecks: PropTypes.array.isRequired, +}; + +export default PageSpeedLineChart;