-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: update icon classname * fix: translate react node origin * test: e2e tests * chore: test workflow * chore: remove unnecessary dependencies * chore: update dependencies * chore: vite config * chore: fix util version * fix: dendrogram e2e tests * chore: ci workflow * test: update e2e
- Loading branch information
Showing
81 changed files
with
477 additions
and
196 deletions.
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 |
---|---|---|
|
@@ -35,3 +35,8 @@ logs | |
|
||
# temp | ||
temp-gallery.md | ||
|
||
# Tools | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
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
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
42 changes: 20 additions & 22 deletions
42
packages/graphs/src/core/transform/translate-react-node-origin.ts
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,30 +1,28 @@ | ||
import { BaseTransform, idOf } from '@antv/g6'; | ||
import type { DrawData, Size } from '@antv/g6'; | ||
import { BaseTransform, parseSize } from '@antv/g6'; | ||
|
||
/** | ||
* HTML 元素的默认原点位置在左上角,而 G6 的默认原点位置在中心,所以需要调整 dx 和 dy | ||
*/ | ||
export class TranslateReactNodeOrigin extends BaseTransform { | ||
public afterLayout() { | ||
const { graph, model, element } = this.context; | ||
public beforeDraw(input: DrawData): DrawData { | ||
const { graph, element } = this.context; | ||
|
||
graph.getNodeData().forEach((datum) => { | ||
const nodeId = idOf(datum); | ||
const { | ||
add: { nodes: nodesToAdd }, | ||
update: { nodes: nodesToUpdate }, | ||
} = input; | ||
|
||
const node = element!.getElement(nodeId); | ||
if (!node) return; | ||
|
||
const style = graph.getElementRenderStyle(nodeId); | ||
const { size } = style; | ||
|
||
model.updateNodeData([ | ||
{ | ||
id: nodeId, | ||
// HTML 元素的默认原点位置在左上角,而 G6 的默认原点位置在中心,所以需要调整 dx 和 dy | ||
style: { | ||
dx: -size[0] / 2, | ||
dy: -size[1] / 2, | ||
}, | ||
}, | ||
]); | ||
[...nodesToAdd.values(), ...nodesToUpdate.values()].forEach((datum) => { | ||
// @ts-expect-error private method invoke | ||
element!.computeElementDefaultStyle('node', { graph, datum }); | ||
const style = element!.getDefaultStyle(datum.id); | ||
const [width, height] = parseSize(style.size as Size); | ||
if (!datum.style) datum.style = {}; | ||
datum.style.dx = -width / 2; | ||
datum.style.dy = -height / 2; | ||
}); | ||
|
||
graph.draw(); | ||
return input; | ||
} | ||
} |
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
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,25 +1,13 @@ | ||
import { Dendrogram as DendrogramComponent, DendrogramOptions } from '@ant-design/graphs'; | ||
import { treeToGraphData } from '@antv/g6'; | ||
import React from 'react'; | ||
import data from '../datasets/algorithm-category.json'; | ||
import { useGraphOptions } from './hooks/useQueryOptions'; | ||
|
||
export const Dendrogram = () => { | ||
const options: DendrogramOptions = { | ||
const options = useGraphOptions<DendrogramOptions>({ | ||
autoFit: 'view', | ||
data: treeToGraphData(data), | ||
direction: 'vertical', | ||
compact: true, | ||
behaviors: (prev) => [ | ||
...prev, | ||
{ | ||
key: 'hover-activate', | ||
type: 'hover-activate', | ||
degree: Infinity, | ||
direction: 'in', | ||
inactiveState: 'inactive', | ||
}, | ||
], | ||
}; | ||
data, | ||
}); | ||
|
||
return <DendrogramComponent {...options} />; | ||
}; |
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
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
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,33 @@ | ||
import { GraphOptions, mergeOptions } from '@ant-design/graphs'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
export const useGraphOptions = <T extends Omit<GraphOptions, 'data'>>(options: T): T => { | ||
const [params] = useSearchParams(); | ||
const queryParams = Object.fromEntries(params) as any; | ||
|
||
Object.keys(queryParams).forEach((key) => { | ||
if (queryParams[key] === 'true') { | ||
queryParams[key] = true; | ||
} | ||
if (queryParams[key] === 'false') { | ||
queryParams[key] = false; | ||
} | ||
}); | ||
|
||
queryParams.devicePixelRatio = 4; | ||
|
||
queryParams.transforms = () => { | ||
return (transforms) => { | ||
return [ | ||
...transforms.filter((transform: any) => transform.key !== 'collapse-expand-react-node'), | ||
{ | ||
...transforms.find((transform: any) => transform.key === 'collapse-expand-react-node'), | ||
enable: queryParams.collapseExpand, | ||
...(queryParams.collapseExpandTrigger && { trigger: queryParams.collapseExpandTrigger }), | ||
}, | ||
]; | ||
}; | ||
}; | ||
|
||
return mergeOptions(options, queryParams) as any; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
13 changes: 6 additions & 7 deletions
13
...phs/tests/demos/indented-tree-default.tsx → ...ages/graphs/tests/demos/indented-tree.tsx
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,16 +1,15 @@ | ||
import type { IndentedTreeOptions } from '@ant-design/graphs'; | ||
import { G6, IndentedTree as IndentedTreeComponent } from '@ant-design/graphs'; | ||
import { IndentedTree as IndentedTreeComponent } from '@ant-design/graphs'; | ||
import React from 'react'; | ||
import data from '../datasets/algorithm-category.json'; | ||
|
||
const { treeToGraphData } = G6; | ||
import { useGraphOptions } from './hooks/useQueryOptions'; | ||
|
||
export const IndentedTree = () => { | ||
const options: IndentedTreeOptions = { | ||
const options = useGraphOptions<IndentedTreeOptions>({ | ||
autoFit: 'view', | ||
type: 'default', | ||
data: treeToGraphData(data), | ||
}; | ||
data, | ||
animation: false, | ||
}); | ||
|
||
return <IndentedTreeComponent {...options} />; | ||
}; |
Oops, something went wrong.