Skip to content

Commit 697b0bd

Browse files
committed
feat: attach root & leaf classes
Signed-off-by: Andres Correa Casablanca <castarco@coderspirit.xyz>
1 parent 182e351 commit 697b0bd

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/BeautifulTree.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export function BeautifulTree({
2525
const { tree: treeWithLayout, maxX, maxY } = computeLayout(tree)
2626
const { width, height, sizeUnit = 'px' } = svgProps
2727

28-
const xDivisor = maxX + 2
29-
const yDivisor = maxY + 2
28+
const xCoef = width / (maxX + 2)
29+
const yCoef = height / (maxY + 2)
3030

3131
return (
3232
<svg
@@ -48,10 +48,10 @@ export function BeautifulTree({
4848
return (
4949
<line
5050
key={`${id}-edge-${idx}`}
51-
x1={((edge.start.x + 1) * width) / xDivisor}
52-
y1={((edge.start.y + 1) * height) / yDivisor}
53-
x2={((edge.end.x + 1) * width) / xDivisor}
54-
y2={((edge.end.y + 1) * height) / yDivisor}
51+
x1={(edge.start.x + 1) * xCoef}
52+
y1={(edge.start.y + 1) * yCoef}
53+
x2={(edge.end.x + 1) * xCoef}
54+
y2={(edge.end.y + 1) * yCoef}
5555
/>
5656
)
5757
})}
@@ -61,9 +61,11 @@ export function BeautifulTree({
6161
return (
6262
<circle
6363
key={`${id}-node-${idx}`}
64-
className={'beautiful-tree-node'}
65-
cx={((aX + 1) * width) / xDivisor}
66-
cy={((aY + 1) * height) / yDivisor}
64+
className={`beautiful-tree-node${
65+
node.meta.isRoot ? ' beautiful-tree-root' : ''
66+
}${node.meta.isLeaf ? ' beautiful-tree-leaf' : ''}`}
67+
cx={(aX + 1) * xCoef}
68+
cy={(aY + 1) * yCoef}
6769
r="5"
6870
/>
6971
)

0 commit comments

Comments
 (0)