Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,41 @@ describe('listTable init test', () => {
frozenTable.release();
});

test('listTable frame border should match short content with frozen rows', () => {
const optionWithShortFrozenRows = {
...option,
columns: columns.slice(0, 5).map(column => ({
...column,
width: 180
})),
frozenColCount: 0,
rightFrozenColCount: 0,
frozenRowCount: 3,
bottomFrozenRowCount: 1,
container: createDiv(),
records: records.slice(0, 6),
widthMode: 'standard',
theme: {
frameStyle: {
borderLineWidth: [1, 1, 1, 1],
borderColor: 'red'
}
}
};
optionWithShortFrozenRows.container.style.position = 'relative';
optionWithShortFrozenRows.container.style.width = '900px';
optionWithShortFrozenRows.container.style.height = '500px';

const frozenTable = new ListTable(optionWithShortFrozenRows);
const { scenegraph } = frozenTable;
const contentBottom = scenegraph.bottomFrozenGroup.attribute.y + scenegraph.bottomFrozenGroup.attribute.height;

expect(scenegraph.tableGroup.attribute.height).toBe(contentBottom);
expect(scenegraph.tableGroup.border.attribute.height).toBe(contentBottom + 1);

frozenTable.release();
});

test('listTable should support decreasing rightFrozenColCount by setter with row series number', () => {
const optionWithRightFrozen = {
...option,
Expand Down
47 changes: 47 additions & 0 deletions packages/vtable/examples/debug/issue-5277-frozen-row-border.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as VTable from '../../src';

const CONTAINER_ID = 'vTable';

const generateRecords = (count: number) =>
Array.from({ length: count }, (_, index) => ({
id: index + 1,
name: `Name ${index + 1}`,
city: ['Beijing', 'Shanghai', 'Shenzhen', 'Hangzhou', 'Chengdu', 'Wuhan'][index % 6],
sales: 1000 + index * 100,
profit: 120 + index * 10
}));

export function createTable() {
const container = document.getElementById(CONTAINER_ID);
if (!container) {
return;
}
container.style.width = '900px';
container.style.height = '500px';

const columns: VTable.ColumnsDefine = [
{ field: 'id', title: 'ID', width: 120 },
{ field: 'name', title: 'Name', width: 180 },
{ field: 'city', title: 'City', width: 180 },
{ field: 'sales', title: 'Sales', width: 180 },
{ field: 'profit', title: 'Profit', width: 180 }
];

const option: VTable.ListTableConstructorOptions = {
container,
records: generateRecords(6),
frozenRowCount: 3,
bottomFrozenRowCount: 1,
columns,
widthMode: 'standard',
theme: {
frameStyle: {
borderLineWidth: [1, 1, 1, 1],
borderColor: 'red'
}
}
};

const tableInstance = new VTable.ListTable(option);
window.tableInstance = tableInstance;
}
4 changes: 4 additions & 0 deletions packages/vtable/examples/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export const menus = [
path: 'debug',
name: 'issue-5213-row-series-number-aggregation'
},
{
path: 'debug',
name: 'issue-5277-frozen-row-border'
},
{
path: 'debug',
name: 'issue-4761-update-records-edit-render'
Expand Down
168 changes: 96 additions & 72 deletions packages/vtable/src/scenegraph/scenegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,78 +1363,6 @@ export class Scenegraph {
height: tableHeight
} as any);

if (this.tableGroup.border) {
const rectAttributes = this.tableGroup.border?.attribute;
let borderTop;
let borderRight;
let borderBottom;
let borderLeft;
if ((rectAttributes as any)?.strokeArrayWidth) {
borderTop = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[0]
: (rectAttributes.lineWidth as number) ?? 0;
borderRight = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[1]
: (rectAttributes.lineWidth as number) ?? 0;
borderBottom = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[2]
: (rectAttributes.lineWidth as number) ?? 0;
borderLeft = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[3]
: (rectAttributes.lineWidth as number) ?? 0;
} else {
borderTop = (rectAttributes?.lineWidth as number) ?? 0;
borderRight = (rectAttributes?.lineWidth as number) ?? 0;
borderBottom = (rectAttributes?.lineWidth as number) ?? 0;
borderLeft = (rectAttributes?.lineWidth as number) ?? 0;
}
if (this.tableGroup.border.type === 'rect') {
if (this.table.theme.frameStyle?.innerBorder) {
this.tableGroup.border.setAttributes({
x: this.table.tableX + borderLeft / 2,
y: this.table.tableY + borderTop / 2,
width: this.tableGroup.attribute.width - borderLeft / 2 - borderRight / 2,
height: this.tableGroup.attribute.height - borderTop / 2 - borderBottom / 2
});
} else {
this.tableGroup.border.setAttributes({
x: this.table.tableX - borderLeft / 2,
y: this.table.tableY - borderTop / 2,
width: this.tableGroup.attribute.width + borderLeft / 2 + borderRight / 2,
height: this.tableGroup.attribute.height + borderTop / 2 + borderBottom / 2
});
}
} else if (this.tableGroup.border.type === 'group') {
if (this.table.theme.frameStyle?.innerBorder) {
this.tableGroup.border.setAttributes({
x: this.table.tableX + borderLeft / 2,
y: this.table.tableY + borderTop / 2,
width: this.tableGroup.attribute.width - borderLeft / 2 - borderRight / 2,
height: this.tableGroup.attribute.height - borderTop / 2 - borderBottom / 2
});
(this.tableGroup.border.firstChild as IRect)?.setAttributes({
x: 0,
y: 0,
width: this.tableGroup.attribute.width - borderLeft / 2 - borderRight / 2,
height: this.tableGroup.attribute.height - borderTop / 2 - borderBottom / 2
});
} else {
this.tableGroup.border.setAttributes({
x: this.table.tableX - borderLeft / 2,
y: this.table.tableY - borderTop / 2,
width: this.tableGroup.attribute.width + borderLeft / 2 + borderRight / 2,
height: this.tableGroup.attribute.height + borderTop / 2 + borderBottom / 2
});
(this.tableGroup.border.firstChild as IRect)?.setAttributes({
x: borderLeft / 2,
y: borderTop / 2,
width: this.tableGroup.attribute.width,
height: this.tableGroup.attribute.height
});
}
}
}

const hasFrozenCols = this.table.frozenColCount > 0;
const hasRightFrozenCols = this.table.rightFrozenColCount > 0;
const hasFrozenRows = this.table.frozenRowCount > 0;
Expand Down Expand Up @@ -1510,10 +1438,106 @@ export class Scenegraph {
});
}

if (hasBottomFrozenRows && !this.table.containerFit?.height) {
const actualContentBottom = Math.max(
this.colHeaderGroup.attribute.y + this.colHeaderGroup.attribute.height,
this.cornerHeaderGroup.attribute.y + this.cornerHeaderGroup.attribute.height,
this.rightTopCornerGroup.attribute.y + this.rightTopCornerGroup.attribute.height,
this.rowHeaderGroup.attribute.y + this.rowHeaderGroup.attribute.height,
this.bodyGroup.attribute.y + this.bodyGroup.attribute.height,
this.rightFrozenGroup.attribute.y + this.rightFrozenGroup.attribute.height,
this.leftBottomCornerGroup.attribute.y + this.leftBottomCornerGroup.attribute.height,
this.bottomFrozenGroup.attribute.y + this.bottomFrozenGroup.attribute.height,
this.rightBottomCornerGroup.attribute.y + this.rightBottomCornerGroup.attribute.height
);

if (actualContentBottom > 0 && actualContentBottom < this.tableGroup.attribute.height) {
this.tableGroup.setAttribute('height', actualContentBottom);
}
}

this.updateTableGroupBorder();

// update dom container size
this.updateDomContainer();
}

updateTableGroupBorder() {
if (!this.tableGroup.border) {
return;
}

const rectAttributes = this.tableGroup.border?.attribute;
let borderTop;
let borderRight;
let borderBottom;
let borderLeft;
if ((rectAttributes as any)?.strokeArrayWidth) {
borderTop = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[0]
: (rectAttributes.lineWidth as number) ?? 0;
borderRight = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[1]
: (rectAttributes.lineWidth as number) ?? 0;
borderBottom = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[2]
: (rectAttributes.lineWidth as number) ?? 0;
borderLeft = (rectAttributes as any).strokeArrayWidth
? (rectAttributes as any).strokeArrayWidth[3]
: (rectAttributes.lineWidth as number) ?? 0;
} else {
borderTop = (rectAttributes?.lineWidth as number) ?? 0;
borderRight = (rectAttributes?.lineWidth as number) ?? 0;
borderBottom = (rectAttributes?.lineWidth as number) ?? 0;
borderLeft = (rectAttributes?.lineWidth as number) ?? 0;
}
if (this.tableGroup.border.type === 'rect') {
if (this.table.theme.frameStyle?.innerBorder) {
this.tableGroup.border.setAttributes({
x: this.table.tableX + borderLeft / 2,
y: this.table.tableY + borderTop / 2,
width: this.tableGroup.attribute.width - borderLeft / 2 - borderRight / 2,
height: this.tableGroup.attribute.height - borderTop / 2 - borderBottom / 2
});
} else {
this.tableGroup.border.setAttributes({
x: this.table.tableX - borderLeft / 2,
y: this.table.tableY - borderTop / 2,
width: this.tableGroup.attribute.width + borderLeft / 2 + borderRight / 2,
height: this.tableGroup.attribute.height + borderTop / 2 + borderBottom / 2
});
}
} else if (this.tableGroup.border.type === 'group') {
if (this.table.theme.frameStyle?.innerBorder) {
this.tableGroup.border.setAttributes({
x: this.table.tableX + borderLeft / 2,
y: this.table.tableY + borderTop / 2,
width: this.tableGroup.attribute.width - borderLeft / 2 - borderRight / 2,
height: this.tableGroup.attribute.height - borderTop / 2 - borderBottom / 2
});
(this.tableGroup.border.firstChild as IRect)?.setAttributes({
x: 0,
y: 0,
width: this.tableGroup.attribute.width - borderLeft / 2 - borderRight / 2,
height: this.tableGroup.attribute.height - borderTop / 2 - borderBottom / 2
});
} else {
this.tableGroup.border.setAttributes({
x: this.table.tableX - borderLeft / 2,
y: this.table.tableY - borderTop / 2,
width: this.tableGroup.attribute.width + borderLeft / 2 + borderRight / 2,
height: this.tableGroup.attribute.height + borderTop / 2 + borderBottom / 2
});
(this.tableGroup.border.firstChild as IRect)?.setAttributes({
x: borderLeft / 2,
y: borderTop / 2,
width: this.tableGroup.attribute.width,
height: this.tableGroup.attribute.height
});
}
}
}

updateRowHeight(row: number, detaY: number, skipTableHeightMap?: boolean) {
detaY = Math.round(detaY);
updateRowHeight(this, row, detaY, skipTableHeightMap);
Expand Down
Loading