Skip to content

Commit

Permalink
refactor: 函数命名getCrossBackgroundColor、测试用例使用createPivotSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyu.zjt committed Sep 8, 2023
1 parent 63db80b commit cc9ac56
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 2 additions & 4 deletions packages/s2-core/__tests__/unit/cell/row-cell-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { get } from 'lodash';
import { createPivotSheet, getContainer } from 'tests/util/helpers';
import { createPivotSheet } from 'tests/util/helpers';
import type { RowCell } from '@antv/s2';
import simpleData from '../../data/simple-data.json';
import { PivotSheet } from '@/index';
import type { SpreadSheet } from '@/sheet-type';
import type { TextAlign } from '@/common';

Expand Down Expand Up @@ -117,7 +115,7 @@ describe('Row Cell Tests', () => {
});

describe('Cross Background Color Tests', () => {
const s2 = new PivotSheet(getContainer(), simpleData, {
const s2 = createPivotSheet({
width: 800,
height: 600,
});
Expand Down
12 changes: 7 additions & 5 deletions packages/s2-core/src/cell/base-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,19 @@ export abstract class BaseCell<T extends SimpleBBox> extends Group {
return fillResult;
}

protected getBackgroundColorByCross(rowIndex: number) {
protected getCrossBackgroundColor(rowIndex: number) {
const { crossBackgroundColor, backgroundColorOpacity } =
this.getStyle().cell;

let backgroundColor = this.getStyle().cell.backgroundColor;

if (crossBackgroundColor && rowIndex % 2 === 0) {
// 隔行颜色的配置
// 偶数行展示灰色背景,因为index是从0开始的
backgroundColor = crossBackgroundColor;
return { backgroundColorOpacity, backgroundColor: crossBackgroundColor };
}
return { backgroundColorOpacity, backgroundColor };

return {
backgroundColorOpacity,
backgroundColor: this.getStyle().cell.backgroundColor,
};
}
}
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/data-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export class DataCell extends BaseCell<ViewMeta> {
}

public getBackgroundColor() {
const backgroundColorByCross = this.getBackgroundColorByCross(
const backgroundColorByCross = this.getCrossBackgroundColor(
this.meta.rowIndex,
);
let backgroundColor = backgroundColorByCross.backgroundColor;
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class RowCell extends HeaderCell {

public getBackgroundColor() {
const { backgroundColor, backgroundColorOpacity } =
this.getBackgroundColorByCross(this.meta.rowIndex);
this.getCrossBackgroundColor(this.meta.rowIndex);
return this.getBackgroundColorByCondition(
backgroundColor,
backgroundColorOpacity,
Expand Down

0 comments on commit cc9ac56

Please sign in to comment.