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] highlight band #16889

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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/ElementHighlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export default function ElementHighlights() {
<MenuItem value={'none'}>none</MenuItem>
<MenuItem value={'item'}>item</MenuItem>
<MenuItem value={'series'}>series</MenuItem>
<MenuItem value={'group'}>group</MenuItem>
</TextField>
<TextField
select
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { AxisInteractionData } from '../useChartInteraction/useChartInteraction.types';
import { HighlightScope } from './highlightConfig.types';
import { HighlightItemData } from './useChartHighlight.types';

export const createIsHighlighted =
(highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null) =>
(
highlightScope: HighlightScope | null | undefined,
highlightedItem: HighlightItemData | null,
axisInteractionData: AxisInteractionData | undefined,
) =>
(item: HighlightItemData | null): boolean => {
if (!highlightScope || !highlightedItem || !item) {
if (!highlightScope || !item) {
return false;
}

if (highlightScope.highlight === 'group') {
return axisInteractionData?.x?.index === item.dataIndex;
}

if (!highlightedItem) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type HighlightOptions = 'none' | 'item' | 'series';
export type HighlightOptions = 'none' | 'item' | 'series' | 'group';

export type FadeOptions = 'none' | 'series' | 'global';

Expand All @@ -8,6 +8,7 @@ export type HighlightScope = {
* - 'none': no highlight.
* - 'item': only highlight the item.
* - 'series': highlight all elements of the same series.
* - 'group': highlight all elements of the same group.
* @default 'none'
*/
highlight?: HighlightOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
selectorChartsInteractionAxis,
selectorChartsInteractionXAxis,
useSelector,
useStore,
} from '@mui/x-charts/internals';
import { SeriesId } from '../../../../models/seriesType/common';
import { ChartSeriesType } from '../../../../models/seriesType/config';
import { UseChartSeriesSignature } from '../../corePlugins/useChartSeries/useChartSeries.types';
Expand Down Expand Up @@ -62,10 +68,11 @@ export const selectorChartsIsHighlighted = createSelector(
[
selectorChartsHighlightScope,
selectorChartsHighlightedItem,
selectorChartsInteractionAxis,
(_, item: HighlightItemData | null) => item,
],
(highlightScope, highlightedItem, item) =>
createIsHighlighted(highlightScope, highlightedItem)(item),
(highlightScope, highlightedItem, axisInteractionData, item) =>
createIsHighlighted(highlightScope, highlightedItem, axisInteractionData)(item),
);

export const selectorChartsIsFaded = createSelector(
Expand Down
Loading