Skip to content

Commit 5efe4ae

Browse files
committed
Got spacing to where we wanted it to be, still considering moving mapped data function into separate file to keep Flow.tsx clean
1 parent e517bd6 commit 5efe4ae

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/types/hierarchyData.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ import { Tree } from "./tree"
22

33

44
export interface hierarchyData {
5-
children?: hierarchyData[],
6-
data: Tree,
7-
depth: number,
8-
height: number,
9-
parent: hierarchyData | null
10-
}
5+
id: string,
6+
position: { x: number, y: number },
7+
type: string,
8+
data: { label: string },
9+
style: {
10+
borderRadius: string,
11+
borderWidth: string,
12+
borderColor: string,
13+
display: string,
14+
justifyContent: string,
15+
placeItems: string,
16+
backgroundColor: string,
17+
}
18+
}

src/webview/Flow.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ const OverviewFlow = () => {
6161

6262
// Create a holder for the heirarchical data (msg.value), data comes in an object of all the Trees
6363
const root : d3.HierarchyNode<Tree> = d3.hierarchy(data)
64-
6564

66-
//create tree layout and give nodes their positions
67-
const treeLayout : d3.TreeLayout<unknown> = d3.tree().size([800, 500])
65+
// Dynamically adjust height and width of display depending on the amount of nodes
66+
const totalNodes : number = root.descendants().length;
67+
const width : number = Math.max(totalNodes * 100, 800);
68+
const height = Math.max(totalNodes * 20, 500)
69+
70+
71+
//create tree layout and give nodes their positions and
72+
const treeLayout : d3.TreeLayout<unknown> = d3.tree()
73+
.size([ width, height ])
74+
.separation((a: d3.HierarchyPointNode<Node>, b: d3.HierarchyPointNode<Node>) => (a.parent == b.parent ? 2 : 2.5))
75+
76+
6877
treeLayout(root);
6978
// Iterate through each Tree and create a node
7079
root.each((node: any) : void => {

0 commit comments

Comments
 (0)