Skip to content

Commit

Permalink
[charts] Fix log scale with null data (#15337)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Nov 8, 2024
1 parent 1b6c93d commit 7c4c924
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/x-charts/src/BarChart/extremums.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const buildData = (
]
: [],
layout,
valueFormatter: () => '',
},
},
axis: {
Expand Down
8 changes: 6 additions & 2 deletions packages/x-charts/src/LineChart/extremums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ type GetValues = (d: [number, number]) => [number, number];

function getSeriesExtremums(
getValues: GetValues,
data: (number | null)[],
stackedData: [number, number][],
filter?: ExtremumFilter,
): [number, number] {
return stackedData.reduce<[number, number]>(
(seriesAcc, stackedValue, index) => {
if (data[index] === null) {
return seriesAcc;
}
const [base, value] = getValues(stackedValue);
if (
filter &&
Expand All @@ -41,7 +45,7 @@ export const getExtremumY: ExtremumGetter<'line'> = (params) => {
})
.reduce(
(acc, seriesId) => {
const { area, stackedData } = series[seriesId];
const { area, stackedData, data } = series[seriesId];
const isArea = area !== undefined;

const filter = getFilters?.({
Expand All @@ -57,7 +61,7 @@ export const getExtremumY: ExtremumGetter<'line'> = (params) => {
? (d) => d
: (d) => [d[1], d[1]];

const seriesExtremums = getSeriesExtremums(getValues, stackedData, filter);
const seriesExtremums = getSeriesExtremums(getValues, data, stackedData, filter);

const [seriesMin, seriesMax] = seriesExtremums;
return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
CartesianChartSeriesType,
ChartSeries,
ChartSeriesDefaultized,
ChartSeriesType,
} from '../../models/seriesType/config';
import type { AxisConfig, AxisId } from '../../models/axis';
Expand All @@ -11,7 +11,7 @@ export type ExtremumGettersConfig<T extends ChartSeriesType = CartesianChartSeri
};

type ExtremumGetterParams<T extends ChartSeriesType> = {
series: Record<SeriesId, ChartSeries<T>>;
series: Record<SeriesId, ChartSeriesDefaultized<T>>;
axis: AxisConfig;
axisIndex: number;
isDefaultAxis: boolean;
Expand Down

0 comments on commit 7c4c924

Please sign in to comment.