Skip to content

Commit dc520f0

Browse files
[tools] Migrate from recharts to MUI X Charts (#147)
1 parent 5ab6cc5 commit dc520f0

File tree

5 files changed

+96
-58
lines changed

5 files changed

+96
-58
lines changed

tools-public/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
"dependencies": {
1212
"@googleapis/sheets": "^4.0.2",
1313
"@mui/toolpad": "^0.1.40",
14+
"@mui/x-charts": "^6.19.3",
15+
"@mui/system": "^5.0.0",
1416
"@octokit/core": "^4.2.1",
1517
"axios": "^1.3.6",
1618
"dayjs": "^1.11.8",
1719
"google-auth-library": "^8.8.0",
1820
"graphql": "^16.6.0",
1921
"graphql-request": "^6.0.0",
2022
"mysql": "^2.18.1",
21-
"recharts": "^2.8.0",
2223
"ssh2-promise": "^1.0.3"
2324
},
2425
"devDependencies": {

tools-public/pnpm-lock.yaml

+51-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools-public/toolpad/application.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
apiVersion: v1
22
kind: application
3-
spec: {}
3+
spec: { authentication: {}, authorization: {} }
+40-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
2+
import Box from '@mui/system/Box';
3+
import { PieChart, pieArcLabelClasses } from '@mui/x-charts/PieChart';
24
import { createComponent } from '@mui/toolpad/browser';
3-
import { PieChart, Pie, Cell, Tooltip } from 'recharts';
45

56
// Copied from https://wpdatatables.com/data-visualization-color-palette/
67
const COLORS = [
@@ -16,29 +17,46 @@ const COLORS = [
1617
];
1718

1819
export interface PieChartProps {
19-
data: object[];
20+
data: any[];
21+
loading: boolean;
2022
}
2123

22-
function PieChartExport({ data }: PieChartProps) {
24+
const height = 300;
25+
const width = 300;
26+
27+
function PieChartExport({ data, loading }: PieChartProps) {
28+
if (loading) {
29+
return <Box sx={{ width, height, display: 'flex', alignItems: 'center', px: 2 }}>Loading…</Box>;
30+
}
31+
2332
return (
24-
<PieChart width={300} height={300}>
25-
<Pie
26-
data={data}
27-
cx={150}
28-
cy={150}
29-
innerRadius={0}
30-
outerRadius={80}
31-
fill="#8884d8"
32-
dataKey="value"
33-
>
34-
{data.map((entry, index) => (
35-
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
36-
))}
37-
</Pie>
38-
<Tooltip
39-
formatter={(value) => Intl.NumberFormat('en', { notation: 'compact' }).format(value)}
33+
<div>
34+
<PieChart
35+
series={[
36+
{
37+
data: data.map((entry, index) => ({
38+
id: index,
39+
label: entry.name,
40+
color: COLORS[index % COLORS.length],
41+
value: entry.value,
42+
})),
43+
arcLabel: (item) => item.label!,
44+
arcLabelMinAngle: 30,
45+
valueFormatter: ({ value }) =>
46+
Intl.NumberFormat('en', { notation: 'compact' }).format(value),
47+
},
48+
]}
49+
sx={{
50+
[`& .${pieArcLabelClasses.root}`]: {
51+
fill: 'white',
52+
fontWeight: 'bold',
53+
},
54+
}}
55+
width={width}
56+
height={height}
57+
slotProps={{ legend: { hidden: true } }}
4058
/>
41-
</PieChart>
59+
</div>
4260
);
4361
}
4462

@@ -54,4 +72,6 @@ export default createComponent(PieChartExport, {
5472
],
5573
},
5674
},
75+
loadingPropSource: ['data'],
76+
loadingProp: 'loading',
5777
});

tools-public/toolpad/pages/npmVersion/page.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ spec:
3030
page.parameters.package
3131
- component: codeComponent.PieChart
3232
name: codeComponent_PieChart
33-
layout:
34-
columnSize: 1
3533
props:
3634
data:
3735
$$jsExpression: |
@@ -58,6 +56,8 @@ spec:
5856
return acc
5957
}, {})
6058
).map((group) => ({ name: group[0], value: group[1] }))
59+
layout:
60+
columnSize: 1
6161
queries:
6262
- name: downloadsVersions
6363
query:

0 commit comments

Comments
 (0)