Skip to content

Commit

Permalink
fix: 修复存在字段标记时, 紧凑模式下有几率显示省略号的问题 (#3061)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Jan 2, 2025
1 parent aca03ac commit d200b13
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
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) +
dataCellIconWidth;

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

0 comments on commit d200b13

Please sign in to comment.