From cc9ac56af926171d8db2b3e38ee0898b8651d52e Mon Sep 17 00:00:00 2001 From: "huiyu.zjt" Date: Fri, 8 Sep 2023 17:23:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=87=BD=E6=95=B0=E5=91=BD?= =?UTF-8?q?=E5=90=8DgetCrossBackgroundColor=E3=80=81=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=BD=BF=E7=94=A8createPivotSheet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s2-core/__tests__/unit/cell/row-cell-spec.ts | 6 ++---- packages/s2-core/src/cell/base-cell.ts | 12 +++++++----- packages/s2-core/src/cell/data-cell.ts | 2 +- packages/s2-core/src/cell/row-cell.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/s2-core/__tests__/unit/cell/row-cell-spec.ts b/packages/s2-core/__tests__/unit/cell/row-cell-spec.ts index 8d1119202f..18ca4ad3d9 100644 --- a/packages/s2-core/__tests__/unit/cell/row-cell-spec.ts +++ b/packages/s2-core/__tests__/unit/cell/row-cell-spec.ts @@ -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'; @@ -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, }); diff --git a/packages/s2-core/src/cell/base-cell.ts b/packages/s2-core/src/cell/base-cell.ts index c6e6bf240e..0a1c4523e4 100644 --- a/packages/s2-core/src/cell/base-cell.ts +++ b/packages/s2-core/src/cell/base-cell.ts @@ -463,17 +463,19 @@ export abstract class BaseCell 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, + }; } } diff --git a/packages/s2-core/src/cell/data-cell.ts b/packages/s2-core/src/cell/data-cell.ts index 50faba7f97..0703ee72c6 100644 --- a/packages/s2-core/src/cell/data-cell.ts +++ b/packages/s2-core/src/cell/data-cell.ts @@ -308,7 +308,7 @@ export class DataCell extends BaseCell { } public getBackgroundColor() { - const backgroundColorByCross = this.getBackgroundColorByCross( + const backgroundColorByCross = this.getCrossBackgroundColor( this.meta.rowIndex, ); let backgroundColor = backgroundColorByCross.backgroundColor; diff --git a/packages/s2-core/src/cell/row-cell.ts b/packages/s2-core/src/cell/row-cell.ts index 0c01473659..413a77f5e1 100644 --- a/packages/s2-core/src/cell/row-cell.ts +++ b/packages/s2-core/src/cell/row-cell.ts @@ -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,