Skip to content

Commit

Permalink
Merge pull request #1762 from VisActor/1697-feature-tree-mode-icon-po…
Browse files Browse the repository at this point in the history
…sition

1697 feature tree mode icon position
  • Loading branch information
fangsmile committed May 22, 2024
2 parents 0f98cd3 + 250b762 commit 88e7345
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "feat: tree mode can set icon #1697\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
10 changes: 6 additions & 4 deletions packages/vtable/src/body-helper/body-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export class BodyHelper {
): ColumnIconOption[] {
//加入固定列图标 排序 文本中元素
const iconArr: ColumnIconOption[] = [];

const hierarchyIcon = this.getHierarchyIcon(col, row);
if (hierarchyIcon) {
iconArr.push(hierarchyIcon);
}

const { icon: iconDefine } = this._table.getBodyColumnDefine(col, row);

if (iconDefine) {
Expand Down Expand Up @@ -66,10 +72,6 @@ export class BodyHelper {
addIcon(iconResults);
}
}
const hierarchyIcon = this.getHierarchyIcon(col, row);
if (hierarchyIcon) {
iconArr.push(hierarchyIcon);
}

context &&
iconArr.forEach((i, index) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/vtable/src/scenegraph/layout/compute-col-width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ function computeAutoColWidth(
if ((hd as HeaderData)?.hierarchyLevel) {
cellHierarchyIndent =
((hd as HeaderData).hierarchyLevel ?? 0) * ((layoutMap as PivotHeaderLayoutMap).rowHierarchyIndent ?? 0);
if (
(layoutMap as PivotHeaderLayoutMap).rowHierarchyTextStartAlignment &&
!table.internalProps.headerHelper.getHierarchyIcon(col, row)
) {
cellHierarchyIndent += table.internalProps.headerHelper.getHierarchyIconWidth();
}
}
} else {
deltaRow = prepareDeltaRow;
Expand All @@ -379,6 +385,12 @@ function computeAutoColWidth(
Array.isArray(indexArr) && table.getHierarchyState(col, row) !== HierarchyState.none
? (indexArr.length - 1) * ((layoutMap as SimpleHeaderLayoutMap).hierarchyIndent ?? 0)
: 0;
if (
(layoutMap as SimpleHeaderLayoutMap).hierarchyTextStartAlignment &&
!table.internalProps.bodyHelper.getHierarchyIcon(col, row)
) {
cellHierarchyIndent += table.internalProps.headerHelper.getHierarchyIconWidth();
}
}
}

Expand Down
42 changes: 34 additions & 8 deletions packages/vtable/src/scenegraph/utils/text-icon-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ export function createCellContent(
lineClamp,
wordBreak: 'break-word',
whiteSpace: text.length === 1 && !autoWrapText ? 'no-wrap' : 'normal',
dx:
(textAlign === 'left' ? (!contentLeftIcons.length && !contentRightIcons.length ? hierarchyOffset : 0) : 0) +
_contentOffset
dx: (textAlign === 'left' ? (!contentLeftIcons.length ? hierarchyOffset : 0) : 0) + _contentOffset
};
const wrapText = new Text(cellTheme.text ? (Object.assign({}, cellTheme.text, attribute) as any) : attribute);
wrapText.name = 'text';
Expand Down Expand Up @@ -287,15 +285,33 @@ export function createCellContent(
align: textAlign,
baseline: textBaseline
});

const dealWithIconComputeVar = {
addedHierarchyOffset: 0
}; //为了只增加一次indent的缩进值,如果有两个icon都dealWithIcon的话
contentLeftIcons.forEach(icon => {
const iconMark = dealWithIcon(icon, undefined, cellGroup.col, cellGroup.row, range, table);
const iconMark = dealWithIcon(
icon,
undefined,
cellGroup.col,
cellGroup.row,
range,
table,
dealWithIconComputeVar
);
iconMark.role = 'icon-content-left';
iconMark.name = icon.name;
cellContent.addLeftOccupyingIcon(iconMark);
});
contentRightIcons.forEach(icon => {
const iconMark = dealWithIcon(icon, undefined, cellGroup.col, cellGroup.row, range, table);
const iconMark = dealWithIcon(
icon,
undefined,
cellGroup.col,
cellGroup.row,
range,
table,
dealWithIconComputeVar
);
iconMark.role = 'icon-content-right';
iconMark.name = icon.name;
cellContent.addRightOccupyingIcon(iconMark);
Expand Down Expand Up @@ -377,7 +393,10 @@ export function dealWithIcon(
col?: number,
row?: number,
range?: CellRange,
table?: BaseTableAPI
table?: BaseTableAPI,
dealWithIconComputeVar?: {
addedHierarchyOffset: number;
}
): Icon {
// positionType在外部处理
const iconAttribute = {} as any;
Expand All @@ -403,16 +422,23 @@ export function dealWithIcon(

let hierarchyOffset = 0;
if (
(!dealWithIconComputeVar || dealWithIconComputeVar?.addedHierarchyOffset === 0) &&
isNumber(col) &&
isNumber(row) &&
table &&
(icon.funcType === IconFuncTypeEnum.collapse || icon.funcType === IconFuncTypeEnum.expand)
(icon.funcType === IconFuncTypeEnum.collapse ||
icon.funcType === IconFuncTypeEnum.expand ||
icon.positionType === IconPosition.contentLeft ||
icon.positionType === IconPosition.contentRight)
) {
// compute hierarchy offset
// hierarchyOffset = getHierarchyOffset(col, row, table);
hierarchyOffset = range
? getHierarchyOffset(range.start.col, range.start.row, table)
: getHierarchyOffset(col, row, table);
if (dealWithIconComputeVar) {
dealWithIconComputeVar.addedHierarchyOffset = 1;
}
}

iconAttribute.marginLeft = (icon.marginLeft ?? 0) + hierarchyOffset;
Expand Down

0 comments on commit 88e7345

Please sign in to comment.