Skip to content

Commit cc9245a

Browse files
committed
Fix pivot table background settings application for nulls
1 parent c8803a9 commit cc9245a

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/server/modes/charts/plugins/datalens/preparers/backend-pivot-table/helpers/backgroundColor.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
} from '../../../../../../../../shared';
88
import {
99
ApiV2Annotations,
10+
GradientNullModes,
1011
PseudoFieldTitle,
1112
getFakeTitleOrTitle,
1213
} from '../../../../../../../../shared';
@@ -231,8 +232,19 @@ export const prepareBackgroundColorSettings = (args: PrepareBackgroundColorSetti
231232
const fieldColorValues = Array.from(colorValues);
232233

233234
continuousColorsByField[guid] = {};
235+
const nilValue =
236+
backgroundSettings.settings.gradientState.nullMode === GradientNullModes.AsZero
237+
? 0
238+
: null;
239+
240+
const colorValuesWithoutNull = fieldColorValues.reduce<number[]>((acc, cv) => {
241+
const colorValue = cv === null ? nilValue : cv;
242+
if (colorValue !== null) {
243+
acc.push(Number(colorValue));
244+
}
234245

235-
const colorValuesWithoutNull = fieldColorValues.filter((cv): cv is number => cv !== null);
246+
return acc;
247+
}, []);
236248

237249
const min = Math.min(...colorValuesWithoutNull);
238250
const max = Math.max(...colorValuesWithoutNull);
@@ -250,12 +262,15 @@ export const prepareBackgroundColorSettings = (args: PrepareBackgroundColorSetti
250262

251263
fieldColorValues.forEach((value) => {
252264
const colorValue = getContinuousColorValue(value);
253-
if (colorValue === null) {
265+
if (
266+
colorValue === null &&
267+
backgroundSettings.settings.gradientState.nullMode !== GradientNullModes.AsZero
268+
) {
254269
return;
255270
}
256271

257272
const color = colorizePivotTableCell(colorValue, chartColorsConfig, [min, max]);
258-
continuousColorsByField[guid][String(value)] = color?.backgroundColor || null;
273+
continuousColorsByField[guid][String(colorValue)] = color?.backgroundColor || null;
259274
});
260275
});
261276

@@ -317,7 +332,10 @@ export const colorizePivotTableByFieldBackgroundSettings = (
317332
const {settings, colorFieldGuid} = backgroundColorSettings;
318333
const colorKey = cell.colorKey;
319334

320-
if (!colorKey) {
335+
if (
336+
!colorKey &&
337+
backgroundColorSettings.settings.gradientState.nullMode !== GradientNullModes.AsZero
338+
) {
321339
continue;
322340
}
323341

src/server/modes/charts/plugins/datalens/preparers/backend-pivot-table/helpers/color.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ServerColor} from '../../../../../../../../shared';
2-
import {ApiV2Annotations, isMeasureName} from '../../../../../../../../shared';
2+
import {ApiV2Annotations, GradientNullModes, isMeasureName} from '../../../../../../../../shared';
33
import type {ChartColorsConfig} from '../../../types';
44
import {colorizePivotTableCell} from '../../../utils/color-helpers';
55
import type {AnnotationsMap, PivotDataCellValue, PivotDataRows} from '../types';
@@ -110,11 +110,13 @@ export const colorizePivotTableByColorField = (args: ColorizeByColorFieldArgs) =
110110
}
111111

112112
const {colorValues, min, max} = colorSettings;
113+
const nilValue = colorsConfig.nullMode === GradientNullModes.AsZero ? 0 : null;
113114

114115
rows.forEach((row, rowIndex) => {
115116
for (let i = rowHeaderLength; i < row.cells.length; i++) {
116117
const cell = row.cells[i];
117-
const colorValue = colorValues[rowIndex][i - rowHeaderLength];
118+
const rawColorValue = colorValues[rowIndex][i - rowHeaderLength];
119+
const colorValue = rawColorValue === null ? nilValue : rawColorValue;
118120

119121
const isInvalidColorValue = colorValue === null;
120122

0 commit comments

Comments
 (0)