Added onHover events to pie chart
This commit is contained in:
1 parent
6ed7e77079
commit
8b8bfb8b2e
1 file changed
+103
-85
@@ -58,23 +58,27 @@ const StatBox = ({ icon, title, value }) => {
|
|||||||
* @param {string} props.color - The color of the text.
|
* @param {string} props.color - The color of the text.
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
*/
|
*/
|
||||||
const PieCenterLabel = ({ value, color }) => {
|
const PieCenterLabel = ({ value, color, setExpand }) => {
|
||||||
const { width, height } = useDrawingArea();
|
const { width, height } = useDrawingArea();
|
||||||
return (
|
return (
|
||||||
<text
|
<g
|
||||||
className="pie-label"
|
transform={`translate(${width / 2}, ${height / 2})`}
|
||||||
x={width / 2}
|
onMouseEnter={() => setExpand(true)}
|
||||||
y={height / 2}
|
|
||||||
style={{
|
|
||||||
fill: color,
|
|
||||||
fontSize: "45px",
|
|
||||||
textAnchor: "middle",
|
|
||||||
dominantBaseline: "central",
|
|
||||||
userSelect: "none",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{value}
|
<circle cx={0} cy={0} r={width / 3} fill="transparent" />
|
||||||
</text>
|
<text
|
||||||
|
className="pie-label"
|
||||||
|
style={{
|
||||||
|
fill: color,
|
||||||
|
fontSize: "45px",
|
||||||
|
textAnchor: "middle",
|
||||||
|
dominantBaseline: "central",
|
||||||
|
userSelect: "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
</text>
|
||||||
|
</g>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -305,11 +309,13 @@ const PageSpeedDetails = () => {
|
|||||||
return props;
|
return props;
|
||||||
};
|
};
|
||||||
|
|
||||||
const pieSize = { width: 300, height: 205 };
|
const pieSize = { width: 200, height: 200 };
|
||||||
const pieData = getPieData(data.audits);
|
const pieData = getPieData(data.audits);
|
||||||
const colorMap = getColors(performance);
|
const colorMap = getColors(performance);
|
||||||
|
|
||||||
const [highlightedItem, setHighLightedItem] = useState(null);
|
const [highlightedItem, setHighLightedItem] = useState(null);
|
||||||
|
const [expand, setExpand] = useState(false);
|
||||||
|
console.log(expand);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className="page-speed-details" gap={theme.gap.large}>
|
<Stack className="page-speed-details" gap={theme.gap.large}>
|
||||||
@@ -419,82 +425,94 @@ const PageSpeedDetails = () => {
|
|||||||
<Typography component="h2">Performance report</Typography>
|
<Typography component="h2">Performance report</Typography>
|
||||||
<Box p={theme.gap.ml}>
|
<Box p={theme.gap.ml}>
|
||||||
<Stack mx="auto" width="fit-content" alignItems="center">
|
<Stack mx="auto" width="fit-content" alignItems="center">
|
||||||
<PieChart
|
<Box onMouseLeave={() => setExpand(false)}>
|
||||||
series={[
|
{expand ? (
|
||||||
{
|
<PieChart
|
||||||
data: [
|
series={[
|
||||||
{
|
{
|
||||||
value: 100,
|
data: [
|
||||||
color: colorMap.bg,
|
{
|
||||||
|
value: 100,
|
||||||
|
color: colorMap.bg,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
outerRadius: 65,
|
||||||
|
cx: pieSize.width / 2,
|
||||||
},
|
},
|
||||||
],
|
...pieData,
|
||||||
outerRadius: 65,
|
]}
|
||||||
cx: pieSize.width / 2,
|
width={pieSize.width}
|
||||||
},
|
height={pieSize.height}
|
||||||
{
|
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
||||||
data: [
|
onHighlightChange={setHighLightedItem}
|
||||||
|
slotProps={{
|
||||||
|
legend: { hidden: true },
|
||||||
|
}}
|
||||||
|
tooltip={{ trigger: "none" }}
|
||||||
|
sx={{
|
||||||
|
"&:has(.MuiPieArcLabel-faded) .pie-label": {
|
||||||
|
fill: "rgba(0,0,0,0) !important",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PieCenterLabel
|
||||||
|
value={performance}
|
||||||
|
color={colorMap.text}
|
||||||
|
setExpand={setExpand}
|
||||||
|
/>
|
||||||
|
{pieData?.map((pie) => (
|
||||||
|
<PieValueLabel
|
||||||
|
key={pie.id}
|
||||||
|
value={pie.data[0].value}
|
||||||
|
startAngle={pie.startAngle}
|
||||||
|
endAngle={pie.endAngle}
|
||||||
|
color={pie.data[0].color}
|
||||||
|
highlighted={highlightedItem?.seriesId === pie.id}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</PieChart>
|
||||||
|
) : (
|
||||||
|
<PieChart
|
||||||
|
series={[
|
||||||
{
|
{
|
||||||
value: performance,
|
data: [
|
||||||
color: colorMap.stroke,
|
{
|
||||||
|
value: 100,
|
||||||
|
color: colorMap.bg,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
outerRadius: 65,
|
||||||
|
cx: pieSize.width / 2,
|
||||||
},
|
},
|
||||||
],
|
|
||||||
innerRadius: 60,
|
|
||||||
outerRadius: 70,
|
|
||||||
paddingAngle: 5,
|
|
||||||
cornerRadius: 5,
|
|
||||||
startAngle: 0,
|
|
||||||
endAngle: (performance / 100) * 360,
|
|
||||||
cx: pieSize.width / 2,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
width={pieSize.width}
|
|
||||||
height={pieSize.height}
|
|
||||||
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
|
||||||
tooltip={{ trigger: "none" }}
|
|
||||||
>
|
|
||||||
<PieCenterLabel value={performance} color={colorMap.text} />
|
|
||||||
</PieChart>
|
|
||||||
<PieChart
|
|
||||||
series={[
|
|
||||||
{
|
|
||||||
data: [
|
|
||||||
{
|
{
|
||||||
value: 100,
|
data: [
|
||||||
color: colorMap.bg,
|
{
|
||||||
|
value: performance,
|
||||||
|
color: colorMap.stroke,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
innerRadius: 60,
|
||||||
|
outerRadius: 70,
|
||||||
|
paddingAngle: 5,
|
||||||
|
cornerRadius: 5,
|
||||||
|
startAngle: 0,
|
||||||
|
endAngle: (performance / 100) * 360,
|
||||||
|
cx: pieSize.width / 2,
|
||||||
},
|
},
|
||||||
],
|
]}
|
||||||
outerRadius: 65,
|
width={pieSize.width}
|
||||||
cx: pieSize.width / 2,
|
height={pieSize.height}
|
||||||
},
|
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
||||||
...pieData,
|
tooltip={{ trigger: "none" }}
|
||||||
]}
|
>
|
||||||
width={pieSize.width}
|
<PieCenterLabel
|
||||||
height={pieSize.height}
|
value={performance}
|
||||||
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
color={colorMap.text}
|
||||||
highlightedItem={highlightedItem}
|
setExpand={setExpand}
|
||||||
onHighlightChange={setHighLightedItem}
|
/>
|
||||||
slotProps={{
|
</PieChart>
|
||||||
legend: { hidden: true },
|
)}
|
||||||
}}
|
</Box>
|
||||||
tooltip={{ trigger: "none" }}
|
|
||||||
sx={{
|
|
||||||
"&:has(.MuiPieArcLabel-faded) .pie-label": {
|
|
||||||
fill: "rgba(0,0,0,0) !important",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<PieCenterLabel value={performance} color={colorMap.text} />
|
|
||||||
{pieData?.map((pie) => (
|
|
||||||
<PieValueLabel
|
|
||||||
key={pie.id}
|
|
||||||
value={pie.data[0].value}
|
|
||||||
startAngle={pie.startAngle}
|
|
||||||
endAngle={pie.endAngle}
|
|
||||||
color={pie.data[0].color}
|
|
||||||
highlighted={highlightedItem?.seriesId === pie.id}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</PieChart>
|
|
||||||
<Typography component="h2" mt={theme.gap.xs}>
|
<Typography component="h2" mt={theme.gap.xs}>
|
||||||
Performance
|
Performance
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|||||||
Reference in new issue
Block a user