From 747087ee2ee504e080c0a4ad10e2494557b3c7d9 Mon Sep 17 00:00:00 2001
From: Rouak-stha
Date: Sat, 30 Sep 2023 21:57:50 +0545
Subject: [PATCH 1/6] feat(react): Allow Different Tree Orientations
---
@beautiful-tree/react/src/BeautifulTree.tsx | 25 +
.../src/stories/BeautifulTree.stories.ts | 60 +
.../react/src/tests/BeautifulTree.test.tsx | 68 +
.../__snapshots__/BeautifulTree.test.tsx.snap | 15049 ++++++++++++++++
4 files changed, 15202 insertions(+)
diff --git a/@beautiful-tree/react/src/BeautifulTree.tsx b/@beautiful-tree/react/src/BeautifulTree.tsx
index 0669637..a526d16 100644
--- a/@beautiful-tree/react/src/BeautifulTree.tsx
+++ b/@beautiful-tree/react/src/BeautifulTree.tsx
@@ -23,6 +23,8 @@ export type NodeContentGetter = (
data?: Readonly> | undefined,
) => JSX.Element | string
+type Orientation = 'D-T' | 'L-R' | 'R-L' | 'T-D'
+
export interface BeautifulTreeProps {
readonly id: string
readonly svgProps: {
@@ -33,6 +35,7 @@ export interface BeautifulTreeProps {
readonly nodeShape?: 'circle' | 'rect'
readonly hCoef?: number
readonly tree: Tree
+ readonly orientation?: Orientation
readonly computeLayout?:
| ((tree: Readonly) => Readonly)
| undefined
@@ -57,12 +60,31 @@ function runClassesGetter(
return cssClasses.length === 0 ? '' : ` ${cssClasses.join(' ')}`
}
+function calculateTransformation(orientation: Orientation): string {
+ switch (orientation) {
+ case 'D-T': {
+ return 'rotate(180)'
+ }
+ case 'L-R': {
+ return 'rotate(-90)'
+ }
+ case 'R-L': {
+ return 'rotate(90)'
+ }
+ case 'T-D': {
+ //default
+ return ''
+ }
+ }
+}
+
export function BeautifulTree({
id,
svgProps,
nodeShape,
hCoef = 1,
tree,
+ orientation = 'T-D',
computeLayout,
getNodeClass,
getNodeShape,
@@ -81,6 +103,8 @@ export function BeautifulTree({
const widthCenterShift = maxNodeWidth * 0.5
const heightCenterShift = maxNodeHeight * 0.5
const maxNodeRadius = maxNodeHeight * 0.5
+ const transformValue = calculateTransformation(orientation)
+ const transform = { ...(transformValue && { transform: transformValue }) }
return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+