Skip to content

Commit

Permalink
refactor: remove Circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
fangsmile committed Feb 26, 2024
1 parent e40f0c0 commit 92a8837
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 124 deletions.
57 changes: 0 additions & 57 deletions packages/vtable/src/scenegraph/component/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import type {
import { Icon } from '../graphic/icon';
import type { BaseTableAPI } from '../../ts-types/base-table';
import type { percentCalcObj } from '../../render/layout';
import { ProgressBarStyle } from '../../body-helper/style/ProgressBarStyle';
import { getQuadProps } from '../utils/padding';
import { getProp } from '../utils/get-prop';
import type { Group } from '../graphic/group';
import { resizeCellGroup } from '../group-creater/column-helper';

export function dealWithCustom(
customLayout: ICustomLayout,
Expand Down Expand Up @@ -467,55 +462,3 @@ function parseToGraphic(g: any, props: any) {
// }
}
}

export function getCustomCellMergeCustom(col: number, row: number, cellGroup: Group, table: BaseTableAPI) {
if (table.internalProps.customMergeCell) {
const customMerge = table.getCustomMerge(col, row);
if (customMerge) {
const {
range: customMergeRange,
text: customMergeText,
style: customMergeStyle,
customLayout: customMergeLayout,
customRender: customMergeRender
} = customMerge;

if (customMergeLayout || customMergeRender) {
const customResult = dealWithCustom(
customMergeLayout,
customMergeRender,
customMergeRange.start.col,
customMergeRange.start.row,
table.getColsWidth(customMergeRange.start.col, customMergeRange.end.col),
table.getRowsHeight(customMergeRange.start.row, customMergeRange.end.row),
false,
table.heightMode === 'autoHeight',
[0, 0, 0, 0],
table
);

const customElementsGroup = customResult.elementsGroup;

if (cellGroup.childrenCount > 0 && customElementsGroup) {
cellGroup.insertBefore(customElementsGroup, cellGroup.firstChild);
} else if (customElementsGroup) {
cellGroup.appendChild(customElementsGroup);
}

const rangeHeight = table.getRowHeight(row);
const rangeWidth = table.getColWidth(col);

const { width: contentWidth } = cellGroup.attribute;
const { height: contentHeight } = cellGroup.attribute;
cellGroup.contentWidth = contentWidth;
cellGroup.contentHeight = contentHeight;

resizeCellGroup(cellGroup, rangeWidth, rangeHeight, customMergeRange, table);

return customResult;
}
}
}

return undefined;
}
111 changes: 108 additions & 3 deletions packages/vtable/src/scenegraph/group-creater/cell-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
CheckboxColumnDefine,
ColumnDefine,
ColumnTypeOption,
ICustomRender,
ImageColumnDefine,
MappingRule,
ProgressbarColumnDefine,
Expand All @@ -22,7 +21,6 @@ import { createProgressBarCell } from './cell-type/progress-bar-cell';
import { createSparkLineCellGroup } from './cell-type/spark-line-cell';
import { createCellGroup } from './cell-type/text-cell';
import { createVideoCellGroup } from './cell-type/video-cell';
import type { ICustomLayoutFuc } from '../../ts-types/customLayout';
import type { BaseTableAPI, PivotTableProtected } from '../../ts-types/base-table';
import { getCellCornerRadius, getStyleTheme } from '../../core/tableHelper';
import { isPromise } from '../../tools/helper';
Expand All @@ -31,11 +29,11 @@ import { CartesianAxis } from '../../components/axis/axis';
import { createCheckboxCellGroup } from './cell-type/checkbox-cell';
// import type { PivotLayoutMap } from '../../layout/pivot-layout';
import type { PivotHeaderLayoutMap } from '../../layout/pivot-header-layout';
import { resizeCellGroup } from './column-helper';
import { getHierarchyOffset } from '../utils/get-hierarchy-offset';
import { getQuadProps } from '../utils/padding';
import { convertInternal } from '../../tools/util';
import { updateCellContentHeight, updateCellContentWidth } from '../utils/text-icon-layout';
import { isArray } from '@visactor/vutils';

export function createCell(
type: ColumnTypeOption,
Expand Down Expand Up @@ -747,3 +745,110 @@ function dealWithMergeCellSize(
}
}
}

export function resizeCellGroup(
cellGroup: Group,
rangeWidth: number,
rangeHeight: number,
range: CellRange,
table: BaseTableAPI
) {
const { col, row } = cellGroup;
const dx = -table.getColsWidth(range.start.col, col - 1);
const dy = -table.getRowsHeight(range.start.row, row - 1);

cellGroup.forEachChildren((child: IGraphic) => {
child.setAttributes({
dx: (child.attribute.dx ?? 0) + dx,
dy: (child.attribute.dy ?? 0) + dy
});
});

const lineWidth = cellGroup.attribute.lineWidth;
const isLineWidthArray = isArray(lineWidth);
const newLineWidth = [0, 0, 0, 0];

if (col === range.start.col) {
newLineWidth[3] = isLineWidthArray ? lineWidth[3] : lineWidth;
}
if (row === range.start.row) {
newLineWidth[0] = isLineWidthArray ? lineWidth[0] : lineWidth;
}
if (col === range.end.col) {
newLineWidth[1] = isLineWidthArray ? lineWidth[1] : lineWidth;
}
if (row === range.end.row) {
newLineWidth[2] = isLineWidthArray ? lineWidth[2] : lineWidth;
}

const widthChange = rangeWidth !== cellGroup.attribute.width;
const heightChange = rangeHeight !== cellGroup.attribute.height;

cellGroup.setAttributes({
width: rangeWidth,
height: rangeHeight,
strokeArrayWidth: newLineWidth
} as any);

cellGroup.mergeStartCol = range.start.col;
cellGroup.mergeStartRow = range.start.row;
cellGroup.mergeEndCol = range.end.col;
cellGroup.mergeEndRow = range.end.row;

return {
widthChange,
heightChange
};
}

export function getCustomCellMergeCustom(col: number, row: number, cellGroup: Group, table: BaseTableAPI) {
if (table.internalProps.customMergeCell) {
const customMerge = table.getCustomMerge(col, row);
if (customMerge) {
const {
range: customMergeRange,
text: customMergeText,
style: customMergeStyle,
customLayout: customMergeLayout,
customRender: customMergeRender
} = customMerge;

if (customMergeLayout || customMergeRender) {
const customResult = dealWithCustom(
customMergeLayout,
customMergeRender,
customMergeRange.start.col,
customMergeRange.start.row,
table.getColsWidth(customMergeRange.start.col, customMergeRange.end.col),
table.getRowsHeight(customMergeRange.start.row, customMergeRange.end.row),
false,
table.heightMode === 'autoHeight',
[0, 0, 0, 0],
table
);

const customElementsGroup = customResult.elementsGroup;

if (cellGroup.childrenCount > 0 && customElementsGroup) {
cellGroup.insertBefore(customElementsGroup, cellGroup.firstChild);
} else if (customElementsGroup) {
cellGroup.appendChild(customElementsGroup);
}

const rangeHeight = table.getRowHeight(row);
const rangeWidth = table.getColWidth(col);

const { width: contentWidth } = cellGroup.attribute;
const { height: contentHeight } = cellGroup.attribute;
cellGroup.contentWidth = contentWidth;
cellGroup.contentHeight = contentHeight;

resizeCellGroup(cellGroup, rangeWidth, rangeHeight, customMergeRange, table);

return customResult;
}
}
}

return undefined;
}
60 changes: 2 additions & 58 deletions packages/vtable/src/scenegraph/group-creater/column-helper.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* eslint-disable no-undef */
import type { IGraphic, IThemeSpec } from '@src/vrender';
import type { IThemeSpec } from '@src/vrender';
import type { CellLocation, CellRange, TextColumnDefine } from '../../ts-types';
import type { Group } from '../graphic/group';
import { getProp, getRawProp } from '../utils/get-prop';
import type { MergeMap } from '../scenegraph';
import { createCell } from './cell-helper';
import { createCell, resizeCellGroup } from './cell-helper';
import type { BaseTableAPI } from '../../ts-types/base-table';
import { getCellCornerRadius, getStyleTheme } from '../../core/tableHelper';
import { isPromise } from '../../tools/helper';
import { dealPromiseData } from '../utils/deal-promise-data';
import { isArray } from '@visactor/vutils';
import { dealWithCustom } from '../component/custom';
/**
* 创建复合列 同一列支持创建不同类型单元格
Expand Down Expand Up @@ -270,61 +269,6 @@ export function getColumnGroupTheme(
return { theme: columnTheme, hasFunctionPros };
}

export function resizeCellGroup(
cellGroup: Group,
rangeWidth: number,
rangeHeight: number,
range: CellRange,
table: BaseTableAPI
) {
const { col, row } = cellGroup;
const dx = -table.getColsWidth(range.start.col, col - 1);
const dy = -table.getRowsHeight(range.start.row, row - 1);

cellGroup.forEachChildren((child: IGraphic) => {
child.setAttributes({
dx: (child.attribute.dx ?? 0) + dx,
dy: (child.attribute.dy ?? 0) + dy
});
});

const lineWidth = cellGroup.attribute.lineWidth;
const isLineWidthArray = isArray(lineWidth);
const newLineWidth = [0, 0, 0, 0];

if (col === range.start.col) {
newLineWidth[3] = isLineWidthArray ? lineWidth[3] : lineWidth;
}
if (row === range.start.row) {
newLineWidth[0] = isLineWidthArray ? lineWidth[0] : lineWidth;
}
if (col === range.end.col) {
newLineWidth[1] = isLineWidthArray ? lineWidth[1] : lineWidth;
}
if (row === range.end.row) {
newLineWidth[2] = isLineWidthArray ? lineWidth[2] : lineWidth;
}

const widthChange = rangeWidth !== cellGroup.attribute.width;
const heightChange = rangeHeight !== cellGroup.attribute.height;

cellGroup.setAttributes({
width: rangeWidth,
height: rangeHeight,
strokeArrayWidth: newLineWidth
} as any);

cellGroup.mergeStartCol = range.start.col;
cellGroup.mergeStartRow = range.start.row;
cellGroup.mergeEndCol = range.end.col;
cellGroup.mergeEndRow = range.end.row;

return {
widthChange,
heightChange
};
}

function dealMerge(range: CellRange, mergeMap: MergeMap, table: BaseTableAPI, forceUpdate: boolean) {
let cellWidth = 0;
let cellHeight = 0;
Expand Down
4 changes: 2 additions & 2 deletions packages/vtable/src/scenegraph/layout/update-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { getProp } from '../utils/get-prop';
import { getQuadProps } from '../utils/padding';
import { updateCellContentHeight } from '../utils/text-icon-layout';
import type { IProgressbarColumnBodyDefine } from '../../ts-types/list-table/define/progressbar-define';
import { dealWithCustom, getCustomCellMergeCustom } from '../component/custom';
import { dealWithCustom } from '../component/custom';
import { updateImageCellContentWhileResize } from '../group-creater/cell-type/image-cell';
import { getStyleTheme } from '../../core/tableHelper';
import { isMergeCellGroup } from '../utils/is-merge-cell-group';
import type { BaseTableAPI } from '../../ts-types/base-table';
import { resizeCellGroup } from '../group-creater/column-helper';
import { resizeCellGroup, getCustomCellMergeCustom } from '../group-creater/cell-helper';
import type { IGraphic } from '@src/vrender';
import { getCellMergeRange } from '../../tools/merge-range';

Expand Down
7 changes: 3 additions & 4 deletions packages/vtable/src/scenegraph/layout/update-width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import { CartesianAxis } from '../../components/axis/axis';
import { getStyleTheme } from '../../core/tableHelper';
import type { BaseTableAPI } from '../../ts-types/base-table';
import type { IProgressbarColumnBodyDefine } from '../../ts-types/list-table/define/progressbar-define';
import { dealWithCustom, getCustomCellMergeCustom } from '../component/custom';
import { dealWithCustom } from '../component/custom';
import type { Group } from '../graphic/group';
import type { Icon } from '../graphic/icon';
import { updateImageCellContentWhileResize } from '../group-creater/cell-type/image-cell';
import { createProgressBarCell } from '../group-creater/cell-type/progress-bar-cell';
import { createSparkLineCellGroup } from '../group-creater/cell-type/spark-line-cell';
import { resizeCellGroup } from '../group-creater/column-helper';
import { resizeCellGroup, getCustomCellMergeCustom } from '../group-creater/cell-helper';
import type { Scenegraph } from '../scenegraph';
import { getCellMergeInfo } from '../utils/get-cell-merge';
import { getProp } from '../utils/get-prop';
import { isMergeCellGroup } from '../utils/is-merge-cell-group';
import { getQuadProps } from '../utils/padding';
import { updateCellContentWidth } from '../utils/text-icon-layout';
import { computeRowHeight, computeRowsHeight } from './compute-row-height';
import { computeRowHeight } from './compute-row-height';
import { updateCellHeightForRow } from './update-height';
import { getHierarchyOffset } from '../utils/get-hierarchy-offset';
import { getCellMergeRange } from '../../tools/merge-range';
Expand Down

0 comments on commit 92a8837

Please sign in to comment.