Skip to content

Commit

Permalink
feat(tree): expose the nodes map for custom layers
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed May 5, 2024
1 parent ce46163 commit 40d4164
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/tree/src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const InnerTree = <Datum,>({
partialMargin
)

const { nodes, links, linkGenerator, setCurrentNode } = useTree<Datum>({
const { nodes, nodeByUid, links, linkGenerator, setCurrentNode } = useTree<Datum>({
data,
identity,
layout,
Expand Down Expand Up @@ -171,13 +171,14 @@ const InnerTree = <Datum,>({
const customLayerProps: CustomLayerProps<Datum> = useMemo(
() => ({
nodes,
nodeByUid,
links,
innerWidth,
innerHeight,
linkGenerator,
setCurrentNode,
}),
[nodes, links, innerWidth, innerHeight, linkGenerator, setCurrentNode]
[nodes, nodeByUid, links, innerWidth, innerHeight, linkGenerator, setCurrentNode]
)

return (
Expand Down
1 change: 1 addition & 0 deletions packages/tree/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ export const useTree = <Datum = DefaultDatum>({

return {
nodes,
nodeByUid,
links,
linkGenerator,
setCurrentNode,
Expand Down
1 change: 1 addition & 0 deletions packages/tree/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export type LabelComponent<Datum> = FunctionComponent<LabelComponentProps<Datum>

export interface CustomLayerProps<Datum> {
nodes: readonly ComputedNode<Datum>[]
nodeByUid: Record<string, ComputedNode<Datum>>
links: readonly ComputedLink<Datum>[]
innerWidth: number
innerHeight: number
Expand Down

0 comments on commit 40d4164

Please sign in to comment.