Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Jan 15, 2025
2 parents 78e83f8 + 6db57cd commit e786718
Show file tree
Hide file tree
Showing 86 changed files with 1,122 additions and 749 deletions.
9 changes: 0 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ commands:
# See https://stackoverflow.com/a/73411601
command: corepack enable --install-directory ~/bin

- when:
condition:
not:
equal: [stable, << parameters.react-version >>]
steps:
- run:
name: Change pnpm setting to not install peer dependencies
command: pnpm config set auto-install-peers false --location project

- run:
name: View install environment
command: |
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/create-cherry-pick-pr.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: Create cherry-pick PR
on:
pull_request_target:
branches:
- 'next'
- 'v*.x'
- 'master'
types: ['closed']
branches: [master, next, 'v[0-9]+.x']
types: [closed]

permissions: {}

Expand Down
9 changes: 9 additions & 0 deletions docs/data/charts/getting-started/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ The outer margin space is where information like axes, titles, and legends are d

See the [Styling documentation](/x/react-charts/styling/#placement) for complete details.

## Server-side rendering

The chart support server-side rendering under two conditions:

1. The `width` and `height` props needs to be provided.
2. The animation should be disabled with the `skipAnimation` prop.

The reason is that it is not possible to compute the SVG dimensions on the server, and the `skipAnimation` ensures that the animation is not in an "empty" state when first rendering.

## Axis management

MUI X Charts take a flexible approach to axis management, with support for multiple axes and any combination of scales and ranges.
Expand Down
111 changes: 111 additions & 0 deletions docs/data/charts/legend/CustomLegend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles';
import { useLegend } from '@mui/x-charts/hooks';
import { LineChart } from '@mui/x-charts/LineChart';

function LineWithMark({ color, size }) {
return (
<svg
viewBox="0 0 24 24"
width={size}
height={size}
stroke={color}
strokeWidth={3}
strokeLinecap="round"
fill="none"
>
<path d="M 1 12.5 L 7 12.5 M 17 12.5 L 23 12.5" />
<circle cx={12} cy={12.5} r={5} />
</svg>
);
}

function DashedLine({ color, size }) {
return (
<svg
viewBox="0 0 24 24"
width={size}
height={size}
stroke={color}
strokeWidth={3}
fill="none"
>
<path d="M 1 12.5 L 23 12.5" strokeDasharray="5 3" />
</svg>
);
}

function MyCustomLegend() {
const { items } = useLegend();
return (
<Stack direction="row" gap={3}>
{items.map((item) => {
const { label, id, color, seriesId } = item;
return (
<Box key={id} sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
{seriesId === 'avg' ? (
<DashedLine color={color} size={20} />
) : (
<LineWithMark color={color} size={20} />
)}
<Typography sx={{ display: 'inline-block' }}>{`${label}`}</Typography>
</Box>
);
})}
</Stack>
);
}

const dataset = [
{ month: 'Jan', '1991_2020_avg': 4.1, 2023: 3.9 },
{ month: 'Fev', '1991_2020_avg': 4.7, 2023: 8.9 },
{ month: 'Mar', '1991_2020_avg': 7.5, 2023: 9.5 },
{ month: 'Apr', '1991_2020_avg': 10.6, 2023: 11.5 },
{ month: 'May', '1991_2020_avg': 13.8, 2023: 15.5 },
{ month: 'Jun', '1991_2020_avg': 16.7, 2023: 16.4 },
{ month: 'Jul', '1991_2020_avg': 18.9, 2023: 19.5 },
{ month: 'Aug', '1991_2020_avg': 18.8, 2023: 20.5 },
{ month: 'Sep', '1991_2020_avg': 15.8, 2023: 16.4 },
{ month: 'Oct', '1991_2020_avg': 11.9, 2023: 13.2 },
{ month: 'Nov', '1991_2020_avg': 7.6, 2023: 8.1 },
{ month: 'Dec', '1991_2020_avg': 4.7, 2023: 6.1 },
];

export default function CustomLegend() {
const theme = useTheme();

return (
<Box
sx={{ height: 300, width: '100%', display: 'flex', flexDirection: 'column' }}
>
<LineChart
dataset={dataset}
series={[
{
id: 'avg',
label: 'temp. avg. 1991-2020 (°C)',
dataKey: '1991_2020_avg',
showMark: false,
color: theme.palette.text.primary,
},
{
id: '2023-temp',
label: 'temp. 2023 (°C)',
dataKey: '2023',
color: theme.palette.primary.main,
},
]}
xAxis={[{ dataKey: 'month', scaleType: 'band', id: 'x-axis' }]}
sx={{
[`& .MuiLineElement-series-avg`]: {
strokeDasharray: '10 5',
},
}}
slots={{ legend: MyCustomLegend }}
/>
</Box>
);
}
116 changes: 116 additions & 0 deletions docs/data/charts/legend/CustomLegend.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles';
import { useLegend } from '@mui/x-charts/hooks';
import { LineChart } from '@mui/x-charts/LineChart';

type IconProps = {
color: string;
size: number;
};

function LineWithMark({ color, size }: IconProps) {
return (
<svg
viewBox="0 0 24 24"
width={size}
height={size}
stroke={color}
strokeWidth={3}
strokeLinecap="round"
fill="none"
>
<path d="M 1 12.5 L 7 12.5 M 17 12.5 L 23 12.5" />
<circle cx={12} cy={12.5} r={5} />
</svg>
);
}

function DashedLine({ color, size }: IconProps) {
return (
<svg
viewBox="0 0 24 24"
width={size}
height={size}
stroke={color}
strokeWidth={3}
fill="none"
>
<path d="M 1 12.5 L 23 12.5" strokeDasharray="5 3" />
</svg>
);
}

function MyCustomLegend() {
const { items } = useLegend();
return (
<Stack direction="row" gap={3}>
{items.map((item) => {
const { label, id, color, seriesId } = item;
return (
<Box key={id} sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
{seriesId === 'avg' ? (
<DashedLine color={color} size={20} />
) : (
<LineWithMark color={color} size={20} />
)}
<Typography sx={{ display: 'inline-block' }}>{`${label}`}</Typography>
</Box>
);
})}
</Stack>
);
}

const dataset = [
{ month: 'Jan', '1991_2020_avg': 4.1, 2023: 3.9 },
{ month: 'Fev', '1991_2020_avg': 4.7, 2023: 8.9 },
{ month: 'Mar', '1991_2020_avg': 7.5, 2023: 9.5 },
{ month: 'Apr', '1991_2020_avg': 10.6, 2023: 11.5 },
{ month: 'May', '1991_2020_avg': 13.8, 2023: 15.5 },
{ month: 'Jun', '1991_2020_avg': 16.7, 2023: 16.4 },
{ month: 'Jul', '1991_2020_avg': 18.9, 2023: 19.5 },
{ month: 'Aug', '1991_2020_avg': 18.8, 2023: 20.5 },
{ month: 'Sep', '1991_2020_avg': 15.8, 2023: 16.4 },
{ month: 'Oct', '1991_2020_avg': 11.9, 2023: 13.2 },
{ month: 'Nov', '1991_2020_avg': 7.6, 2023: 8.1 },
{ month: 'Dec', '1991_2020_avg': 4.7, 2023: 6.1 },
];

export default function CustomLegend() {
const theme = useTheme();

return (
<Box
sx={{ height: 300, width: '100%', display: 'flex', flexDirection: 'column' }}
>
<LineChart
dataset={dataset}
series={[
{
id: 'avg',
label: 'temp. avg. 1991-2020 (°C)',
dataKey: '1991_2020_avg',
showMark: false,
color: theme.palette.text.primary,
},
{
id: '2023-temp',
label: 'temp. 2023 (°C)',
dataKey: '2023',
color: theme.palette.primary.main,
},
]}
xAxis={[{ dataKey: 'month', scaleType: 'band', id: 'x-axis' }]}
sx={{
[`& .MuiLineElement-series-avg`]: {
strokeDasharray: '10 5',
},
}}
slots={{ legend: MyCustomLegend }}
/>
</Box>
);
}
15 changes: 12 additions & 3 deletions docs/data/charts/legend/legend.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Charts - Legend
productId: x-charts
components: ChartsLegend, DefaultChartsLegend, ChartsText, ContinuousColorLegend, PiecewiseColorLegend, ChartsLabel, ChartsLabelMark, ChartsLabelGradient
components: ChartsLegend, ChartsText, ContinuousColorLegend, PiecewiseColorLegend
---

# Charts - Legend
Expand All @@ -18,8 +18,6 @@ In chart components, the legend links series with `label` properties and their c

This section explains how to customize the legend using classes and properties.

In order to fully customize the legend with custom components, see an example at the [HTML components docs](https://mui.com/x/react-charts/components/#html-components).

### Dimensions

Much of the customization can be done using CSS properties.
Expand Down Expand Up @@ -80,6 +78,17 @@ Make sure that the legend container has a fixed height or width to enable scroll

{{"demo": "ScrollableLegend.js"}}

### Custom component

For advanced customization, you can create your own legend with `useLegend`.
This hook returns the items that the default legend would plot.
Allowing you to focus on the rendering.

This demo show how to use it with slots.
Another demo in [HTML components docs](/x/react-charts/components/#html-components) shows how to use it with composition.

{{"demo": "CustomLegend.js"}}

## Color legend

To display legend associated to a [colorMap](https://mui.com/x/react-charts/styling/#values-color), you can use:
Expand Down
18 changes: 12 additions & 6 deletions docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,9 @@ If the updated values do not fit your use case, you can [override them](/x/react
+const { rangePosition } = usePickerRangePositionContext();

-const { onRangePositionChange } = props;
+const { onRangePositionChange } = usePickerRangePositionContext();
-onRangePositionChange('start');
+const { setRangePosition } = usePickerRangePositionContext();
+setRangePosition('start');
```

### Slot: `toolbar`
Expand Down Expand Up @@ -777,7 +779,9 @@ If the updated values do not fit your use case, you can [override them](/x/react
+const { rangePosition } = usePickerRangePositionContext();

-const { onRangePositionChange } = props;
+const { onRangePositionChange } = usePickerRangePositionContext();
-onRangePositionChange('start');
+const { setRangePosition } = usePickerRangePositionContext();
+setRangePosition('start');
```

### Slot: `tabs`
Expand Down Expand Up @@ -807,7 +811,9 @@ If the updated values do not fit your use case, you can [override them](/x/react
+const { rangePosition } = usePickerRangePositionContext();

-const { onRangePositionChange } = props;
+const { onRangePositionChange } = usePickerRangePositionContext();
-onRangePositionChange('start');
+const { setRangePosition } = usePickerRangePositionContext();
+setRangePosition('start');
```

### Slot: `actionBar`
Expand Down Expand Up @@ -992,7 +998,7 @@ This hook has been removed in favor of the new `useMultiInputRangeField` hook wi
```

:::success
The associated types have also been removed. [Learn how to migrate them](/x/migration/migration-pickers-v7/#removed-types).
The associated types have also been removed. [Learn how to migrate them](/x/migration/migration-pickers-v7/#removed-types).
:::

### `useMultiInputTimeRangeField`
Expand Down Expand Up @@ -1044,7 +1050,7 @@ This hook has been removed in favor of the new `useMultiInputRangeField` hook wi
```

:::success
The associated types have also been removed. [Learn how to migrate them](/x/migration/migration-pickers-v7/#removed-types).
The associated types have also been removed. [Learn how to migrate them](/x/migration/migration-pickers-v7/#removed-types).
:::

### `useMultiInputDateTimeRangeField`
Expand Down Expand Up @@ -1096,7 +1102,7 @@ This hook has been removed in favor of the new `useMultiInputRangeField` hook wi
```

:::success
The associated types have also been removed. [Learn how to migrate them](/x/migration/migration-pickers-v7/#removed-types).
The associated types have also been removed. [Learn how to migrate them](/x/migration/migration-pickers-v7/#removed-types).
:::

### `usePickerContext`
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@emotion/react": "^11.14.0",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.14.0",
"@mui/docs": "6.3.1",
"@mui/docs": "6.4.0",
"@mui/icons-material": "^5.16.14",
"@mui/joy": "^5.0.0-beta.51",
"@mui/lab": "^5.0.0-alpha.175",
Expand Down Expand Up @@ -103,7 +103,7 @@
"@babel/plugin-transform-react-constant-elements": "^7.25.9",
"@babel/preset-typescript": "^7.26.0",
"@mui/internal-docs-utils": "^1.0.16",
"@mui/internal-scripts": "^1.0.32",
"@mui/internal-scripts": "^1.0.33",
"@types/chance": "^1.1.6",
"@types/d3-scale": "^4.0.8",
"@types/d3-scale-chromatic": "^3.1.0",
Expand Down
Loading

0 comments on commit e786718

Please sign in to comment.