Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(conditional-formatting): configuration exceptions are specificall… #1750

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -868,7 +868,7 @@ describe('Test conditional formatting service', () => {
color: '#2e55ef',
value: {
type: CFValueType.num,
value: -5, // this wrong value is filter
value: -5,
},
},
{
Expand All @@ -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(() => {
Expand All @@ -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)',
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,25 @@ 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) => {
for (let index = 0; index < splitValue.length; index++) {
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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const getValueByType = (value: IValueConfig, matrix: ObjectMatrix< number
case 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;
Expand Down
Loading