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: 列头绘制多列文本时错误的使用了数值单元格的样式 close #2359 #2364

Merged
merged 1 commit into from
Oct 13, 2023
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
140 changes: 140 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-2359-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* @description spec for issue #2359
* https://github.com/antvis/S2/issues/2359
* 明细表: 自定义列头误用 dataCell 样式
*/
import { pick } from 'lodash';
import { createTableSheet } from 'tests/util/helpers';
import { TableColCell, drawObjectText } from '../../src';
import type { S2CellType, S2Options } from '@/common/interface';

class TestColCell extends TableColCell {
drawTextShape() {
drawObjectText(this, {
values: [['A', 'B', 'C']],
});
}
}

const s2Options: S2Options = {
width: 300,
height: 480,
showSeriesNumber: true,
colCell: (...args) => new TestColCell(...args),
};

describe('Table Sheet Custom Multiple Values Tests', () => {
test('should use current cell text theme', () => {
const s2 = createTableSheet(s2Options);

s2.setTheme({
colCell: {
measureText: {
fontSize: 12,
},
bolderText: {
fontSize: 14,
},
text: {
fontSize: 20,
fill: 'red',
},
},
dataCell: {
text: {
fontSize: 30,
fill: 'green',
},
},
});
s2.render();

const mapTheme = (cell: S2CellType) => {
return cell
.getTextShapes()
.map((shape) => pick(shape.attr(), ['fill', 'fontSize']));
};

const colCellTexts = s2
.getColumnNodes()
.map((node) => mapTheme(node.belongsCell));

const dataCellTexts = s2.interaction
.getPanelGroupAllDataCells()
.map(mapTheme);

expect(colCellTexts).toMatchInlineSnapshot(`
Array [
Array [
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
],
Array [
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
],
]
`);

expect(dataCellTexts).toMatchInlineSnapshot(`
Array [
Array [
Object {
"fill": "#000000",
"fontSize": 12,
},
],
Array [
Object {
"fill": "#000000",
"fontSize": 12,
},
],
Array [
Object {
"fill": "#000000",
"fontSize": 12,
},
],
Array [
Object {
"fill": "green",
"fontSize": 30,
},
],
Array [
Object {
"fill": "green",
"fontSize": 30,
},
],
Array [
Object {
"fill": "green",
"fontSize": 30,
},
],
]
`);
});
});
4 changes: 1 addition & 3 deletions packages/s2-core/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ const calX = (
const getDrawStyle = (cell: S2CellType) => {
const { isTotals } = cell.getMeta();
const isMeasureField = (cell as ColCell).isMeasureField?.();
const cellStyle = cell.getStyle(
isMeasureField ? CellTypes.COL_CELL : CellTypes.DATA_CELL,
);
const cellStyle = cell.getStyle(cell.cellType || CellTypes.DATA_CELL);

let textStyle: TextTheme;
if (isMeasureField) {
Expand Down