Skip to content

Commit

Permalink
fix: render maxLines text correctly after render twice
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyu.zjt committed Feb 1, 2025
1 parent 330bbf2 commit f51ba4c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-3087-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @description spec for issue #3087
* https://github.com/antvis/S2/issues/3087
*/
import { TableSheet } from '../../src';
import { getContainer } from '../util/helpers';

const data = Array(100).fill({
province: 'aaaa'.repeat(100),
city: 'aa',
});

describe('Table MaxLines Tests', () => {
test('should render maxLines text correctly after render twice', async () => {
const tableSheet = new TableSheet(
getContainer(),
{
fields: {
columns: ['province', 'city'],
},
meta: [
{
field: 'province',
name: '省份',
},
{
field: 'city',
name: '城市',
},
],
data,
},
{
width: 600,
height: 480,
style: {
colCell: {
maxLines: 3,
wordWrap: true,
textOverflow: 'ellipsis',
},
dataCell: {
maxLines: 3,
wordWrap: true,
textOverflow: 'ellipsis',
},
},
},
);

await tableSheet.render();
const actualText1 = tableSheet.facet.getDataCells()[0].getActualText();

await tableSheet.render();
const actualText2 = tableSheet.facet.getDataCells()[0].getActualText();

expect(actualText1).toEqual(actualText2);
});
});
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/base-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export abstract class BaseCell<T extends SimpleBBox> extends Group {

const maxLines = Math.max(
1,
Math.floor((displayHeight - padding) / lineHeight),
Math.round((displayHeight - padding) / lineHeight),
);

return maxLines;
Expand Down

0 comments on commit f51ba4c

Please sign in to comment.