From b2a1208fa799ea0b0da601076cee2afdc1c285b4 Mon Sep 17 00:00:00 2001 From: Bernardo Belchior Date: Tue, 25 Feb 2025 17:39:46 +0100 Subject: [PATCH 1/6] [charts] Remove redundant default axis --- .../useChartCartesianAxis/defaultizeAxis.ts | 76 +++++++++---------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts b/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts index f357a6f2dfdba..25fdd7590af6c 100644 --- a/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts +++ b/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts @@ -26,9 +26,6 @@ export function defaultizeAxis( ): AxisConfig[] { const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY; - const hasNoDefaultAxis = - inAxis === undefined || inAxis.findIndex(({ id }) => id === DEFAULT_AXIS_KEY) === -1; - const offsets = { top: 0, right: 0, @@ -37,50 +34,49 @@ export function defaultizeAxis( none: 0, }; - const parsedAxes = [ - ...(inAxis ?? []), - ...(hasNoDefaultAxis ? [{ id: DEFAULT_AXIS_KEY, scaleType: 'linear' as const }] : []), - ].map((axisConfig, index) => { - const dataKey = axisConfig.dataKey; - const defaultPosition = axisName === 'x' ? ('bottom' as const) : ('left' as const); + const parsedAxes = (inAxis || [{ id: DEFAULT_AXIS_KEY, scaleType: 'linear' as const }]).map( + (axisConfig, index) => { + const dataKey = axisConfig.dataKey; + const defaultPosition = axisName === 'x' ? ('bottom' as const) : ('left' as const); - const position = axisConfig.position ?? 'none'; - const dimension = axisName === 'x' ? 'height' : 'width'; + const position = axisConfig.position ?? 'none'; + const dimension = axisName === 'x' ? 'height' : 'width'; - const height = axisName === 'x' ? DEFAULT_AXIS_SIZE_HEIGHT : 0; - const width = axisName === 'y' ? DEFAULT_AXIS_SIZE_WIDTH : 0; + const height = axisName === 'x' ? DEFAULT_AXIS_SIZE_HEIGHT : 0; + const width = axisName === 'y' ? DEFAULT_AXIS_SIZE_WIDTH : 0; - const sharedConfig = { - id: `defaultized-${axisName}-axis-${index}`, - // The fist axis is defaultized to the bottom/left - ...(index === 0 ? { position: defaultPosition } : {}), - height, - width, - offset: offsets[position], - ...axisConfig, - }; + const sharedConfig = { + id: `defaultized-${axisName}-axis-${index}`, + // The fist axis is defaultized to the bottom/left + ...(index === 0 ? { position: defaultPosition } : {}), + height, + width, + offset: offsets[position], + ...axisConfig, + }; - // Increment the offset for the next axis - if (position !== 'none') { - offsets[position] += - (axisConfig as any)[dimension] ?? (dimension === 'height' ? height : width); - } + // Increment the offset for the next axis + if (position !== 'none') { + offsets[position] += + (axisConfig as any)[dimension] ?? (dimension === 'height' ? height : width); + } - // If `dataKey` is NOT provided - if (dataKey === undefined || axisConfig.data !== undefined) { - return sharedConfig; - } + // If `dataKey` is NOT provided + if (dataKey === undefined || axisConfig.data !== undefined) { + return sharedConfig; + } - if (dataset === undefined) { - throw new Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`); - } + if (dataset === undefined) { + throw new Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`); + } - // If `dataKey` is provided - return { - ...sharedConfig, - data: dataset.map((d) => d[dataKey]), - }; - }); + // If `dataKey` is provided + return { + ...sharedConfig, + data: dataset.map((d) => d[dataKey]), + }; + }, + ); return parsedAxes; } From 5f966e0830b9bb14a6fc67f57302b423ce2a9ade Mon Sep 17 00:00:00 2001 From: Bernardo Belchior Date: Wed, 26 Feb 2025 09:50:27 +0100 Subject: [PATCH 2/6] Fix issue in heatmap. Add unit tests. --- .../x-charts-pro/src/Heatmap/Heatmap.test.tsx | 6 ++ packages/x-charts-pro/src/Heatmap/Heatmap.tsx | 10 ++- .../x-charts/src/BarChart/BarChart.test.tsx | 8 ++ .../x-charts/src/LineChart/LineChart.test.tsx | 8 ++ .../src/ScatterChart/ScatterChart.test.tsx | 6 ++ .../useChartCartesianAxis/defaultizeAxis.ts | 73 ++++++++++--------- 6 files changed, 74 insertions(+), 37 deletions(-) diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx index d7d0720670214..c057e49faa433 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx @@ -23,4 +23,10 @@ describe(' - License', () => { expect(await screen.findAllByText('MUI X Missing license key')).not.to.equal(null); }); + + it('should render "No data to display" when axes are empty arrays', () => { + render(); + + expect(screen.getByText('No data to display')).toBeVisible(); + }); }); diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx index f15ea4db71190..5ec24cfac0af9 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx @@ -22,6 +22,7 @@ import { ChartsOverlaySlotProps, ChartsOverlaySlots, } from '@mui/x-charts/ChartsOverlay'; +import { DEFAULT_X_AXIS_KEY } from '@mui/x-charts/constants'; import { ChartContainerPro, ChartContainerProProps } from '../ChartContainerPro'; import { HeatmapSeriesType } from '../models/seriesType/heatmap'; import { HeatmapPlot } from './HeatmapPlot'; @@ -129,7 +130,14 @@ const Heatmap = React.forwardRef(function Heatmap( const clipPathId = `${id}-clip-path`; const defaultizedXAxis = React.useMemo( - () => xAxis.map((axis) => ({ scaleType: 'band' as const, categoryGapRatio: 0, ...axis })), + () => + (xAxis && xAxis.length > 0 ? xAxis : [{}]).map((axis) => ({ + id: DEFAULT_X_AXIS_KEY, + scaleType: 'band' as const, + categoryGapRatio: 0, + data: [], + ...axis, + })), [xAxis], ); diff --git a/packages/x-charts/src/BarChart/BarChart.test.tsx b/packages/x-charts/src/BarChart/BarChart.test.tsx index 8f598d3d21d89..652d158145322 100644 --- a/packages/x-charts/src/BarChart/BarChart.test.tsx +++ b/packages/x-charts/src/BarChart/BarChart.test.tsx @@ -2,6 +2,8 @@ import * as React from 'react'; import { createRenderer } from '@mui/internal-test-utils/createRenderer'; import { describeConformance } from 'test/utils/describeConformance'; import { BarChart } from '@mui/x-charts/BarChart'; +import { expect } from 'chai'; +import { screen } from '@mui/internal-test-utils'; describe('', () => { const { render } = createRenderer(); @@ -28,4 +30,10 @@ describe('', () => { ], }), ); + + it('should render "No data to display" when axes are empty arrays', () => { + render(); + + expect(screen.getByText('No data to display')).toBeVisible(); + }); }); diff --git a/packages/x-charts/src/LineChart/LineChart.test.tsx b/packages/x-charts/src/LineChart/LineChart.test.tsx index 441d32c31e96c..8cf1e45c8684d 100644 --- a/packages/x-charts/src/LineChart/LineChart.test.tsx +++ b/packages/x-charts/src/LineChart/LineChart.test.tsx @@ -2,6 +2,8 @@ import * as React from 'react'; import { createRenderer } from '@mui/internal-test-utils/createRenderer'; import { describeConformance } from 'test/utils/describeConformance'; import { LineChart } from '@mui/x-charts/LineChart'; +import { expect } from 'chai'; +import { screen } from '@mui/internal-test-utils'; describe('', () => { const { render } = createRenderer(); @@ -27,4 +29,10 @@ describe('', () => { ], }), ); + + it('should render "No data to display" when axes are empty arrays', () => { + render(); + + expect(screen.getByText('No data to display')).toBeVisible(); + }); }); diff --git a/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx b/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx index 732a19fa566aa..0cc6fbddc68f3 100644 --- a/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx +++ b/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx @@ -159,4 +159,10 @@ describe('', () => { const labelY = await screen.findByText('600'); expect(labelY).toBeVisible(); }); + + it('should render "No data to display" when axes are empty arrays', () => { + render(); + + expect(screen.getByText('No data to display')).toBeVisible(); + }); }); diff --git a/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts b/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts index 25fdd7590af6c..5f299698a1922 100644 --- a/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts +++ b/packages/x-charts/src/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.ts @@ -34,49 +34,50 @@ export function defaultizeAxis( none: 0, }; - const parsedAxes = (inAxis || [{ id: DEFAULT_AXIS_KEY, scaleType: 'linear' as const }]).map( - (axisConfig, index) => { - const dataKey = axisConfig.dataKey; - const defaultPosition = axisName === 'x' ? ('bottom' as const) : ('left' as const); + const inputAxes = + inAxis && inAxis.length > 0 ? inAxis : [{ id: DEFAULT_AXIS_KEY, scaleType: 'linear' as const }]; - const position = axisConfig.position ?? 'none'; - const dimension = axisName === 'x' ? 'height' : 'width'; + const parsedAxes = inputAxes.map((axisConfig, index) => { + const dataKey = axisConfig.dataKey; + const defaultPosition = axisName === 'x' ? ('bottom' as const) : ('left' as const); - const height = axisName === 'x' ? DEFAULT_AXIS_SIZE_HEIGHT : 0; - const width = axisName === 'y' ? DEFAULT_AXIS_SIZE_WIDTH : 0; + const position = axisConfig.position ?? 'none'; + const dimension = axisName === 'x' ? 'height' : 'width'; - const sharedConfig = { - id: `defaultized-${axisName}-axis-${index}`, - // The fist axis is defaultized to the bottom/left - ...(index === 0 ? { position: defaultPosition } : {}), - height, - width, - offset: offsets[position], - ...axisConfig, - }; + const height = axisName === 'x' ? DEFAULT_AXIS_SIZE_HEIGHT : 0; + const width = axisName === 'y' ? DEFAULT_AXIS_SIZE_WIDTH : 0; - // Increment the offset for the next axis - if (position !== 'none') { - offsets[position] += - (axisConfig as any)[dimension] ?? (dimension === 'height' ? height : width); - } + const sharedConfig = { + id: `defaultized-${axisName}-axis-${index}`, + // The fist axis is defaultized to the bottom/left + ...(index === 0 ? { position: defaultPosition } : {}), + height, + width, + offset: offsets[position], + ...axisConfig, + }; - // If `dataKey` is NOT provided - if (dataKey === undefined || axisConfig.data !== undefined) { - return sharedConfig; - } + // Increment the offset for the next axis + if (position !== 'none') { + offsets[position] += + (axisConfig as any)[dimension] ?? (dimension === 'height' ? height : width); + } - if (dataset === undefined) { - throw new Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`); - } + // If `dataKey` is NOT provided + if (dataKey === undefined || axisConfig.data !== undefined) { + return sharedConfig; + } - // If `dataKey` is provided - return { - ...sharedConfig, - data: dataset.map((d) => d[dataKey]), - }; - }, - ); + if (dataset === undefined) { + throw new Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`); + } + + // If `dataKey` is provided + return { + ...sharedConfig, + data: dataset.map((d) => d[dataKey]), + }; + }); return parsedAxes; } From c1dbd772bf8cdcd0a28a0068d8513962f5997fcc Mon Sep 17 00:00:00 2001 From: Bernardo Belchior Date: Wed, 26 Feb 2025 11:28:37 +0100 Subject: [PATCH 3/6] Accept proposal for default axes --- packages/x-charts-pro/src/Heatmap/Heatmap.tsx | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx index 5ec24cfac0af9..6e1899becda70 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx @@ -135,15 +135,33 @@ const Heatmap = React.forwardRef(function Heatmap( id: DEFAULT_X_AXIS_KEY, scaleType: 'band' as const, categoryGapRatio: 0, - data: [], + data: + series?.[0]?.data && series[0].data.length > 0 + ? Array.from( + { length: Math.max(...series[0].data.map(([xIndex]) => xIndex)) }, + (_, index) => index + 1, + ) + : [], ...axis, })), - [xAxis], + [series, xAxis], ); const defaultizedYAxis = React.useMemo( - () => yAxis.map((axis) => ({ scaleType: 'band' as const, categoryGapRatio: 0, ...axis })), - [yAxis], + () => + (yAxis && yAxis.length > 0 ? yAxis : [{}]).map((axis) => ({ + scaleType: 'band' as const, + categoryGapRatio: 0, + data: + series?.[0]?.data && series[0].data.length > 0 + ? Array.from( + { length: Math.max(...series[0].data.map(([_, yIndex]) => yIndex)) }, + (_, index) => index + 1, + ) + : [], + ...axis, + })), + [series, yAxis], ); const defaultizedZAxis = React.useMemo( From 4764808877b308698ca51cc5f87b39219304bc83 Mon Sep 17 00:00:00 2001 From: Bernardo Belchior Date: Wed, 26 Feb 2025 12:32:14 +0100 Subject: [PATCH 4/6] Update defaulting. Add tests. --- .../x-charts-pro/src/Heatmap/Heatmap.test.tsx | 31 +++++++++++++++++++ packages/x-charts-pro/src/Heatmap/Heatmap.tsx | 30 +++++++++--------- .../x-charts/src/ChartsXAxis/ChartsXAxis.tsx | 1 + .../x-charts/src/ChartsYAxis/ChartsYAxis.tsx | 1 + 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx index c057e49faa433..cba54ce739145 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx @@ -29,4 +29,35 @@ describe(' - License', () => { expect(screen.getByText('No data to display')).toBeVisible(); }); + + describe('axis defaults', () => { + const series = [ + { + data: [ + [-1, 3, 7], + [1, 5, 8], + ], + }, + ] as const; + + it('should render default axes when axes are empty arrays and series contain data', () => { + render(); + + const xAxisTickLabels = screen.getAllByTestId('ChartsXAxisTickLabel'); + expect(xAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['-1', '1']); + + const yAxisTickLabels = screen.getAllByTestId('ChartsYAxisTickLabel'); + expect(yAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['3', '5']); + }); + + it('should render default axes when axes are an array of an empty object and series contain data', () => { + render(); + + const xAxisTickLabels = screen.getAllByTestId('ChartsXAxisTickLabel'); + expect(xAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['-1', '1']); + + const yAxisTickLabels = screen.getAllByTestId('ChartsYAxisTickLabel'); + expect(yAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['3', '5']); + }); + }); }); diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx index 6e1899becda70..c8a1c10d2a310 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx @@ -101,6 +101,20 @@ const defaultColorMap = interpolateRgbBasis([ const seriesConfig: ChartSeriesConfig<'heatmap'> = { heatmap: heatmapSeriesConfig }; +function getDefaultDataForAxis(series: HeatmapProps['series'], dimension: number) { + if (series?.[0]?.data === undefined || series[0].data.length === 0) { + return []; + } + + const uniqueValues = new Set(); + + series[0].data.forEach((dataPoint) => uniqueValues.add(dataPoint[dimension])); + + return Array.from(uniqueValues.values()); +} +const getDefaultDataForXAxis = (series: HeatmapProps['series']) => getDefaultDataForAxis(series, 0); +const getDefaultDataForYAxis = (series: HeatmapProps['series']) => getDefaultDataForAxis(series, 1); + const Heatmap = React.forwardRef(function Heatmap( inProps: HeatmapProps, ref: React.Ref, @@ -135,13 +149,7 @@ const Heatmap = React.forwardRef(function Heatmap( id: DEFAULT_X_AXIS_KEY, scaleType: 'band' as const, categoryGapRatio: 0, - data: - series?.[0]?.data && series[0].data.length > 0 - ? Array.from( - { length: Math.max(...series[0].data.map(([xIndex]) => xIndex)) }, - (_, index) => index + 1, - ) - : [], + data: axis.data ? undefined : getDefaultDataForXAxis(series), ...axis, })), [series, xAxis], @@ -152,13 +160,7 @@ const Heatmap = React.forwardRef(function Heatmap( (yAxis && yAxis.length > 0 ? yAxis : [{}]).map((axis) => ({ scaleType: 'band' as const, categoryGapRatio: 0, - data: - series?.[0]?.data && series[0].data.length > 0 - ? Array.from( - { length: Math.max(...series[0].data.map(([_, yIndex]) => yIndex)) }, - (_, index) => index + 1, - ) - : [], + data: axis.data ? undefined : getDefaultDataForYAxis(series), ...axis, })), [series, yAxis], diff --git a/packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx b/packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx index de7cb706cb5f6..1c25d3252377d 100644 --- a/packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx +++ b/packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx @@ -278,6 +278,7 @@ function ChartsXAxis(inProps: ChartsXAxisProps) { diff --git a/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx b/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx index fa71cd0029be0..3719764e2bb6f 100644 --- a/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx +++ b/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx @@ -208,6 +208,7 @@ function ChartsYAxis(inProps: ChartsYAxisProps) { From f81ee769e72983904c76665c8d02412751c27439 Mon Sep 17 00:00:00 2001 From: Bernardo Belchior Date: Wed, 26 Feb 2025 14:30:41 +0100 Subject: [PATCH 5/6] Fix default axis data generation --- .../x-charts-pro/src/Heatmap/Heatmap.test.tsx | 22 +++++++++++++++---- packages/x-charts-pro/src/Heatmap/Heatmap.tsx | 20 ++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx index cba54ce739145..e08466182fefe 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx @@ -44,20 +44,34 @@ describe(' - License', () => { render(); const xAxisTickLabels = screen.getAllByTestId('ChartsXAxisTickLabel'); - expect(xAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['-1', '1']); + expect(xAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['0', '1']); const yAxisTickLabels = screen.getAllByTestId('ChartsYAxisTickLabel'); - expect(yAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['3', '5']); + expect(yAxisTickLabels.map((t) => t.textContent)).to.deep.equal([ + '0', + '1', + '2', + '3', + '4', + '5', + ]); }); it('should render default axes when axes are an array of an empty object and series contain data', () => { render(); const xAxisTickLabels = screen.getAllByTestId('ChartsXAxisTickLabel'); - expect(xAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['-1', '1']); + expect(xAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['0', '1']); const yAxisTickLabels = screen.getAllByTestId('ChartsYAxisTickLabel'); - expect(yAxisTickLabels.map((t) => t.textContent)).to.deep.equal(['3', '5']); + expect(yAxisTickLabels.map((t) => t.textContent)).to.deep.equal([ + '0', + '1', + '2', + '3', + '4', + '5', + ]); }); }); }); diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx index c8a1c10d2a310..0d89fb7040187 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.tsx @@ -22,7 +22,7 @@ import { ChartsOverlaySlotProps, ChartsOverlaySlots, } from '@mui/x-charts/ChartsOverlay'; -import { DEFAULT_X_AXIS_KEY } from '@mui/x-charts/constants'; +import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '@mui/x-charts/constants'; import { ChartContainerPro, ChartContainerProProps } from '../ChartContainerPro'; import { HeatmapSeriesType } from '../models/seriesType/heatmap'; import { HeatmapPlot } from './HeatmapPlot'; @@ -106,11 +106,10 @@ function getDefaultDataForAxis(series: HeatmapProps['series'], dimension: number return []; } - const uniqueValues = new Set(); - - series[0].data.forEach((dataPoint) => uniqueValues.add(dataPoint[dimension])); - - return Array.from(uniqueValues.values()); + return Array.from( + { length: Math.max(...series[0].data.map((dataPoint) => dataPoint[dimension])) + 1 }, + (_, index) => index, + ); } const getDefaultDataForXAxis = (series: HeatmapProps['series']) => getDefaultDataForAxis(series, 0); const getDefaultDataForYAxis = (series: HeatmapProps['series']) => getDefaultDataForAxis(series, 1); @@ -145,23 +144,22 @@ const Heatmap = React.forwardRef(function Heatmap( const defaultizedXAxis = React.useMemo( () => - (xAxis && xAxis.length > 0 ? xAxis : [{}]).map((axis) => ({ - id: DEFAULT_X_AXIS_KEY, + (xAxis && xAxis.length > 0 ? xAxis : [{ id: DEFAULT_X_AXIS_KEY }]).map((axis) => ({ scaleType: 'band' as const, categoryGapRatio: 0, - data: axis.data ? undefined : getDefaultDataForXAxis(series), ...axis, + data: axis.data ?? getDefaultDataForXAxis(series), })), [series, xAxis], ); const defaultizedYAxis = React.useMemo( () => - (yAxis && yAxis.length > 0 ? yAxis : [{}]).map((axis) => ({ + (yAxis && yAxis.length > 0 ? yAxis : [{ id: DEFAULT_Y_AXIS_KEY }]).map((axis) => ({ scaleType: 'band' as const, categoryGapRatio: 0, - data: axis.data ? undefined : getDefaultDataForYAxis(series), ...axis, + data: axis.data ?? getDefaultDataForYAxis(series), })), [series, yAxis], ); From 3322dbd359b04c1019934314cf4f2594d0829be3 Mon Sep 17 00:00:00 2001 From: Bernardo Belchior Date: Thu, 27 Feb 2025 10:04:16 +0100 Subject: [PATCH 6/6] Update packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Signed-off-by: Bernardo Belchior --- packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx index e08466182fefe..1bef9c67f750b 100644 --- a/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx +++ b/packages/x-charts-pro/src/Heatmap/Heatmap.test.tsx @@ -34,7 +34,7 @@ describe(' - License', () => { const series = [ { data: [ - [-1, 3, 7], + [0, 3, 7], [1, 5, 8], ], },