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: 修复存在字段标记时, 紧凑模式下有几率显示省略号的问题 #3061

Merged
merged 1 commit into from
Jan 2, 2025
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
60 changes: 59 additions & 1 deletion packages/s2-core/__tests__/spreadsheet/compare-layout-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* https://github.com/antvis/S2/issues/2385
*/
import { PivotSheet, SpreadSheet, TableSheet } from '@/sheet-type';
import { LayoutWidthType, type S2Options } from '../../src';
import { LayoutWidthType, customMerge, type S2Options } from '../../src';
import * as mockDataConfig from '../data/data-issue-2385.json';
import { getContainer } from '../util/helpers';

Expand Down Expand Up @@ -320,6 +320,64 @@ describe('Compare Layout Tests', () => {
expectTextOverflowing(s2);
});

test.each([{ showIcon: true }, { showIcon: false }])(
'should get max col leaf node width for pivot sheet conditions and header action icons by %o',
async (options) => {
const s2 = new PivotSheet(
getContainer(),
customMerge(mockDataConfig, { fields: { columns: [] } }),
{
...s2Options,
headerActionIcons: options.showIcon
? [
{
icons: ['SortDown'],
belongsCell: 'colCell',
},
]
: [],
conditions: {
icon: [
{
field: 'price',
position: 'left',
mapping(fieldValue: number) {
if (!fieldValue) {
return null;
}

return fieldValue > 0
? {
fill: 'red',
icon: 'CellUp',
}
: {
fill: 'green',
icon: 'CellDown',
};
},
},
],
},
},
);

s2.setDataCfg({
meta: [
{
field: 'price',
name: '环比差值',
formatter: () => '2,248.92万',
},
],
});

await s2.render();

expectTextOverflowing(s2);
},
);

test.each([
{ text: '中文文本测试中文文本测试', width: 145 },
{ text: '中文文本测试中文文本123', width: 142 },
Expand Down
7 changes: 3 additions & 4 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,9 @@ export class PivotFacet extends FrozenFacet {
dataCellIconStyle?.margin?.left +
dataCellIconStyle?.margin?.right
: 0;
const cellLabelWidth = this.measureTextWidth(
cellLabel as string,
dataCellTextStyle,
);
const cellLabelWidth =
this.measureTextWidth(cellLabel as string, dataCellTextStyle) +
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
dataCellIconWidth;

if (cellLabelWidth > maxDataLabelWidth) {
maxDataLabel = cellLabel as string;
Expand Down
Loading