diff --git a/common/changes/@visactor/vtable/fix-no-round-size_2024-07-09-03-15.json b/common/changes/@visactor/vtable/fix-no-round-size_2024-07-09-03-15.json new file mode 100644 index 000000000..182a81a93 --- /dev/null +++ b/common/changes/@visactor/vtable/fix-no-round-size_2024-07-09-03-15.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vtable", + "comment": "fix: add tolerance for scroll in _disableColumnAndRowSizeRound mode", + "type": "none" + } + ], + "packageName": "@visactor/vtable" +} \ No newline at end of file diff --git a/packages/vtable/src/scenegraph/component/table-component.ts b/packages/vtable/src/scenegraph/component/table-component.ts index 136df282f..dcf46f92b 100644 --- a/packages/vtable/src/scenegraph/component/table-component.ts +++ b/packages/vtable/src/scenegraph/component/table-component.ts @@ -344,7 +344,13 @@ export class TableComponent { const frozenColsWidth = this.table.getFrozenColsWidth(); const bottomFrozenRowsHeight = this.table.getBottomFrozenRowsHeight(); const rightFrozenColsWidth = this.table.getRightFrozenColsWidth(); - if (totalWidth > tableWidth) { + + // _disableColumnAndRowSizeRound环境中,可能出现 + // getAllColsWidth/getAllRowsHeight(A) + getAllColsWidth/getAllRowsHeight(B) < getAllColsWidth/getAllRowsHeight(A+B) + // (由于小数在取数时被省略) + // 这里加入tolerance,避免出现无用滚动 + const sizeTolerance = this.table.options.customConfig?._disableColumnAndRowSizeRound ? 1 : 0; + if (totalWidth > tableWidth + sizeTolerance) { const y = Math.min(tableHeight, totalHeight); const rangeEnd = Math.max(0.05, (tableWidth - frozenColsWidth) / (totalWidth - frozenColsWidth)); @@ -384,7 +390,7 @@ export class TableComponent { }); } - if (totalHeight > tableHeight) { + if (totalHeight > tableHeight + sizeTolerance) { const x = Math.min(tableWidth, totalWidth); const rangeEnd = Math.max(0.05, (tableHeight - frozenRowsHeight) / (totalHeight - frozenRowsHeight)); diff --git a/packages/vtable/src/state/state.ts b/packages/vtable/src/state/state.ts index 52fa80bd6..3562e0ba4 100644 --- a/packages/vtable/src/state/state.ts +++ b/packages/vtable/src/state/state.ts @@ -903,7 +903,12 @@ export class StateManager { setScrollTop(top: number) { // 矫正top值范围 const totalHeight = this.table.getAllRowsHeight(); - top = Math.max(0, Math.min(top, totalHeight - this.table.scenegraph.height)); + // _disableColumnAndRowSizeRound环境中,可能出现 + // getAllColsWidth/getAllRowsHeight(A) + getAllColsWidth/getAllRowsHeight(B) < getAllColsWidth/getAllRowsHeight(A+B) + // (由于小数在取数时被省略) + // 这里加入tolerance,避免出现无用滚动 + const sizeTolerance = this.table.options.customConfig?._disableColumnAndRowSizeRound ? 1 : 0; + top = Math.max(0, Math.min(top, totalHeight - this.table.scenegraph.height - sizeTolerance)); top = Math.ceil(top); // 滚动期间清空选中清空 如果调用接口hover状态需要保留,但是如果不调用updateHoverPos透视图处于hover状态的图就不能及时更新 所以这里单独判断了isPivotChart if (top !== this.scroll.verticalBarPos || this.table.isPivotChart()) { @@ -943,7 +948,13 @@ export class StateManager { const totalWidth = this.table.getAllColsWidth(); const frozenWidth = this.table.getFrozenColsWidth(); - left = Math.max(0, Math.min(left, totalWidth - this.table.scenegraph.width)); + // _disableColumnAndRowSizeRound环境中,可能出现 + // getAllColsWidth/getAllRowsHeight(A) + getAllColsWidth/getAllRowsHeight(B) < getAllColsWidth/getAllRowsHeight(A+B) + // (由于小数在取数时被省略) + // 这里加入tolerance,避免出现无用滚动 + const sizeTolerance = this.table.options.customConfig?._disableColumnAndRowSizeRound ? 1 : 0; + + left = Math.max(0, Math.min(left, totalWidth - this.table.scenegraph.width - sizeTolerance)); left = Math.ceil(left); // 滚动期间清空选中清空 if (left !== this.scroll.horizontalBarPos) {