Skip to content

Commit

Permalink
fix: 🐛 fix the min dragging width for the adaptive mode (#110)
Browse files Browse the repository at this point in the history
* fix: 🐛 fix the min dragging width for the adaptive mode

* refactor: ♻️ add the function to get the min cell width
  • Loading branch information
xingwanying authored Aug 2, 2021
1 parent 61c517f commit c854bc8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/s2-core/src/common/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ interface StoreKey {
drillDownDataCache: DrillDownDataCache[];
// 每个层级下钻的维度缓存
drillDownFieldInLevel: DrillDownFieldInLevel[];
[key: string]: any;
// 列宽等分模式下初始化计算的列宽
adaptiveColWidth: number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export default function processDefaultColWidthByType(
// if (!facet.spreadsheet.isValueInCols()) {
// cellCfg.width = WidthType.ValueInRow;
// }
facet.spreadsheet.store.set('adaptiveColWidth', colWidth);

return colWidth;
}
24 changes: 21 additions & 3 deletions packages/s2-core/src/interaction/row-col-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,28 @@ export class RowColResize extends BaseInteraction {
});
}

// 获取列拖拽的最小宽度
private getMinCellWidth = () => {
let adaptiveColWidth: number;
// 列等宽平铺模式下,需要限定拖拽最小宽度为等宽值
if (
this.spreadsheet.isColAdaptive() &&
!this.spreadsheet.isHierarchyTreeType()
) {
adaptiveColWidth = this.spreadsheet.store.get(
'adaptiveColWidth',
) as number;
}
const cellWidth = adaptiveColWidth || MIN_CELL_WIDTH;
return cellWidth;
};

private resizeMouseMove = (ev: any) => {
// is dragging
if (this.resizeGroup && this.resizeGroup.get('visible')) {
ev.preventDefault();

const minCellWidth = this.getMinCellWidth();
const info = this.getResizeInfo();
const children = this.resizeGroup.get('children');
if (children) {
Expand All @@ -218,10 +236,10 @@ export class RowColResize extends BaseInteraction {
if (info.type === 'col') {
// 横向移动
let offset = ev.originalEvent.offsetX - this.startPos.offsetX;
if (start[1] + offset - info.offsetX < MIN_CELL_WIDTH) {
if (start[1] + offset - info.offsetX < minCellWidth) {
// 禁止拖到最小宽度
this.startPos.offsetX = info.offsetX + MIN_CELL_WIDTH;
offset = info.offsetX + MIN_CELL_WIDTH - start[1];
this.startPos.offsetX = info.offsetX + minCellWidth;
offset = info.offsetX + minCellWidth - start[1];
} else {
this.startPos.offsetX = ev.originalEvent.offsetX;
}
Expand Down

0 comments on commit c854bc8

Please sign in to comment.