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: render maxLines text correctly after render twice #3089

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
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
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),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from Math.floor to Math.round in the calculation of maxLines may affect the rendering behavior. Ensure that this change does not introduce any unintended side effects, especially in edge cases where the line height and display height are close to each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

问题根因分析

  1. 数值截断逻辑矛盾
    计算逻辑:(displayHeight - padding) / lineHeight = (61 - 16) / 16 = 2.8125
  2. 条件判断逻辑缺陷
    isCustomHeight 触发条件:只有当 isCustomHeight = true 时才会执行计算,但代码中该参数默认值为 false,在二次渲染时外部传入 true,导致逻辑分歧。

);

return maxLines;
Expand Down
Loading