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

[charts] Move item highligh feature to plugin system #16211

Merged
merged 21 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions docs/data/charts/highlighting/ControlledHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function ControlledHighlight() {

const handleHighLightedItem = (event) => {
setHighLightedItem((prev) => ({
seriesId: 'A',
...prev,
dataIndex: Number(event.target.value),
}));
Expand Down
1 change: 1 addition & 0 deletions docs/data/charts/highlighting/ControlledHighlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function ControlledHighlight() {

const handleHighLightedItem = (event: any) => {
setHighLightedItem((prev) => ({
seriesId: 'A',
JCQuintas marked this conversation as resolved.
Show resolved Hide resolved
...prev,
dataIndex: Number(event.target.value),
}));
Expand Down
26 changes: 26 additions & 0 deletions docs/data/migration/migration-charts-v7/migration-charts-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@
The `resolveSizeBeforeRender` prop has been removed from all components.
If you were using this prop, you can safely remove it.

## Replacing `useHighlighted` by `useItemHighlighted` and `useItemHighlightedGetter`

The `useHighlighted` hook that gave access to the internal highlight state has been removed.

To know if your item is highlighted, we recommend using `useItemHighlighted` hook:

Check warning on line 155 in docs/data/migration/migration-charts-v7/migration-charts-v7.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.We] Try to avoid using first-person plural like 'we'. Raw Output: {"message": "[Google.We] Try to avoid using first-person plural like 'we'.", "location": {"path": "docs/data/migration/migration-charts-v7/migration-charts-v7.md", "range": {"start": {"line": 155, "column": 38}}}, "severity": "WARNING"}
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved

```jsx
const { isFaded, isHighlighted } = useItemHighlighted({
seriesId,
dataIndex,
});
```

If you're in a case where you have multiple series id to test (for example in the tooltip), you can use the lower level hook `useItemHighlightedGetter`.
This hook being lower level only test is the item match with the highlight or fade scope.
So an item could at the same time have `isFaded` and `isHighlighted` returning `true`.

```jsx
const { isFaded, isHighlighted } = useItemHighlightedGetter();

const itemIsHighlighted = isHighlighted({ seriesId, dataIndex });

// First make sure the item is not highlighted.
const itemIsFaded = !itemIsHighlighted && isFaded({ seriesId, dataIndex });
```

## Rename `labelFontSize` and `tickFontSize` props ✅

The `labelFontSize` and `tickFontSize` props have been removed in favor of the style objects `labelStyle` and `tickStyle` respectively.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/bar-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/chart-container-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/chart-container.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 0 additions & 2 deletions docs/pages/x/api/charts/chart-data-provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"props": {
"colors": { "type": { "name": "any" }, "default": "blueberryTwilightPalette" },
"height": { "type": { "name": "any" } },
"highlightedItem": { "type": { "name": "any" } },
"id": { "type": { "name": "any" } },
"margin": { "type": { "name": "any" } },
"onHighlightChange": { "type": { "name": "any" } },
"series": { "type": { "name": "any" } },
"skipAnimation": { "type": { "name": "any" } },
"width": { "type": { "name": "any" } }
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/heatmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/line-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/pie-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/scatter-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/scatter-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/spark-line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"highlightedItem": {
"type": {
"name": "shape",
"description": "{ dataIndex?: number, seriesId?: number<br>&#124;&nbsp;string }"
"description": "{ dataIndex?: number, seriesId: number<br>&#124;&nbsp;string }"
}
},
"id": { "type": { "name": "string" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"hideLegend": { "description": "If <code>true</code>, the legend is not rendered." },
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/charts/bar-chart/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"hideLegend": { "description": "If <code>true</code>, the legend is not rendered." },
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"description": "The height of the chart in px. If not defined, it takes the height of the parent element."
},
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"description": "The height of the chart in px. If not defined, it takes the height of the parent element."
},
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
"height": {
"description": "The height of the chart in px. If not defined, it takes the height of the parent element."
},
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
},
"margin": {
"description": "The margin between the SVG and the drawing area. It&#39;s used for leaving some space for extra information such as the x- and y-axis or legend. Accepts an object with the optional properties: <code>top</code>, <code>bottom</code>, <code>left</code>, and <code>right</code>."
},
"onHighlightChange": { "description": "The callback fired when the highlighted item changes." },
"series": {
"description": "The array of series to display. Each type of series has its own specificity. Please refer to the appropriate docs page to learn more about it."
},
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/charts/heatmap/heatmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"description": "The height of the chart in px. If not defined, it takes the height of the parent element."
},
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"hideLegend": { "description": "If <code>true</code>, the legend is not rendered." },
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"hideLegend": { "description": "If <code>true</code>, the legend is not rendered." },
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/charts/pie-chart/pie-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"hideLegend": { "description": "If <code>true</code>, the legend is not rendered." },
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"hideLegend": { "description": "If <code>true</code>, the legend is not rendered." },
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"hideLegend": { "description": "If <code>true</code>, the legend is not rendered." },
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"description": "The height of the chart in px. If not defined, it takes the height of the parent element."
},
"highlightedItem": {
"description": "The item currently highlighted. Turns highlighting into a controlled prop."
"description": "The highlighted item. Used when the highlight is controlled."
},
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
Expand Down
5 changes: 3 additions & 2 deletions packages/x-charts-pro/src/BarChartPro/BarChartPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ BarChartPro.propTypes = {
*/
hideLegend: PropTypes.bool,
/**
* The item currently highlighted. Turns highlighting into a controlled prop.
* The highlighted item.
* Used when the highlight is controlled.
*/
highlightedItem: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}),
/**
* This prop is used to help implement the accessibility logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ ChartContainerPro.propTypes = {
*/
height: PropTypes.number,
/**
* The item currently highlighted. Turns highlighting into a controlled prop.
* The highlighted item.
* Used when the highlight is controlled.
*/
highlightedItem: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}),
/**
* This prop is used to help implement the accessibility logic.
Expand Down
5 changes: 3 additions & 2 deletions packages/x-charts-pro/src/Heatmap/Heatmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,12 @@ Heatmap.propTypes = {
*/
height: PropTypes.number,
/**
* The item currently highlighted. Turns highlighting into a controlled prop.
* The highlighted item.
* Used when the highlight is controlled.
*/
highlightedItem: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}),
/**
* This prop is used to help implement the accessibility logic.
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts-pro/src/Heatmap/HeatmapItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import useSlotProps from '@mui/utils/useSlotProps';
import composeClasses from '@mui/utils/composeClasses';
import { useItemHighlighted } from '@mui/x-charts/context';
import { useItemHighlighted } from '@mui/x-charts/hooks';
import { useInteractionItemProps, SeriesId } from '@mui/x-charts/internals';
import { HeatmapClasses, getHeatmapUtilityClass } from './heatmapClasses';

Expand Down
5 changes: 3 additions & 2 deletions packages/x-charts-pro/src/LineChartPro/LineChartPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ LineChartPro.propTypes = {
*/
hideLegend: PropTypes.bool,
/**
* The item currently highlighted. Turns highlighting into a controlled prop.
* The highlighted item.
* Used when the highlight is controlled.
*/
highlightedItem: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}),
/**
* This prop is used to help implement the accessibility logic.
Expand Down
5 changes: 3 additions & 2 deletions packages/x-charts-pro/src/ScatterChartPro/ScatterChartPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ ScatterChartPro.propTypes = {
*/
hideLegend: PropTypes.bool,
/**
* The item currently highlighted. Turns highlighting into a controlled prop.
* The highlighted item.
* Used when the highlight is controlled.
*/
highlightedItem: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}),
/**
* This prop is used to help implement the accessibility logic.
Expand Down
4 changes: 4 additions & 0 deletions packages/x-charts-pro/src/internals/plugins/allPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {
UseChartInteractionSignature,
useChartZAxis,
UseChartZAxisSignature,
useChartHighlight,
UseChartHighlightSignature,
} from '@mui/x-charts/internals';
import { useChartProZoom, UseChartProZoomSignature } from './useChartProZoom';

export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [
UseChartZAxisSignature,
UseChartCartesianAxisSignature<TSeries>,
UseChartInteractionSignature,
UseChartHighlightSignature,
UseChartProZoomSignature,
];

Expand All @@ -26,5 +29,6 @@ export const ALL_PLUGINS = [
useChartZAxis,
useChartCartesianAxis,
useChartInteraction,
useChartHighlight,
useChartProZoom,
];
5 changes: 3 additions & 2 deletions packages/x-charts/src/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ BarChart.propTypes = {
*/
hideLegend: PropTypes.bool,
/**
* The item currently highlighted. Turns highlighting into a controlled prop.
* The highlighted item.
* Used when the highlight is controlled.
*/
highlightedItem: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}),
/**
* This prop is used to help implement the accessibility logic.
Expand Down
Loading
Loading