Skip to content

Commit

Permalink
Merge branch 'v0.0.1' into v0.0.1-normalizing
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/s2-core/src/components/index.tsx
  • Loading branch information
brucetoo committed Apr 23, 2021
2 parents 355c682 + e03996c commit 7087ec2
Show file tree
Hide file tree
Showing 18 changed files with 575 additions and 506 deletions.
7 changes: 0 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
},
"parser": "@typescript-eslint/parser",
"plugins": ["prettier", "@typescript-eslint", "import"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"project": "./tsconfig.json",
"sourceType": "module"
},
"settings": {
"jest": {
"version": 26
Expand Down
3 changes: 3 additions & 0 deletions packages/s2-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
"transform": {
"\\.(less|css)$": "jest-less-loader",
"\\.svg$": "jest-raw-loader"
},
"moduleNameMapper": {
"^src/(.*)": "<rootDir>/src/$1"
}
}
}
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/corner-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CornerCell extends BaseCell<Node> {
return;
}
const extraPadding = this.spreadsheet.isHierarchyTreeType()
? ICON_RADIUS * 2 + DEFAULT_PADDING * 2
? ICON_RADIUS * 2 + DEFAULT_PADDING
: 0;
const textStyle = _.get(
this.headerConfig,
Expand Down
3 changes: 2 additions & 1 deletion packages/s2-core/src/cell/data-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
renderText,
updateShapeAttr,
} from '../utils/g-renders';
import { getDerivedDataState } from '../utils/text';
import { isSelected } from '../utils/selected';
import { VALUE_FIELD } from '../common/constant';
import { ViewMeta } from '../common/interface';
Expand Down Expand Up @@ -354,7 +355,7 @@ export class Cell extends BaseCell<ViewMeta> {
} else {
value = _.get(data, [0, derivedValue]);
}
const up = _.isNumber(value) ? value >= 0 : false;
const up = getDerivedDataState(value);
const formatter = this.spreadsheet.dataSet.getFieldFormatter(
derivedValue,
);
Expand Down
51 changes: 28 additions & 23 deletions packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { Node } from '../index';
import { BaseCell } from './base-cell';
import { FONT_SIZE } from '../theme/default';

const ICON_SIZE = ICON_RADIUS * 2;

export class RowCell extends BaseCell<Node> {
protected headerConfig: RowHeaderConfig;

Expand Down Expand Up @@ -60,9 +62,7 @@ export class RowCell extends BaseCell<Node> {

public destroy(): void {
super.destroy();
if (this.gm) {
this.gm.destroy();
}
this.gm?.destroy();
}

protected handleRestOptions(...options) {
Expand Down Expand Up @@ -133,14 +133,14 @@ export class RowCell extends BaseCell<Node> {
) {
const { x, y, height, width } = this.meta;
for (let i = 0; i < iconTypes.length; i++) {
const iconSize = ICON_RADIUS * 2;
const iconRight = (iconSize + DEFAULT_PADDING) * (iconTypes.length - i);
const iconRight =
(FONT_SIZE + DEFAULT_PADDING) * (iconTypes.length - i);
const icon = new GuiIcon({
type: iconTypes[i],
x: x + width - iconRight,
y: y + (height - iconSize) / 2,
width: iconSize,
height: iconSize,
y: y + (height - FONT_SIZE) / 2,
width: FONT_SIZE,
height: FONT_SIZE,
});
icon.set('visible', false);
icon.on('click', (e: Event) => {
Expand Down Expand Up @@ -206,6 +206,7 @@ export class RowCell extends BaseCell<Node> {
isLeaf,
isTotals,
isCustom,
level,
} = this.meta;
let content = this.getFormattedValue(label);
// grid & is totals content is empty
Expand All @@ -216,23 +217,23 @@ export class RowCell extends BaseCell<Node> {
// indent in tree
const textIndent = this.getTextIndent();
const textStyle = this.getRowTextStyle(isTotals || isCustom, isLeaf);
const padding = DEFAULT_PADDING * level + DEFAULT_PADDING;
const maxWidth =
cellWidth -
textIndent -
DEFAULT_PADDING * 2 -
(this.isTreeType() ? ICON_RADIUS * 2 : 0);
cellWidth - textIndent - padding - (this.isTreeType() ? ICON_SIZE : 0);
const text = getEllipsisText(content, maxWidth, textStyle);
const textY = getAdjustPosition(y, cellHeight, offset, height, FONT_SIZE);
const textY =
getAdjustPosition(y, cellHeight, offset, height, FONT_SIZE) +
FONT_SIZE / 2;
const textXPadding = this.isTreeType() ? padding : cellWidth / 2;
const leafExtraPadding =
isLeaf || isTotals ? ICON_SIZE + DEFAULT_PADDING : 0;
const textX = x + textIndent + textXPadding - leafExtraPadding;

const textX =
x +
textIndent +
(this.isTreeType() ? DEFAULT_PADDING * 2 : cellWidth / 2);
const textAlign = this.isTreeType() ? 'start' : 'center';
const textShape = this.addShape('text', {
attrs: {
x: textX,
y: textY + FONT_SIZE / 2,
y: textY,
textAlign,
text,
...textStyle,
Expand Down Expand Up @@ -284,16 +285,20 @@ export class RowCell extends BaseCell<Node> {
isCollapsed,
id,
hierarchy,
level,
} = this.meta;
const textIndent = this.getTextIndent();
const textY = getAdjustPosition(y, cellHeight, offset, height, FONT_SIZE);
const iconSize = ICON_RADIUS * 2;
const padding = DEFAULT_PADDING * level;
const baseIconX = x + textIndent - ICON_SIZE;
const iconX = level >= 1 ? baseIconX + padding : baseIconX;
const iconY = textY + (FONT_SIZE - ICON_SIZE) / 2;
const icon = new GuiIcon({
type: isCollapsed ? 'plus' : 'MinusSquare',
x: x + textIndent - iconSize,
y: textY + (FONT_SIZE - iconSize) / 2,
width: iconSize,
height: iconSize,
x: iconX,
y: iconY,
width: ICON_SIZE,
height: ICON_SIZE,
});
icon.on('click', () => {
// 折叠行头时因scrollY没变,导致底层出现空白
Expand Down
16 changes: 12 additions & 4 deletions packages/s2-core/src/components/export/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const Export: React.FC<ExportProps> = ({
downloadOringinalText = '下载原始数据',
downloadFormatText = '下载格式化数据',
successText = '操作成功',
errorText = '操作失败',
sheet,
fileName = 'sheet',
...restProps
Expand All @@ -46,14 +47,21 @@ export const Export: React.FC<ExportProps> = ({

const exportData = (isFormat: boolean) => {
const data = copyData(sheet, '\t', isFormat);
copyToClipboard(data);
message.success(successText);
if (copyToClipboard(data)) {
message.success(successText);
} else {
message.error(errorText);
}
};

const downLoadData = (isFormat: boolean) => {
const data = copyData(sheet, ',', isFormat);
download(data, fileName);
message.success(successText);
try {
download(data, fileName);
message.success(successText);
} catch (err) {
message.error(errorText);
}
};

const menu = (
Expand Down
Loading

0 comments on commit 7087ec2

Please sign in to comment.