diff --git a/Client/src/Pages/PageSpeed/Details/index.css b/Client/src/Pages/PageSpeed/Details/index.css
index 39f0c60a5..96cd787c5 100644
--- a/Client/src/Pages/PageSpeed/Details/index.css
+++ b/Client/src/Pages/PageSpeed/Details/index.css
@@ -51,3 +51,18 @@
width: 22px;
height: 22px;
}
+.page-speed-details .MuiPieArcLabel-root {
+ font-size: var(--env-var-font-size-small-plus);
+ transition: fill 300ms ease;
+}
+.page-speed-details .MuiPieArcLabel-faded {
+ fill: rgba(0, 0, 0, 0.3);
+}
+.page-speed-details .pie-label,
+.page-speed-details .pie-value-label {
+ transition: all 400ms ease;
+}
+
+.page-speed-details .MuiPieArc-root {
+ stroke: inherit;
+}
diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx
index 8dcf240b6..f5671be2e 100644
--- a/Client/src/Pages/PageSpeed/Details/index.jsx
+++ b/Client/src/Pages/PageSpeed/Details/index.jsx
@@ -58,22 +58,70 @@ const StatBox = ({ icon, title, value }) => {
* @param {string} props.color - The color of the text.
* @returns {JSX.Element}
*/
-const PieCenterLabel = ({ value, color }) => {
- const { width, height, left, top } = useDrawingArea();
+const PieCenterLabel = ({ value, color, setExpand }) => {
+ const { width, height } = useDrawingArea();
return (
- setExpand(true)}
>
- {value}
-
+
+
+ {value}
+
+
+ );
+};
+
+/**
+ * A component that renders a label on a pie chart slice.
+ * The label is positioned relative to the center of the pie chart and is optionally highlighted.
+ *
+ * @param {Object} props
+ * @param {number} props.value - The value to display inside the pie slice.
+ * @param {number} props.startAngle - The starting angle of the pie slice in degrees.
+ * @param {number} props.endAngle - The ending angle of the pie slice in degrees.
+ * @param {string} props.color - The color of the label text when highlighted.
+ * @param {boolean} props.highlighted - Determines if the label should be highlighted or not.
+ * @returns {JSX.Element}
+ */
+const PieValueLabel = ({ value, startAngle, endAngle, color, highlighted }) => {
+ const { width, height } = useDrawingArea();
+
+ // Compute the midpoint angle in radians
+ const angle = (((startAngle + endAngle) / 2) * Math.PI) / 180;
+ const radius = height / 3.7; // length from center of the circle to where the text is positioned
+
+ // Calculate x and y positions
+ const x = Math.sin(angle) * radius;
+ const y = -Math.cos(angle) * radius;
+
+ return (
+
+
+ +{value}
+
+
);
};
@@ -114,7 +162,7 @@ const PageSpeedDetails = () => {
title: "Cumulative Layout Shift",
description:
"Cumulative Layout Shift measures the movement of visible elements within the viewport.",
- score: 1,
+ score: 0.1,
scoreDisplayMode: "numeric",
displayValue: "0",
numericValue: 0,
@@ -126,7 +174,7 @@ const PageSpeedDetails = () => {
title: "Speed Index",
description:
"Speed Index shows how quickly the contents of a page are visibly populated.",
- score: 1,
+ score: 0.9,
scoreDisplayMode: "numeric",
displayValue: "0.6s",
numericValue: 567.8934352052013,
@@ -138,7 +186,7 @@ const PageSpeedDetails = () => {
title: "First Contentful Paint",
description:
"First Contentful Paint marks the time at which the first text or image is painted.",
- score: 0.1,
+ score: 0.8,
scoreDisplayMode: "numeric",
displayValue: "0.4s",
numericValue: 419,
@@ -150,7 +198,7 @@ const PageSpeedDetails = () => {
title: "Largest Contentful Paint",
description:
"Largest Contentful Paint marks the time at which the largest text or image is painted.",
- score: 1,
+ score: 0.6,
scoreDisplayMode: "numeric",
displayValue: "0.4s",
numericValue: 422.5,
@@ -162,7 +210,7 @@ const PageSpeedDetails = () => {
title: "Total Blocking Time",
description:
"Sum of all time periods between FCP and Time to Interactive",
- score: 1,
+ score: 0.9,
scoreDisplayMode: "numeric",
displayValue: "20ms",
numericValue: 16,
@@ -188,24 +236,6 @@ const PageSpeedDetails = () => {
cls: 25,
};
- /**
- * Calculates the performance score based on the provided audit data and weights.
- *
- * @param {Object} audits - An object containing audit data.
- * @param {Object} audits. - An object for each performance metric.
- * @param {number} audits..score - The score for the specific metric.
- * @returns {number} The calculated performance score, rounded to the nearest integer.
- */
- const calculatePerformance = (audits) => {
- let sum = 0;
- Object.keys(audits).forEach((key) => {
- if (audits[key].score) sum += audits[key].score * weights[key];
- });
- return Math.round(sum);
- };
-
- var performance = calculatePerformance(data.audits);
-
/**
* Retrieves color properties based on the performance value.
*
@@ -219,8 +249,74 @@ const PageSpeedDetails = () => {
return theme.pie.default;
};
+ /**
+ * Calculates and formats the data needed for rendering a pie chart based on audit scores and weights.
+ * This function generates properties for each pie slice, including angles, radii, and colors.
+ * It also calculates performance based on the weighted values.
+ *
+ * @returns {Array