Skip to content

Commit

Permalink
feat(tree): add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed May 5, 2024
1 parent 70db97a commit adff587
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 7 deletions.
7 changes: 3 additions & 4 deletions packages/tree/src/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ export const Label = <Datum,>({ label, animatedProps }: LabelComponentProps<Datu

return (
<animated.g
transform={to([animatedProps.x, animatedProps.y], (x, y) => `translate(${x}, ${y})`)}
style={{
pointerEvents: 'none',
}}
data-testid={`label.${label.id}`}
transform={to([animatedProps.x, animatedProps.y], (x, y) => `translate(${x},${y})`)}
>
<animated.g transform={animatedProps.rotation.to(rotation => `rotate(${rotation})`)}>
{theme.labels.text.outlineWidth > 0 && (
Expand All @@ -29,6 +27,7 @@ export const Label = <Datum,>({ label, animatedProps }: LabelComponentProps<Datu
</text>
)}
<text
data-testid={`label.${label.id}.label`}
style={theme.labels.text}
textAnchor={label.textAnchor}
dominantBaseline={label.baseline}
Expand Down
8 changes: 6 additions & 2 deletions packages/tree/src/Labels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ export const Labels = <Datum,>({
})

return (
<>
<g
style={{
pointerEvents: 'none',
}}
>
{transition((animatedProps, label) =>
createElement(labelComponent, {
label,
animatedProps,
})
)}
</>
</g>
)
}
4 changes: 3 additions & 1 deletion packages/tree/src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ const InnerTree = <Datum,>({
links,
innerWidth,
innerHeight,
linkGenerator,
setCurrentNode,
}),
[nodes, links, innerWidth, innerHeight]
[nodes, links, innerWidth, innerHeight, linkGenerator, setCurrentNode]
)

return (
Expand Down
2 changes: 2 additions & 0 deletions packages/tree/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export interface CustomLayerProps<Datum> {
links: ComputedLink<Datum>[]
innerWidth: number
innerHeight: number
linkGenerator: LinkGenerator
setCurrentNode: (node: ComputedNode<Datum> | null) => void
}
export type CustomSvgLayer<Datum> = FunctionComponent<CustomLayerProps<Datum>>

Expand Down
Loading

0 comments on commit adff587

Please sign in to comment.