-
Notifications
You must be signed in to change notification settings - Fork 199
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
feat: 新增treeLineShow配置和usePolyline,给树形表头扩展配置线性功能(优化版) #3022
Open
gb853940223
wants to merge
6
commits into
antvis:next
Choose a base branch
from
gb853940223:tree-line-v2
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4873ede
feat: 新增treeLineShow配置和usePolyline,给树形表头扩展配置线性功能
gongbei-wps a8363ee
Merge branch 'next' into tree-line
lijinke666 d4bac48
Merge branch 'next' of https://github.com/gb853940223/S2 into tree-line
gongbei-wps 812823b
feat: 新增treeLineShow配置和usePolyline,给树形表头扩展配置线性功能(优化版)
gongbei-wps 82c81ef
Merge branch 'tree-line' of https://github.com/gb853940223/S2 into tr…
gongbei-wps 9aa3ba0
Merge branch 'antvis:next' into tree-line
gb853940223 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import type { S2DataConfig, S2Options } from '@/common'; | ||
import { get } from 'lodash'; | ||
import { CustomTreeData, customTreeFields } from 'tests/data/data-custom-tree'; | ||
import * as mockDataConfig from 'tests/data/simple-data.json'; | ||
import { createPivotSheet, getContainer } from 'tests/util/helpers'; | ||
import { CornerNodeType, PivotSheet } from '../../src'; | ||
import { CornerNodeType, Node, PivotSheet } from '../../src'; | ||
|
||
const s2Options: S2Options = { | ||
width: 200, | ||
|
@@ -110,5 +112,170 @@ describe('SpreadSheet Tree Mode Tests', () => { | |
expect(seriesNumberCell.getTreeIcon()).toBeFalsy(); | ||
expect(rowCell.getTreeIcon()).toBeTruthy(); | ||
}); | ||
|
||
// https://github.com/antvis/S2/issues/2995 | ||
test('should render correctly tree polyline', async () => { | ||
const customTreeDataCfg: S2DataConfig = { | ||
data: CustomTreeData, | ||
fields: customTreeFields, | ||
}; | ||
// 正常渲染树形图和polyline | ||
const customTreeOptions: S2Options = { | ||
debug: true, | ||
width: 600, | ||
height: 480, | ||
hierarchyType: 'tree', | ||
style: { | ||
rowCell: { | ||
showTreeLine: true, | ||
}, | ||
}, | ||
}; | ||
const s2 = new PivotSheet( | ||
container, | ||
customTreeDataCfg, | ||
customTreeOptions, | ||
); | ||
|
||
await s2.render(); | ||
const dottedLinesLenght = s2.getDottedLinesLengh(); | ||
|
||
expect(dottedLinesLenght).toEqual(8); | ||
// 渲染polyline时的坐标位置与节点位置一致 | ||
function getTreeIconCfg(node: Node) { | ||
if ( | ||
get(node, 'belongsCell.treeIcon.cfg') && | ||
!get(node, 'belongsCell.treeIcon.cfg.destroyed') | ||
) { | ||
return get(node, 'belongsCell.treeIcon.cfg'); | ||
} | ||
|
||
return { | ||
x: 8 + node.level * 14, | ||
y: node.y + node.height / 2 - 10 / 2, | ||
width: 10, | ||
height: 10, | ||
}; | ||
} | ||
const maxLevel = s2.facet.getRowNodes(0)?.[0]?.hierarchy?.maxLevel; | ||
const colHeaderHeight = s2.facet.getColNodes(0)?.[0]?.hierarchy?.height; | ||
const viewportHeight = | ||
s2.facet.panelBBox.viewportHeight + colHeaderHeight; | ||
const offsetHeight = s2.facet.getScrollOffset().scrollY; | ||
const dottedLines = s2.getDottedLines(); | ||
|
||
for (let i = 0; i <= maxLevel; i++) { | ||
const rowNodes = s2.facet.getRowNodes(i); | ||
|
||
rowNodes.forEach((rowNode) => { | ||
if (rowNode.children.length) { | ||
const childs: Node[] = []; | ||
|
||
rowNode.children.forEach((child) => { | ||
const rowNodeTreeIconCfg = getTreeIconCfg(rowNode); | ||
const childTreeIconCfg = getTreeIconCfg(child); | ||
|
||
if (rowNodeTreeIconCfg && childTreeIconCfg) { | ||
const x1 = | ||
rowNode.x + | ||
rowNodeTreeIconCfg.x + | ||
rowNodeTreeIconCfg.width / 2; | ||
let y1 = | ||
colHeaderHeight + | ||
rowNodeTreeIconCfg.y + | ||
rowNodeTreeIconCfg.height; | ||
|
||
if (childs?.length > 0) { | ||
const preChild = childs?.pop()!; | ||
const preChildTreeIconCfg = getTreeIconCfg(preChild); | ||
|
||
y1 = | ||
colHeaderHeight + | ||
preChildTreeIconCfg.y + | ||
preChildTreeIconCfg.height / 2; | ||
} | ||
|
||
childs.push(child); | ||
const x2 = child.x + childTreeIconCfg.x; | ||
const y2 = | ||
colHeaderHeight + | ||
childTreeIconCfg.y + | ||
childTreeIconCfg.height / 2; | ||
const points = [ | ||
[ | ||
x1, | ||
Math.min( | ||
Math.max(y1 - offsetHeight, colHeaderHeight), | ||
viewportHeight, | ||
), | ||
], | ||
[ | ||
x1, | ||
Math.min( | ||
Math.max(y2 - offsetHeight, colHeaderHeight), | ||
viewportHeight, | ||
), | ||
], | ||
]; | ||
|
||
if ( | ||
y2 - offsetHeight >= colHeaderHeight && | ||
y2 - offsetHeight <= viewportHeight | ||
) { | ||
points.push([x2, y2 - offsetHeight]); | ||
} | ||
|
||
const isExist = dottedLines.some((line) => { | ||
const pointsLine = line?.attributes?.points; | ||
|
||
return JSON.stringify(points) === JSON.stringify(pointsLine); | ||
}); | ||
|
||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(isExist).toEqual(true); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// 树形图全部收起时,不展示polyline | ||
const customTreeOptions1: S2Options = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 展开和收起可以分两个 test 断言, 而不是写在一起 |
||
debug: true, | ||
width: 600, | ||
height: 480, | ||
hierarchyType: 'tree', | ||
style: { | ||
rowCell: { | ||
showTreeLine: true, | ||
collapseAll: true, | ||
}, | ||
}, | ||
}; | ||
|
||
s2.setOptions(customTreeOptions1); | ||
await s2.render(); | ||
const dottedLines1 = s2.getDottedLinesLengh(); | ||
|
||
expect(dottedLines1).toEqual(0); | ||
// showTreeLine为false时, 关闭polyline | ||
const customTreeOptions2: S2Options = { | ||
debug: true, | ||
width: 600, | ||
height: 480, | ||
hierarchyType: 'tree', | ||
style: { | ||
rowCell: { | ||
showTreeLine: false, | ||
}, | ||
}, | ||
}; | ||
|
||
s2.setOptions(customTreeOptions2); | ||
await s2.render(); | ||
const dottedLines2 = s2.getDottedLinesLengh(); | ||
|
||
expect(dottedLines2).toEqual(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Polyline } from '@antv/g-lite'; | ||
|
||
// 存储已绘制的连接线,用于销毁 | ||
export const dottedTreeLines: Polyline[] = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -109,6 +109,10 @@ export interface RowCellStyle extends BaseCellStyle, CellTextWordWrapStyle { | |||||
* @description 优先级 `collapseFields` > `expandDepth` > `collapseAll` | ||||||
*/ | ||||||
expandDepth?: number | null; | ||||||
/** | ||||||
* 是否配置线性样式,默认不配置 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
showTreeLine: boolean; | ||||||
} | ||||||
|
||||||
export interface ColCellStyle extends BaseCellStyle, CellTextWordWrapStyle { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单测有点复杂了, 后面不太好维护, 可以直接给实际渲染的连接线的坐标等做一个快照测试 toMatchSnapshot()