Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(conditional-formatting): configuration exceptions are specifically handled (#1750)
Gpound.liu37a77873c6e5
diff --git a/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.ts b/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.tsindex 8a024bfbc0..5fe3205234 100644--- a/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.ts+++ b/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.ts@@ -848,7 +848,7 @@ describe('Test conditional formatting service', () => {});});});- it('Need to filter if the set value is wrong', () => {+ it('The colors are consistent, but the values are interchangeable', () => {const params: IConditionFormattingRule<IColorScale> = {ranges: [{ startRow: 0, startColumn: 0, endRow: 5, endColumn: 6 }],cfId: testBed.getConditionalFormattingRuleModel().createCfId(testBed.unitId, testBed.subUnitId),@@ -868,7 +868,7 @@ describe('Test conditional formatting service', () => {color: '#2e55ef',value: {type: CFValueType.num,- value: -5, // this wrong value is filter+ value: -5,},},{@@ -882,26 +882,6 @@ describe('Test conditional formatting service', () => {],},};- /**- * the same as- [{- index: 0,- color: '#d0d9fb',- value: {- type: CFValueType.num,- value: 1,- },- },- {- index: 2,- color: 'rgb(231, 37, 143)',- value: {- type: CFValueType.num,- value: 3,- },- },- ]- */testBed.getConditionalFormattingRuleModel().addRule(testBed.unitId, testBed.subUnitId, params);testBed.getConditionalFormattingService().composeStyle(testBed.unitId, testBed.subUnitId, 1, 0);const dispose = testBed.getConditionalFormattingService().ruleComputeStatus$.subscribe(() => {@@ -914,14 +894,14 @@ describe('Test conditional formatting service', () => {expect(one).toEqual({style: {bg: {- rgb: 'rgb(208,217,251)',+ rgb: 'rgb(46,85,239)',},},});expect(two).toEqual({style: {bg: {- rgb: 'rgb(220,127,197)',+ rgb: 'rgb(139,61,191)',},},});diff --git a/packages/sheets-conditional-formatting/src/services/calculate-unit/color-scale.ts b/packages/sheets-conditional-formatting/src/services/calculate-unit/color-scale.tsindex 86ca6d372e..3427a12677 100644--- a/packages/sheets-conditional-formatting/src/services/calculate-unit/color-scale.ts+++ b/packages/sheets-conditional-formatting/src/services/calculate-unit/color-scale.ts@@ -48,31 +48,26 @@ export const colorScaleCellCalculateUnit: ICalculateUnit = {});});- const _colorList = [...ruleConfig.config].sort((a, b) => a.index - b.index).map((config) => {+ const _configList = [...ruleConfig.config].sort((a, b) => a.index - b.index).map((config) => {return {value: getValueByType(config.value, matrix, { ...context, cfId: rule.cfId }), color: new ColorKit(config.color),};});// If the formula triggers the calculation, wait for the result,// and use the previous style cache until the result comes out- const isFormulaWithoutSuccess = _colorList.some((item) => isObject(item.value) ? item.value.status !== FormulaResultStatus.SUCCESS : false);+ const isFormulaWithoutSuccess = _configList.some((item) => isObject(item.value) ? item.value.status !== FormulaResultStatus.SUCCESS : false);if (isFormulaWithoutSuccess) {return conditionalFormattingFormulaService.getCache(context.unitId, context.subUnitId, rule.cfId) ?? computeResult;}- const colorList = _colorList.map((item) => {- return { ...item, value: isObject(item.value) ? Number(item.value.result) ?? 0 : item.value ?? 0 };- }).reduce((res, cur) => {- const pre = res[res.length - 1];- if (pre && cur.value <= pre.value) {- return res;- }- res.push(cur);- return res;- }, [] as {- value: number;- color: ColorKit;- }[]);+ const colorList = _configList+ .map((item) => item.color)+ .reduce((result, color, index) => {+ result.result.push({ color, value: result.sortValue[index] });+ return result;+ }, { result: [] as { value: number;color: ColorKit }[],+ sortValue: _configList.map((item) => item.value.result as number).sort((a, b) => a - b) })+ .result;if (colorList.length <= 1) {return computeResult;diff --git a/packages/sheets-conditional-formatting/src/services/calculate-unit/icon-set.ts b/packages/sheets-conditional-formatting/src/services/calculate-unit/icon-set.tsindex 7a6da1fc92..ea0aa11789 100644--- a/packages/sheets-conditional-formatting/src/services/calculate-unit/icon-set.ts+++ b/packages/sheets-conditional-formatting/src/services/calculate-unit/icon-set.ts@@ -63,16 +63,17 @@ export const iconSetCalculateUnit: ICalculateUnit = {operator: ruleConfig.config[index].operator,value: Number(item.result) || 0,})).reduce((result, cur, index, list) => {+ const item = ruleConfig.config[index];if (!index || index === list.length - 1) {- result.push(cur);+ result.push({ ...cur, iconId: item.iconId, iconType: item.iconType });} else {const pre = list[index - 1];if (!compareWithNumber(pre, cur.value)) {- result.push(cur);+ result.push({ ...cur, iconId: item.iconId, iconType: item.iconType });}}return result;- }, [] as { operator: CFNumberOperator;value: number }[]);+ }, [] as { operator: CFNumberOperator;value: number;iconType: string;iconId: string }[]);const isShowValue = ruleConfig.isShowValue === undefined ? true : !!ruleConfig.isShowValue;matrix.forValue((row, col, value) => {@@ -80,7 +81,7 @@ export const iconSetCalculateUnit: ICalculateUnit = {const item = splitValue[index];const start = { ...item };const end = { ...item };- const { iconId, iconType } = ruleConfig.config[index];+ const { iconId, iconType } = item;if (index === 0) {if (compareWithNumber(item, value)) {computeResult.setValue(row, col, { iconId, iconType, isShowValue });diff --git a/packages/sheets-conditional-formatting/src/services/calculate-unit/utils.ts b/packages/sheets-conditional-formatting/src/services/calculate-unit/utils.tsindex 69d775b267..61dd46fa52 100644--- a/packages/sheets-conditional-formatting/src/services/calculate-unit/utils.ts+++ b/packages/sheets-conditional-formatting/src/services/calculate-unit/utils.ts@@ -143,7 +143,7 @@ export const getValueByType = (value: IValueConfig, matrix: ObjectMatrix< numbercase CFValueType.percentile:{const list = matrix.toNativeArray().sort((a, b) => a - b);const v = Math.max(Math.min(Number(value.value) || 0, 100), 0);- const index = ((list.length - 1) * v) / 100;+ const index = (list.length - 1) * v / 100;const intIndex = Math.floor(index);const decimalIndex = index - intIndex;const result = list[intIndex] + (list[Math.min(intIndex + 1, list.length - 1)] - list[intIndex]) * decimalIndex;