From 0c98c78b6899d3b524c02e58d14669e1dbe0694b Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:57:02 +0200 Subject: [PATCH] [charts] Fix area with log scale (#13791) --- packages/x-charts/src/LineChart/AreaPlot.tsx | 8 +++++++- packages/x-charts/src/LineChart/extremums.ts | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/x-charts/src/LineChart/AreaPlot.tsx b/packages/x-charts/src/LineChart/AreaPlot.tsx index daa51ea9d69a..edf60f0893ad 100644 --- a/packages/x-charts/src/LineChart/AreaPlot.tsx +++ b/packages/x-charts/src/LineChart/AreaPlot.tsx @@ -91,7 +91,13 @@ const useAggregatedData = () => { }>() .x((d) => xScale(d.x)) .defined((_, i) => connectNulls || data[i] != null) - .y0((d) => d.y && yScale(d.y[0])!) + .y0((d) => { + const value = d.y && yScale(d.y[0])!; + if (Number.isNaN(value)) { + return yScale.range()[0]; + } + return value; + }) .y1((d) => d.y && yScale(d.y[1])!); const curve = getCurveFactory(series[seriesId].curve); diff --git a/packages/x-charts/src/LineChart/extremums.ts b/packages/x-charts/src/LineChart/extremums.ts index 5393d4e3ba70..56f972dfdeba 100644 --- a/packages/x-charts/src/LineChart/extremums.ts +++ b/packages/x-charts/src/LineChart/extremums.ts @@ -41,7 +41,8 @@ export const getExtremumY: ExtremumGetter<'line'> = (params) => { const { area, stackedData } = series[seriesId]; const isArea = area !== undefined; - const getValues: GetValuesTypes = isArea ? (d) => d : (d) => [d[1], d[1]]; // Since this series is not used to display an area, we do not consider the base (the d[0]). + const getValues: GetValuesTypes = + isArea && axis.scaleType !== 'log' ? (d) => d : (d) => [d[1], d[1]]; // Since this series is not used to display an area, we do not consider the base (the d[0]). const seriesExtremums = getSeriesExtremums(getValues, stackedData);