Skip to content

Commit

Permalink
[charts] Remove deprecated highlight properties (#15191)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Nov 5, 2024
1 parent f955ebb commit 4c11e44
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 86 deletions.
5 changes: 3 additions & 2 deletions docs/data/charts/bars/BarAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Slider from '@mui/material/Slider';
import FormControlLabel from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox';
import { BarChart } from '@mui/x-charts/BarChart';
import { HighlightScope } from '@mui/x-charts/context';

export default function BarAnimation() {
const [seriesNb, setSeriesNb] = React.useState(2);
Expand Down Expand Up @@ -67,10 +68,10 @@ export default function BarAnimation() {
);
}

const highlightScope = {
const highlightScope: HighlightScope = {
highlight: 'series',
fade: 'global',
} as const;
};

const series = [
{
Expand Down
16 changes: 8 additions & 8 deletions docs/data/charts/highlighting/ControlledHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default function ControlledHighlight() {
seriesId: 'A',
dataIndex: 0,
});
const [highlighted, setHighlighted] = React.useState('item');
const [faded, setFaded] = React.useState('global');
const [highlight, setHighlight] = React.useState('item');
const [fade, setFade] = React.useState('global');

const handleHighLightedSeries = (event, newHighLightedSeries) => {
if (newHighLightedSeries !== null) {
Expand Down Expand Up @@ -80,8 +80,8 @@ export default function ControlledHighlight() {
series={barChartsProps.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
},
}))}
highlightedItem={highlightedItem}
Expand All @@ -98,8 +98,8 @@ export default function ControlledHighlight() {
<TextField
select
label="highlighted"
value={highlighted}
onChange={(event) => setHighlighted(event.target.value)}
value={highlight}
onChange={(event) => setHighlight(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand All @@ -109,8 +109,8 @@ export default function ControlledHighlight() {
<TextField
select
label="faded"
value={faded}
onChange={(event) => setFaded(event.target.value)}
value={fade}
onChange={(event) => setFade(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand Down
16 changes: 8 additions & 8 deletions docs/data/charts/highlighting/ControlledHighlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default function ControlledHighlight() {
seriesId: 'A',
dataIndex: 0,
});
const [highlighted, setHighlighted] = React.useState('item');
const [faded, setFaded] = React.useState('global');
const [highlight, setHighlight] = React.useState('item');
const [fade, setFade] = React.useState('global');

const handleHighLightedSeries = (event: any, newHighLightedSeries: string) => {
if (newHighLightedSeries !== null) {
Expand Down Expand Up @@ -81,8 +81,8 @@ export default function ControlledHighlight() {
series={barChartsProps.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
} as HighlightScope,
}))}
highlightedItem={highlightedItem}
Expand All @@ -99,8 +99,8 @@ export default function ControlledHighlight() {
<TextField
select
label="highlighted"
value={highlighted}
onChange={(event) => setHighlighted(event.target.value)}
value={highlight}
onChange={(event) => setHighlight(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand All @@ -110,8 +110,8 @@ export default function ControlledHighlight() {
<TextField
select
label="faded"
value={faded}
onChange={(event) => setFaded(event.target.value)}
value={fade}
onChange={(event) => setFade(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand Down
32 changes: 16 additions & 16 deletions docs/data/charts/highlighting/ElementHighlights.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const pieChartsParams = {
export default function ElementHighlights() {
const [chartType, setChartType] = React.useState('bar');
const [withArea, setWithArea] = React.useState(false);
const [highlighted, setHighlighted] = React.useState('item');
const [faded, setFaded] = React.useState('global');
const [highlight, setHighlight] = React.useState('item');
const [fade, setFade] = React.useState('global');

const handleChartType = (event, newChartType) => {
if (newChartType !== null) {
Expand Down Expand Up @@ -123,8 +123,8 @@ export default function ElementHighlights() {
series={barChartsParams.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
},
}))}
/>
Expand All @@ -137,8 +137,8 @@ export default function ElementHighlights() {
...series,
area: withArea,
highlightScope: {
highlighted,
faded,
highlight,
fade,
},
}))}
/>
Expand All @@ -150,8 +150,8 @@ export default function ElementHighlights() {
series={scatterChartsParams.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
},
}))}
/>
Expand All @@ -163,8 +163,8 @@ export default function ElementHighlights() {
series={pieChartsParams.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
},
}))}
/>
Expand All @@ -179,9 +179,9 @@ export default function ElementHighlights() {
>
<TextField
select
label="highlighted"
value={highlighted}
onChange={(event) => setHighlighted(event.target.value)}
label="highlight"
value={highlight}
onChange={(event) => setHighlight(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand All @@ -190,9 +190,9 @@ export default function ElementHighlights() {
</TextField>
<TextField
select
label="faded"
value={faded}
onChange={(event) => setFaded(event.target.value)}
label="fade"
value={fade}
onChange={(event) => setFade(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand Down
32 changes: 16 additions & 16 deletions docs/data/charts/highlighting/ElementHighlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ const pieChartsParams = {
export default function ElementHighlights() {
const [chartType, setChartType] = React.useState('bar');
const [withArea, setWithArea] = React.useState(false);
const [highlighted, setHighlighted] = React.useState('item');
const [faded, setFaded] = React.useState('global');
const [highlight, setHighlight] = React.useState('item');
const [fade, setFade] = React.useState('global');

const handleChartType = (event: any, newChartType: string) => {
if (newChartType !== null) {
Expand Down Expand Up @@ -124,8 +124,8 @@ export default function ElementHighlights() {
series={barChartsParams.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
} as HighlightScope,
}))}
/>
Expand All @@ -138,8 +138,8 @@ export default function ElementHighlights() {
...series,
area: withArea,
highlightScope: {
highlighted,
faded,
highlight,
fade,
} as HighlightScope,
}))}
/>
Expand All @@ -151,8 +151,8 @@ export default function ElementHighlights() {
series={scatterChartsParams.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
} as HighlightScope,
}))}
/>
Expand All @@ -164,8 +164,8 @@ export default function ElementHighlights() {
series={pieChartsParams.series.map((series) => ({
...series,
highlightScope: {
highlighted,
faded,
highlight,
fade,
} as HighlightScope,
}))}
/>
Expand All @@ -180,9 +180,9 @@ export default function ElementHighlights() {
>
<TextField
select
label="highlighted"
value={highlighted}
onChange={(event) => setHighlighted(event.target.value)}
label="highlight"
value={highlight}
onChange={(event) => setHighlight(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand All @@ -191,9 +191,9 @@ export default function ElementHighlights() {
</TextField>
<TextField
select
label="faded"
value={faded}
onChange={(event) => setFaded(event.target.value)}
label="fade"
value={fade}
onChange={(event) => setFade(event.target.value)}
sx={{ minWidth: 150 }}
>
<MenuItem value={'none'}>none</MenuItem>
Expand Down
15 changes: 0 additions & 15 deletions packages/x-charts/src/PieChart/PieArc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { styled } from '@mui/material/styles';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
import { PieItemId } from '../models';
import { HighlightScope } from '../context';

export interface PieArcClasses {
/** Styles applied to the root element. */
Expand Down Expand Up @@ -64,10 +63,6 @@ export type PieArcProps = Omit<React.SVGProps<SVGPathElement>, 'ref' | 'id'> &
PieArcOwnerState & {
cornerRadius: SpringValue<number>;
endAngle: SpringValue<number>;
/**
* @deprecated Use the `isFaded` or `isHighlighted` props instead.
*/
highlightScope?: Partial<HighlightScope>;
innerRadius: SpringValue<number>;
onClick?: (event: React.MouseEvent<SVGPathElement, MouseEvent>) => void;
outerRadius: SpringValue<number>;
Expand All @@ -90,7 +85,6 @@ function PieArc(props: PieArcProps) {
outerRadius,
paddingAngle,
startAngle,
highlightScope,
...other
} = props;

Expand Down Expand Up @@ -137,15 +131,6 @@ PieArc.propTypes = {
// ----------------------------------------------------------------------
classes: PropTypes.object,
dataIndex: PropTypes.number.isRequired,
/**
* @deprecated Use the `isFaded` or `isHighlighted` props instead.
*/
highlightScope: PropTypes.shape({
fade: PropTypes.oneOf(['global', 'none', 'series']),
faded: PropTypes.oneOf(['global', 'none', 'series']),
highlight: PropTypes.oneOf(['item', 'none', 'series']),
highlighted: PropTypes.oneOf(['item', 'none', 'series']),
}),
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
isFaded: PropTypes.bool.isRequired,
isHighlighted: PropTypes.bool.isRequired,
Expand Down
3 changes: 0 additions & 3 deletions packages/x-charts/src/PieChart/PieArcPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ValueWithHighlight,
useTransformData,
} from './dataTransform/useTransformData';
import { useHighlighted } from '../context';

export interface PieArcPlotSlots {
pieArc?: React.JSXElementConstructor<PieArcProps>;
Expand Down Expand Up @@ -95,7 +94,6 @@ function PieArcPlot(props: PieArcPlotProps) {
...defaultTransitionConfig,
immediate: skipAnimation,
});
const { highlightScope } = useHighlighted();

if (data.length === 0) {
return null;
Expand Down Expand Up @@ -133,7 +131,6 @@ function PieArcPlot(props: PieArcPlotProps) {
id={id}
color={item.color}
dataIndex={index}
highlightScope={highlightScope}
isFaded={item.isFaded}
isHighlighted={item.isHighlighted}
onClick={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export type HighlightOptions = 'none' | 'item' | 'series';
export type FadeOptions = 'none' | 'series' | 'global';

export type HighlightScope = {
/**
* @deprecated Use `highlight` instead.
*/
highlighted?: HighlightOptions;
/**
* The scope of highlighted elements.
* - 'none': no highlight.
Expand All @@ -46,10 +42,6 @@ export type HighlightScope = {
* @default 'none'
*/
highlight?: HighlightOptions;
/**
* @deprecated Use `fade` instead.
*/
faded?: FadeOptions;
/**
* The scope of faded elements.
* - 'none': no fading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ export type HighlightedProviderProps = {
onHighlightChange?: (highlightedItem: HighlightItemData | null) => void;
};

const mergeDeprecatedOptions = (options?: Partial<HighlightScope>): HighlightScope => {
const { highlighted, faded, ...other } = options ?? {};
return {
highlight: highlighted,
fade: faded,
...other,
};
};

function HighlightedProvider({
children,
highlightedItem: highlightedItemProps,
Expand All @@ -58,7 +49,7 @@ function HighlightedProvider({
const seriesData = series[seriesType as ChartSeriesType];
Object.keys(seriesData?.series ?? {}).forEach((seriesId) => {
const seriesItem = seriesData?.series[seriesId];
map.set(seriesId, mergeDeprecatedOptions(seriesItem?.highlightScope));
map.set(seriesId, seriesItem?.highlightScope);
});
});
return map;
Expand Down

0 comments on commit 4c11e44

Please sign in to comment.