Skip to content

Commit f94802e

Browse files
committed
test: draw random trees in storybook
Signed-off-by: Andres Correa Casablanca <castarco@coderspirit.xyz>
1 parent f501a71 commit f94802e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/stories/BeautifulTree.stories.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,29 @@ export const Centered3_Wide_Tree_D: Story = {
422422
getEdgeClass: getCssFromEdgeData,
423423
},
424424
}
425+
426+
const buildRandomTree = (maxDepth = 4): Readonly<Tree> => {
427+
const numChildren = maxDepth > 0 ? Math.floor(Math.random() * 4) : 0
428+
const tree: Tree = {
429+
// eslint-disable-next-line prefer-spread
430+
children: Array.apply(undefined, { length: numChildren } as unknown[]).map(
431+
() => ({ node: buildRandomTree(maxDepth - 1) }),
432+
),
433+
}
434+
435+
return tree
436+
}
437+
438+
export const Centered3_Wide_Tree_Random: Story = {
439+
args: {
440+
id: 'centered3-wide-tree-random',
441+
svgProps: {
442+
width: 400,
443+
height: 400,
444+
},
445+
tree: buildRandomTree(),
446+
computeLayout: computeSmartLayout,
447+
getNodeClass: getCssFromNodeData,
448+
getEdgeClass: getCssFromEdgeData,
449+
},
450+
}

0 commit comments

Comments
 (0)