Skip to content
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

Migrate Chart component to X charts library #2500

Merged
merged 51 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a8938dc
Initial setup
apedroferreira Aug 16, 2023
fd1845c
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Aug 16, 2023
e520b34
Migrate to X-charts
apedroferreira Aug 22, 2023
bafb0a3
Fix empty chart, add legend and tooltip and some other improvements
apedroferreira Aug 22, 2023
e956563
Improve empty chart state, fix chart controls overflow, some more ref…
apedroferreira Aug 23, 2023
a2030db
Open series editor on first series creation, use color palette from X…
apedroferreira Aug 24, 2023
78e2573
More fixes
apedroferreira Aug 25, 2023
0737638
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Aug 25, 2023
a6169af
Another fix
apedroferreira Aug 25, 2023
60bf213
And more
apedroferreira Aug 25, 2023
d055cf2
Fix scatter charts
apedroferreira Aug 25, 2023
8c46fd8
Fix lint
apedroferreira Aug 25, 2023
0f0b1fe
Remove chart from future components
apedroferreira Aug 28, 2023
e9b0fb8
Try latest charts version
apedroferreira Aug 30, 2023
391c4a2
Try to make tests work with ESM modules
apedroferreira Aug 30, 2023
9163c99
Try something else
apedroferreira Aug 30, 2023
a50adde
Use transformIgnorePatterns
apedroferreira Aug 30, 2023
7636924
Adjust integration tests
apedroferreira Aug 30, 2023
2d68f8e
ugh
apedroferreira Aug 30, 2023
ed6685d
Try to fix viteimports issue + fix CI tests
apedroferreira Aug 30, 2023
875b645
No need for recharts here after all
apedroferreira Aug 31, 2023
c9e2a1a
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Aug 31, 2023
77a3abb
Update yarn.lock
apedroferreira Aug 31, 2023
9c6133e
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Aug 31, 2023
b2eded4
Fix crashes when data is invalid
apedroferreira Aug 31, 2023
2fd816c
Try recharts in dependencies instead of devDependencies
apedroferreira Aug 31, 2023
fc326a0
Fix from mui public
apedroferreira Aug 31, 2023
054d4b5
Add recharts to optimizeDeps again
apedroferreira Aug 31, 2023
ea1a78b
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Aug 31, 2023
cc929d0
Fix z-index and something else I don't remember
apedroferreira Aug 31, 2023
5a00875
Update packages/toolpad-app/src/server/toolpadAppBuilder.ts
apedroferreira Sep 1, 2023
209ecd2
Revert back to circular progress spinner
apedroferreira Sep 1, 2023
e891543
Handle null data
apedroferreira Sep 1, 2023
a6edeab
This does nothing after all
apedroferreira Sep 1, 2023
db8ea44
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Sep 4, 2023
71feabd
Update yarn.lock
apedroferreira Sep 4, 2023
aa0d365
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Sep 19, 2023
f708acb
Remove vite commonjs plugin, update x charts library
apedroferreira Sep 19, 2023
8dc92d9
Fix tests and remove all children: []
apedroferreira Sep 19, 2023
7d7a22d
Remove children: []
apedroferreira Sep 19, 2023
296c0a1
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Sep 27, 2023
c8fe778
Update library
apedroferreira Sep 27, 2023
e196afa
Remove jest config
apedroferreira Sep 27, 2023
7953e47
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Oct 18, 2023
29d9eaf
Update x-charts, show better xKey and yKey errors
apedroferreira Oct 18, 2023
4e26346
Fix showing of undefined values
apedroferreira Oct 18, 2023
fd6b67d
Fix automatic chart colors on duplicate
apedroferreira Oct 18, 2023
1bfd9f0
Fix width issues with long labels
apedroferreira Oct 19, 2023
e66fbfa
Merge remote-tracking branch 'upstream/master' into migrate-x-charts
apedroferreira Oct 31, 2023
bc7e5fb
Update x-charts
apedroferreira Oct 31, 2023
82f1315
Fix error and loading states
apedroferreira Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/npm-stats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"start": "NODE_OPTIONS='--max-old-space-size=396' toolpad start"
},
"dependencies": {
"@mui/toolpad": "0.1.28",
"recharts": "2.8.0"
"@mui/toolpad": "0.1.28"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@argos-ci/core": "0.11.1",
"@jest/globals": "29.7.0",
"@mui/monorepo": "https://github.com/mui/material-ui.git",
"@mui/x-charts": "6.0.0-alpha.11",
"@next/eslint-plugin-next": "13.4.19",
"@playwright/test": "1.38.0",
"@testing-library/jest-dom": "6.1.3",
Expand Down
12 changes: 12 additions & 0 deletions packages/toolpad-app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ const transpiledModules = [
'data-uri-to-buffer',
'fetch-blob',
'formdata-polyfill',
'd3-scale',
'd3-array',
'internmap',
'd3-interpolate',
'd3-color',
'd3-format',
'd3-time',
'd3-time-format',
'd3-shape',
'd3-path',
'@mui/x-charts/esm',
apedroferreira marked this conversation as resolved.
Show resolved Hide resolved
'@babel/runtime/helpers/esm',
];

module.exports = /** @type {import('jest').Config} */ ({
Expand Down
1 change: 1 addition & 0 deletions packages/toolpad-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@mui/toolpad-utils": "0.1.28",
"@mui/types": "7.2.4",
"@mui/utils": "5.14.10",
"@mui/x-charts": "6.0.0-alpha.11",
"@mui/x-data-grid": "6.14.0",
"@mui/x-data-grid-pro": "6.14.0",
"@mui/x-date-pickers": "6.14.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/toolpad-app/src/server/toolpadAppBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ export function createViteConfig({
'@mui/material/useMediaQuery',
'@mui/utils',
'@mui/utils/useEventCallback',
'@mui/x-charts',
'@mui/x-charts/ResponsiveChartContainer',
'@mui/x-charts/ChartsXAxis',
'@mui/x-charts/ChartsYAxis',
'@mui/x-charts/ChartsLegend',
'@mui/x-charts/ChartsTooltip',
'@mui/x-charts/ChartsAxisHighlight',
'@mui/x-charts/colorPalettes',
'@mui/x-data-grid-pro',
'@mui/x-date-pickers/AdapterDayjs',
'@mui/x-date-pickers/DesktopDatePicker',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface FutureComponentSpec {
}

const FUTURE_COMPONENTS = new Map<string, FutureComponentSpec>([
['Chart', { url: 'https://github.com/mui/mui-toolpad/issues/789', displayName: 'Chart' }],
['Map', { url: 'https://github.com/mui/mui-toolpad/issues/864', displayName: 'Map' }],
['Drawer', { url: 'https://github.com/mui/mui-toolpad/issues/1540', displayName: 'Drawer' }],
['Html', { url: 'https://github.com/mui/mui-toolpad/issues/1311', displayName: 'Html' }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function NodeAttributeEditor<P extends object>({
propType={argType}
jsRuntime={jsBrowserRuntime}
renderControl={(params) => (
<Box sx={{ flex: 1 }}>
<Box sx={{ flex: 1, maxWidth: '100%' }}>
<Control nodeId={node.id} {...params} propType={argType} />
</Box>
)}
Expand Down
44 changes: 33 additions & 11 deletions packages/toolpad-app/src/toolpad/propertyControls/ChartData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import BarChartIcon from '@mui/icons-material/BarChart';
import ShowChartIcon from '@mui/icons-material/ShowChart';
import LegendToggleIcon from '@mui/icons-material/LegendToggle';
import { evaluateBindable } from '@mui/toolpad-core/jsRuntime';
import { blueberryTwilightPalette } from '@mui/x-charts/colorPalettes';
import * as appDom from '../../appDom';
import type { EditorProps } from '../../types';
import PropertyControl from '../../components/PropertyControl';
Expand Down Expand Up @@ -58,6 +59,8 @@ function ChartDataPropEditor({

const appTheme = React.useMemo(() => createToolpadAppTheme(dom), [dom]);

const defaultPalette = blueberryTwilightPalette(appTheme.palette.mode);

const [dataSeriesEditIndex, setDataSeriesEditIndex] = React.useState<number | null>(null);
const [popoverAnchorElement, setPopoverAnchorElement] = React.useState<HTMLElement | null>(null);

Expand All @@ -72,13 +75,20 @@ function ChartDataPropEditor({
label: newDataSeriesLabel,
kind: 'line',
data: [],
color:
newDataSeriesCount % 2 === 0
? appTheme.palette.secondary.main
: appTheme.palette.primary.main,
color: defaultPalette[(newDataSeriesCount - 1) % defaultPalette.length],
},
]);
}, [appTheme, onChange, value]);
}, [defaultPalette, onChange, value]);

const previousDataSeriesCountRef = React.useRef(value.length);
React.useEffect(() => {
if (previousDataSeriesCountRef.current === 0 && value.length === 1) {
setDataSeriesEditIndex(0);
setPopoverAnchorElement(document.getElementById('data-series-button-1'));
}

previousDataSeriesCountRef.current = value.length;
}, [value.length]);

const handleDataSeriesClick = React.useCallback(
(index: number) => (event: React.MouseEvent<HTMLElement>) => {
Expand All @@ -90,9 +100,13 @@ function ChartDataPropEditor({

const handleDuplicateDataSeries = React.useCallback(
(index: number) => () => {
onChange([...value.slice(0, index + 1), value[index], ...value.slice(index + 1)]);
onChange([
...value.slice(0, index + 1),
{ ...value[index], color: defaultPalette[(index + 1) % defaultPalette.length] },
...value.slice(index + 1),
]);
},
[onChange, value],
[defaultPalette, onChange, value],
);

const handleRemoveDataSeries = React.useCallback(
Expand Down Expand Up @@ -213,9 +227,11 @@ function ChartDataPropEditor({
const dataResult = (evaluateBindable(jsBrowserRuntime, dataSeries.data, pageState).value ||
[]) as NonNullable<ChartDataSeries['data']>;

return dataResult
.flatMap((dataSeriesPoint) => Object.keys(dataSeriesPoint))
.filter((key, index, array) => array.indexOf(key) === index);
return Array.isArray(dataResult)
? dataResult
.flatMap((dataSeriesPoint) => Object.keys(dataSeriesPoint))
.filter((key, index, array) => array.indexOf(key) === index)
: [];
}),
[jsBrowserRuntime, pageState, value],
);
Expand All @@ -233,10 +249,16 @@ function ChartDataPropEditor({
return (
<ListItem key={index} disableGutters>
<ListItemButton
id={`data-series-button-${index + 1}`}
onClick={handleDataSeriesClick(index)}
aria-describedby={popoverId}
>
<ListItemText primary={label} />
<ListItemText
primary={label}
primaryTypographyProps={{
style: { overflow: 'hidden', textOverflow: 'ellipsis' },
}}
/>
</ListItemButton>
<IconButton
aria-label="Duplicate data series"
Expand Down
4 changes: 2 additions & 2 deletions packages/toolpad-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"@mui/material": "5.14.10",
"@mui/toolpad-core": "0.1.28",
"@mui/toolpad-utils": "0.1.28",
"@mui/x-charts": "6.0.0-alpha.11",
"@mui/x-data-grid-pro": "6.14.0",
"@mui/x-date-pickers": "6.14.0",
"@mui/x-license-pro": "6.10.2",
"dayjs": "1.11.9",
"markdown-to-jsx": "7.3.2",
"react-error-boundary": "4.0.11",
"react-hook-form": "7.46.1",
"recharts": "2.8.0"
"react-hook-form": "7.46.1"
},
"devDependencies": {
"@types/react": "18.2.21",
Expand Down
Loading