Skip to content

Commit

Permalink
[@mantine/charts] Add support for nested properties in dataKey (#5886)
Browse files Browse the repository at this point in the history
* [@mantine/core] Combobox: Add onClose prop to Combobox component

* call both close handlers

* undo formatting

* format code

* Refactor Combobox component to use onDropdownClose callback

* Fix: `SegmentedControl` design breaks when inside a modal

* remove unused code

* remove unused code

* Fix: Chart legend not displaying values when they are nested

* Fix: add return type for `updateChartLegendPayload` & `updateChartTooltipPayload`

* undo code changes for `SegmentedControl` component

* format code
  • Loading branch information
ID-JA authored Jul 12, 2024
1 parent 3a8395f commit decbcfe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
17 changes: 16 additions & 1 deletion packages/@mantine/charts/src/ChartLegend/ChartLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ import { ChartSeries } from '../types';
import { getSeriesLabels } from '../utils';
import classes from './ChartLegend.module.css';

function updateChartLegendPayload(payload: Record<string, any>[]): Record<string, any>[] {
return payload.map((item) => {
const newDataKey = item.dataKey.split('.').pop();
return {
...item,
dataKey: newDataKey,
payload: {
...item.payload,
name: newDataKey,
dataKey: newDataKey,
},
};
});
}

export function getFilteredChartLegendPayload(payload: Record<string, any>[]) {
return payload.filter((item) => item.color !== 'none');
return updateChartLegendPayload(payload.filter((item) => item.color !== 'none'));
}

export type ChartLegendStylesNames = 'legendItem' | 'legendItemColor' | 'legendItemName' | 'legend';
Expand Down
14 changes: 13 additions & 1 deletion packages/@mantine/charts/src/ChartTooltip/ChartTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ import { ChartSeries } from '../types';
import { getSeriesLabels } from '../utils';
import classes from './ChartTooltip.module.css';

function updateChartTooltipPayload(payload: Record<string, any>[]): Record<string, any>[] {
return payload.map((item) => {
const newDataKey = item.name.split('.').pop();
return {
...item,
name: newDataKey,
};
});
}

export function getFilteredChartTooltipPayload(payload: Record<string, any>[], segmentId?: string) {
const duplicatesFilter = payload.filter((item) => item.fill !== 'none' || !item.color);
const duplicatesFilter = updateChartTooltipPayload(
payload.filter((item) => item.fill !== 'none' || !item.color)
);

if (!segmentId) {
return duplicatesFilter;
Expand Down

0 comments on commit decbcfe

Please sign in to comment.