Skip to content

Commit

Permalink
fix: fix series resize area (#858)
Browse files Browse the repository at this point in the history
* fix: fix series resize

* refactor: refine code style

* feat: remove resize limit
  • Loading branch information
wjgogogo authored Dec 3, 2021
1 parent 9386688 commit 76407db
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
14 changes: 7 additions & 7 deletions packages/s2-core/src/cell/corner-cell.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IShape, Point, ShapeAttrs } from '@antv/g-canvas';
import { isEmpty, isEqual, last, max } from 'lodash';
import { KEY_SERIES_NUMBER_NODE } from './../common/constant/basic';
import { TextAlign } from './../common/interface/theme';
import { shouldAddResizeArea } from './../utils/interaction/resize';
import { HeaderCell } from './header-cell';
import {
Expand Down Expand Up @@ -143,7 +143,7 @@ export class CornerCell extends HeaderCell {
* 绘制折叠展开的icon
*/
private drawTreeIcon() {
if (!this.showTreeIcon() || this.meta.cornerType !== CornerNodeType.ROW) {
if (!this.showTreeIcon() || this.meta.cornerType === CornerNodeType.Col) {
return;
}
const { hierarchyCollapse } = this.headerConfig;
Expand Down Expand Up @@ -233,15 +233,15 @@ export class CornerCell extends HeaderCell {
const { cornerType, field } = this.meta;
const { rows } = this.headerConfig;
return (
cornerType === CornerNodeType.ROW &&
cornerType === CornerNodeType.Row &&
(this.spreadsheet.isHierarchyTreeType() || last(rows) === field)
);
}

private getResizeAreaEffect() {
const { key } = this.meta;
const { cornerType } = this.meta;

if (key === KEY_SERIES_NUMBER_NODE) {
if (cornerType === CornerNodeType.Series) {
return ResizeAreaEffect.Series;
}

Expand Down Expand Up @@ -349,8 +349,8 @@ export class CornerCell extends HeaderCell {
const cornerTextStyle = this.getStyle().bolderText;
const { cornerType } = this.meta;

const textAlign =
cornerType === CornerNodeType.ROW ? cornerTextStyle.textAlign : 'right';
const textAlign: TextAlign =
cornerType === CornerNodeType.Col ? 'right' : cornerTextStyle.textAlign;

return {
...cornerTextStyle,
Expand Down
3 changes: 2 additions & 1 deletion packages/s2-core/src/common/interface/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 角头 node 类型
export enum CornerNodeType {
ROW = 'row',
Row = 'row',
Col = 'col',
Series = 'series',
}
6 changes: 3 additions & 3 deletions packages/s2-core/src/facet/header/corner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class CornerHeader extends BaseHeader<CornerHeaderConfig> {
// different type different height
sNode.height = colsHierarchy?.sampleNodeForLastLevel?.height;
sNode.isPivotMode = true;
sNode.cornerType = CornerNodeType.ROW;
sNode.cornerType = CornerNodeType.Series;
cornerNodes.push(sNode);
}

Expand All @@ -146,7 +146,7 @@ export class CornerHeader extends BaseHeader<CornerHeaderConfig> {
cNode.seriesNumberWidth = seriesNumberWidth;
cNode.isPivotMode = true;
cNode.spreadsheet = s2;
cNode.cornerType = CornerNodeType.ROW;
cNode.cornerType = CornerNodeType.Row;
cornerNodes.push(cNode);
} else {
// spreadsheet type grid mode
Expand All @@ -164,7 +164,7 @@ export class CornerHeader extends BaseHeader<CornerHeaderConfig> {
cNode.height = colsHierarchy.sampleNodeForLastLevel.height;
cNode.field = field;
cNode.isPivotMode = true;
cNode.cornerType = CornerNodeType.ROW;
cNode.cornerType = CornerNodeType.Row;
cNode.spreadsheet = s2;
cornerNodes.push(cNode);
});
Expand Down
18 changes: 0 additions & 18 deletions packages/s2-core/src/interaction/row-column-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,6 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
});
}

private isResizeMoreThanMaxCornerWidthLimit(offsetX: number) {
const resizeInfo = this.getResizeInfo();

const isResizeFreezeRowHeader =
resizeInfo.effect !== ResizeAreaEffect.Cell &&
this.spreadsheet.isFrozenRowHeader();

const { width: canvasWidth } = this.spreadsheet.options;
const maxCornerWidth = Math.floor(canvasWidth * CORNER_MAX_WIDTH_RATIO);
const isMoreThanMaxRowHeaderWidthLimit = offsetX >= maxCornerWidth;

return isResizeFreezeRowHeader && isMoreThanMaxRowHeaderWidthLimit;
}

private resizeMouseMove = (event: CanvasEvent) => {
if (!this.resizeReferenceGroup?.get('visible')) {
return;
Expand Down Expand Up @@ -359,10 +345,6 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
guideLineStart: ResizeGuideLinePath,
guideLineEnd: ResizeGuideLinePath,
) {
if (this.isResizeMoreThanMaxCornerWidthLimit(originalEvent.offsetX)) {
return;
}

let offsetX = originalEvent.offsetX - this.resizeStartPosition.offsetX;
if (resizeInfo.width + offsetX < MIN_CELL_WIDTH) {
// 禁止拖到最小宽度
Expand Down

0 comments on commit 76407db

Please sign in to comment.