Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复分割线在深色背景下颜色渲染异常 & 内容宽高未包含分割线的问题 #2961

Merged
merged 3 commits into from
Nov 7, 2024
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 @@ -563,13 +563,17 @@ Object {
},
"splitLine": Object {
"borderDash": Array [],
"horizontalBorderColor": "#3471F9",
"horizontalBorderColorOpacity": 0.2,
"horizontalBorderWidth": 2,
"shadowColors": Object {
"left": "rgba(0,0,0,0.1)",
"right": "rgba(0,0,0,0)",
},
"shadowWidth": 8,
"showShadow": true,
"verticalBorderColor": "#5286FA",
"verticalBorderColorOpacity": 0.25,
"verticalBorderWidth": 2,
},
}
Expand Down Expand Up @@ -1138,13 +1142,17 @@ Object {
},
"splitLine": Object {
"borderDash": Array [],
"horizontalBorderColor": "#7899ff",
"horizontalBorderColorOpacity": 0.2,
"horizontalBorderWidth": 2,
"shadowColors": Object {
"left": "rgba(0,0,0,0.1)",
"right": "rgba(0,0,0,0)",
},
"shadowWidth": 8,
"showShadow": true,
"verticalBorderColor": "#7899ff",
"verticalBorderColorOpacity": 0.25,
"verticalBorderWidth": 2,
},
}
Expand Down Expand Up @@ -1713,13 +1721,17 @@ Object {
},
"splitLine": Object {
"borderDash": Array [],
"horizontalBorderColor": "#326EF4",
"horizontalBorderColorOpacity": 0.2,
"horizontalBorderWidth": 2,
"shadowColors": Object {
"left": "rgba(0,0,0,0.1)",
"right": "rgba(0,0,0,0)",
},
"shadowWidth": 8,
"showShadow": true,
"verticalBorderColor": "#326EF4",
"verticalBorderColorOpacity": 0.25,
"verticalBorderWidth": 2,
},
}
Expand Down Expand Up @@ -2288,13 +2300,17 @@ Object {
},
"splitLine": Object {
"borderDash": Array [],
"horizontalBorderColor": "#BAC1CC",
"horizontalBorderColorOpacity": 0.2,
"horizontalBorderWidth": 2,
"shadowColors": Object {
"left": "rgba(0,0,0,0.1)",
"right": "rgba(0,0,0,0)",
},
"shadowWidth": 8,
"showShadow": true,
"verticalBorderColor": "#BAC1CC",
"verticalBorderColorOpacity": 0.25,
"verticalBorderWidth": 2,
},
}
Expand Down Expand Up @@ -2863,13 +2879,17 @@ Object {
},
"splitLine": Object {
"borderDash": Array [],
"horizontalBorderColor": "#326EF4",
"horizontalBorderColorOpacity": 0.2,
"horizontalBorderWidth": 2,
"shadowColors": Object {
"left": "rgba(0,0,0,0.1)",
"right": "rgba(0,0,0,0)",
},
"shadowWidth": 8,
"showShadow": true,
"verticalBorderColor": "#326EF4",
"verticalBorderColorOpacity": 0.25,
"verticalBorderWidth": 2,
},
}
Expand Down Expand Up @@ -3438,13 +3458,17 @@ Object {
},
"splitLine": Object {
"borderDash": Array [],
"horizontalBorderColor": "#326EF4",
"horizontalBorderColorOpacity": 0.2,
"horizontalBorderWidth": 2,
"shadowColors": Object {
"left": "rgba(0,0,0,0.1)",
"right": "rgba(0,0,0,0)",
},
"shadowWidth": 8,
"showShadow": true,
"verticalBorderColor": "#326EF4",
"verticalBorderColorOpacity": 0.25,
"verticalBorderWidth": 2,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,11 @@ describe('PivotSheet Tests', () => {
});

test('should get content height', () => {
expect(s2.facet.getContentHeight()).toEqual(120);
expect(s2.facet.getContentHeight()).toEqual(122);
});

test('should get content width', () => {
expect(s2.facet.getContentWidth()).toEqual(384);
expect(s2.facet.getContentWidth()).toEqual(386);
});

test('should get layout width type', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('TableSheet Tests', () => {
});

test('should get content height', () => {
expect(s2.facet.getContentHeight()).toEqual(120);
expect(s2.facet.getContentHeight()).toEqual(122);
});

test('should get content width', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/common/interface/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export interface SplitLine {
/** 线性变化右侧颜色 */
right: string;
};

/** 分割线虚线 */
borderDash?: LineStyleProps['lineDash'];
}
Expand Down
1 change: 0 additions & 1 deletion packages/s2-core/src/facet/bbox/panel-bbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class PanelBBox extends BaseBBox {
this.x = cornerPosition.x + Frame.getVerticalBorderWidth(this.spreadsheet);
this.y =
cornerPosition.y + Frame.getHorizontalBorderWidth(this.spreadsheet);

this.minX = this.x;
this.minY = this.y;

Expand Down
79 changes: 51 additions & 28 deletions packages/s2-core/src/facet/header/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,50 +90,73 @@ export class Frame extends Group {
private addCornerRightBorder() {
const { cornerWidth, cornerHeight, viewportHeight, position, spreadsheet } =
this.cfg;
const {
verticalBorderColor,
verticalBorderColorOpacity,
horizontalBorderWidth,
} = spreadsheet.theme?.splitLine!;

const { verticalBorderColor, verticalBorderColorOpacity } =
spreadsheet.theme?.splitLine!;
const frameVerticalWidth = Frame.getVerticalBorderWidth(spreadsheet);
const frameHorizontalWidth = Frame.getHorizontalBorderWidth(spreadsheet);
const x = position.x + cornerWidth + frameVerticalWidth! / 2;

// 表头和表身的单元格背景色不同, 分割线不能一条线拉通, 不然视觉不协调.
// 分两条线绘制, 默认和分割线所在区域对应的单元格边框颜色保持一致
const {
verticalBorderColor: headerVerticalBorderColor,
verticalBorderColorOpacity: headerVerticalBorderColorOpacity,
} =
spreadsheet.options.seriesNumber?.enable || spreadsheet.isPivotMode()
? spreadsheet.theme.cornerCell!.cell!
: spreadsheet.theme.colCell!.cell!;
backgroundColor,
backgroundColorOpacity,
} = spreadsheet.options.seriesNumber?.enable || spreadsheet.isPivotMode()
? spreadsheet.theme.cornerCell!.cell!
: spreadsheet.theme.colCell!.cell!;

renderLine(this, {
x1: x,
y1: position.y,
x2: x,
y2: position.y + cornerHeight,
stroke: verticalBorderColor || headerVerticalBorderColor,
lineWidth: frameVerticalWidth,
strokeOpacity:
verticalBorderColorOpacity || headerVerticalBorderColorOpacity,
/**
* G 6.0 颜色混合模式有调整, 相同颜色的 Line 在不同背景色绘制, 实际渲染的颜色会不一致
* 在绘制分割线前, 先填充一个和单元格相同的底色, 保证分割线和单元格边框表现一致
*/
[
{ stroke: backgroundColor, strokeOpacity: backgroundColorOpacity },
{
stroke: verticalBorderColor || headerVerticalBorderColor,
strokeOpacity:
verticalBorderColorOpacity || headerVerticalBorderColorOpacity,
},
].forEach(({ stroke, strokeOpacity }) => {
renderLine(this, {
x1: x,
y1: position.y,
x2: x,
y2: position.y + cornerHeight,
lineWidth: frameVerticalWidth,
stroke,
strokeOpacity,
});
});

const {
verticalBorderColor: cellVerticalBorderColor,
verticalBorderColorOpacity: cellVerticalBorderColorOpacity,
backgroundColor: cellBackgroundColor,
backgroundColorOpacity: cellBackgroundColorOpacity,
} = spreadsheet.theme.dataCell!.cell!;

renderLine(this, {
x1: x,
y1: position.y + cornerHeight + horizontalBorderWidth!,
x2: x,
y2: position.y + cornerHeight + horizontalBorderWidth! + viewportHeight,
stroke: verticalBorderColor || cellVerticalBorderColor,
lineWidth: frameVerticalWidth,
strokeOpacity:
verticalBorderColorOpacity || cellVerticalBorderColorOpacity,
[
{
stroke: cellBackgroundColor,
strokeOpacity: cellBackgroundColorOpacity,
},
{
stroke: verticalBorderColor || cellVerticalBorderColor,
strokeOpacity:
verticalBorderColorOpacity || cellVerticalBorderColorOpacity,
},
].forEach(({ stroke, strokeOpacity }) => {
renderLine(this, {
x1: x,
y1: position.y + cornerHeight + frameHorizontalWidth!,
x2: x,
y2: position.y + cornerHeight + frameHorizontalWidth! + viewportHeight,
lineWidth: frameVerticalWidth,
stroke,
strokeOpacity,
});
});
}

Expand Down
12 changes: 10 additions & 2 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,12 +1048,20 @@ export class PivotFacet extends FrozenFacet {
public getContentWidth(): number {
const { rowsHierarchy, colsHierarchy } = this.layoutResult;

return rowsHierarchy.width + colsHierarchy.width;
return (
rowsHierarchy.width +
colsHierarchy.width +
Frame.getVerticalBorderWidth(this.spreadsheet)
);
}

public getContentHeight(): number {
const { rowsHierarchy, colsHierarchy } = this.layoutResult;

return rowsHierarchy.height + colsHierarchy.height;
return (
rowsHierarchy.height +
colsHierarchy.height +
Frame.getHorizontalBorderWidth(this.spreadsheet)
);
}
}
6 changes: 5 additions & 1 deletion packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ export class TableFacet extends FrozenFacet {
const { getTotalHeight } = this.getViewCellHeights();
const { colsHierarchy } = this.layoutResult;

return getTotalHeight() + colsHierarchy.height;
return (
getTotalHeight() +
colsHierarchy.height +
Frame.getHorizontalBorderWidth(this.spreadsheet)
);
}
}
4 changes: 4 additions & 0 deletions packages/s2-core/src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,11 @@ export const getTheme = (
},
// ------------- split line -----------------
splitLine: {
horizontalBorderColor: basicColors[12],
horizontalBorderColorOpacity: 0.2,
horizontalBorderWidth: 2,
verticalBorderColor: basicColors[11],
verticalBorderColorOpacity: 0.25,
verticalBorderWidth: 2,
showShadow: true,
shadowWidth: 8,
Expand Down
Loading
Loading