diff --git a/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-area-chart-stacked-percentage-with-zeros-visually-looks-correct-1-snap.png b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-area-chart-stacked-percentage-with-zeros-visually-looks-correct-1-snap.png index d53744abdf..f262be3ea8 100644 Binary files a/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-area-chart-stacked-percentage-with-zeros-visually-looks-correct-1-snap.png and b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-area-chart-stacked-percentage-with-zeros-visually-looks-correct-1-snap.png differ diff --git a/src/chart_types/xy_chart/rendering/rendering.areas.test.ts b/src/chart_types/xy_chart/rendering/rendering.areas.test.ts index b49cd2daa4..6c9180a3ea 100644 --- a/src/chart_types/xy_chart/rendering/rendering.areas.test.ts +++ b/src/chart_types/xy_chart/rendering/rendering.areas.test.ts @@ -1114,10 +1114,10 @@ describe('Rendering points - areas', () => { { datum: [1546300800000, 0], initialY0: null, - initialY1: null, + initialY1: 0, x: 1546300800000, y0: null, - y1: null, + y1: 0, }, { datum: [1546387200000, 5], diff --git a/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts b/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts index d8d39344b2..86ec0059eb 100644 --- a/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts +++ b/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts @@ -449,17 +449,17 @@ describe('Stacked Series Utils', () => { const stackedValues: Map = new Map(); stackedValues.set(1, { values: [0, 0, 0], - percent: [null, null, null], + percent: [0, 0, 0], total: 0, }); const formattedDatum = getStackedFormattedSeriesDatum({ x: 1, y1: 0 }, stackedValues, 0, false, true); expect(formattedDatum).toEqual({ datum: undefined, initialY0: null, - initialY1: null, + initialY1: 0, x: 1, y0: null, - y1: null, + y1: 0, }); }); }); diff --git a/src/chart_types/xy_chart/utils/stacked_series_utils.ts b/src/chart_types/xy_chart/utils/stacked_series_utils.ts index 9a81594406..779c4496e3 100644 --- a/src/chart_types/xy_chart/utils/stacked_series_utils.ts +++ b/src/chart_types/xy_chart/utils/stacked_series_utils.ts @@ -22,7 +22,7 @@ import { ScaleType } from '../../../scales'; /** @internal */ export interface StackedValues { values: number[]; - percent: Array; + percent: Array; total: number; } @@ -105,7 +105,7 @@ export function computeYStackedMapValues( ); const percent = stackArray.values.map((value) => { if (stackArray.total === 0) { - return null; + return 0; } return value / stackArray.total; }); @@ -192,11 +192,11 @@ export function getStackedFormattedSeriesDatum( let y1: number | null = null; let y0: number | null | undefined = null; if (isPercentageMode) { - if (data.y1 != null && stack.total !== 0) { - y1 = data.y1 / stack.total; + if (data.y1 != null) { + y1 = stack.total !== 0 ? data.y1 / stack.total : 0; } - if (data.y0 != null && stack.total !== 0) { - y0 = data.y0 / stack.total; + if (data.y0 != null) { + y0 = stack.total !== 0 ? data.y0 / stack.total : 0; } } else { y1 = data.y1; diff --git a/stories/area/8_stacked_percentage_zeros.tsx b/stories/area/8_stacked_percentage_zeros.tsx index e52c234277..408836d94b 100644 --- a/stories/area/8_stacked_percentage_zeros.tsx +++ b/stories/area/8_stacked_percentage_zeros.tsx @@ -117,7 +117,7 @@ const DATA = [ [1585735200000, 83], [1585749600000, 46], [1585764000000, 7], - [1585778400000, 2], + [1585778400000, null], [1585792800000, 12], [1585807200000, 44], [1585821600000, 84], @@ -172,7 +172,7 @@ const DATA = [ [1585735200000, 8], [1585749600000, 2], [1585764000000, 0], - [1585778400000, 0], + [1585778400000, null], [1585792800000, 0], [1585807200000, 1], [1585821600000, 6], @@ -227,7 +227,7 @@ const DATA = [ [1585735200000, 3], [1585749600000, 1], [1585764000000, 1], - [1585778400000, 0], + [1585778400000, null], [1585792800000, 0], [1585807200000, 2], [1585821600000, 1],