Skip to content

Commit fd3cf1d

Browse files
committed
refactor: split preprocessing into own function
1 parent b8968f9 commit fd3cf1d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

www/js/blocktree.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ const status_to_color = {
3030
"headers-only": "yellow",
3131
}
3232

33-
function draw() {
34-
data = state_data
33+
function preprocess_data(data) {
3534
let header_infos = data.header_infos;
3635
let tip_infos = [];
3736
let node_infos = data.nodes;
@@ -92,7 +91,15 @@ function draw() {
9291

9392
// assigns the data to a hierarchy using parent-child relationships
9493
// and maps the node data to the tree layout
95-
var root_node = treemap(d3.hierarchy(treeData));
94+
const root_node = treemap(d3.hierarchy(treeData));
95+
const max_height = Math.max(...header_infos.map(d => d.height))
96+
97+
return [root_node, max_height, htoi]
98+
}
99+
100+
function draw() {
101+
let data = state_data
102+
const [root_node, max_height, htoi] = preprocess_data(data)
96103

97104
var svg = d3
98105
.select("#drawing-area")
@@ -308,7 +315,6 @@ function draw() {
308315

309316
let offset_x = 0;
310317
let offset_y = 0;
311-
let max_height = Math.max(...header_infos.map(d => d.height))
312318
let max_height_tip = root_node.leaves().filter(d => d.data.data.height == max_height)[0]
313319
if (max_height_tip !== undefined) {
314320
offset_x = o.x(max_height_tip, htoi);

0 commit comments

Comments
 (0)